Skip to content

fix(machine-health): run the elevated pass from a manifest-verified admin-only copy - #10372

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-9071-40407750247-1
Oct 26, 2026
Merged

melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-9071-40407750247-1

Conversation

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor

Refs: #9071

Summary

Opened by the work-resolve-issue lane. The run's own summary:

The elevated pass's launcher now carries a bootstrap and a SHA-256 manifest, hashed at prepare time, covering the orchestrator, the lib and check scripts, the catalog and its schemas. The bootstrap first pins PSModulePath to machine-wide folders and gives Path and every HKCU\Environment name its system value. It then refuses (exit 4, nothing copied or run) a file that is missing or changed after prepare. Otherwise it copies the checked bytes into a new ProgramData folder that only Administrators and SYSTEM can open, runs the orchestrator from that copy, and removes it. Check jobs keep the pinned module path. elevation-matrix.md's residual risk and SKILL.md's Show-and-ask text now describe the narrower risk, following the owner's recorded decision (both hardenings, prepare-time hashes as the trust anchor).

Remaining work

  • File the follow-up issue for a release-signed elevated-pass manifest, which would close the window that remains before prepare. This lane cannot file issues.

Not verified

  • The Pester suites (New-ElevatedLaunch.Tests.ps1, Invoke-CheckWithTimeout.Tests.ps1) were not run: this Linux lane has no pwsh available to it and runs only the named wrappers. They run in pr-test-windows.yml's machine-health Pester step on the PR.
  • The launch-string round trip that gets past the manifest check needs the admin token for its ProgramData staging folder, so it is skipped unless the test process is elevated. Whether the GitHub-hosted Windows runner is elevated was not confirmed. The same path also runs unelevated through the bootst
  • PSScriptAnalyzer was not run (no pwsh here, and no repository config or CI step for it was found).
  • The person-run check from the decision is not done: one real UAC-elevated pass on a Windows host with a lib script changed after prepare, to show that it is refused.
  • check-affected sub-checks that run checked-tree code (validate-plugins parts, changed-skills) were skipped by the wrapper, and typos is not installed. These run in the PR's CI.

