When multi-hop services or AI agents must narrow a user's permissions without calling the Identity Provider on every hop, use offline-attenuated capability tokens (Biscuit or Macaroons) so callers can append restrictions cryptographically without being able to strip them.
TL;DR30-second simplified summary▾
When Service A calls Service B and passes along the user's bearer JWT, Service B inherits the exact same broad permissions as Service A—even if Service B only needed read-only access to one folder for 30 seconds. Narrowing a traditional JWT requires an online round-trip to the Identity Provider (token exchange), adding latency and turning the IdP into a runtime single point of failure.
Decentralized capability tokens—Macaroons (symmetric HMAC chaining) and Biscuit (asymmetric Ed25519 + Datalog policies)—solve this with offline attenuation. Any holder of a token can append a new restriction (caveat, such as op=read or exp < now + 60s) without contacting the issuer. Because each caveat is cryptographically chained into the signature, stripping a caveat invalidates the token, while appending a caveat strictly narrows what the token can do.
The key architectural choice is symmetric vs. asymmetric verification: Macaroons verify fast with HMAC-SHA256 but require sharing a secret with the verifier, whereas Biscuit uses Ed25519 public-key verification so any microservice can verify attenuated tokens locally.
Why Forwarding Static Bearer JWTs Creates Confused Deputies.
Why this matters: Show how forwarding an un-narrowed JWT across microservices or AI agents leaks broad authority and why online IdP token exchange bottlenecks.
Suppose Alice logs in and gets a bearer JWT with scope: bucket:prod:rw valid for 1 hour. She asks Service A to generate a PDF report; Service A forwards her JWT to Service B (an untrusted PDF renderer), which only needs to read /reports/alice.csv.
Because a JWT's RSA/EdDSA signature covers a fixed payload signed by the Identity Provider (IdP), Service A cannot edit the JWT to say read-only or prefix=/reports. If Service B is compromised—or tricked via SSRF—it holds Alice's full bucket:prod:rw key.
The naive fix is OAuth2 On-Behalf-Of Token Exchange: Service A calls the IdP before calling Service B to mint a narrower JWT. At 50,000 internal RPCs/sec across 5 hops, that adds 5 synchronous IdP round-trips per request and turns the IdP into a global SPOF.
Static JWT Forwarding vs. Offline Token Attenuation
Offline attenuation restricts downstream services to least privilege without contacting the Identity Provider.
HMAC Chaining (Macaroons) vs. Ed25519 + Datalog (Biscuit).
Why this matters: Compare how Macaroons and Biscuit bind caveats cryptographically so anyone can add restrictions offline but nobody can remove them.
Macaroons chain HMAC-SHA256 tags: the issuer computes . To add caveat , Service A computes and ships (id, [c1], t1)—discarding . Because SHA-256 is one-way, Service B cannot invert back to to drop , yet the storage verifier (which knows ) can recompute the chain.
Biscuit solves Macaroons' shared-secret limitation using asymmetric Ed25519 block chaining plus a tiny embedded Datalog logic engine. The issuer signs Block 0 with its private root key; anyone can append Block 1 (carrying check if operation == "read") signed with an ephemeral keypair baked into the chain. Downstream services verify the entire chain using only the issuer's public key.
How Biscuit Blocks Chain Ed25519 Signatures & Datalog Caveats
Each appended block narrows authority cryptographically; removing any block breaks the signature chain.
| Choice | What it buys | What it costs |
|---|---|---|
| Static JWT (OAuth2) | Stateless public-key verify; universal library support. | Cannot attenuate offline; broad scope leaks across multi-hop calls. |
| Macaroons (HMAC Chain) | Ultra-fast symmetric HMAC (~1 us); tiny wire size; offline attenuation. | Verifier must share symmetric root secret with issuer (harder across org boundaries). |
| Biscuit (Ed25519 + Datalog) | Asymmetric public-key verify + expressive Datalog policies + offline attenuation. | Larger token (~300–800B) and Ed25519 verify cost (~50–100 us per block). |
Enforcing Monotonic Attenuation & Fail-Closed Caveat Verification.
Why this matters: Implement a deterministic caveat-chain verifier that rejects stripped caveats, expired tokens, and unmet Datalog predicates.
The core security invariant is monotonic attenuation: a derived token's allowed action set must always be a subset of its parent's.
import hashlib, hmac
class MacaroonVerifier:
def __init__(self, root_key: bytes) -> None:
if len(root_key) < 32:
raise ValueError('Root key must be >= 32 bytes')
self.root_key = root_key
def attenuate(self, tag: bytes, caveat: str) -> bytes:
if not caveat or '=' not in caveat:
raise ValueError('Caveat must be non-empty key=val')
return hmac.new(tag, caveat.encode(), hashlib.sha256).digest()
def verify(self, token_id: str, caveats: list[str], presented_tag: bytes, ctx: dict) -> bool:
tag = hmac.new(self.root_key, token_id.encode(), hashlib.sha256).digest()
for cav in caveats:
tag = hmac.new(tag, cav.encode(), hashlib.sha256).digest()
if not hmac.compare_digest(tag, presented_tag):
return False # Tampered or stripped caveat
return all(self._check_caveat(c, ctx) for c in caveats)
def _check_caveat(self, cav: str, ctx: dict) -> bool:
k, v = cav.split('=', 1)
if k == 'op':
return ctx.get('op') == v
if k == 'exp':
return int(ctx.get('now', 1 << 62)) <= int(v)
return False # Fail closed on unknown caveatCryptographic Chain Check Followed by Fail-Closed Caveat Evaluation
Constant-time signature verification plus fail-closed caveat evaluation prevents privilege escalation.
Ed25519 Verification Cost, Revocation IDs & Simulation.
Why this matters: Quantify verification CPU cost at 50K RPS and handle emergency revocation without turning every request into a DB lookup.
Verification cost scales linearly with the number of appended blocks. At ~50–100 us per Ed25519 verification on modern x86_64 cores, a 3-block Biscuit token takes ~200 us (~5,000 verifications/sec per CPU core), whereas Macaroon HMAC-SHA256 takes ~2 us.
Because capability tokens are verified offline, revoking a compromised root token before expiry requires a lightweight revocation ID per block (revocation_id = hash(block_sig)). Edge gateways hold a small Redis/in-memory revocation set (only active revoked IDs until their exp passes) rather than storing every issued token.
Interactive Visual Simulation
Offline Attenuation & Tamper Detection Flow
Auth Issuer
Root Ed25519 Key
Service A
Appends op=read
Compromised Hop
Tries Strip Caveat
Storage Verifier
Public-Key Verify
scope
prod:rw
blocks
1
idp_calls
1
When NOT to Use Capability Tokens, Assumptions & Glossary.
Why this matters: Identify workloads where OAuth2 JWTs remain simpler, document revocation assumptions, and define core terms.
When NOT to Use Macaroons or Biscuit
- Single-hop browser-to-API apps: If tokens never cross untrusted downstream services or AI agents, a short-lived standard JWT is simpler and universally supported by third-party SaaS gateways.
- Strict instant global kill-switch: Offline verification means a pushed revocation list has propagation lag (e.g., 1–5s); ultra-sensitive bank wires should pair tokens with an online session check.
Assumptions & Limitations
- Clock Sync: Time-based caveats (
exp < now + 60s) assume bounded NTP clock skew across services. - Datalog Guardrails: Biscuit evaluators bound Datalog execution steps/facts (
max_facts,max_iterations) to prevent adversarial tokens from triggering CPU DoS.
Concise Glossary
- Offline Attenuation: Narrowing a token's permissions locally by appending cryptographic restrictions without contacting the issuer.
- Caveat: A predicate/restriction attached to a token (e.g., read-only, path prefix, expiry) that must hold at verification time.
- Confused Deputy: A privileged service tricked into misusing its broad authority on behalf of a less-trusted caller.
- Macaroon: Capability token using chained symmetric HMAC-SHA256 signatures.
- Biscuit: Capability token using asymmetric Ed25519 signature chains and a bounded Datalog policy engine.
An autonomous AI agent needs to delegate a 30-second read-only task on /reports/q4.csv to a third-party sandboxed tool worker without calling the central IdP. Which token design fits best?
Practice: Make the trade-off yourself.
Why can't Service A simply edit a standard JWT's `scope` claim from `rw` to `read` before forwarding it to Service B?