Skip to content

Replace API keys with scoped macaroons - #275

Closed
benthecarman wants to merge 1 commit into
lightningdevkit:mainfrom
benthecarman:macaroon-alt-pr-273
Closed

Replace API keys with scoped macaroons#275
benthecarman wants to merge 1 commit into
lightningdevkit:mainfrom
benthecarman:macaroon-alt-pr-273

Conversation

@benthecarman

Copy link
Copy Markdown
Collaborator

Alternative to #273 for #140. The shared API key gives every client full access. Replace it with standard v2 macaroons so applications can receive scoped, independently revocable credentials and add restrictions locally.

The implementation supports first-party permission, RPC-method, and expiry caveats. Every caveat must pass; permission sets intersect, and API-issued children inherit the caller's caveats. Root keys stay in private server files. The CLI and MCP expose creation, listing, revocation, and effective permissions; attenuate-macaroon works offline.

No dependencies were added. The shared v2 codec uses the server and client's existing HMAC implementations, with constant-time verification through ring. Checked-in vectors come from pymacaroons 0.13.0, which also verified output from the Rust CLI.

Behavior to review:

  • This replaces x-auth signing with the macaroon bearer header over TLS. Clients must upgrade and use the new credentials. There is no per-request signature or replay protection.
  • Revoking a root ID invalidates its locally attenuated copies. Credentials created through the API have independent IDs and inherit caveats, but do not inherit later revocation of their issuer.
  • Expiry and revocation apply to new requests and subscriptions. Existing event streams remain open, as in Add scoped API key permissions #273.
  • Third-party caveats and unknown conditions are rejected. Tokens are limited to 4096 binary bytes and 32 caveats.

Validation:

  • Workspace tests with default and all features.
  • Full end-to-end suite: 9 configuration tests, 51 server/CLI tests, and 4 MCP tests. Rechecked the two macaroon lifecycle tests after the final bootstrap-file change.
  • Rust 1.85 Clippy with all features and warnings denied, using the repository's documented lint options.
  • Nightly formatting check and regenerated protobuf types.

AI assistance: OpenAI Codex.

Use standard v2 macaroons so clients can restrict permissions, RPC
methods, and expiry without access to server root keys. Support separate
credentials with independent revocation through gRPC, the CLI, and MCP.
Carry caller restrictions into newly issued credentials to prevent
privilege escalation.

Replace request HMAC headers with bearer macaroons over TLS. Clients
must use the new credentials; existing event streams retain admission-
time authorization. Add reference vectors and tests for token parsing,
attenuation, persistence, and live authentication.

AI assistance: OpenAI Codex.
@ldk-reviews-bot

Copy link
Copy Markdown

👋 Hi! I see this is a draft PR.
I'll wait to assign reviewers until you mark it as ready for review.
Just convert it out of draft status when you're ready for review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants