Skip to content

Add windows ssh - #519

Open
Cristi1324 wants to merge 1 commit into
cloudbase:mainfrom
Cristi1324:add-windows-ssh
Open

Cristi1324 wants to merge 1 commit into
cloudbase:mainfrom
Cristi1324:add-windows-ssh

Conversation

@Cristi1324

@Cristi1324 Cristi1324 commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Description

A Windows minion can use SSH or WinRM. [windows_minion] protocol selects that protocol for a new minion. The default is winrm. OS morphing and the reachability check read connection_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

  • New feature
  • Bug fix
  • Refactoring (no functional changes)
  • Documentation update
  • Infrastructure / CI
  • Performance improvement

Changes Made

  • [windows_minion] protocol defaults to winrm. ssh selects the SSH connection.
  • An unset port uses 22 for ssh and 5986 for winrm. A set port is used for either protocol.
  • A missing protocol selects WinRM. The port does not select the protocol.
  • A deployed minion keeps the protocol and the port saved in connection_info.
  • OS morphing uses SSH when protocol is ssh, and WinRM when protocol is winrm or missing.
  • The SSH session is one powershell.exe process. Each command runs in a child powershell.exe. exit ends that child.
  • The session writes the child exit code on the done marker and returns that code.
  • reg.exe closes the PowerShell session before it runs.
  • poll_instance_until_reachable() follows the same protocol rule. SSH runs exit 0. WinRM runs whoami.
  • An SSH reachability check requires a password or a private key.
  • The core returns the OpenSSH guest script. The provider runs that script and opens the SSH port.
  • The script starts sshd. A port other than 22 is written to sshd_config.
  • The guest firewall rule uses every profile and allows edge traversal.
  • The public key is written to administrators_authorized_keys. Every member of Administrators can use that key.
  • A username and a password add a single-quoted net.exe user line. One of those values leaves that line out.
  • cloudbase_init=True prefixes the script with #ps1_sysnative.
  • windows_openssh_agent_command() returns that script as an encoded powershell.exe command.

How to Test

  • Test a deployment with [windows_minion] protocol unset. Confirm the minion accepts WinRM on port 5986 and OS morphing completes.
  • Test a deployment with protocol=ssh and the port unset. Confirm OpenSSH starts, the login succeeds on port 22, and OS morphing completes.
  • Test a deployment with protocol=ssh and a custom port. Confirm sshd listens on that port and the login succeeds.
  • Test a deployment with protocol=winrm and a custom port. Confirm the minion accepts WinRM on that port.
  • Test a deployment with a saved connection_info that has a port and no protocol. Confirm OS morphing uses WinRM on that port.
  • Test a deployment with protocol=ssh and an Administrators account whose name is not Administrator. Confirm the key login succeeds.
  • Test a deployment with protocol=ssh and both a username and a password in the OpenSSH script. Confirm that account can log in with the key.
  • Test a deployment with protocol=ssh that loads and unloads a registry hive. Confirm reg.exe finishes and the next morphing command still runs.

Checklist

  • Self-reviewed the code
  • Added or updated tests
  • Existing tests pass locally (tox -e fmt,pep8,py3)
  • Updated documentation if needed

Related Issues

Depends on: https://github.com/cloudbase/coriolis-docker/pull/11
Provider PRs are optional.

@Cristi1324
Cristi1324 force-pushed the add-windows-ssh branch 6 times, most recently from 77cd612 to 410335f Compare September 9, 2026 13:21
@Cristi1324
Cristi1324 marked this pull request as ready for review September 9, 2026 13:30
@Cristi1324 Cristi1324 self-assigned this Sep 30, 2026
@Cristi1324
Cristi1324 force-pushed the add-windows-ssh branch 2 times, most recently from 6b4eb45 to 3536313 Compare October 1, 2026 12:55
@fabi200123
fabi200123 self-requested a review October 15, 2026 13:18

@fabi200123 fabi200123 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also add a test that uses the key. From what I see you only have 1 that uses the password

Comment thread coriolis/windows_minion.py Outdated
)
account_line = ""
if username is not None:
account_line = "net.exe user %s %s" % (username, password)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread coriolis/windows_conn.py Outdated
WINRM_HTTPS_PORT = 5986


def uses_winrm(connection_info):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread coriolis/windows_conn.py Outdated
WINRM_HTTPS_PORT = 5986


def uses_winrm(connection_info):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Cristi1324
Cristi1324 marked this pull request as draft October 27, 2026 09:26
@Cristi1324
Cristi1324 force-pushed the add-windows-ssh branch 3 times, most recently from 8c81098 to be48300 Compare October 27, 2026 14:06
@Cristi1324
Cristi1324 marked this pull request as ready for review October 28, 2026 11:21
Comment thread coriolis/providers/provider_utils.py Outdated
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(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you give up on the helper var?

Comment thread coriolis/windows_conn.py Outdated
"""
protocol = CONF.windows_minion.protocol
if protocol in (None, ""):
return CONNECTION_SSH

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Cristi1324
Cristi1324 marked this pull request as draft November 16, 2026 11:03
@Cristi1324
Cristi1324 marked this pull request as ready for review November 16, 2026 15:33
@Cristi1324
Cristi1324 requested a review from Dany9966 November 16, 2026 15:33
Comment thread coriolis/windows_conn.py Resolved
Comment thread coriolis/osmorphing/osmount/windows.py Resolved
Comment thread coriolis/windows_conn.py Resolved
Comment thread coriolis/windows_conn.py Resolved
Comment thread coriolis/windows_conn.py Resolved
Comment thread coriolis/windows_minion.py Resolved
Comment thread coriolis/windows_minion.py Resolved
Comment thread coriolis/windows_ssh.py Resolved
Comment thread coriolis/windows_ssh.py Resolved
Comment thread requirements.txt
python-memcached>=1.56
python-barbicanclient
python-swiftclient>=3.2
git+https://github.com/cloudbase/pywinrm.git@requests#egg=pywinrm

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this moved?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Cristi1324
Cristi1324 force-pushed the add-windows-ssh branch 4 times, most recently from e2f4b77 to d8ac1ba Compare November 25, 2026 13:45
Comment thread coriolis/osmorphing/osmount/windows.py Outdated
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Maybe use WinRM port as default since the default protocol returned by connection_protocol is winrm too.

Comment thread coriolis/windows_minion.py Outdated
Set cloudbase_init to prefix ``#ps1_sysnative``.
"""
account_line = ""
if username is not None and password is not None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the below, since this basically means that it accepts empty strings too:

Suggested change
if username is not None and password is not None:
if username and password:

Comment thread coriolis/windows_ssh.py Resolved
Add Windows minion OpenSSH setup.

Use native ps commands.

Add connection_type conf option for windows minion(ssh or winrm).

Add configurable minion port.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants