-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Windows hosts through WinRM #216
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,72 @@ | ||
# Copyright 2015 Google Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# Changes: | ||
# April 2019: Modified example found here: | ||
# https://github.com/GoogleCloudPlatform/compute-image-windows/blob/master/examples/windows_auth_python_sample.py | ||
# to enable WinRM with vagrant. | ||
|
||
module VagrantPlugins | ||
module Google | ||
module Action | ||
# Sets up a temporary WinRM password using Google's method for | ||
# establishing a new password over encrypted channels. | ||
class SetupWinrmPassword | ||
def initialize(app, env) | ||
@app = app | ||
@logger = Log4r::Logger.new("vagrant_google::action::setup_winrm_password") | ||
end | ||
|
||
def setup_password(env, instance, zone, user) | ||
# Setup | ||
compute = env[:google_compute] | ||
server = compute.servers.get(instance, zone) | ||
password = server.reset_windows_password(user) | ||
|
||
env[:ui].info("Temp Password: #{password}") | ||
|
||
password | ||
end | ||
|
||
def call(env) | ||
# Get the configs | ||
zone = env[:machine].provider_config.zone | ||
zone_config = env[:machine].provider_config.get_zone_config(zone) | ||
|
||
instance = zone_config.name | ||
user = env[:machine].config.winrm.username | ||
pass = env[:machine].config.winrm.password | ||
|
||
# Get Temporary Password, set WinRM password | ||
temp_pass = setup_password(env, instance, zone, user) | ||
env[:machine].config.winrm.password = temp_pass | ||
|
||
# Wait for WinRM To be Ready | ||
env[:ui].info("Waiting for WinRM To be ready") | ||
env[:machine].communicate.wait_for_ready(60) | ||
|
||
# Use WinRM to Change Password to one in Vagrantfile | ||
env[:ui].info("Changing password from temporary to winrm password") | ||
winrmcomm = VagrantPlugins::CommunicatorWinRM::Communicator.new(env[:machine]) | ||
cmd = "net user #{user} #{pass}" | ||
opts = { elevated: true } | ||
winrmcomm.test(cmd, opts) | ||
|
||
# Update WinRM password to reflect updated one | ||
env[:machine].config.winrm.password = pass | ||
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So while debugging I noticed that winrm options are not really set:
I suspect it may be because we never set up the winrm capability in the provider, like Azure did:
I'm raising this since this may cause issues in the future as Vagrant has some autodetect logic which this may break.
Can you take a look?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had originally had all the features from the Azure plugin included, like this capability file but refactored it out when it didn't seem to do anything. I am confused as to what the difference is between including the details in the config (e.g. config.winrm.*) and the need for setting up
env[:machine_winrm_info]
via this capability.The WinRM communicator does not appear to need this winrm_info, using the details from the Vagrantfile config instead. However, I do see that there is a
machine_ssh_info
, so it would make sense to mimic that with WinRM.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some more digging, I've found that if I add in a
read_winrm_info
functionality, I am actually breaking things. I've found that in the following file, it has a default way of computing winrm_info if it is not explicitly defined. That must be why it works without adding in this functionality.https://github.com/hashicorp/vagrant/blob/2c4a40fccbcd1869c7ea457d6f251c67c30eda71/plugins/communicators/winrm/helper.rb#L9
Would this be sufficient? Else I can explicitly add in this functionality, though I am still troubleshooting it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should've been more clear here, sorry m(_ _)m
So, ideally we would want the provider to explicitly set that guest capability to make sure we don't rely on heuristics. However, if it's too difficult I'm also open leaving that as an explicit TODO in the code and creating an issue for the future.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take another shot at implementing this and see if I can get it working correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go ahead and use the default heuristics.