Lion Cipher Lab

Build macaroons from scratch: bearer tokens anyone can narrow and no one can widen

Why it matters

Most access tokens can only be made narrower by the server that issued them. If a service holds a powerful token and wants to hand a batch job read-only access to one folder, it has to call the issuer and ask for a new token, and many teams skip that and just hand over the powerful one. Macaroons, from a 2014 Google and Chalmers paper, flip this: anyone holding a macaroon can add a restriction (a 'caveat') to it offline, in microseconds, and the result is strictly weaker. Nobody can take a restriction off, because the signature is a chain of HMACs and removing a link would mean running HMAC…

What you'll learn

Steps in this lab

  1. What you are building, and the one idea it rests on
  2. Set up a working folder
  3. Write the library: mint, attenuate, serialize, verify
  4. Mint a token and watch the chain grow
  5. The tamper matrix: try to widen your own token
  6. Delegation: service, batch job, vendor, each one narrower
  7. Where macaroons really break: the caveat language
  8. Third-party caveats: make another service vouch, then bind the proof
  9. Macaroons vs JWT vs Biscuit
  10. Judgment: what macaroons do not fix, and when to reach for them

Open the full interactive lab →