Automation
GitHub Actions: contain a suspect cache before resuming deployments
A runbook for mapping GitHub Actions caches, containing possible contamination and restoring a deployment pipeline with verified trust boundaries.
A pipeline builds an application on pull requests; another deploys the default branch to Azure. After a cache change, the team finds that a job triggered by untrusted input could write to a scope restored by a trusted job. A successful deployment does not prove that the restored files were trustworthy.
The goal is not to erase every cache before investigating. Establish which entries could have been written, which jobs restored them and what authority those jobs held. Then resume from a clean chain. This fictional scenario complements the pull_request_target containment runbook.
Contain and preserve evidence
Pause deployments and jobs that could write or restore affected caches. Cancel queued runs and retain logs, workflow definitions at the commits used, run IDs, triggers, SHAs, keys, refs and the UTC window. Export the available cache inventory before deletion, without downloading or executing its contents on a trusted workstation.
For each consuming job, record GitHub permissions, referenced secrets, environments, OIDC access and Azure roles. If a privileged job restored a suspect cache, treat credentials available to it as potentially exposed: bound the impact, investigate writes and follow the appropriate revocation or rotation procedures. Disabling caching does not undo an action already performed.
Map writers and readers
For every cache step, including caching enabled by language setup actions or reusable workflows, record the cached paths, key, restore prefixes, trigger and effective ref. Identify which jobs can restore each entry and what they execute afterward.
cache: key, version, ref, available creation and last-access times
writer: workflow@commit, event, run ID, actor, runner
inputs: PR code, artifacts, scripts, dependencies, restored cache
reader: workflow@commit, ref, run ID, exact key or fallback
authority: GitHub token, secrets, OIDC, cloud roles, runner access
effects: publication, deployment, changes and supporting evidence
status: confirmed / possible / unknown Scope follows branch and event rules, not workflow names. Matching keys alone do not prove that an entry was shared: check the ref, cache version and restore logs. Restore prefixes may select an entry other than the exact key. Missing evidence makes the path indeterminate, not cleared.
Check the protections actually in force
On GitHub.com, low-trust events running in the default branch context receive read-only access to that branch’s cache by default. Explicit cache-mode: write or write-only can override that protection. Check the documentation and behavior for your platform and version; do not infer safety from the event name alone.
Inspect workflow- and job-level overrides, as well as steps that execute untrusted code or consume untrusted artifacts before writing a cache. Even a trusted push job can become dangerous if it executes contaminated input. Never store secrets in a cache: some pull request workflows can read it.
A key containing the lockfile hash reduces accidental collisions, but is neither a signature nor proof of provenance. Dependency caches, build outputs and scripts remain inputs whose origin matters. Do not restore an entry from an untrusted context into a job with secrets or elevated permissions.
Rebuild a trustworthy baseline
After capturing metadata, delete suspect entries and entries whose provenance cannot be established within the affected scope. Check refs and IDs before deletion to avoid removing unrelated caches. Quarantine or rebuild exposed persistent runners. Investigate affected artifacts and external systems too: deleting a cache does not clean them.
First repair the versioned workflow: keep low-trust triggers read-only, separate jobs that execute PR code from publishing jobs, and prevent privileged jobs from restoring untrusted entries. Restrict permissions and OIDC trust to what is needed. A new key prefix helps start cold, but does not replace deletion of affected entries or repair of the trust boundary.
Run a clean build from an approved commit on a clean runner without restoring a cache. Verify dependencies using the lockfile and available integrity controls, produce a traceable artifact and compare it using the team’s checks. A lockfile does not protect against a compromised producer or build tool.
Test, decide and roll back
Before resuming, run these checks in an isolated repository or environment with test data:
- A low-trust run attempts to write to the default branch cache. Verify denial or the actual absence of a write in logs and inventory, including when a step only emits a warning.
- A deployment job must not restore an entry from the untrusted scenario, including through a fallback key. Verify the key and ref actually restored, or confirm a cache miss.
- The cold build succeeds without cache; a trusted job then populates the new cache and a second approved run restores it as intended.
Passing tests do not prove every contamination path is absent. Record uncovered scenarios and obtain service-owner and security approval. Deploy a bounded canary from the clean artifact, monitor GitHub and Azure writes, and expand only when the checks hold.
If a check fails, pause deployment and caching again, restore the previously approved application version and configuration, then verify the actual service and resource state. Application rollback does not erase external writes or credential exposure: investigate and compensate separately. If provenance remains unknown, keep the privileged pipeline paused.