Skip to content

fix(windows): enforce SSH access policy during node provisioning - #9710

Open
Thibault Cohen (titilambert) wants to merge 10 commits into
mainfrom
fix-windows-enforce-ssh-access
Open

Thibault Cohen (titilambert) wants to merge 10 commits into
mainfrom
fix-windows-enforce-ssh-access

Conversation

@titilambert

@titilambert Thibault Cohen (titilambert) commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

When Windows SSH access is disabled, provisioning currently skips OpenSSH configuration without explicitly stopping or disabling an existing sshd service. On Windows Server 2025 images where sshd is running after boot, SSH therefore remains active despite the requested policy.

This change:

  • Stops and disables sshd when SSH access is disabled, without installing OpenSSH if it is absent.
  • Consolidates SSH policy handling in Install-OpenSSH. When enabling SSH, it keeps the service stopped and disabled while replacing inherited authorized keys and applying ACLs, then enables and starts it only after those steps succeed. Key/ACL preparation errors fail provisioning without reactivating the service.
  • Preserves OpenSSH installation and configuration in BasePrep when SSH is enabled. NodePrep reapplies the current policy and keys on every real node, including PIS-cached nodes that skip BasePrep; this does not depend on an SSH-only change triggering a rebake.
  • Ships the same implementation in the CSE package and CustomData, loading the inline copy after cached CSE scripts for compatibility with older packages.
  • Adds Windows2025_DisableSSH, which checks that sshd is stopped and its startup type is Disabled. SSH-enabled Windows bakes retain SSH validation; Windows scenarios that explicitly skip SSH connectivity use RunCommand for guest checks in both PIS stages. Linux behavior is unchanged.

Validation:

  • Passed 51 targeted Pester tests for SSH behavior and PIS phase placement, plus the existing cross-directory logger guard. These ran with PowerShell 7.6.7 and Pester 5.7.1 on Linux, with Windows service operations mocked. Regression coverage includes key-preparation and ACL failures, fresh installation, and re-enabling a cached disabled service.
  • Passed go test ./pkg/agent -run '^TestWindowsCustomData' -count=1 and git diff --check.
  • For commit 35536a0c92, GitHub Pester, Windows Unit Test Results, and Go unit-test checks have passed. Azure E2E runs and Windows VHD builds are still pending/in progress; end-to-end validation of this revision is not yet complete.

Which issue(s) this PR fixes:

Fixes Windows SSH access remaining enabled when the requested SSH policy is disabled. No linked GitHub issue.

@titilambert

Copy link
Copy Markdown
Contributor Author

This change is part of the following stack:

Change managed by git-spice.

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Windows Unit Test Results

  3 files   19 suites   1m 17s ⏱️
594 tests 594 ✅ 0 💤 0 ❌
619 runs  619 ✅ 0 💤 0 ❌

Results for commit f9b40b9.

♻️ This comment has been updated with latest results.

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Existing bake-time administrator keys remain authorized because the installation helper appends live keys without replacing stale ones.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

Moves Windows SSH policy enforcement into NodePrep for PIS compatibility.

Changes:

  • Enables, disables, or installs OpenSSH based on live policy.
  • Adds Pester coverage for SSH behavior and phase placement.
  • Embeds enforcement through the CustomData helper.
File Description
parts/​windows/​windowscsehelper.ps1 Adds SSH policy enforcement.
parts/​windows/​windowscsehelper.tests.ps1 Tests enforcement and failures.
parts/​windows/​kuberneteswindowssetup.ps1.template Moves SSH handling to NodePrep.
parts/​windows/​kuberneteswindowssetup.pisphases.tests.ps1 Verifies PIS phase placement.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread parts/windows/windowscsehelper.ps1 Outdated
Copilot AI balanced review requested due to automatic review settings October 14, 2026 14:51

Copilot AI 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.

🔵 Needs a closer look

Existing PIS-baked SSH keys remain authorized because the live keys are appended rather than replacing stale keys.

1 open finding

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 14, 2026 20:37

Copilot AI 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.

🟡 Changes recommended

The Windows PIS bake flow still requires SSH authentication but no longer installs its test key.