Fix

  • plugins/machine-health/skills/audit/scripts/windows/lib/Invoke-ElevatedBootstrap.ps1: new; Test-ElevatedPassPath, Get-SystemEnvironmentVariable (CreateEnvironmentBlock with no token), Get-ElevatedPassEnvironment, New-ElevatedStagingFolder (random ProgramData folder created owned by Administrators wi
  • plugins/machine-health/skills/audit/scripts/windows/lib/New-ElevatedLaunch.ps1: new Get-ElevatedPassManifest (orchestrator, lib/.ps1, checks/.ps1, catalog/checks.jsonc, catalog/schemas/*.json, hidden files included; refuses a name the bootstrap would refuse); the launcher now holds the bootstrap f
  • plugins/machine-health/skills/audit/scripts/windows/lib/Invoke-CheckWithTimeout.ps1: each check job sets PSModulePath to the caller's value, since a child pwsh adds the user module folder back at startup
  • plugins/machine-health/skills/audit/scripts/windows/lib/Write-ElevationBanner.ps1: banner and coverage text say 'the launcher script' instead of 'a one-command script'
  • plugins/machine-health/skills/audit/reference/windows/elevation-matrix.md: new Bootstrap step 3 (steps renumbered to 6); residual risk now lists files changed before prepare (prepare-time manifest narrows the window between the owner's look and the copy without closing it; a release-signed manifest
  • plugins/machine-health/skills/audit/SKILL.md: Elevated pass intro says 'one shown script'; Show-and-ask text describes the copy, the manifest check and the remaining risk
  • plugins/machine-health/skills/audit/tests/windows/lib/New-ElevatedLaunch.Tests.ps1: launcher shape and AST/manifest tests rewritten; launch-string refusal tests (lib script changed or removed after prepare -> exit 4, orchestrator not run); Get-ElevatedPassManifest, Get-ElevatedPassEnvironment, Ge
  • plugins/machine-health/skills/audit/tests/windows/lib/Invoke-CheckWithTimeout.Tests.ps1: test that the job runs under the caller's PSModulePath
  • .changes/machine-health/fix-9071-verify-elevated-pass-files-5c2e8a17.md: minor changelog fragment (Security, Changed), written by hand because new-changelog-fragment refuses a detached HEAD

Verification

The runner ran each check from the base copy against 5df7a20:

  • scripts/check-changelog-fragments.sh --check: passed

The run reports:

  • read https: //learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_psmodulepath?view=powershell-7.5: PowerShell 7 builds PSModulePath at each start, prefixing the User, System (AllUsers, $Env:ProgramFiles\PowerShell\Modules) and $PSHOME paths, so a child pwsh puts the us
  • read https: //learn.microsoft.com/en-us/windows/win32/api/userenv/nf-userenv-createenvironmentblock: with hToken NULL the returned block contains system variables only; free it with DestroyEnvironmentBlock
  • read https: //learn.microsoft.com/en-us/dotnet/api/system.io.filesystemaclextensions.createdirectory: creates the directory with the given DirectorySecurity, and returns an existing directory as is (why the folder name is random and its owner is rechecked)
  • /home/runner/work/claude-code-plugins/claude-code-plugins/.lane/checks/bin/check-changelog-fragments: all 4 fragments under .changes/ valid
  • /home/runner/work/claude-code-plugins/claude-code-plugins/.lane/checks/bin/check-affected: 9 passed, 7 skipped over 9 changed files (skips: shellcheck/ruff no matching files, typos not installed, validate-plugins and changed-skills sub-checks that run checked-tree code)
  • cant-fail-scan --file New-ElevatedLaunch.Tests.ps1 --check: PASS, 21 test blocks, no gating findings
  • cant-fail-scan --file Invoke-CheckWithTimeout.Tests.ps1 --check: PASS, 10 test blocks, no gating findings
  • fresh-context review subagent over the whole diff: no runtime or PowerShell-semantics bugs; four findings, all fixed: docs overstated the pin (startup-read variables act before it, now listed as residual risk), Path is now pinned even when HKCU\Environment does not define it, prepare now applies the
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/40407750247

Left out: the items under Not verified.

Related

#9071

Lane-Activity: work-resolve-issue/resolve-issue
@github-actions

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 5df7a20b8acc9c157bda2e4eea6b87c43e4a6797: 0 finding(s), 0 as inline comments.

No security findings in PR #10372 at head 5df7a20. critical-findings: 0

I read the whole diff and the PR context. I also read Resolve-SkillRoot.ps1, the other places the audit scripts reference the skill root, and the elevation matrix rows. No file in the diff matches a TRUSTED PATHS glob.

What the change does: the elevated pass now runs a hash-checked copy of its files from an Administrators/SYSTEM-only ProgramData folder, after pinning PSModulePath, Path and the HKCU\Environment names. This narrows what the elevated process trusts compared with the base, where the hash covered only a one-command script.

I looked for these exploit paths and found none that is new or unaccepted:

  • Injection into the launcher. Manifest keys must pass Test-ElevatedPassPath at prepare time, a strict allow-list with no dots-first segment, .., :, spaces or quotes. They are then written as single-quoted literals, and the values are hex digests. The function bodies embedded in the launcher are covered by the shown SHA-256, and Get-ElevatedLaunch still binds the approved hash to the script bytes.
  • Path traversal when copying. The same regex is enforced in the elevated process, so a key cannot escape the staging folder. A mismatch, missing or unreadable file returns 4 before anything is copied or run.
  • Time-of-check/time-of-use between hashing and copying. Each file is read once and the verified bytes are the ones written to the copy.
  • Staging folder. The name is a random GUID. It is created with a protected DACL of Administrators and SYSTEM only, Administrators as owner, and no inheritance from C:\ProgramData. The bootstrap rechecks the owner and rejects a reparse point.
  • Files the copy loads. Resolve-SkillRoot derives the root from $PSScriptRoot, so dot-sourced lib files and catalog/schema files resolve inside the verified copy. The elevated checks I read do not load other code from the install tree.
  • Authorization gate. The SKILL.md "Show and ask" rewrite keeps the explicit owner-yes rule and the refusal in -p runs. It now discloses the remaining risk more precisely, so the rewrite does not soften that control.
  • Manifests. No plugin.json or marketplace.json change.

Residual risks the PR itself states: files modified before prepare, variables pwsh reads at startup that are set only in the parent process and not in HKCU\Environment, and a pwsh installed under the user profile. These were already present in the base and are now narrower. I did not report them.

Spend: none that bills. The change adds no paid-plan or billing surface.

@github-actions

Copy link
Copy Markdown
Contributor

claude-review reviewed 5df7a20b8acc9c157bda2e4eea6b87c43e4a6797: 0 finding(s), 0 as inline comments.

Code review: no findings

I read all 857 lines of the diff and the PR context. I had no shell, so I ran no code and no tests. The PowerShell and Pester behavior below comes from reading the code, not from running it.

What I checked

  • Manifest coverage. I checked that the staged copy holds every file the elevated pass loads. The orchestrator's -ResultPath branch dot-sources only lib/*.ps1 and reads catalog/checks.jsonc. The seven checks with an elevation-matrix row are disk-space, drivers, tpm-bitlocker, defender-exclusions, startup-items, app-last-use and backup-status. None of them reads reference/, cisa-kev.json, Format-ShortReport.ps1 or Get-ResearchCandidate.ps1, so those files are correctly left out of the manifest. Set-ApprovalState, Publish-CheckupView and Get-RemediationId do reach outside it, but the elevated branch never calls them.
  • Launcher parsing. Get-ElevatedLaunch now picks the Invoke-ElevatedBootstrap call by command name and reads only the single-quoted ResultPath and ResultFileId values. The Manifest hashtable argument is skipped by the StringConstantExpressionAst check, so it does not break the parse.
  • Exit 4 path. The refusal happens before any staging folder is created. The tests are consistent with that. The stderr text matches the *refused*Stub-Lib.ps1* assertion, and the exit 4 cases are not gated on elevation.
  • Job module path. Invoke-CheckWithTimeout now sets PSModulePath inside each job. For standard (non-elevated) runs this passes the caller's own value, so I see no behavior change there.
  • Closing issue. The PR says Refs: #9071 and has no Closing issue section, so there are no acceptance criteria to check.

Manifest lines: the diff touches no plugin.json or marketplace.json. The bump: minor fragment matches the change, which adds a security hardening and drops the elevated pass's view of a per-user PSWindowsUpdate module. The fragment documents that.

Left undone by the PR, per its own description

  • The follow-up issue for a release-signed manifest has not been filed. The lane could not file it.
  • The Pester suites were not run, because the lane had no pwsh.
  • The one real UAC-elevated check on a Windows host is not done. That check is a lib script changed after prepare, to show it is refused.
  • The launch-string round-trip test is skipped unless the test process is elevated, and the PR does not confirm whether the hosted Windows runner is elevated. If it is not, that path is covered only through the bootstrap's staging-folder seam. Please check the Windows CI run to see whether the round-trip case ran or skipped.

Residual risk: the PR's docs list what the change leaves open. They name files changed before prepare, variables pwsh reads at startup, and a pwsh under the user profile. This matches the owner's recorded decision, so I do not count it as a finding.

Spend: this changes no billing. The new Pester cases and the extra CI step use only existing CI minutes.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The unattended merge path armed native auto-merge at head 5df7a20b8acc9c157bda2e4eea6b87c43e4a6797.

@melodic-automation-lanes
melodic-automation-lanes Bot added this pull request to the merge queue Oct 26, 2026
Merged via the queue into main with commit 940b7bf Oct 26, 2026
42 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-9071-40407750247-1 branch October 26, 2026 22:41
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.

0 participants