Skip to content

Submit the dependency snapshot without a third-party binary holding the write token (#655) - #656

Merged
erikdarlingdata merged 3 commits into
devfrom
fix/655-dependency-snapshot
Oct 15, 2026
Merged

erikdarlingdata merged 3 commits into
devfrom
fix/655-dependency-snapshot

Conversation

@erikdarlingdata

@erikdarlingdata erikdarlingdata commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Claude posting for Erik Darling.

Reworks .github/workflows/dependency-submission.yml so no third-party binary runs while a write token is present. The component-detection action (which downloaded the latest microsoft/component-detection release at run time) is gone.

Changes

  • .github/workflows/dependency-submission.yml
    • detect job: contents: read, windows-latest, checkout with persist-credentials: false, setup-dotnet, wasm-tools workload, and the restores unchanged (solution, the two installer projects, the SSMS project via MSBuild, all -p:NuGetAudit=false with the original comment). Then runs the new script and uploads snapshot.json as artifact dependency-snapshot (actions/upload-artifact at the pin release.yml uses, v7.0.2).
    • submit job: needs: detect, contents: write, ubuntu-latest, no checkout. actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 (v8.0.2 is 7 days old, so v8.0.1 from 2026-03-11 is the newest release at least two weeks old), then one gh api --method POST ... dependency-graph/snapshots --input snapshot.json step that prints result and message and exits 1 on INVALID.
    • Workflow-level permissions: {}; each job sets its own. Push triggers (main, dev) and workflow_dispatch kept. Header comment rewritten: why two jobs, dev snapshots feed no alerts and the dev trigger exists to exercise the workflow; the downloaded-binary sentence is dropped.
    • github.sha, ref and run_id reach the script through env vars, not spliced into the script text (a branch name can contain a quote).
  • .github/scripts/New-DependencySnapshot.ps1 (new): reads every obj/project.assets.json (skipping .claude/, tmp-*/, bin/), writes the snapshot. Throws when it finds no assets file or zero resolved packages (replaces the old fail-on-empty).

Decisions

  • Correlator is submit, not Dependency submission_submit. At the old action's commit a02aeda, dist/index.js has getInput("correlator")?.trim() || github_context.job, and github.context.job is the job id submit. The correlator therefore stays submit, but this does not make the new snapshot replace the old action's (corrected in round 1): GitHub keys snapshots on correlator plus detector name, and the detector name differs (Component Detection there, performancestudio-assets-snapshot here). The old action's snapshot exists only on dev and is left beside this one; main never received one.
  • Snapshot shape follows the coordinator's follow-up from run 38657114293, which GitHub accepted: resolved keys are the package URLs themselves, dependencies list package URLs (all present in the same manifest), scope is development for tests/** and runtime otherwise.
  • Runtime-specific targets (tfm/rid, e.g. net472/win-x86, .NETFramework,Version=v4.7.2/win-x64, net10.0/browser-wasm) repeat the plain target's packages; the script keeps only the plain target per framework. Every project here has exactly one framework, so manifests are named by csproj path with no (tfm) suffix. (My first run emitted 16 manifests including the RID copies; fixed before committing.)
  • The old action's runs on dev already restored cleanly on the runner (run 38657114293: every step green), so the restore steps carry over unchanged.

Local verification

  • Restored PlanViewer.sln, both installer projects (dotnet restore) and PlanViewer.Ssms.csproj (MSBuild 2022 BuildTools -t:Restore -p:Configuration=Release), all -p:NuGetAudit=false: 9 assets files.
  • Script run with a fake sha, ref refs/heads/fix/655-dependency-snapshot, run id 999999: valid JSON, 9 manifests, 533 resolved packages.
Manifest Resolved Direct Scope
server/PlanShare/PlanShare.csproj 7 2 runtime
src/PlanViewer.App 82 16 runtime
src/PlanViewer.Cli 69 3 runtime
src/PlanViewer.Core 40 5 runtime
src/PlanViewer.Ssms.Installer 2 1 runtime
src/PlanViewer.Ssms 127 4 runtime
src/PlanViewer.Web 31 5 runtime
tests/PlanViewer.Core.Tests 143 7 development
tests/PlanViewer.Ssms.Installer.Tests 32 4 development
  • System.Security.Cryptography.Pkcs@10.0.13: direct in Core; indirect in App, Cli and Core.Tests.
  • MessagePack@2.5.307: direct in PlanViewer.Ssms (7 dependencies listed).
  • Every dependencies entry (all manifests) exists as a key in the same resolved map: 0 dangling.
  • YAML parse (PyYAML): yaml ok.
  • dotnet build PlanViewer.sln -c Debug: 0 warnings, 0 errors (no NU warnings). No tests run; nothing touches code or tests.

Real submission

Generated a snapshot for the pushed head (sha a98c6c7, ref refs/heads/fix/655-dependency-snapshot, correlator submit) and posted it with the same gh api command the workflow uses, under the local gh login. Response, verbatim:

  • result: ACCEPTED
  • message: The snapshot was accepted, but it is not for the default branch. It will not update dependency results for the repository.

Nothing was submitted for dev or main.

Not verified

  • The workflow itself has not run on a runner: the artifact upload/download round trip, pwsh on windows-latest (the script was run under local PowerShell 7), and gh/jq in the ubuntu job. The first run on dev after merge exercises all three.
  • Acceptance on main (the dependency graph showing System.Security.Cryptography.Pkcs and MessagePack) can only be checked after the next dev-to-main merge.
  • Issue Dependency submission: keep the write token away from the component-detection binary #655 also asked to drop dev from the push trigger; the brief keeps it, so it stays until the first dev run is green.

Review round 1

Applied in commit 74d552c. Items are from the round-1 security review.

  1. Medium, PlanShare: added a "Restore PlanShare" step (dotnet restore server/PlanShare/PlanShare.csproj -p:NuGetAudit=false) after "Restore solution". Finding while verifying: tests/PlanViewer.Core.Tests has a project reference to PlanShare, so the solution restore already restores it (I deleted server/PlanShare/obj, ran only the solution restore, and the assets file came back). The CI snapshot therefore already had 9 manifests; the explicit step keeps PlanShare covered if that reference ever goes away.
  2. Low, failed restore: (a) "Restore SSMS projects" now has shell: bash, so the first failing command fails the step. (b) The script throws after reading an assets file whose logs has an entry with level Error, naming the file and the first code.
  3. Low, sha and ref from the artifact: submit runs jq --arg sha "$GITHUB_SHA" --arg ref "$GITHUB_REF" --arg id "$GITHUB_RUN_ID" '.sha = $sha | .ref = $ref | .job.id = $id' snapshot.json > body.json and posts body.json. detect still writes the fields, so a local script run produces a complete file.
  4. Low, result check: the step fails unless result is SUCCESS or ACCEPTED (a missing result fails too), and on an HTTP error it prints response.json first (if ! gh api ... > response.json; then cat response.json; exit 1; fi). Result and message are still printed.
  5. Low, replacement claim: detector name unchanged. The comment above "Build dependency snapshot" and the "Decisions" bullet below are corrected: the old action's dev snapshot is left beside this one, and main never received one.
  6. Low, ordering: workflow-level concurrency: group: dependency-submission-${{ github.ref }}, cancel-in-progress: true.
  7. Low, scope: no detection logic. The script's comments now say development is for tests/ projects only and that build-time packages in product projects (ILLink, the WASM DevServer, VSSDK.BuildTools) are listed as runtime, which only affects alert triage.
  8. Low, #Requires -Version 7.0 is now line 1 of the script.

Not done: the review's optional suggestions (a coverage check over every csproj, rebuilding the whole envelope in submit, a branch-head check in submit); the rulings for this round were narrower.

Local proofs (round 1)

  • Restores: dotnet restore PlanViewer.sln, server/PlanShare/PlanShare.csproj, both installer projects, and the SSMS project with MSBuild 2022 BuildTools, all -p:NuGetAudit=false, all exit 0. server/PlanShare/obj was deleted first. Note: the vswhere recipe in the brief returns nothing here because only Build Tools are installed; it needs -products *.
  • Script with fake sha, ref refs/heads/main, run id 123, -Correlator submit: 9 manifests, 533 resolved packages from 9 assets files. Per manifest (resolved, direct/indirect): PlanShare 7 (2/5), App 82 (16/66), Cli 69 (3/66), Core 40 (5/35), Ssms.Installer 2 (1/1), Ssms 127 (4/123), Web 31 (5/26), Core.Tests 143 (7/136), Ssms.Installer.Tests 32 (4/28).
  • Item 2b: a temp tree outside the repo with a copy of the PlanShare assets file, project.restore.projectPath inside the tree, and logs: [{code: NU1101, level: Error}]. The script threw ...\proj\obj\project.assets.json: restore logged 1 error(s), first NU1101. The snapshot would be incomplete. and wrote no output. Control with a Warning log: succeeded. Temp tree deleted.
  • Item 3 (jq 1.7.1, Git Bash): sha/ref/job.id changed from aaaa.../refs/heads/main/123 to deadbeef/refs/heads/dev/999; manifests unchanged (9).
  • Item 4: the same check logic on fake responses: {"result":"INVALID"} fails, {"result":"ACCEPTED","message":"x"} passes, {} fails, {"result":"SUCCESS"} passes. A failing command that writes {"message":"Not Found"} to stdout and exits 1: the body is printed and the step fails.
  • YAML parse: yaml ok.
  • Not run: the workflow on a runner (still true), and no test suite or build; nothing touches code.

Closes #655

🤖 Generated with Claude Code

https://claude.ai/code/session_018MrD9SGvLFx4kJaeGZyXG9

…he write token (#655)

Split dependency-submission.yml into a read-only detect job that builds the snapshot from
obj/project.assets.json with a repo script, and a write-token submit job that only downloads
the artifact and posts it with gh api.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018MrD9SGvLFx4kJaeGZyXG9
@erikdarlingdata
erikdarlingdata marked this pull request as ready for review October 15, 2026 00:13
@claude

claude Bot commented Oct 15, 2026

Copy link
Copy Markdown

Reviewed the workflow and script. I found no correctness or injection problems, and I did not run the workflow.

  • Injection: github.sha, ref and run_id reach the script through env vars. The only value spliced into a run: block is github.repository, which is not attacker-controlled.
  • Token separation: The submit job has no checkout and runs no repo code, so that part is fine.
  • Low severity, residual trust: snapshot.json is produced in detect, where restore runs package and MSBuild code. submit posts it unvalidated. A compromised restore could therefore forge dependency-graph contents (not the repo itself), because the write token only posts what the artifact says. The impact is limited to the graph and is acceptable here. A cheap hardening would be to have submit check with jq that .sha equals github.sha and .ref equals github.ref before posting.
  • Low severity, never exercised: The artifact round trip, pwsh on windows-latest and jq in the ubuntu job have not run on a runner, as the PR notes. Watch the first dev run.
  • Not touched: No version bumps, no NoWarn changes, no Core/Web links and no T-SQL changes.
  • Tests: There are no tests for the script. Its shape logic (RID-target dedup, direct versus indirect, scope) is only verified by hand, which is reasonable for CI tooling.

- Restore PlanShare in its own step.
- Restore SSMS projects under bash so the first failing restore fails the step.
- Script fails when an assets file logs a restore Error; add #Requires -Version 7.0.
- submit rewrites sha, ref and job id from the run, fails unless result is SUCCESS or
  ACCEPTED, and prints the response body on an HTTP error.
- Concurrency group per ref so the latest commit's graph is submitted last.
- Correct the correlator comment (the old action's snapshot is not replaced) and the scope comment.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018MrD9SGvLFx4kJaeGZyXG9
@claude

claude Bot commented Oct 15, 2026

Copy link
Copy Markdown

Reviewed the workflow split and New-DependencySnapshot.ps1. I found no blocking issues, and I haven't run the workflow or the script.

  • The detect job has contents: read and the submit job has contents: write. submit checks out nothing and runs no repo code. It overwrites sha, ref and job.id from the run context, so the artifact can't redirect the snapshot to a different commit.
  • The zero-warning, version-bump, Blazor-link and TRY_CAST conventions don't apply to this diff.
  • Optional: the multi-line jq and gh api commands in the submit step's run: block have no \ continuations. They read as single long lines with runs of spaces. That is valid shell, but the YAML is hard to read, and a line-based editor that reflows them could break them.
  • Optional: there is no test for the script. Its manifest naming, the tfm/rid de-duplication and the tests/* scope rule are only exercised by a live run. A small Pester test over a fixture project.assets.json would catch regressions.

🤖 Generated with Claude Code

Cosmetic: the two multi-line commands had been flattened into single
lines with runs of spaces. Same commands, same behavior.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018MrD9SGvLFx4kJaeGZyXG9
@claude

claude Bot commented Oct 15, 2026

Copy link
Copy Markdown

Reviewed the workflow and New-DependencySnapshot.ps1. I found no blocking issues.

  • The write token is only in the submit job. That job has no checkout and runs no repo code.
  • github.* values reach the script through env vars, not spliced into script text.
  • The pinned action SHAs and the zero-warnings, version and TRY_CAST conventions aren't affected, since no code or T-SQL changes.

Two non-blocking points:

  • Untested on a runner: the artifact round trip, pwsh on windows-latest, and jq/gh on ubuntu have never run. Watch the first dev run.
  • Test coverage: the snapshot script has no tests. The failure paths (no assets file, restore error log, runtime-identifier target dedup) were only checked by hand. A small Pester test would stop them regressing silently.

I'm not proposing any change to the workflow itself.

@erikdarlingdata
erikdarlingdata merged commit 4f4f59f into dev Oct 15, 2026
3 checks passed
@erikdarlingdata
erikdarlingdata deleted the fix/655-dependency-snapshot branch October 15, 2026 00:34
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.

1 participant