1 open finding
1 resolved since last review

🧠 Review effort: Balanced

Comment thread parts/windows/kuberneteswindowssetup.ps1.template Outdated
Copilot AI balanced review requested due to automatic review settings October 15, 2026 02:44

Copilot AI 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.

🔵 Needs a closer look

Native Windows service behavior is only mock-tested, and Windows Server 2025 and PIS Azure E2E validation remains pending.

1 open finding

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 19, 2026 13:14

Copilot AI 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.

🔵 Needs a closer look

Windows service operations have only mocked validation, and Windows 2025 and PIS Azure E2E validation remains pending.

1 open issue

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 20, 2026 16:04

Copilot AI 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.

🔵 Needs a closer look

Windows service operations are mock-tested, but live Windows 2025 and PIS validation remains pending.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 20, 2026 17:33

Copilot AI 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.

🟡 Changes recommended

Starting sshd before replacing inherited keys can leave stale credentials usable after provisioning fails.

1 open issue

Review effort: Balanced

Comment thread staging/cse/windows/sshfunc.ps1 Outdated
Copilot AI balanced review requested due to automatic review settings October 21, 2026 12:56

Copilot AI 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.

🔵 Needs a closer look

Windows service operations are mocked, and Windows 2025/PIS Azure validation remains pending.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 21, 2026 16:40

Copilot AI 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.

🔵 Needs a closer look

Security-sensitive Windows provisioning and cached-image compatibility need human review after pending Azure E2E and VHD-build validation completes.

No open issues 🎉

Review effort: Balanced

Apply SSH policy in NodePrep for both standard and PIS-cached nodes. Stop and disable sshd when SSH access is disabled, and allow previously disabled services to start when SSH is enabled. Keep the policy helper embedded in CustomData for compatibility with older CSE packages.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Preserve the authorized keys file and its ACL while removing stale PIS keys. Cover repeated configuration and cleanup failures.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Limit RunCommand guest validation to Windows scenarios that skip SSH connectivity, and restore existing SSH startup ordering.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Stop and disable sshd before replacing inherited authorized keys. Enable it only after key and ACL preparation succeeds, including on fresh installations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 21, 2026 19:36
@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage

Package Line Rate Health
test 0% ❌
windows 27% ❌
staging_cse_windows Package 1 65% ➖
debug 0% ❌
provisioningscripts 2% ❌
parts_windows Package 1 73% ➖
Summary 38% (1670 / 6844) ❌

@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage

Package Line Rate Health
github.com/Azure/agentbaker/aks-node-controller 72% ➖
github.com/Azure/agentbaker/aks-node-controller/common 100% ✔
github.com/Azure/agentbaker/aks-node-controller/helpers 68% ➖
github.com/Azure/agentbaker/aks-node-controller/parser 88% ✔
github.com/Azure/agentbaker/aks-node-controller/pkg/gpu 100% ✔
github.com/Azure/agentbaker/aks-node-controller/pkg/nodeconfigutils 89% ✔
github.com/Azure/agentbaker/aks-node-controller/utils 0% ❌
github.com/Azure/agentbaker/apiserver 24% ❌
github.com/Azure/agentbaker/cmd 0% ❌
github.com/Azure/agentbaker/cmd/starter 0% ❌
github.com/Azure/agentbaker/fuzz/api 0% ❌
github.com/Azure/agentbaker/hotfix/render-nodecustomdata 0% ❌
github.com/Azure/agentbaker/pkg/agent 78% ➖
github.com/Azure/agentbaker/pkg/agent/datamodel 77% ➖
github.com/Azure/agentbaker/pkg/agent/toggles 0% ❌
github.com/Azure/agentbaker/pkg/vhdbuilder/datamodel 87% ✔
Summary 74% (5836 / 7828) ➖

Copilot AI 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.

🔵 Needs a closer look

Security-sensitive Windows provisioning and cached-image compatibility changes need completed Azure E2E and Windows VHD validation before human approval.

No open issues 🎉

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage

Package Line Rate Health
shellspec spec 28% ❌
Summary 28% (4556 / 15971) ❌

This branch has not been deployed

No deployments
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.

4 participants