A key’s day

Part 1 recap · Code

Code: the short version

Finding a key starts the work. Confirming it’s dead finishes it.

Take the full lesson Part 2 recap: People

Where the copies are

Issued by Stripe, kept in the vault, then 12 copies:

  1. Clipboard
  2. Laptop file
  3. Terminal history
  4. Settings file
  5. Commit on the laptop
  6. Git history on the code server
  7. Teammate laptop 1
  8. Teammate laptop 2
  9. Teammate laptop 3
  10. Main branch
  11. Build log
  12. Preview image

Plus any copies from the side stories: a doc, a chat, an AI chat, a ticket, and an incident channel. Code scanners can’t see these unless they’re connected.

The day, step by step

  1. Mission · 8:45 AM A developer gets a mission.
  2. Secrets Secrets let software prove who it is.
  3. SDLC Every change goes around a loop.
  4. Laptop · 9:20 AM Copied to a laptop.
  5. Terminal · 9:35 AM Pasted in to test it quickly.
  6. Editor · 10:10 AM Hardcoded to save time.
  7. Commit and push · 10:50 AM Two checks, both switched off.
  8. Shared and approved · 11:30 AM Shared with the team, approved in review.
  9. Git history · 2:05 PM Deleted, but still working.
  10. Pipeline · 2:12 PM The build copies it again.
  11. Detect · 4:40 PM TruffleHog finds the copies.
  12. Verify · 4:45 PM Is it still live?
  13. Analyze · 4:55 PM What can it reach?
  14. Notify · 5:10 PM The right owner gets the alert.
  15. Rotate · 6:05 PM Swap in a new key.
  16. Confirm · 6:20 PM Confirmed: the old key is dead.

How it ended

Swap in a new key. Every step before this found the problem. This step removes it.

Confirmed: the old key is dead. The leftover copies are harmless now, because their key is off.

Try it with TruffleHog open source

Install TruffleHog first; its README lists the options. Run these only on folders, images and buckets you’re allowed to scan.

  1. Laptop. Can scan files and folders on the laptop when someone runs it.

    trufflehog filesystem ./billing
  2. On the laptop: the pre-commit hook. Runs as a pre-commit hook through native Git hooks, the pre-commit framework, or Husky.

    trufflehog git file://. --since-commit HEAD --results=verified,unknown --fail --trust-local-git-config
  3. On the code server: the push check. Runs as a pre-receive hook on self-hosted code servers that allow server hooks, such as GitHub Enterprise Server and GitLab Self-Managed.

    trufflehog git file://. --bare --results=verified --fail
  4. On the pull request: the CI check. The official GitHub Action scans the commits in the push or the pull request range and fails the job when a key is found.

    trufflehog git file://. --since-commit main --branch HEAD --results=verified,unknown --fail
  5. Git history. Scans every commit still reachable from a branch or tag, including commit messages, so a deleted line is still found.

    trufflehog git file://.
  6. Pipeline. Two different jobs. In the pipeline, open source checks the change and can fail the build, with a ready-made GitHub Action, a documented GitLab CI job, or one command in any other CI tool.

    trufflehog docker --image example/billing:preview
  7. Analyze. Shows detailed permissions for about 20 of the most commonly leaked key types.

    trufflehog analyze

Keep going