Skip to content

Windows password: never in SSM, sealed to a one-time key (#1587) - #1617

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/1587-windows-password-ssm
Nov 13, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/1587-windows-password-ssm

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1587

What

SetWindowsAdminPasswordViaSSM, the default path of spawn connect --rdp, used to generate the password on the CLI. It then put it in the commands parameter of AWS-RunPowerShellScript (ConvertTo-SecureString "<pw>"). SSM keeps that parameter for about 30 days, and anyone with ssm:ListCommands can read it.

It now uses the scheme EC2 GetPasswordData uses:

  1. spawn generates a single-use RSA-3072 key pair in memory for the call.
  2. The PowerShell carries only the public key (modulus and exponent).
  3. On the instance, the script draws a 20-character password from RandomNumberGenerator. It uses the same four character classes as GenerateWindowsPassword, one of each guaranteed, with no modulo bias, Fisher-Yates shuffled. It then sets the password, sets never-expire, and enables the account as before.
  4. The script prints only SPAWN-SEALED-PASSWORD:<base64 RSA-OAEP-SHA256 ciphertext>. It uses RSACng, which is in .NET Framework 4.6.2+, i.e. every supported Windows Server, and falls back to RSA.Create() for .NET on other platforms.
  5. spawn decrypts the reply with the private key, which never leaves the process.

The SSM history now holds a public key and ciphertext. A Windows whose .NET cannot run the script fails the command, and connect's existing fallback to GetPasswordData applies.

GenerateWindowsPassword stays exported, because pkg/aws is public surface, so the API is unchanged.

Tests

  • TestWindowsSetAdminPasswordScript: the script carries the public key and no password literal, and is identical across calls with one key.
  • TestOpenSealedWindowsPassword: round-trips the reply, refuses a reply with no marker, and refuses a reply sealed to another key.
  • TestWindowsPasswordScriptRunsInPowerShell runs the real script, with the two account cmdlets stubbed, in Windows PowerShell 5.1 on the Test (Windows) CI job (the RSACng path) and in pwsh where installed (it passed locally with pwsh on macOS). It checks that the reply decrypts, the password meets the complexity rule, and the password is never printed in clear. I watched it fail when I made the script echo $pw.

There is no IAM, user-data or spored change.

Live checks needed before merge (owner)

Run in 435415984226, with --ttl 30m.

  1. Launch a Windows instance, e.g. spawn launch --os windows --ttl 30m.
  2. Run spawn connect <name> --rdp. It should print an Administrator password, and RDP (--via-ssm) should log in with it.
  3. aws ssm list-commands --instance-id <id> --region us-east-1 --query 'Commands[].Parameters.commands' should show RSAEncryptionPadding and a base64 modulus, and no ConvertTo-SecureString ".
  4. aws ssm get-command-invocation --command-id <id> --instance-id <id> --region us-east-1 --query StandardOutputContent should show only the SPAWN-SEALED-PASSWORD: ciphertext.
  5. Optional, if one is available: repeat on a Windows Server 2016 AMI (the .NET 4.6.2 floor).
  6. Terminate the instance and leak-check.

@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.13043% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/aws/windows_password.go 89.13% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Live check (dev, 2026-11-13; Windows Server 2022 on m7i.large):

  • spawn connect --rdp --via-ssm printed the Administrator password (20 chars) and opened the SSM RDP tunnel.
  • SSM history shows RSAEncryptionPadding and no ConvertTo-SecureString "…" literal. The command output carries only the SPAWN-SEALED-PASSWORD: ciphertext.
  • The plaintext password appears in 0 SSM command parameters and 0 outputs (compared locally, never printed).
  • Not verified: the interactive RDP login with that password, because the GUI client can't be driven headless.

Instance terminated; leak check clean. Two UX notes from the run: --os windows needs an explicit --ami, and a burstable type is refused. Both are by design, and the errors are clear.

scttfrdmn and others added 2 commits November 13, 2026 15:33
spawn connect --rdp interpolated the generated Administrator password
into an AWS-RunPowerShellScript command, which SSM keeps for ~30 days,
readable with ssm:ListCommands. Now, as GetPasswordData does, the
instance generates the password, sets it, and prints it RSA-OAEP-SHA256
encrypted to a 3072-bit key spawn makes per call in memory; the command
carries only the public key. A test runs the script in a real PowerShell
(Windows PowerShell on the Windows runner, pwsh elsewhere) and opens
what it prints.
@scttfrdmn
scttfrdmn marked this pull request as ready for review November 13, 2026 23:34
@scttfrdmn
scttfrdmn force-pushed the fix/1587-windows-password-ssm branch from f42112c to 45b5f7b Compare November 13, 2026 23:34
@scttfrdmn
scttfrdmn merged commit c128e7a into main Nov 13, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1587-windows-password-ssm branch November 13, 2026 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security: Windows Administrator password is embedded in an AWS-RunPowerShellScript command parameter

1 participant