One rushed docker push, with a stray .env file left in the build folder, can be enough for someone else to start using your company's AWS key before your coffee has cooled. This is not a vague warning: a newly presented experiment shows that API keys in Docker images published to public registries are harvested and used so fast that "just delete the image" almost always comes too late.
An experiment shows scanners need only seconds
According to BleepingComputer (17 November 2026), Billy Tsouvalas and Nick Nikiforakis of Stony Brook University published 300 honeypot images across eight public registries. Over four months they planted AWS, OpenAI and Anthropic keys, plus decoy SSH and database credentials, and watched who used them. The results were presented at the ACM CCS conference.
The numbers worth remembering:
- The images were pulled more than 75,000 times, and the planted AWS keys received over 140,000 API calls from about 5,000 IP addresses.
- The fastest use of an AWS key came 7.86 seconds after the image appeared on Docker Hub; the median time to first call was about 51 seconds, and all 100 AWS keys were used within 15 minutes.
- The OpenAI and Anthropic keys were hijacked quickly to drain the test accounts' balances.
The most instructive detail is how the attackers work. Almost nobody ran the containers. Scanners unpack the image layers or query the registry API to read the filesystem directly. That means a secret in any layer is exposed, even if a later layer deletes the file.
The researchers say they reported the issue to Docker in May but only received an acknowledgement, and a small re-test in August showed no new defences. Businesses should not wait for the platform to fix this for them.
Why deleting the file in a later step does not save the secret
A Docker image is an append-only stack of layers. COPY .env . creates a layer containing the file; a later RUN rm .env only adds a layer that hides it, while the original layer stays intact and extractable. Values passed through ARG or ENV remain in the image metadata. Docker even ships a build check called SecretsUsedInArgOrEnv to flag this class of mistake.
For outsourced projects the risk is higher: images are often built from individual laptops, and the product owner rarely reads the Dockerfile. One wrong push to a public repository is all it takes.
Passing keys into a build without leaving a trace
Docker's official documentation describes build secrets: the secret comes from the build client and is available only temporarily inside the build container, for the duration of the single RUN instruction that needs it, and it never lands in a layer. The example below uses a private npm token during dependency installation, with current BuildKit.
# syntax=docker/dockerfile:1
FROM node:22-slim
WORKDIR /app
COPY package.json package-lock.json ./
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc \
npm ci
COPY . .
CMD ["node", "server.js"]At build time, pass the secret from a file or environment variable on the build machine:
$ docker build --secret id=npmrc,src=$HOME/.npmrc -t myapp:latest .How it works: --secret makes the file available to the build session, and --mount=type=secret exposes it at the target path for that RUN only. Without target, the default path is /run/secrets/<id>. For environment-variable style secrets, use the env option, for example --mount=type=secret,id=aws-key-id,env=AWS_ACCESS_KEY_ID.
Runtime credentials do not belong in the image at all. Inject them through environment variables or your server's secret management when the container starts.
Auditing your existing images in 15 minutes
Your engineers can work through this list:
- List every image the company pushes to a registry and confirm which repositories are public and which are private.
- Review the command history:
docker history --no-trunc myapp:latest, looking forENV,ARG,COPY .envor any command containing a token. - Export the image and search it:
docker save myapp:latest -o myapp.tar, extract withtar -xf myapp.tar -C /tmp/img, thengrep -rIl "AKIA" /tmp/imgor search for the key prefix of the providers you use. - Check that
.dockerignoreexcludes.env,.git,*.pemand cloud config folders. - Add secret scanning to the pipeline before the push. Our post on CI/CD secrets leaks that hijacked thousands of GitHub accounts shows how a pipeline becomes the weak point when keys sit in the wrong place.
If you find a key in an image that was ever public, treat it as compromised: revoke it and issue a new one first, then clean up the image. Deleting an image does not recall a key that has already been copied. Afterwards, check provider logs (CloudTrail for AWS, usage pages for AI services) for unfamiliar calls.
Limiting the damage when a key can still leak
No process is perfect, so shrink the blast radius:
- One key per purpose, least privilege, and a spending cap on AI keys. Our article on AI API keys hunted by automated agents covers these limits in detail.
- Prefer short-lived credentials issued through roles over static keys stored in files.
- Set billing alerts so abnormal usage is noticed early.
- Make it a rule that any image containing company source code goes to a private repository by default.
The Wyndham incident, where data was exposed because a password sat inside an app, has the same root cause: secrets travelling with the product to people who should never see them.
If your team runs or commissions systems on Docker and is not sure what its images contain, start with the layer-history scan above. If you would like a second pair of eyes, take a look at the projects Besoft has delivered and get in touch to talk it through.
References
- BleepingComputer, "Cloud keys leaked in Docker Hub images are stolen within seconds", 17 November 2026: https://www.bleepingcomputer.com/news/security/cloud-keys-leaked-in-docker-hub-images-are-stolen-within-seconds/
- Docker Docs, "Build secrets": https://docs.docker.com/build/building/secrets/
- Docker Docs, "SecretsUsedInArgOrEnv": https://docs.docker.com/reference/build-checks/secrets-used-in-arg-or-env/






