Public Docker Hub images leak cloud keys that attackers use in seconds
Attackers use secrets exposed in public Docker Hub images within seconds. Here is who is at risk, what to rotate first and how to find leaked keys early.
TL;DR: Cloud keys and other secrets baked into public Docker Hub images get found and used by attackers about eight seconds after they go public. Assume any key that ever touched a public image is burned, and rotate it.
What happened
BleepingComputer reported that attackers pull credentials and access secrets out of public Docker Hub images and abuse them seconds after the image goes public, in some cases in about eight seconds. Read the original report from BleepingComputer for the full story.
The speed matters more than the number. Attackers watch new public images automatically, so the gap between pushing a mistake and someone using it is too short for a person to notice and delete it. Removing the image afterwards does not help, because a copy may already exist.
Am I affected?
You may be if any image you publish to a public registry was built from a directory that contained a key, a token, a password or a configuration file with one. Common causes are an environment file copied into the image, a key written into a build step, or a credential left in an earlier layer. A later layer that deletes the file does not remove it from the earlier one.
If you find a secret in a public image, act in this order: revoke and rotate the key first, then look at the provider's access logs for use you do not recognise, then fix the build so it cannot happen again, for example by passing secrets at runtime instead of baking them in.
How to check with Stackurity
Stackurity's agent and stackurity scan find keys, tokens and passwords written in files, including keys for AWS, GitHub and others with a recognised format, and passwords set in configuration files, so a key committed next to your Dockerfile can be found before it reaches an image. The value never leaves the machine: only the file, line, setting name, a fingerprint and a masked preview are sent. A finding has an owner and a rotate-by date, and a later complete scan shows whether the key is verified gone. Stackurity does not state that it reads secrets inside layers of images already published to a registry, so keep scanning your repositories and build directories as well. The remediation documentation explains how fixes are ordered.
Start a free trial of Stackurity to scan your repositories for leaked keys.