Repository navigation
integration-proxy: persistent DID-bound connections, signed requests and capabilities (candidate for #54) - #72
Closed
michielbdejong wants to merge 1 commit into
Closed
michielbdejong wants to merge 1 commit into
michielbdejong wants to merge 1 commit into
Conversation
…ure and capability auth Before this change, a rotating connection code was the only place a grant lived, so idleness, a lost response, a second tab or a second device each cost the user a new OAuth flow. This implements #40 items A, B and C on top of #42's 30-day code lifetime. A: a `connections` table holds each grant: a random connection_id, platform, tenant, owning user_id, and the sealed credential with its AAD bound to the row. A row is created at /connect/redeem, which now also returns `connection_id`. Codes minted before this change are migrated into a row on first use. From then on a code seals only a pointer to its row, so the credential has a single server-side copy. Rows expire after 90 days (CONNECTION_IDLE_DAYS) without an authenticated request. The successor code is minted as soon as a request authenticates, so a refused path, a failed refresh or an upstream error no longer costs the connection. Concurrent refreshes are serialized by a lease column, so a rotating refresh token is never spent twice. B: when user_id is did:ad:agent:{pubkey}, the holder of that Ed25519 key can sign a single request instead of presenting a code. The signature covers the connection, method, path+query, timestamp and body digest. It is sent in X-Connection-Id/-Timestamp/-Signature, must fall within ±5 minutes, and is accepted once (recorded in used_challenges). The DID carries its own key, so nothing is resolved or pinned. C: the key holder can also sign a capability {v, connection_id, platform, exp}, presented as `Authorization: Capability <payload>.<sig>`. It can be reused until exp, and the proxy refuses capabilities that live longer than 15 minutes. It is minted client-side, as proposed in HANDOFF-proxy-capabilities.md; the proxy has no minting endpoint. Both signed formats are domain-separated from each other and from Atomic's "{subject} {timestamp}" auth message. Neither rotates anything. Not included, and left open for the maintainer: per-connection revocation, proof of DID possession at connect time, and the idle and lifetime numbers. SECURITY.md and README document the format and the limits. Refs #40 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Being reworked for the interim #54 decision on a new branch, |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #40
Refs #54
Draft. Do not merge. This is the candidate implementation for the auth re-design discussion in #54. The design decisions listed below are still open there.
Why
Today the rotating connection code is the only place a grant lives. It is a single-use bearer token held in one browser, so a lost response, a second tab or a second device each cost the user a fresh OAuth flow. #42 fixed the ten-minute idle loss. This PR fixes the rest by separating grant durability from how a caller authenticates.
Design
A. Persistent
connectionstable. Each row holds a random 43-characterconnection_id, the platform, tenant, owninguser_id(the DID), and the sealed credential. The row is encrypted with XChaCha20-Poly1305, with associated data naming itsconnection_id, so envelopes cannot be swapped between rows./connect/redeemcreates the row and now also returnsconnection_id. The field is additive and not a secret.CONNECTION_IDLE_DAYS) without an authenticated request. Knowing an id does not keep a row alive.refresh_lease_until, 30 s). The winner refreshes and the others wait for its result. A provider that rotates refresh tokens, or detects their reuse, never sees the same one twice.X-Connection-Id.B. Signed requests.
did:ad:agent:{pubkey}contains its own Ed25519 key, so the proxy resolves nothing and pins nothing. A new key is a new DID and needs a new connection.X-Connection-Id,X-Connection-Timestamp(Unix ms) andX-Connection-Signature. The signature is over:used_challenges.C. Capabilities. The key holder signs
{"v":1,"connection_id","platform","exp"}with the domain prefixintegration-proxy-capability-v1\n. A caller that cannot hold the key, such as a sandboxed plugin frame, presents it asAuthorization: Capability <payload>.<sig>.exp. The proxy refuses one that expires more than 15 min ahead.401 capability expired, so the holder knows to mint a new one.integrations/HANDOFF-proxy-capabilities.md. The proxy has no minting endpoint.Both signed formats are domain-separated from each other and from Atomic's
"{subject} {timestamp}"auth message. Verification usesverify_strict, which rejects small-order keys and non-canonical signatures. Full format:integration-proxy/README.md→ "Persistent connections". Guarantees and gaps:integration-proxy/SECURITY.md→ "Persistent connections".Open decisions (tracked in #54)
DELETE /connections/{id}. TodayREVOKED_SUBJECTScan only revoke a whole tenant or DID.user_idis still the hub's unverified assertion. Security does not depend on it, because binding a grant to someone else's DID gives the binder nothing. Recommendation: optional now, required later.FrameBridge) needs only B. The handoff doc needs C.401. If a second node mints its own app DID, it needs its own connection and OAuth flow.Verification
cargo fmt --all -- --check: clean.cargo clippy --all-targets --all-features -- -D warnings: clean.cargo test -- --include-ignoredagainst a fresh localpostgres:16-alpine: 136 passed, 0 failed. It ran three times in a row after rebasing ontoorigin/main2841447 (which includes integration-proxy: a refresh token is destroyed after ten idle minutes #42 via 10c60eb), using cargo 1.98.1 and the CI fixture OAuth env vars. Plaincargo test: 107 passed, 29 ignored.src/did_auth.rscover DID parsing in both base64 alphabets, message binding and domain separation.Not verified:
@tomic/libor atomic-server client has signed against this. The test signer follows the documented format.🤖 Generated with Claude Code