Home/Docs/Architecture Decision Records/ADR-0017: Auth Runtime Postures and Signed Project Binding

ADR-0017: Auth Runtime Postures and Signed Project BindingπŸ”—

StatusπŸ”—

Accepted

ContextπŸ”—

ContextUnity supports local and production deployments with and without Shield. The selected verifier and the signed project binding jointly determine request authority. A token kid selects verifier material; it does not supply semantic project authority before signature verification.

The platform must support local and production deployment both with and without Shield. These are four concrete runtime postures, not one dev|enterprise switch. Multi-project cryptographic isolation without Shield is not a product requirement: a no-Shield deployment intentionally forms one shared HMAC trust domain. At the same time, no missing or nullable project value may become a wildcard or skip a project authorization check.

Local development also needs bounded convenience. The local platform owns the HMAC root and can refresh a missing or expired local operator profile through the local auth flow.

DecisionπŸ”—

Four explicit runtime posturesπŸ”—

ContextUnity resolves one closed runtime posture from the deployment environment (local or production) and Shield enablement (disabled or enabled):

PostureAccepted authorityProject isolation claim
Local without ShieldCU_PLATFORM_SECRET HMAC for local platform/operator and project/service tokensNone between projects in the shared local trust domain
Local with ShieldCU_PLATFORM_SECRET HMAC only for explicitly local platform-operator surfaces; Shield session tokens for project-bound runtimeShield keys isolate project-bound runtime; local platform authority remains separately gated
Production without ShieldCU_PLATFORM_SECRET HMAC for the operator-owned deployment trust domainNone between projects sharing the platform secret
Production with ShieldCU_PROJECT_SECRET only for project-to-Shield bootstrap; Shield-issued Ed25519 sessions for ordinary protected RPCsProject-bound runtime is isolated by Shield project keys and policy

Local/production controls automation and compatibility strictness. Shield enablement controls project-runtime authority. A failed Shield/session check never retries with HMAC, and a failed HMAC check never retries through Shield. Local with Shield may admit both credential families only through an explicit policy that binds each family to its declared surface; token shape or failure cannot select a fallback.

No operator HMAC keyring is introduced. A production no-Shield process may serve more than one manifest project, but every holder of CU_PLATFORM_SECRET belongs to the same trust domain and can mint for that domain. Signed project binding still provides request integrity and exact Router registration matching; it does not create isolation from another holder of the shared root.

Project identity and signed token bindingπŸ”—

manifest.project.id remains the required, non-empty canonical registration and Router routing identity. It is never projected into a local project-id environment variable.

The signed token contract uses a closed project binding:

ProjectBinding = ProjectBound(project_id: non-empty string)
               | PlatformBound

If the wire representation uses project_id: null for PlatformBound, the signed discriminator is still mandatory. A missing binding, an unknown binding kind, a ProjectBound value with a null project, or a legacy token with no binding is not PlatformBound and fails closed unless an explicitly bounded legacy project-token migration rule applies.

The authorization rules are:

  1. unverified kid may select only a bounded verifier candidate;
  2. signature verification completes before semantic project authority is read;
  3. a project-bound operation declares its required project and requires an exact ProjectBound.project_id match;
  4. PlatformBound is admitted only when the token was verified by the platform authority and the target operation is explicitly declared platform-scoped;
  5. a missing required project on a project-bound handler is configuration or authentication failure, not an implicit platform operation;
  6. admin:all expands tenant scope only where authorized; it never overrides project binding;
  7. Router registration requires the verified token project to equal manifest.project.id.

The composite kid retains its project prefix as a lookup hint. Minted tokens carry the signed binding, and verifiers compare the hint/key ownership with it after verification. A legacy token without the binding is admitted only by the code-owned LEGACY_PROJECT_BINDING_MIGRATION_ENABLED compatibility gate as a project-bound token derived from its existing verifier/key relationship; it is never upgraded to PlatformBound. Making kid globally opaque is deferred.

Secret ownership and migrationπŸ”—

CU_PLATFORM_SECRET is the canonical HMAC root for both local and production no-Shield deployments and for the explicitly local platform-operator path in Local with Shield. It is not serialized into manifests, tokens, registration bundles, logs, traces, UDB, or audit payloads.

CU_PROJECT_SECRET is the per-project bootstrap credential used to request a Shield session. It is not a verifier fallback for ordinary Router, Brain, Worker, Forge, or Shield protected RPCs.

For one bounded migration window, a no-Shield posture may use CU_PROJECT_SECRET as the legacy alias only when CU_PLATFORM_SECRET is absent, and must emit a deprecation warning. If both are configured with conflicting values, resolution fails with a configuration error. In a Shield posture, CU_PROJECT_SECRET retains only its bootstrap meaning.

