Skip to main content
Secrets in Public Container Images Get Used in 8 Seconds

Secrets in Public Container Images Get Used in 8 Seconds

KU
· Founder & Chief Editor
• 7 min read•

Researchers planted cloud and AI API keys in 300 public images. Bots used the first AWS key 7.86 seconds after publication, without ever running a container. How keys get into layers, and how to keep them out.

Key takeaways

  • A Stony Brook honeypot study, presented at ACM CCS in November 2026, planted keys in 300 public container images.
  • The first AWS key was used 7.86 seconds after publication, and all 100 within 15 minutes.
  • Bots unpack layers without running containers, so rotate any pushed key immediately and keep secrets out with build secret mounts and pre-push scanning.

A credential inside a public container image is not a risk to fix later. It is an incident that has already happened. A Stony Brook study saw the first planted AWS key used 7.86 seconds after the image went public. If a key ever reached a pushed layer, rotate it first and investigate second.

Verified againstBased on published case studies

Study figures from BleepingComputer's November 17, 2026 report on Tsouvalas and Nikiforakis (Stony Brook University, ACM CCS 2026). Build-secret syntax against Docker's build secrets docs, scanner syntax against the TruffleHog README. Checked November 2026.

What the honeypot measured

Billy Tsouvalas and Nick Nikiforakis published 300 honeypot images across eight public container registries, including Docker Hub and Harbor, over four months. The images carried AWS, OpenAI and Anthropic keys. They presented the results at ACM CCS in November 2026.

MeasureResult
Fastest first use of a planted AWS key7.86 seconds after publication
Median first API call51.19 seconds
Planted AWS keys used100 of 100, all within 15 minutes
API calls against the AWS keys140,000+
Unique source IPsabout 5,000
Image pulls75,000+
OpenAI and Anthropic keyshijacked to drain the test-account balances

These were decoys built to be found, so the numbers measure how fast scanners move, not how many real images leak. The window between push and abuse is still shorter than any human review.

The researchers reported the findings to Docker in May, along with the full paper. They received an acknowledgment and no follow-up. A small re-test in August showed no change.

Nobody had to run the container

The researchers quoted in the BleepingComputer piece say the scanners "overwhelmingly" used static analysis: unpacking image layers or querying the registry API. Their monitoring rarely saw anyone actually run a honeypot image.

That changes the threat model. Many teams assume a secret in an image is safe until someone deploys it, or that a short-lived tag will vanish before anyone notices. Neither holds. An image is a set of tar archives plus a JSON config, and both are public the moment the push completes. A bot watching the registry's feed of new images can pull the manifest, stream the layers, and grep for AKIA, sk- or sk-ant- prefixes without starting anything.

The 5,000 source IPs also mean this is not one attacker you can block. Many independent scanners race each other, and the first to validate a key wins.

Diagram: a Dockerfile copies a .env file into layer 1 and deletes it in layer 3, while scanner bots unpack every layer and the config to find the key

Three ways keys end up in layers

COPY . . with no .dockerignore. The build context is everything in the directory, so .env, .aws/credentials, *.pem and the whole .git/ history go into a layer. The patterns that matter are in .dockerignore patterns that matter.

ENV and ARG for credentials. ENV values are written into the image config, which docker inspect prints for anyone who pulls the image. Build args used in a RUN step show up in docker history. Docker's own docs say build arguments and environment variables "are inappropriate for passing secrets to your build, because they persist in the final image."

RUN rm in a later step. Each instruction adds a layer, and layers are additive. Deleting a file in a later layer hides it from the running container, but the bytes are still in the layer that added it, and anyone can extract them:

Bash
# The "deleted" .env is still recoverable from the image
docker save myorg/app:latest -o app.tar
mkdir app && tar -xf app.tar -C app
for l in $(find app/blobs -type f); do tar -tf "$l" 2>/dev/null | grep -q '\.env$' && echo "$l"; done
docker history --no-trunc myorg/app:latest   # build args and ENV values in plain text

