Repository navigation
Add windows ssh - #519
Add windows ssh#519Cristi1324 wants to merge 1 commit into
Conversation
77cd612 to
410335f
Compare
6b4eb45 to
3536313
Compare
fabi200123
left a comment
There was a problem hiding this comment.
Would like someone else to take a look again over this! But besides the account_line = "net.exe user %s %s" % (username, password) LGTM
|
|
||
| @mock.patch.object(wsman.WSManConnection, "from_connection_info") | ||
| @mock.patch.object(windows_ssh.WindowsSSHConnection, "from_connection_info") | ||
| def test_from_connection_info_ssh(self, mock_ssh, mock_winrm): |
There was a problem hiding this comment.
I would also add a test that uses the key. From what I see you only have 1 that uses the password
| ) | ||
| account_line = "" | ||
| if username is not None: | ||
| account_line = "net.exe user %s %s" % (username, password) |
There was a problem hiding this comment.
Just for safety can you add a check before this that the password doesn't have any spaces in it? If by any chance a password like "hello there" gets sent to net.exe user <username> hello there it will fail the command.
There was a problem hiding this comment.
The password requirements are already handled by the providers. Most, if not all providers that use this script with password already generate or allow passwords that do not contain spaces.
| WINRM_HTTPS_PORT = 5986 | ||
|
|
||
|
|
||
| def uses_winrm(connection_info): |
There was a problem hiding this comment.
I think checking on an extra protocol key would be better than just checking on the port number. Then the providers can explicitly set the protocol when it supports/prefers it.
This method could've been simply return connection_info.get('protocol', WINRM_CONSTANT)
Then you won't have extra checks for protocol either in _protocol_from_connection_info for example.
Maybe even rename this method to get_protocol and then it's super clear what it should return and used for.
There was a problem hiding this comment.
Since this comment, a new core option [windows_minion] connection_type, has been added. This is used to decide if the provider should use winrm or ssh for windows worker. Currently it is set to ssh by default, but if minion_port() is not called by the provider, it'll still use winrm.
There was a problem hiding this comment.
The port no. has nothing to do with the protocol type. We shouldn't assume default ports are being used, I can literally set 22 to the winrm listener (or vice-versa) - and yes, I know thus far we assumed, but if we should plan on supporting custom port numbers, we should at least prepare this feature to be extensible in that direction. I think we should make the port customizable at some point, therefore we'll need 2 options. One for protocol, one for port, and we use default protocol ports in case it's not customized.
For this PR, we can go with only protocol and always use default ports. For future, I'd like to see customizable ports option.
| WINRM_HTTPS_PORT = 5986 | ||
|
|
||
|
|
||
| def uses_winrm(connection_info): |
There was a problem hiding this comment.
The port no. has nothing to do with the protocol type. We shouldn't assume default ports are being used, I can literally set 22 to the winrm listener (or vice-versa) - and yes, I know thus far we assumed, but if we should plan on supporting custom port numbers, we should at least prepare this feature to be extensible in that direction. I think we should make the port customizable at some point, therefore we'll need 2 options. One for protocol, one for port, and we use default protocol ports in case it's not customized.
For this PR, we can go with only protocol and always use default ports. For future, I'd like to see customizable ports option.
8c81098 to
be48300
Compare
| resolved = _protocol_from_connection_info(connection_info, protocol) | ||
| connection_info = windows_conn.with_provider_port(connection_info) | ||
| if resolved == constants.PROTOCOL_SSH: | ||
| return _poll_instance_until_reachable_ssh( |
There was a problem hiding this comment.
Why did you give up on the helper var?
| """ | ||
| protocol = CONF.windows_minion.protocol | ||
| if protocol in (None, ""): | ||
| return CONNECTION_SSH |
There was a problem hiding this comment.
I think it'd be safer if this was set in the provider instead of here, as you risk setting SSH on a platform that doesn't actually support it.
You can have this option defined here and read it from the provider, and in the provider(s) also set based on this option. The core should only do connection_info.get('protocol', 'winrm') imho, we don't need extra logic for ports and whatnot. connection_info should exclusively be populated by the provider with protocol (if set).
Same goes for port. The provider should set the config port only if set. If not, it will set the default for said protocol (which it already does).
Keep it simple :)
There was a problem hiding this comment.
Once all the providers support ssh ofc we can default to that, but the provider should decide that, not the core, core should keep things transparent. The logic should be simple:
- read conn_info from provider;
- set connection client based on that;
- test connection.
be48300 to
4578e9b
Compare
| python-memcached>=1.56 | ||
| python-barbicanclient | ||
| python-swiftclient>=3.2 | ||
| git+https://github.com/cloudbase/pywinrm.git@requests#egg=pywinrm |
There was a problem hiding this comment.
Because it was removed then added back and it was added back in a different place. The commits should probably be squashed at some point and I'll remove this change then.
e2f4b77 to
d8ac1ba
Compare
| port = connection_info.get("port", 5986) | ||
| protocol = windows_conn.connection_protocol(connection_info) | ||
| port = connection_info.get("port") or windows_conn.DEFAULT_PROTOCOL_PORTS.get( | ||
| protocol, windows_conn.SSH_PORT |
There was a problem hiding this comment.
NIT: Maybe use WinRM port as default since the default protocol returned by connection_protocol is winrm too.
| Set cloudbase_init to prefix ``#ps1_sysnative``. | ||
| """ | ||
| account_line = "" | ||
| if username is not None and password is not None: |
There was a problem hiding this comment.
I prefer the below, since this basically means that it accepts empty strings too:
| if username is not None and password is not None: | |
| if username and password: |
Add Windows minion OpenSSH setup. Use native ps commands. Add connection_type conf option for windows minion(ssh or winrm). Add configurable minion port.
d8ac1ba to
1f06d77
Compare
Description
A Windows minion can use SSH or WinRM.
[windows_minion] protocolselects that protocol for a new minion. The default iswinrm. OS morphing and the reachability check readconnection_info. A missing protocol uses WinRM.The SSH path keeps one PowerShell process open. Each morphing command runs in a child
powershell.exe, and that child exit code is returned to the worker. The core also returns the guest script that starts OpenSSH. The provider runs that script and opens the SSH port.Type of Change
Changes Made
[windows_minion] protocoldefaults towinrm.sshselects the SSH connection.sshand 5986 forwinrm. A set port is used for either protocol.connection_info.protocolisssh, and WinRM whenprotocoliswinrmor missing.powershell.exeprocess. Each command runs in a childpowershell.exe.exitends that child.reg.execloses the PowerShell session before it runs.poll_instance_until_reachable()follows the same protocol rule. SSH runsexit 0. WinRM runswhoami.sshd. A port other than 22 is written tosshd_config.administrators_authorized_keys. Every member of Administrators can use that key.net.exe userline. One of those values leaves that line out.cloudbase_init=Trueprefixes the script with#ps1_sysnative.windows_openssh_agent_command()returns that script as an encodedpowershell.execommand.How to Test
[windows_minion] protocolunset. Confirm the minion accepts WinRM on port 5986 and OS morphing completes.protocol=sshand the port unset. Confirm OpenSSH starts, the login succeeds on port 22, and OS morphing completes.protocol=sshand a custom port. Confirmsshdlistens on that port and the login succeeds.protocol=winrmand a custom port. Confirm the minion accepts WinRM on that port.connection_infothat has a port and no protocol. Confirm OS morphing uses WinRM on that port.protocol=sshand an Administrators account whose name is notAdministrator. Confirm the key login succeeds.protocol=sshand both a username and a password in the OpenSSH script. Confirm that account can log in with the key.protocol=sshthat loads and unloads a registry hive. Confirmreg.exefinishes and the next morphing command still runs.Checklist
tox -e fmt,pep8,py3)Related Issues
Depends on: https://github.com/cloudbase/coriolis-docker/pull/11
Provider PRs are optional.