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 #83Data Facts

nandha-datafacts-verifier: Delegatable capability tokens …

Problem #4: Delegatable Auth (True Macaroon-style Capability Tokens)

Author

anilchowdary07 avatar

@anilchowdary07

github profile →
Status
In review
Opened on
Jul 7
Branch
hackathon/nandha-datafacts-verifier

Description

The pitch.

Problem #4: Delegatable Auth (True Macaroon-style Capability Tokens)

This PR introduces an enterprise-grade delegatable capability auth plugin, moving beyond naive delegation to implement a mathematically robust, adversarial-resistant distributed token system.

Architecture Context & Prior Art (#138)
While I submitted this architecture early in the hackathon, I see that PR #138 was recently merged to provide a baseline solution for Problem 04. This PR (#83) remains highly differentiated and pushes the architecture further for high-security environments by introducing Epoch Fencing and strict Resource Binding. Rather than relying on simple TTL expiration like the merged baseline, this implementation introduces a hard cryptographic boundary across epochs, preventing cross-epoch delegation propagation entirely. It also scopes capabilities directly to specific resources via the authorize() resource guard. This introduces a far more robust security posture against persistent threats, supported by the validate_delegation_epoch_fence adversarial validator.

Security Posture vs. Eventual Consistency Alternatives
While other submissions may explore eventual consistency models (such as G-Set CRDTs) for partition tolerance, this architecture explicitly rejects that approach for high-security environments. CRDT-based revocations inherently fail-open during network partitions—meaning a disconnected node will blindly accept revoked tokens until it merges gossip state. By implementing Monotonic Epoch Fencing, this PR intentionally trades eventual consistency for strict security boundaries, ensuring verifiers fail-closed (RevocationViewStaleError) when partitioned. This defensive posture is critical for true capability tokens.

Key Features
Offline Attenuation (delegate API): Implements delegate(parent_token, audience, scopes_subset, ttl) with strict bounds checking. Child tokens are cryptographically signed using their parent's signature as the HMAC key, allowing intermediaries to securely attenuate permissions entirely offline.
O(1) Cascading Transitive Revocation: Eliminates slow recursive database lookups. By anchoring tokens to a cryptographic _chain_hash accumulator, revoking any parent instantly and mathematically invalidates all descendants in O(1) time during verification.
Monotonic Epoch Fencing (Partition Tolerance): Added a global epoch clock to the RevocationStore. If an agent is cut off by a network partition and its view becomes too stale, verify() enforces fail-closed semantics by raising a RevocationViewStaleError.
Adversarial Hardening (Resource Guards): Implemented an authorize() resource guard to actively block Confused Deputy vulnerabilities.
Rigorous Adversarial Validation: Overhauled test_delegatable_auth.py, test_validators.py, and the delegated_auth.py scenario to explicitly simulate and trap 5 attack vectors: Scope Escalation, Stale Parent, Audience Confusion, Confused Deputy, and Epoch Fence Bypasses.
Passes CI locally: 100% test pass rate. Verified against make ci-local (uv sync, ruff format/check, pyright, pytest) with zero linting or type errors.

Try it

Open PR on GitHubView diff

Checkout locally

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