CI build cache and untrusted pull requests
A build cache saves work by reusing results associated with prior build inputs. It is an optimization, not a substitute for testing or authorization. In CI, a pull request may contain unreviewed code or Dockerfile instructions, so its execution and cache permissions must be separated from trusted release jobs.
Worked example
Work offline: the scenarios and evidence are synthetic. Do not run hosted workflows, contact registries, use real credentials or deploy anything for this lesson. Keep the exercise offline. Before any separately authorized runtime check, verify the effective daemon, builder, runner or deployment identity as applicable; use synthetic data, reviewed inputs and bounded resources. Record missing evidence as NOT RUN.
Fictional cache policyPR job: ephemeral runner; no release secrets; isolated cache namespaceRelease job: reviewed commit; approved builder; trusted cache namespaceCache keys: application + platform + build configuration + dependency inputsRelease gate: test actual artifact even on cache hitThird-party actions: reviewed full commit SHA before adoptionBuildKit cache exporters can share build results across jobs; backend support and access controls vary. Partition cache scope by workload and platform, and do not let untrusted writers influence a release cache or artifact selection. Review which paths and branches a backend actually allows; a cache key alone is not an authorization boundary. Do not store credentials in build layers or caches. With GitHub Actions, keep unreviewed code out of privileged pull_request_target or workflow_run contexts; use a separate restricted validation job and do not rely on secret masking as a defense. Avoid persistent privileged runners for untrusted workloads. Pin reviewed third-party actions to full commit SHAs, and review updates instead of trusting moving tags. This example does not use external actions or a shared cache, so no action version or cache backend is assumed tested. Even if every layer is reused, run the required tests and verify release evidence. An immutable action revision identifies code but is not evidence that it is safe. Treat downloaded artifacts and cache entries from less-trusted jobs as untrusted inputs; verify provenance and authorization before any privileged consumer uses them. Do not equate cache hits with passed tests.
Common mistake
A successful cached build is not permission to promote. Shared cache storage is not a trusted artifact repository just because it has a predictable name.
Manual practice
Compare an unreviewed PR and a reviewed release job. Specify runner isolation, credential scope, cache write permissions and test requirements for each; explain why a cache hit cannot skip evidence checks.
Worksheet: lab-fixtures/docker-ci-cd/07-cache-trust/scenario.txt.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
CI build cache and untrusted pull requests — Knowledge check
Apply release and CI/CD reasoning to a fictional scenario.
What does a build cache hit justify?
What should a trusted release job avoid?
Why pin a reviewed third-party action to a full commit SHA?