Canaries¶
Canaries are decoy credentials planted in a VM. Nothing in the VM uses them, so any use of one means something went looking for credentials and tried to send them out.
Turning them on¶
Each kind is a section of canaries.yaml: aws-canary, env-canary and git-canary.
The default plants all three; -name drops one:
catchpen up dev -t -aws-canary # env and git only
catchpen up dev -t -aws-canary,-env-canary,-git-canary # none
The built-in minimal profile has none. Each VM gets its own values, pointing at hosts
that exist nowhere:
| Kind | Planted in the agent user's home |
|---|---|
aws |
~/.aws/credentials, and an endpoint_url in ~/.aws/config. Left out when the VM's env: sets any AWS_* variable. |
env |
~/.env.production, with a database URL, an API URL and token, and a Stripe-style key. |
git |
~/.git-credentials. |
The host keeps each VM's values in vms/<name>/canaries.json.
What counts as a hit¶
- a connection to a canary host through the egress proxy, allowlisted or not;
- a canary value in the name of a host the VM connects to through the egress proxy, in any letter case (host names ignore case) and split by dots or hyphens; that name is kept out of the egress log, the audit log and notifications;
- a canary value in a plain-HTTP request's line or headers (not its body), or in a
package cache request, including percent-encoded in the URL, in URL user info and in
Basiccredentials; - a canary value or host (hosts in any letter case) in what leaves the VM through catchpen:
- the commits that
pull,prand tasks bring out, including headers, author and committer, messages (as stored and as re-encoded to UTF-8), root commits, merges and binary files; - branch names;
- patches, which are made on the host from the commits they export, scanned first;
- a PR's title and body;
- a task's whole result (
catchpen task show, its PR body and notifications) and an agent's notification text; - an API job's progress lines and error (
GET /v1/jobs): once one carries a decoy, all of them are withheld, and the hit is acted on at once. A decoy split across two adjacent lines (or the last line and the error) is found; one split across more, with other text between its halves, or over lines a client read before the second half came, is not. A hit on a VM destroyed by then is audited and notified, with nothing to act on.
What happens on a hit¶
- The request or export is refused. A notification is sent with the offending text withheld.
canary.hitis written to the audit log and sent to notifications, each at most a few times per minute. The audit record comes before step 3, the notification after it (it says what was done).- The VM is dealt with according to
canary_actioninconfig.yaml:
canary_action: pause # default; or stop, or log
pausefreezes the VM as it was, for inspection.catchpen lsshows itpaused, andssh,run,attachand the like refuse it until you runcatchpen resume <name>, which also sets the guest clock. If the VM can't be paused (QEMU's control socket is busy, as duringcatchpen snapshot), it is stopped instead.stoppowers it off at once.logonly records the hit.
Tasks and the pool react on top of that:
- A task whose VM is paused fails at once.
- A task VM with any canary hit by the time it stops, while its transcripts are copied
included, is kept for inspection, whatever
canary_actiondid: as the hit left it, or stopped if the hit came as the task's teardown was stopping it. So is a lost task's (its supervisor gone):catchpen task cancelandtask rmfail rather than destroy it, and stop it unless the hit paused it. While it runs (paused included), it counts against the task budget (tasks.max_vms,tasks.max_memory). - A pool VM with a hit is never handed out, nor counted in the pool: it's kept for
inspection, shown in
catchpen pool lsascanary hit, until you destroy it or runcatchpen pool drain.
If a VM's canaries.json can't be read, or isn't as catchpen wrote it, its proxy, cache
and exports refuse everything, and its notifications, task results and API job output
are withheld.
Responding to a hit¶
- Look at what triggered it:
catchpen audit <name>shows the hit, andcatchpen egress log <name>shows the surrounding requests. - Inspect the paused VM before resuming it.
catchpen snapshot <name>keeps its memory and disk for later analysis, and recordings are incatchpen recordings <name>.catchpen transcriptsrefuses a paused VM; copies made earlier are in~/.local/share/catchpen/transcripts/<name>/. - Then
catchpen resume <name>to continue, orcatchpen destroy <name>. A resumed VM keeps the hit:reset,rebaseand a disk-onlyrestorerefuse it until it is stopped (see snapshots.md).
What goes unseen¶
- Values sent encoded in other ways (base64 in a body, say), or over HTTPS to an
allowed host. Only the URL is percent-decoded and only
Basiccredentials are base64-decoded, so a value percent- or base64-encoded in another header or aBearertoken goes unseen. Exports are matched on the committed bytes, not decoded further, so a value the guest encoded (base64, say) in a file goes unseen too. - Clients that don't use the proxy (database drivers for the
DATABASE_URL, Node'sfetch). Their connections just fail. - Network use in VMs with
egress: openoregress: none. Their exports, notifications and task results are still scanned, and so are cache requests inopenVMs. catchpen cpandcatchpen forward.- Commits the guest pushed to a forge itself (with a deploy key or token). The host has them once it fetches them.
- A careful attacker can tell the decoys from real credentials: the hosts don't
resolve, the GitHub token's checksum is wrong, and the seed's user-data lists them, as
do cloud-init's copies of it under
/var/lib/cloud/in the guest. - If an agent prints the decoys, they end up in transcripts and recordings, where secret scanners may flag them.