This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 572
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISSUE #423: Support using EC2-generated password as the WinRM password
Adds a winrm_info provider capability to support using the EC2 GetPasswordData API as a means of getting the WinRM password. If the winrm.password is set to :aws, go fetch the AWS password data for the machine, decrypt the user-specified private key, and set it as the winrm.password
- Loading branch information
Showing
6 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require "fog" | ||
require "log4r" | ||
|
||
module VagrantPlugins | ||
module AWS | ||
module Action | ||
# This action connects to AWS, verifies credentials work, and | ||
# puts the AWS connection object into the `:aws_compute` key | ||
# in the environment. | ||
class GetWinRMPassword | ||
def initialize(app, env) | ||
@app = app | ||
@logger = Log4r::Logger.new("vagrant_aws::action::get_winrm_password") | ||
end | ||
|
||
def call(env) | ||
machine = env[:machine] | ||
|
||
if machine.config.winrm.password == :aws | ||
machine.ui.info(I18n.t("vagrant_aws.getting_winrm_password")) | ||
|
||
aws = env[:aws_compute] | ||
response = aws.get_password_data({ instance_id: machine.id }) | ||
password_data = response.body['passwordData'] | ||
password_data_bytes = Base64.decode64(password_data) | ||
|
||
# Try to decrypt the password data using each one of the private key files | ||
# set by the user until we hit one that decrypts successfully | ||
machine.config.ssh.private_key_path.each do |private_key_path| | ||
private_key_path = File.expand_path private_key_path | ||
|
||
@logger.info("Decrypting password data using #{private_key_path}") | ||
rsa = OpenSSL::PKey::RSA.new File.read private_key_path | ||
begin | ||
machine.config.winrm.password = rsa.private_decrypt password_data_bytes | ||
@logger.info("Successfully decrypted password data using #{private_key_path}") | ||
rescue OpenSSL::PKey::RSAError | ||
@logger.warn("Failed to decrypt password data using #{private_key_path}") | ||
next | ||
end | ||
|
||
break | ||
end | ||
end | ||
|
||
@app.call(env) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require "vagrant/action/builder" | ||
|
||
module VagrantPlugins | ||
module AWS | ||
module Capability | ||
class WinRMInfo | ||
def self.winrm_info(machine) | ||
machine.action("get_winrm_password") | ||
return {} | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters