Skip to content

Z5: connection-bound caller identity + identity-keyed credential resolution in static-inject #905

Closed as duplicate

Description

@cwiklik

Status (2026-10-05)

Unblocked. The harness-side prerequisite has landed in rossoctl/moca — the harness now sends a
per-request subject and carries an inert placeholder (sh-placeholder-<subject>) instead of a real
key, and placeholder mode is preferred whenever an injector is configured. What remains is entirely
Cortex-side. See the breakdown comment below for the ordered work; steps
1–4 there need nothing further from MOCA.

What this is

Give a tracked home to the deferred per-user half of Z5. This is not a new design: docs/specs/2026-06-19-m13-generalized-credentialed-egress-design.md already specifies generalized credentialed egress, and docs/specs/README.md records that RC1 implements "a static single-tenant slice of Z5 (per-user / RFC 8693 deferred)". This issue is that deferred half.

Please read Z5 and ADR-0006 as the design; this issue records the seam and the open tension rather than restating them.

Why now

rossoctl/moca (formerly rossoctl/serverless-harness) split its multi-session work (moca#220) into three slices. Two are harness-local; the third is this one, tracked on the MOCA side by the stub moca#241. The harness slice — moca#239 — makes the harness send a per-request subject and carry an inert placeholder instead of a real key. Nothing consumes that subject until static-inject can resolve a credential from it.

Until then the harness slice makes the system tenancy-neutral, not multi-tenant safe. That boundary should not be advertised as closed until this lands. MOCA's multi-user isolation design §2.4 cites this issue by number as the evidence that an unmodified Cortex cannot provide per-user egress.

Goal

ADR-0006's (subject ⊕ destination) → credential resolution. Today static-inject resolves by destination host (key_by: host) or a static key (key_by: static, ADR-0026) — one credential per deployment.

The seam

core/plugins/staticinject/resolver.go:17-22 defines:

Resolve(ctx context.Context, key string) (value string, ok bool)

implemented only by MapResolver (:28-34, tests/dev) and a secret_dir-style FileResolver (:39-59, path-contained, fails closed). Per-subject resolution makes that key identity-derived rather than destination-derived. FileResolver already maps one key to one credential file, so the resolver layer needs no change — only a new key_by mode and a source for the identity.

pipeline.Context already carries the identity: core/pipeline/context.go:26 defines an Identity interface (Subject(), ClientID(), Scopes()) and :152 holds the field, populated by whichever auth plugin ran. No plugin currently reads it.

Prior art in this repo

core/plugins/tokenbroker/plugin.go:281-294 already extracts a subject token from the inbound Authorization: Bearer header and exchanges it via client.AcquireToken. token-exchange implements RFC 8693 with a result cache. The exchange machinery exists; what is missing is static-inject keying on a caller identity.

Design tension — settled

The two plugins disagreed about which header carries the subject:

  • P5 deliberately keeps inbound Authorization free for caller authentication, carrying the placeholder on egress Authorization: Bearer <placeholder> with the subject on a separate X-SH-Subject.
  • tokenbroker expects the subject token on the hop's Authorization.

Resolution: neither — the identity must come from the connection, not the request. Keying resolution on the inbound placeholder is a privilege escalation: sh-placeholder-<subject> is predictable and arrives from a model-influenced workload, so any sandbox could present another user's placeholder and receive their real credential. Likewise static-inject's existing Placeholder field is a single literal equality gate, not a lookup key, so against per-subject placeholders it yields either 401 static-inject.placeholder-mismatch for every subject but one, or (gate unset) one shared host-keyed credential and no isolation. MOCA's invariant I3 states it directly: caller identity comes from the connection, never the request.

This is what makes items 3 and 4 of the breakdown (non-TCP listener; identity carried from a CONNECT into the requests bridged inside the tunnel) part of the same issue rather than separate conveniences.

Also missing

Beyond resolution itself, per MOCA's §2.4 capability survey: no audit event is recorded on a successful injection (Z5 specifies the shape), and Cortex listens only on TCP — a Unix-socket listener is what the owed §12.2 decision on moca#277 asks for by name.

Already shipped — not part of this ask

  • 13d80627 — configurable inject_header for x-api-key.
  • adf5d2af — fail closed on an empty resolved credential.

History

Originally opened blocked on moca#239 ("the injector cannot key on a subject the harness does not yet send"). That prerequisite has since landed; the blocked label is removed. Paths in this issue were updated after afb49e9f flattened authbridge/ into the repo root (authbridge/authlib/plugins/ → core/plugins/). Older harness specs and ADR-0032 may still name this repo kagenti-extensions, which redirects here — worth correcting on both sides as those docs are touched.

Activity

  1. added
    enhancement
    blocked
    Identity
    on Sep 8, 2026
  2. pdettori commented on Sep 28, 2026

    @pdettori
    Member

    Rescope proposal: from "per-subject static-inject" to a connection-bound caller-identity contract

    The deployment this issue was written for has changed, and so has the right shape of the ask.

    What changed on the harness side

    serverless-harness is being renamed MOCA and is moving off Kubernetes (its RA1 plan): the primary deployment becomes a supervisor with long-lived worker processes that each multiplex many users' sessions (P6), and Firecracker microVM sandboxes with no network device, whose egress reaches the host only over vsock (P4 / P4.1). One egress proxy per host is shared by every VM on it.

    In that topology the original framing no longer fits. Both options in the "design tension" above — a subject in X-SH-Subject, or a subject token on the hop's Authorization — are asserted by the caller, and a proxy shared across users must not select a credential on anything the caller can assert (Z1's forbidden "shared identity + subject header" pattern). The tension is resolved by neither: identity has to come from how the connection arrived, established by a trusted host-side component.

    What MOCA is doing about it

    To keep this off MOCA's critical path, MOCA will ship a small, single-purpose Go proxy of its own first (moca-egress). This issue therefore no longer blocks MOCA, and is no longer blocked by serverless-harness#239. It becomes: Cortex implements the MOCA proxy contract, and replaces moca-egress once MOCA needs capabilities only Cortex has (IBAC, SPARC, OPA policy, budgets, abctl observability).

    MOCA is keeping that swap cheap on its side: the control plane's credential endpoint is RFC 8693-shaped (so token-exchange can talk to it), audit events follow Z5's shape, and the contract ships with a conformance suite that moca-egress passes first and a Cortex implementation would pass before replacing it.

    Proposed new scope for this issue

    1. Connection-scoped, verified caller identity. A control-plane-signed session grant (Ed25519 JWS) is presented once per connection by a trusted front (for example on the CONNECT, or on a listener only a trusted shim can reach), verified by Cortex, and applied to every request on that connection — including TLS-bridged inner requests. Nothing on an individual request inside the tunnel can change it.
    2. Identity-keyed credential resolution. token-exchange (or a sibling plugin) uses that verified identity as the subject_token, rather than the inner request's Authorization bearer; the inert placeholder is overwritten regardless of its value; the injected header is configurable (e.g. x-api-key for Anthropic, not only Authorization: Bearer); results cached per (identity, audience).
    3. Non-TCP listeners (Unix sockets, which is what vsock guests land on host-side), or an explicitly documented contract for a front shim that owns them.
    4. An audit event on every successful injection (Z5 shape: via, host, method, path, subject, caller identity), with query strings redacted.
    5. Pass the MOCA proxy conformance suite. The contract and suite will be published with the MOCA credential/skills isolation spec; I will link it here when it lands.

    Suggested retitle, if the author agrees: "Connection-bound caller identity and identity-keyed credential resolution (MOCA proxy contract)" — and the blocked label can likely come off. I have not edited the title, body or labels.

  3. cwiklik commented on Oct 5, 2026

    @cwiklik
    CollaboratorAuthor

    Yes — this is still real work, and most of it can be started now.

    The goal, in plain words. Many users share one agent service. Each user has their own API key for
    the model. We don't want the agent to ever hold a real key — the agent reads prompts and tool output,
    so anything it holds can be talked out of it by a malicious prompt. So: give the agent a fake key,
    and have a trusted proxy on the way out swap the fake key for the real key belonging to that user.
    Cortex is that proxy. One sentence: Cortex should be able to tell which user a request belongs to,
    and inject that user's credential.

    What already shipped on the MOCA side. Merged: a per-user credential store, and a per-turn
    exchange that hands the agent a fake key naming the user (sh-placeholder-<user>). This issue used to
    be blocked waiting on that. It isn't anymore.

    What's missing in Cortex. static-inject chooses a credential by destination host, or by one
    fixed key. It has no concept of who is calling. So with many users you get one of two bad outcomes:
    everyone shares a single credential (no isolation), or everyone but one person gets a 401.

    One trap to know about. The obvious fix is to read the user's name out of the fake key in the
    request. Don't — the fake key is predictable and it arrives from code the model can influence, so any
    sandbox could present someone else's fake key and get their real credential. Identity has to come from
    something the caller can't choose, which is why the real fix is connection-based.

    What to build, in order. Steps 1–4 need nothing from MOCA:

    1. Resolve by identity. Add a key_by: identity mode to static-inject that uses
      pctx.Identity.Subject() as the resolver key. The pieces are already there — pipeline.Context
      carries an Identity interface (core/pipeline/context.go:26, :152) that no plugin currently
      reads, and FileResolver already maps one key to one credential file. This is the core of the
      issue and it's mostly wiring.
    2. Audit event on each successful injection — subject, host, method, path, query redacted. Small
      and self-contained.
    3. A non-TCP listener (Unix sockets). Cortex is TCP-only today; moca#277 asks for this by name.
    4. Connection-scoped identity. Establish identity once from how the connection arrived and apply
      it to every request on that connection, including requests bridged inside a CONNECT tunnel.
      Cortex has tls_bridge already, but identity doesn't survive into the inner requests.
    5. Then verify MOCA's specific signed grant format and run their conformance suite. This is the
      only step that's actually waiting
      on MOCA.

    Step 1 is the natural first PR — it closes the headline gap on its own.

    Tracking: epic rossoctl/rossoctl#2546 (Stream 1) lists "moca#241 / cortex#905 — Z5 injector
    dependency" as open; moca#241 is the MOCA-side stub pointing here; MOCA's spec index names this as a
    prerequisite for MU3, which retires a documented stopgap where the real key passes through the agent's
    memory on every turn.

    I'll retitle this issue and fix the stale file paths (the code moved from authbridge/authlib/ to
    core/plugins/) so it reads like the above. Happy to walk through step 1 together.

    /cc @huang195

  4. removed
    blocked
    on Oct 5, 2026
  5. changed the title [-]Z5: per-subject credential resolution in static-inject (RFC 8693)[/-] [+]Z5: connection-bound caller identity + identity-keyed credential resolution in static-inject[/+] on Oct 5, 2026
  6. pdettori commented on Oct 21, 2026

    @pdettori
    Member

    Gap analysis (2026-10-21): Cortex as the egress proxy for MOCA's sandbox service

    The question we're answering: what does Cortex need before it can be the egress proxy for MOCA's sandbox service (SBX0, Firecracker microVMs on a shared host)? At minimum it has to inject each user's keys in place of a placeholder, and let MOCA run other Cortex plugins as extensions.

    Read against Cortex main at 15da639 and MOCA main at 95ff373. This is a reading of the code; we have not built or run Cortex. The target is the contract in MOCA MI1 §8 and the conformance suite in §12.3. This updates the dated §2.4 survey (taken at 403d5d2) to today's HEAD.

    The ordered breakdown above (steps 1–5) still holds. Items G5, G7 and G8 below are not in it and should be added.

    Gaps that block per-user key injection

    # MOCA needs Cortex at 15da639 In the breakdown?
    G1 Caller identity from the connection, never the request The forward listener is unauthenticated. Proxy-Authorization is deleted without being checked (forwardproxy/server.go:1133). Session ids come from client headers (core/session/idheader.go). pctx.Identity is only set by inbound jwt-validation, so it is nil on the forward path step 4
    G2 A Unix-socket listener, and accepting listening descriptors handed over by vmpool (SCM_RIGHTS on a control socket; the descriptor is the identity, MI1 §8.3) Every listener is net.Listen("tcp", …) (bootstrap.go:88, cmd/cortex/listeners.go:75) step 3 (Unix sockets). Descriptor handover is not listed
    G3 Identity set at CONNECT carried into the requests bridged inside the tunnel bridgedHandler (server.go:1033) passes only process info. serveOutbound builds a fresh pipeline.Context per request (:321) step 4
    G4 Credential selected by (identity, host), resolved through MOCA's RFC 8693-shaped token endpoint and cached static-inject supports only key_by: host | static, with one secret_dir per process (staticinject/plugin.go:22-25). token-exchange exchanges the inbound bearer, so a bearer would have to live inside the guest step 1, plus a resolver that calls the token endpoint
    G5 Always overwrite the header the credential's binding declares: Bearer, Basic for git over HTTPS, x-api-key static-inject returns 401 when there is no Bearer (plugin.go:188). Git's credential helper sends Basic, so git fails. abph_ handles are not a substitute: the placeholder-swap design has "no handle-level audience binding in v1" no
    G6 Exactly one audit event per injection: subject, sandbox, host, method, path without the query string, the credential's name None step 2
    G7 Plain HTTP to a host that has a credential → 403 plaintext_credential, with nothing injected static-inject does not check pctx.Scheme. An absolute-form http:// request (server.go:308) would have the credential injected in cleartext no
    G8 Fail closed on hosts that have a credential: always intercept, 502 upstream_unverified when verification fails, never a silent tunnel When the client doesn't trust the CA, Cortex falls back to an opaque tunnel (tlsbridge/decision.go:239). DefaultPassthroughHosts starts with GitHub (:85), the main host that needs a credential. passthrough_hosts: [] overrides the list; nothing turns off the fallback no

    Egress policy MOCA needs whether or not a credential is involved

    • Deny-by-default destination allowlist with a named 403 destination_denied. Not found: skip_hosts is a bypass list. An opa rule on the CONNECT pipeline might cover it; we have not checked.
    • SSRF guard: resolve the name once, refuse loopback, link-local (including 169.254.169.254), private, unique-local and the host's own addresses, then dial the address that was checked so a second DNS answer cannot redirect the connection. Not found.
    • Caps: per-VM concurrent connections and a hard per-session request cap → 429. Not found. session-budget keys on pctx.Session.ID, which comes from client headers.
    • WebSocket: Upgrade is stripped on intercepted requests (server.go:1138). MOCA's contract allows upgrades.
    • Already matching: inner Host ≠ CONNECT authority → 421 (server.go:344), and the upstream certificate is verified before a leaf is minted.

    Control and multi-tenant hygiene

    • Runtime binding channel: Register{vm_id, sid, grant, listen_fd} / Rebind / Unregister, with callers admitted by SO_PEERCRED and every live VM re-registered after a proxy restart. The session API is read-only and unauthenticated (sessionapi/server.go:199, docs/session-api.md), and hot reload refuses listener changes.
    • Session recording on a shared host: decrypted prompts and replies from every tenant go into one store that the unauthenticated session API serves. Multi-tenant use needs this off, or scoped per identity.
    • Grant verification (step 5): MOCA distributes Ed25519 keys as kid:base64-DER, not JWKS. Small.

    Plugins as extensions

    The plugin model fits. Plugins register in init() behind build tags, so MOCA can link its own identity and resolver plugins into a downstream build without forking Cortex. Three things to keep in mind:

    1. Plugins see only intercepted traffic. MOCA intercepts only hosts that have a credential, plus an opt-in inspect list, so every plugin's hosts have to be on that list.
    2. Plugins need the connection-derived identity in both fields. opa reads pctx.Identity; session-budget, inference-router and ibac read pctx.Session, which comes from client headers. G1/G3 must fill both, and should override any session header the client sends.
    3. ibac, tool-prune and context-guru read bodies. MOCA's contract streams bodies and never buffers them, so these become per-host opt-ins. ibac also needs the user's intent, which lives on the harness side and would have to arrive over the control channel.

    Smaller alternative

    If MOCA puts its own front end in front of Cortex, Cortex has less to do. That front end would own the vsock sockets, the connection → sandbox binding, the allowlist, the SSRF check and the control channel, and stamp the verified identity onto the guest's plaintext CONNECT. Cortex would then need: trust that identity header only on the front end's socket (G1, scoped down); G3; G4; G5; G6; G7; and dial the address the front end pinned rather than resolve the name again. That is P4.1 §12.2's "Go shim" option.

    MOCA's current position is unchanged (MI1 D4): moca-egress first, then Cortex via the §12.3 suite once a Cortex-only plugin is needed. Neither moca-egress nor the suite exists yet. MOCA-side status is on moca#241.

    Assisted-By: Claude (Anthropic AI) [email protected]

  7. pdettori commented on Oct 22, 2026

    @pdettori
    Member

    Superseded by #1490: Cortex as the egress proxy for MOCA's sandbox service (SBX). Cortex maintainers asked for one epic with an issue per gap, so the design sessions can take them one at a time.

    Everything actionable here has moved into a child issue. Each one has the current code evidence (Cortex main d4394da), what MOCA's contract needs, design questions, and the MOCA conformance case that proves it is done:

    This issue Now
    Breakdown step 1: resolve by identity #1478
    Breakdown step 2: audit event #1482
    Breakdown step 3: non-TCP listener #1477 (adds fd handover and a control channel)
    Breakdown step 4: connection-scoped identity #1476
    Breakdown step 5: grant + conformance suite #1489
    Gap analysis G5 / G7 / G8 #1479 / #1481 / #1480
    Egress policy: allow list, SSRF, caps #1483, #1484, #1485
    Session recording on a shared host #1486
    Plugins under a streaming contract; WebSocket #1487, #1488

    The epic replaces #905 under rossoctl/rossoctl#2546. The MOCA-side stub is still rossoctl/moca#241. Closing.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Identityenhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions