Lion Cipher Lab

Recover a "deleted" secret from Docker image layers — then keep it out with BuildKit secret mounts

Why it matters

A huge share of real credential leaks are not fancy hacks — someone baked an API token into a container image and shipped it to a registry anyone can pull. The dangerous part is that it FEELS safe: you add the file, use it, then `rm` it in the next line and the final container has no trace. But a Docker image is a stack of frozen layers, and deleting a file only hides it — the layer that added it is still there for anyone with the image. Learning to pull that secret back out yourself is the fastest way to never make the mistake, and the fix (build secrets) is one line.

What you'll learn

Steps in this lab

  1. Why secrets get stuck in images (read this first)
  2. Set up a tiny project with a secret
  3. Build the image the naive (leaky) way
  4. Confirm the file is 'gone' at runtime — then watch it reappear in the metadata
  5. Recover the 'deleted' file out of the layers
  6. Fix it properly: a BuildKit secret mount
  7. A second line of defense: multi-stage builds
  8. Re-measure: prove the secret is gone
  9. When to use what — the judgment to keep

Open the full interactive lab →