Build with secrets that never become layers

BuildKit secret mounts expose a file to a single RUN step at /run/secrets/<id> and never write it to an image layer:

Dockerfile
# syntax=docker/dockerfile:1
FROM python:3.13-slim
WORKDIR /app
COPY requirements.txt .
RUN --mount=type=secret,id=pip_token,env=PIP_TOKEN \
    pip install --index-url "https://__token__:${PIP_TOKEN}@pypi.example.com/simple" -r requirements.txt
COPY . .
Bash
docker build --secret id=pip_token,env=PIP_TOKEN -t myorg/app:latest .
docker build --secret id=aws,src=$HOME/.aws/credentials -t myorg/app:latest .

Pair this with a .dockerignore that excludes .env*, *.pem, .aws/, .ssh/ and .git/. The secret mount covers the credentials you meant to use. The ignore file covers the ones you forgot were in the directory.

Scan the image you push, not just the repo

Git secret scanning does not see what ends up in an image, because the leak is often a file that was never committed (.env, a local credentials file). Scan the built image in CI before docker push, and fail the job on a verified hit:

Bash
trufflehog docker --image docker://myorg/app:latest --results=verified
trufflehog docker --image file://app.tar --results=verified

Then remove the reason a static key exists at all. A CI job that pushes to ECR does not need an AWS_SECRET_ACCESS_KEY if it can assume a role through OIDC federation from GitHub Actions to AWS. A key that expires in an hour is worth far less to the bot that finds it.

Questions people ask

Does deleting the image or the tag fix a leaked key?

No. The study's median first use was 51 seconds, so by the time anyone notices, the key has almost certainly been copied. Deleting the tag stops new pulls, but it cannot recall the copies scanners already took. Rotate or revoke the key first, then review its usage logs (CloudTrail for AWS, the provider's usage dashboard for OpenAI or Anthropic), then clean up the image.

Are private registries safe from this?

They are safe from the public-feed scanners the study measured, which is most of the risk. A private image still leaks if the registry is made public by mistake, if the image is mirrored to a public registry, or if anyone with pull access is compromised. Treat secrets in private images as a policy violation, not as an accepted risk.

Does a multi-stage build remove secrets?

Only from the stages you do not push. If a secret is copied into or created in the final stage, it is in a pushed layer. Use RUN --mount=type=secret in whichever stage needs the credential, and keep COPY --from paths narrow.

The decision, concretely

  • A key was in any pushed layer, even for a minute? Rotate it now. Then check how to detect and rotate leaked cloud credentials for the log review.
  • A build needs a token to fetch dependencies? Use RUN --mount=type=secret with docker build --secret, never ARG or ENV.
  • No .dockerignore in the repo? Add one before the next build, and exclude .env*, *.pem, .aws/ and .git/.
  • CI pushes public images? Add an image secret scan as a required step before the push, and replace static cloud keys with OIDC roles.

The call we'd make

Make two controls mandatory for every image that leaves a laptop: BuildKit secret mounts in the Dockerfile and a verified-secrets scan of the built image in CI. Then retire static cloud keys wherever OIDC or workload identity exists. The caveat is that none of this helps once a key is out. A rotation runbook you can execute in minutes matters more than the scanner, because the study shows scanners on the other side are faster than yours.

Sources

Explore topics:DockerDevOps
React
Share this post
Cite this article
Plain text

Kiril Urbonas (2026). Secrets in Public Container Images Get Used in 8 Seconds. DevOpsNess. https://www.devopsness.com/blog/secrets-in-container-images-stolen-in-seconds

Markdown

[Secrets in Public Container Images Get Used in 8 Seconds](https://www.devopsness.com/blog/secrets-in-container-images-stolen-in-seconds) (Kiril Urbonas, DevOpsNess, 2026-11-24)

KU

Kiril Urbonas

Founder & Chief Editor

605 articles
View all articles by Kiril Urbonas

You might have missed

Evergreen posts worth revisiting.