Scoped Bearer Token Auth & PII Diagnostic Redaction #35
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Implement fine-grained scoped bearer token authentication (
read,write,admin) with constant-time token comparison, stable actor identity mapping across token rotations, and comprehensive PII/credential redaction across all structured logs, tracing spans, and error diagnostic output.Background & Technical Rationale
Principle of Least Privilege: Token Scopes
The
lifeservice exposes HTTPS endpoints consumed by automated agents, background workers, and human operators. In accordance with the principle of least privilege:readScope: Allows querying agendas, listing tasks, fetching items, resolving references, searching context, and viewing timeline history. It permits read-only analytical POST requests (e.g./v1/reviews,/v1/next), but strictly rejects all state mutations.writeScope: Allows adding/updating/completing tasks and events, capturing outcomes, adding context, and generating or applying reviewed proposals. It never grants administrative or maintenance operations.adminScope: Required for system-level operations such as backend sync rebaselining (POST /v1/sync) or diagnostic inspections requiring privileged access.An agent operating in an advisory or read-only capacity must be provisioned with a
readtoken. A write token attempting an administrative action must be rejected with HTTP 403 Forbidden.Constant-Time Verification & Secret Protection
To prevent timing attacks that could reveal token characters based on comparison latency:
subtle::ConstantTimeEq).Token Rotation & Stable Actor Identity (Scenario D04)
Bearer tokens must be rotatable without disrupting in-flight operations or breaking idempotency:
actor_id: "usr_alice").life operation get <OP_ID>), the request succeeds under the new token because idempotency and operation ownership are bound to the stable actor identity, not the transient bearer token credential.Diagnostic Redaction & PII Safeguards (Scenario D03)
Diagnostic logs and tracing systems are a frequent source of accidental data exfiltration. The service and CLI must enforce strict diagnostic redaction:
Authorizationheader values, bearer tokens, or password strings..ics) VEVENT/VTODO strings or raw XML/JSON request bodies.request_id).operation_id).radicale,sqlite,hindsight,jev).invalid_input,forbidden,etag_conflict).Exact Technical References & Specifications
1. Operations Security: Authentication & Redaction
From
docs/technical/operations-security.md(lines 35–42):2. Route Scope Ownership Table
From
docs/technical/cli-api.md(lines 27–56):life agendareadlife tasks listreadlife item get IDreadlife resolvereadlife nextreadlife reviewreadlife context searchreadlife timelinereadlife proposal get IDreadlife operation get IDreadlife doctorread(readiness) / public (liveness)life task addwritelife task update IDwritelife task complete/reopen/cancel IDwritelife event addwritelife event update/cancel IDwritelife capturewritelife planwritelife replanwritelife context addwritelife proposal apply IDwritelife proposal reject IDwritelife syncadmin3. Verification Scenarios D03 & D04
From
docs/technical/verification.md(lines 136–137):Formal Citations
docs/technical/operations-security.md:docs/technical/cli-api.md:unauthenticated,forbidden(lines 108–111)docs/technical/verification.md:What to Build
1. Token Verification & Scope Middleware (
src/api/auth.rs)Implement the Axum authentication layer:
Scopeenum:Read,Write,Adminwith hierarchy checks: Note:Admindoes not automatically implyWriteunless explicitly configured;Writedoes never grantAdmin.AuthenticatedActor:Authorization: Bearer <TOKEN>header.<TOKEN>.subtle::ConstantTimeEq.unauthenticated.forbidden.2. Diagnostic Tracing & PII Redaction Layer (
src/logging/redaction.rs)Implement custom tracing subscribers / formatters using
tracing-subscriber:authorization,cookie,proxy-authorizationwith"[REDACTED]".3. Token Rotation & Idempotency Storage Integration (
src/storage/operations.rs)operationstable, associate the journaled record withactor_idrather than the raw bearer token or token digest.actor_id.4. Integration Test Suite (
tests/auth_redaction.rs)readtoken and attemptPOST /v1/tasks. Assert HTTP 403 Forbidden with error codeforbidden.writetoken and attemptPOST /v1/sync. Assert HTTP 403 Forbidden with error codeforbidden.POST /v1/tasksusing Token A (mapped tousr_alice), successfully creating a task underoperation_id: op_rot_1.usr_alice) and remove Token A.POST /v1/tasksrequest with Token B andoperation_id: op_rot_1.Acceptance Criteria
Observable Assertions & Verification
subtle::ConstantTimeEq).readtoken attempting to executePOST /v1/tasksreturn HTTP 403 Forbidden witherror.code: "forbidden"(Scenario D03).writetoken attempting to executePOST /v1/syncreturn HTTP 403 Forbidden witherror.code: "forbidden"(Scenario D03).actor_idto replay and retrieve past operations without triggering duplicate writes (Scenario D04).tests/auth_redaction.rsverify scenarios D03 and D04.Notes
auth::route_access) and the layer is applied to the whole router including the fallback; unlisted/v1routes and all non-/v1paths fail closed atadmin. OnlyGET /health/liveis public.Cargo.tomlauthors chore (Yuris Cakranegara <hello@yuris.dev>) in the same commit that added thesubtledependency, withCargo.lockcommitted.ring::constant_time::verify_slices_are_equalwas not present in the tree;src/api/pagination.rswas extended toConstantTimeEqas a straight improvement.Blocked by
Issue #035: Scoped Bearer Token Auth & PII Diagnostic Redactionto Scoped Bearer Token Auth & PII Diagnostic Redaction