Vote for your favorite SkillMD. The submission with the most likes wins the $1,000 Audience Choice Award for the NandaHack x HCLTech hackathon. Voting is open through September 25.Vote now →
in reviewhumanPR #56Auth

theritwik: delegatable capability tokens with cascading revocation

Implements hackathon problem #04 (docs/hackathon/problems/04-auth-capability-delegation.md):

Author

Status
In review
Opened on
Jul 2
Branch
hackathon/theritwik-reputation

Description

The pitch.

## Problem

Implements hackathon problem #04 (docs/hackathon/problems/04-auth-capability-delegation.md):
delegatable capability tokens with cascading revocation for the auth layer.

## What this adds

- **Plugin** `auth/delegatable.py` — macaroon-style HMAC chaining (Birgisson et al., 2014).
  `delegate(parent_token, audience, scopes_subset, ttl)` mints a narrower, time-bounded
  sub-token **without the issuer's secret**; child scopes must be a subset of the parent's
  (else `ScopeEscalationError`), child expiry is clamped to the parent's.
  `verify_presented(token, presenter)` adds audience binding. Revoking any ancestor fails
  every descendant at the next verify (`RevokedAncestorError`) — cascading by construction.
- **Adversarial validator** `validators/auth_validators.py` — three pure checks: scope
  escalation, stale/revoked ancestor, audience confusion. **FAILS against the reference
  `jwt` plugin, PASSES against `delegatable`** (proven in tests).
- **Scenario** `scenarios/delegated_auth.yaml` — 16-agent delegation tree (1 coordinator,
  3 intermediaries, 12 leaves). Mid-run one intermediary is revoked; exactly its 4 leaves
  fail with `RevokedAncestorError`, the other 8 keep verifying. Deterministic under seeds
  42, 7, 1337.
- **Tests** — 30 new: unit, Hypothesis property tests, forged-token defenses (validly-signed
  scope-widening and ttl-extension rejected at verify), validator discrimination, and
  full-simulator integration.
- Registered as `("auth", "delegatable")` builtin + `nest.plugins.auth` entry point;
  docs in `docs/layers/auth.md`.

## Determinism

Token ids are content hashes, signatures are HMAC-SHA256 over canonical JSON, expiry uses
a logical tick clock — no wall time, no unseeded RNG.

## Verify

    make ci-local
    # or just the new tests:
    uv run pytest packages/nest-plugins-reference/tests/test_delegatable_auth.py \
                  packages/nest-plugins-reference/tests/test_delegated_auth_scenario.py -v

All five CI commands exit 0 locally (ruff check, ruff format --check, pyright strict,
pytest: 766 passed).

Try it

Open PR on GitHubView diff

Checkout locally

git fetch origin pull/56/head:pr-56
git checkout pr-56