Skip to content

ci: harden Actions and Dependabot supply chain (SHA pins, automerge binding, cooldown, feed OIDC, cache split, digest promotion) - #1729

Merged
BenjaminMichaelis merged 3 commits into
mainfrom
claude/hopeful-dijkstra-5c726c
Nov 26, 2026
Merged

BenjaminMichaelis merged 3 commits into
mainfrom
claude/hopeful-dijkstra-5c726c

Conversation

@BenjaminMichaelis

@BenjaminMichaelis BenjaminMichaelis commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Hardens the CI/CD supply chain, following the Tier B leads (3, 4 and 5) and the CI hardening notes from the 2026-11 security audit. This PR changes workflow and Dependabot files only; it changes no repository, org or Azure settings.

What changed

1. SHA-pinned actions. Every uses: in the hand-written workflows is now pinned to a full commit SHA, with a # vX.Y.Z comment that Dependabot keeps up to date. That includes reproducible-containers/buildkit-cache-dance → 5422eac04292c961a382e0f584ea0f03ad9da723 # v3.4.0, the same commit @v3 resolved to. The gh-aw *.lock.yml files were already pinned and are unchanged. Once this PR merges, sha_pinning_required can be turned on.

2. Dependabot auto-merge (Automerge-ContentNugetFeed.yml). Every update still auto-merges, as intended, with these new conditions:

  • The PR author, github.actor and github.triggering_actor must all be dependabot[bot], and the head must be in this repository. A re-run by someone else no longer runs the job.
  • The job fails if the live PR head is no longer the commit the run was triggered for.
  • The approval is posted with commit_id = pull_request.head.sha. Auto-merge is enabled with --match-head-commit for that SHA, which gh sends as expectedHeadOid.
  • The workflow GITHUB_TOKEN drops to contents: read. Every privileged call already used BOT_PAT.

3. Dependabot cooldown (dependabot.yml): 3 days on nuget, npm and github-actions, and 7 days for major versions on nuget and npm (github-actions accepts only default-days). ContentFeedNuget and EssentialCSharp.Shared.Models are exempt: they share $(ToolingPackagesVersion) and carry book content. Security updates bypass cooldown.

4. Private-feed auth through OIDC, keeping the PAT as fallback (build-and-test).

  • If the BuildAndUploadImage environment has the variable AZURE_DEVOPS_FEED_CLIENT_ID, the job:
    • signs in with azure/login (OIDC, allow-no-subscriptions);
    • gets an Azure DevOps token with az account get-access-token --resource 499b84ac-…;
    • writes it into the credentials-only NuGet config, for both the host restore and the Docker nuget_config secret.
  • Otherwise it uses AZURE_DEVOPS_PAT, exactly as before.
  • The job logs Private feed auth mode: oidc|pat.
  • The host restore no longer uses setup-dotnet's source-url, which wrote the token to ../nuget.config and left it there for the whole job. The job now writes ~/.nuget/NuGet/NuGet.Config, the same credentials-only file the Dockerfile already uses, and deletes it right after restore.
  • The job now has id-token: write.
  • New script: scripts/nuget/get-feed-token.sh. Setup steps are under the manual follow-ups below.
  • To fall back to the PAT, delete the AZURE_DEVOPS_FEED_CLIENT_ID variable; the next run uses the PAT.

5. Caches split by trust.

  • Credentialed jobs (build-and-test, copilot-setup-steps) use *-nuget-feed- and buildkit-cache-feed- keys.
  • PR, merge-queue and CodeQL jobs use *-nuget-public- and buildkit-cache-public- keys, and their restore-keys don't fall back to anything else.
  • So main's private-feed NuGet folder and BuildKit NuGet mount are no longer restored into PR builds, and the legacy buildkit-cache-<hash> and Linux-nuget- entries stop being used.

6. Promotion by digest.

  • deploy-development reads the manifest digest it just pushed from the local image's RepoDigests. It fails if the dev ACR :sha tag doesn't point to that digest.
  • It exposes the digest as the job output image-digest, and runs the dev migration and dev deploy by @digest.
  • deploy-production runs az acr import --source <dev>/essentialcsharpweb@<digest> and fails unless prod :sha points to that exact digest.
  • The migration, deploy and verify steps now compare against the built digest instead of a value re-read after import.

Verification

  • actionlint 1.7.7 (with shellcheck) reports nothing on any changed workflow. The one remaining note is a pre-existing SC2086 info in the unchanged CleanupCaches.yml. This PR also removes a pre-existing SC2086 in the old prod import step.
  • shellcheck is clean on get-feed-token.sh. I ran the PAT path locally: a missing token and an unknown mode both exit 1.
  • Not exercised: build-and-test, deploy-* and the automerge job don't run on this PR. They run on push to main or a Dependabot PR. Watch the first main run after merging, especially:
    • Build and test (Ubuntu): feed restore through the user-level config;
    • Push Image to Dev Container Registry: digest capture;
    • Import image from dev ACR to prod ACR: import by digest.
  • Expect a slower first container build on each PR, because PRs no longer borrow main's BuildKit NuGet cache.

Manual follow-ups for the owner (not changed here)

Turn on OIDC for the feed:

  • Create a feed-reader identity with no Azure RBAC roles, in the tenant the intelliTect Azure DevOps org is connected to. Done: ecs-web-nuget-feed-reader-identity.
    • Its federated credential needs issuer https://token.actions.githubusercontent.com, subject repo:IntelliTect/EssentialCSharp.Web:environment:BuildAndUploadImage and audience api://AzureADTokenExchange.
    • If the Azure DevOps org is in a different tenant from AZURE_TENANT_ID, change the workflow's tenant-id.
  • Add the identity to the Azure DevOps org (Basic access) and grant it Feed Reader on the EssentialCSharp feed.
  • Set the environment variable AZURE_DEVOPS_FEED_CLIENT_ID on BuildAndUploadImage. The first main run after merge will use OIDC.
  • Once a main run logs Private feed auth mode: oidc and passes, remove the PAT fallback. Then move the remaining PAT users: Dependabot's nuget-azure-artifacts registry (Dependabot supports Azure OIDC with tenant-id/client-id) and the copilot environment. Finally delete AZURE_DEVOPS_PAT and revoke the PAT.

GitHub settings to consider:

  • sha_pinning_required: enable it under repository Actions settings (allowed actions) now that every workflow is pinned.
  • Development environment branch policy: restrict Development (and BuildAndUploadImage) to main. Today any branch can get the dev identity, which holds registry-wide AcrPush. Consider the same for IntelliTect/try's Development environment, whose identity also has AcrPush on ecsdevacr.
  • Fork PR approval policy: change it from "first-time contributors who are new to GitHub" to "all outside collaborators" or "first-time contributors".
  • Main ruleset: turn on require_last_push_approval and/or dismiss_stale_reviews_on_push, so a push after the bot's approval needs a fresh approval. This is the server-side backstop for the automerge pinning.

Azure settings to consider:

  • ACR tag locking: set writeEnabled=false (az acr repository update --write-enabled false) on released essentialcsharpweb manifests in ecsprodacr, and optionally on promoted digests in ecsdevacr. Also review whether the registry-wide AcrPush grants on the dev ACR are all needed. Basic SKU has no repository-scoped permissions.

Small follow-up found along the way: in scripts/nuget/emit-creds-config.sh, xml_escape mis-escapes <, > and " on bash 5.2 and later, because & in a ${var//pat/rep} replacement now inserts the matched text. PATs and Entra JWTs never contain those characters, so this has no effect today. The fix is to escape & in the replacement strings.

🤖 Generated with Claude Code

BenjaminMichaelis and others added 3 commits November 26, 2026 12:59
- Pin every action in the hand-written workflows to a full commit SHA with
  a version comment (incl. reproducible-containers/buildkit-cache-dance
  v3.4.0 = 5422eac0), so sha_pinning_required can be enabled.
- Dependabot auto-merge: require the PR author, actor and triggering actor
  to be dependabot[bot]; refuse if the live head moved; approve with
  commit_id and enable auto-merge with --match-head-commit for the
  triggering SHA; drop unused GITHUB_TOKEN write scopes.
- Dependabot: 3-day cooldown (7 for majors) on nuget, npm and
  github-actions; ContentFeedNuget and EssentialCSharp.Shared.Models exempt.
- Private feed: optional Entra OIDC auth (azure/login + Azure DevOps access
  token) when vars.AZURE_DEVOPS_FEED_CLIENT_ID is set on BuildAndUploadImage;
  AZURE_DEVOPS_PAT stays as the fallback. Setup in docs/nuget-feed-oidc.md.
- Caches: credentialed builds use *-feed- keys, PR/CodeQL builds use
  *-public- keys with no fallback, so main's private-feed NuGet and BuildKit
  caches are no longer restored into PR builds.
- Promotion: deploy-development records the pushed manifest digest (and
  checks the dev tag matches), deploys dev by digest, and deploy-production
  imports dev@digest and fails unless prod holds that exact manifest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@BenjaminMichaelis
BenjaminMichaelis merged commit 575ca2e into main Nov 26, 2026
21 checks passed
@BenjaminMichaelis
BenjaminMichaelis deleted the claude/hopeful-dijkstra-5c726c branch November 26, 2026 21:55
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