CU_PLATFORM remains execution/observability metadata. CU_LOCAL_PROJECT_ID is not introduced.

Shield's own verifier pathπŸ”—

Shield verifies project sessions directly from its local project public-key database. Bootstrap and project-policy endpoints that already own their DB-backed HMAC/admin-token checks continue to bypass the generic interceptor. Shield does not use SHIELD_MASTER_KEY as a generic bearer-token verifier.

SHIELD_MASTER_KEY itself remains Shield's encryption-at-rest key for private keys, secrets, and policy records. It is not a generic bearer-signing secret.

Service-to-Shield token propagationπŸ”—

When an intermediate execution engine (such as Router) invokes Shield on behalf of an authenticated caller (e.g. to fetch model secrets or perform firewall checks), Router propagates the verified caller token directly as its Authorization bearer. Intermediate engines must not re-mint or re-sign caller tokens with their own service identity. Autonomous service-token minting is strictly restricted to internal background routines where no ingress caller context exists.

Domain authority boundariesπŸ”—

Business applications and domain endpoints evaluate caller authority strictly via capability-based RBAC (permissions) and tenant boundaries (allowed_tenants).

Domain services and business APIs must never restrict access based on internal service topology or caller project provenance. Authenticated callersβ€”whether users, service accounts, host platforms, or external connectorsβ€”are authorized solely by their verified permissions and tenant scope. Internal project binding is an infrastructure concern enforced exclusively at service mesh registration and knowledge graph isolation boundaries, never at domain application gates.

Local operator ergonomicsπŸ”—

contextunity local init performs the one-time local bootstrap:

  • create or preserve the local configuration;
  • generate CU_PLATFORM_SECRET only when it is absent;
  • merge it into the existing local .env without replacing unrelated values;
  • keep the local secret file owner-only (0600);
  • mint and store the default local platform-operator profile.

contextunity local up calls the idempotent local auth readiness path. A valid profile is reused; a missing, expired, or current-secret-invalid profile is automatically reminted. Auto-mint is allowed only in local mode for loopback/local targets. Production and remote targets never auto-mint.

contextunity local auth login remains available for scoped tenants, named profiles, explicit rotation/recovery, and diagnostics. Normal local startup does not require it.

Alternatives consideredπŸ”—

Derive project authority from kidπŸ”—

Rejected. kid is needed for bounded key lookup and rotation, but it is not a signed semantic claim before verification and must not become the request's project authority by itself.

Treat project_id = null as global/platform accessπŸ”—

Rejected. Null is ambiguous with missing legacy or malformed data and creates a fail-open seam. Platform authority requires an explicit signed binding variant, the platform verifier, and an explicitly platform-scoped operation.

Add an operator-owned per-project HMAC keyringπŸ”—

Rejected. ContextUnity makes no multi-project isolation claim without Shield. The keyring would add configuration, rotation, lookup, and test burden without a required product property. Deployments requiring project isolation use Shield.

Keep manual local login as a mandatory startup prerequisiteπŸ”—

Rejected. Local startup already owns the platform secret and target. Automatic bounded renewal removes repeated ceremony without weakening remote or production authentication.

Use SHIELD_MASTER_KEY as a system HMAC rootπŸ”—

Rejected. It conflates database encryption-at-rest with bearer verification and has no production minter/caller in the current repository.

ConsequencesπŸ”—

  • The signed ContextToken binding is consumed by minting, serialization, verification, auth context, registration, and project-bound service callers.
  • Project-bound handlers must declare and test exact project requirements. Missing project evidence and PlatformBound on those handlers reject before tenant or permission-sensitive code.
  • No-Shield project ids remain useful for routing, registration matching, and audit correlation but do not imply isolation inside the shared HMAC domain.
  • Local with Shield has a deliberately explicit dual-authority policy: local platform operator HMAC for local operator surfaces, Shield sessions for project runtime, and no cross-family fallback.
  • Secret-name compatibility is temporary and posture-bounded. Shield bootstrap semantics are never inferred from the no-Shield alias.
  • Local bearer TTLs can remain bounded because startup renews them automatically.

Non-goalsπŸ”—

  • Multi-project cryptographic isolation without Shield.
  • A per-project HMAC keyring or project-controlled verifier configuration.
  • Making kid globally opaque in the same migration.
  • Adding a project security.mode, generic dev|oss|enterprise flag, auth service, OIDC/SAML, or new MCP login surface.
  • Changing tenant-selector payload contracts, Shield prompt namespaces, Redis security, mTLS service roles, or certificate lifecycle.