Skip to content

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 Basic credentials;
  • a canary value or host (hosts in any letter case) in what leaves the VM through catchpen:
  • the commits that pull, pr and 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

  1. The request or export is refused. A notification is sent with the offending text withheld.
  2. canary.hit is 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).
  3. The VM is dealt with according to canary_action in config.yaml:
canary_action: pause    # default; or stop, or log
  • pause freezes the VM as it was, for inspection. catchpen ls shows it paused, and ssh, run, attach and the like refuse it until you run catchpen resume <name>, which also sets the guest clock. If the VM can't be paused (QEMU's control socket is busy, as during catchpen snapshot), it is stopped instead.
  • stop powers it off at once.
  • log only 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_action did: 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 cancel and task rm fail 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 ls as canary hit, until you destroy it or run catchpen 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

  1. Look at what triggered it: catchpen audit <name> shows the hit, and catchpen egress log <name> shows the surrounding requests.
  2. Inspect the paused VM before resuming it. catchpen snapshot <name> keeps its memory and disk for later analysis, and recordings are in catchpen recordings <name>. catchpen transcripts refuses a paused VM; copies made earlier are in ~/.local/share/catchpen/transcripts/<name>/.
  3. Then catchpen resume <name> to continue, or catchpen destroy <name>. A resumed VM keeps the hit: reset, rebase and a disk-only restore refuse 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 Basic credentials are base64-decoded, so a value percent- or base64-encoded in another header or a Bearer token 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's fetch). Their connections just fail.
  • Network use in VMs with egress: open or egress: none. Their exports, notifications and task results are still scanned, and so are cache requests in open VMs.
  • catchpen cp and catchpen 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.