Toutes les vulnérabilités
HIGHSecretsexploited in the wild

SECRET-CONTAINER-LAYER

Secrets · Containers · Secrets baked into container image layers

Résumé

A container image is a stack of immutable, content-addressed layers where each Dockerfile instruction (RUN, COPY, ADD) commits a filesystem diff, so a secret introduced in one layer persists permanently even if a later layer deletes the file. Deleting with RUN rm only writes a whiteout entry in a higher layer; the original bytes remain in the earlier layer's tarball and are recoverable by extracting the image and reading individual layer archives. Secrets passed via ARG or ENV are worse still, as their values are recorded in image metadata and surface directly through docker history, exposing them to anyone who pulls the image or has registry layer-download permissions. Once such an image is pushed to a public or shared registry, the credential leaks to every consumer. BuildKit's RUN --mount=type=secret solves this by exposing a secret to a single build step without writing it to any layer, leaving no trace in the final image.

Comment l’éviter dans votre code

  • Use BuildKit RUN --mount=type=secret for build-time secrets so they never persist in any layer.
  • Never pass secrets via ARG or ENV; they are recorded in image metadata and docker history.
  • Use multi-stage builds so build-time credentials stay out of the final shipped image.
  • Scan images with Trivy or Trufflehog and inspect docker history before pushing to a registry.
  • Rotate any secret ever baked into an image and restrict registry pull and layer-download access.

Références

Vulnérabilités liées

Tout Secrets →