- Added native Deno WebCrypto Ed25519 signature verification middleware for headless edge workloads. - Integrated dual authentication path to `/api/forward-auth` processing signatures and session cookies. - Added dual storage Admin Management routes (`/api/admin/hwk`) securely inserting directly to PostgreSQL and pushing to $O(1)$ Valkey verification set. - Completed all quality gates checks and hermetic mocked tests successfully. Co-authored-by: mrteye <1945243+mrteye@users.noreply.github.com>
4.7 KiB
4.7 KiB
TASK METADATA
- Target Files:
server/http_signatures.ts(New module)server/main.ts(Update/api/forward-authand add admin routes)server/valkey.ts(Ensure SISMEMBER helper exists or is exposed)
- Core Objective: Implement RFC 9421 HTTP Message Signatures verification middleware using native Deno Ed25519 for headless daemons and edge nodes.
- Dependencies: Deno 2.x native
crypto.subtle(Ed25519 support), Valkey access for fingerprint sets. - Additional Important Notes: Must support dual-auth in
/api/forward-auth(Session OR Signature). Verification must complete in <5 microseconds (mostlyO(1)Valkey lookup). TheSignature-Keyuses thehwkparameter via draft-hardt-httpbis-signature-key containing an OKP JWK inline.
Architectural Considerations & Risks
Risks
- Replay Attacks: If the
nonceand strict $\pm 30$s timestamp drift (created/expires) are not strictly validated, attackers could replay intercepted signed requests. - Valkey Exhaustion/Availability: Relying on Valkey for sub-5 microsecond fingerprint checks is fast but introduces a hard dependency on Valkey availability for edge authentication. If Valkey is down, headless clients cannot authenticate.
- Parsing Overhead: Parsing complex
Signature-Inputand canonicalizing HTTP components according to RFC 9421 can be CPU intensive. The implementation must be heavily optimized to avoid DoS vectors. - Header Size Limits: Including raw JWKs in headers (
hwk) increases header size, potentially hitting proxy limits if not managed carefully.
Alternatives Evaluated
- mTLS (Mutual TLS): We already use mTLS/SPIFFE internally (via
spire_ffi.ts). However, for edge nodes/IoT devices traversing multiple proxies or load balancers, HTTP Message Signatures provide application-layer end-to-end integrity that survives TLS termination, making it the superior choice for this specific headless use case. - External NPM Packages: Libraries like
@peertube/http-signatureexist, but adhering to the zero-dependency SDK/pure Deno backend policy dictates a native WebCrypto approach, which is cleaner and guarantees compatibility with Deno 2.x.
Proposed Implementation
Phase 1: Core Cryptography and Parsing (server/http_signatures.ts)
- Create
server/http_signatures.ts. - Implement parsing logic for RFC 9421
Signature-InputandSignatureheaders. - Extract the inline
hwk(Header Web Key) JSON Web Key (JWK) parameter. Ensure it is of typekty="OKP"andcrv="Ed25519". - Generate the SHA-256 fingerprint of the
hwkobject or public key bytes. - Build the Canonical Signature Base string using the requested components
(
@method,@authority,@path,content-digest,created,expires,nonce). - Validate timestamps (
created,expires) with a strict\pm 30seconds drift tolerance against the server's current time. - Use Deno's native
crypto.subtle.importKeyandcrypto.subtle.verify({ name: "Ed25519" })to validate the digital signature.
Phase 2: Valkey Integration & Middleware Export (server/http_signatures.ts)
- Integrate the
O(1)Valkey authorized fingerprint set check. - Query
SISMEMBER auth:hwk:fingerprints <sha256_fingerprint>. If the result is0, deny access immediately. - Wrap this logic into an exportable Hono middleware or helper function
(
verifyHttpSignature).
Phase 3: Route Integration (server/main.ts)
- Modify
/api/forward-auth:- Inspect headers for either a valid Session Cookie OR
Signature/Signature-Inputheaders. - If signature headers exist, invoke
verifyHttpSignature. - If valid, treat the request as authenticated (resolve the app context similarly to the session-based flow). Ensure scopes/roles can be inferred, possibly by mapping the fingerprint to a specific service account or app grant in the DB if necessary (or relying on a default edge role).
- Inspect headers for either a valid Session Cookie OR
- Implement Admin Management Routes:
POST /api/admin/hwk: Accept a public key / JWK, generate its fingerprint, and add it toauth:hwk:fingerprintsusing ValkeySADD.DELETE /api/admin/hwk/:fingerprint: Remove a fingerprint using ValkeySREM.- Protect these routes using the existing global admin middleware.
Phase 4: Testing & Quality Gates
- Write hermetic tests simulating a headless client generating an RFC 9421 signature and submitting it.
- Mock Valkey responses to test authorized vs unauthorized fingerprint checks.
- Validate Deno native Ed25519 verification against a known good signature payload.
- Run
deno fmt,deno task lint,deno task check, anddeno task test.