Skip to content

feat(identitybroker): give each agent its own identity, checked against loaded definitions - #2883

Merged
rdimitrov merged 7 commits into
mainfrom
feat/per-agent-registration
Nov 20, 2026
Merged

rdimitrov merged 7 commits into
mainfrom
feat/per-agent-registration

Conversation

@rdimitrov

@rdimitrov rdimitrov commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Summary

This branch now also carries #2912, #2913, and #2914, which were merged into it. Merging this PR lands the per-agent identity work (#2527) and helper registration and gateway tools (#2555) together. Each merged PR's description keeps its full detail; the sections below cover this PR's own change, with a short summary of the merged ones at the end of each.

Every agent used to share one agent identity, so a grant, AS-1's actor check, and a gateway record could not tell which agent acted. Each agent instance now gets its own identity, and registration checks it against the definitions the broker loaded.

  • Its own identity. An instance gets an ag_ identifier when its incarnation first registers, kept for good, and the SPIFFE ID spiffe://<trust domain>/agent/<ag_ identifier>. The ID carries no definition name, incarnation, or ancestry; the broker's record keeps those. Registering into a new broker session keeps the identity. act.sub is this ID. The shared identity (/mecatl/agent/shared/inst/<incarnation> and the per-process ag_) is removed.
  • Registration checks (design step 4):
    • Check 3: a new instance must name exactly a definition the broker loaded (source, name, and revision), or it is refused with PERMISSION_DENIED.
    • Check 7: an incarnation registered before must keep its owner, host session, definition reference and revision, and parent (ALREADY_EXISTS otherwise). Per D4 (docs(agent-identity): keep a re-registered instance's revision, and pin a schedule's definition #2866), it is not checked against the definitions loaded now.
    • Two first registrations of one incarnation racing each other end with one identity: the one that loses signs again for the winner's.
  • Startup loads definitions. mecak8s runs the definition loader (feat(identitybroker): load agent definition records for the broker #2829) with its agents directories and build ID and hands the records to the broker. A configured directory that cannot be read stops startup; each definition left out or adjusted is logged with its path and reason, never its contents.
  • Definitions are required. NewService refuses an identity broker without IdentityDefinitions, so a missing list fails at startup instead of at every run, and composition with an injected test core loads the configured definitions (review follow-up).
  • The server sends the loaded reference. A session's main agent registers with global/<name> at the loader's revision, or system/main at the release's revision. A name the broker did not load is sent by name only and logged; the broker refuses it. Under an operator harness_context policy, which can order agent-definition sources or exclude one per name so that another source (such as a driver) wins a name the broker loaded, the server is given only the built-in references, so named sessions are refused rather than registered as the operator's definition.
  • identitybroker.CheckRegistration. The client-side check that a registration answers its request moves into the broker package, which owns the ID format: the agent must be an agent instance's SPIFFE ID, and the credential's sub must name it. The credential holder keeps its comparison with the agent it held before.
  • Docs: the stale "becomes a SPIFFE segment" comments are fixed, the operator docs' identityBroker.enabled row describes the new behavior, and the design's "Loading definitions" no longer names the --agents-dir flag (review follow-up from docs(agent-identity): record which source tiers hold global definitions #2874).

Issue relationship

Closes #2527. Closes #2555. Part of #2550 and #2554.

Carries #2912, #2913, and #2914 (#2555), merged into this branch; their closing keywords do not act on a non-default branch, so this PR closes #2555.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

Baseline checks

  • Linting (task lint)
  • Pre-review race suite (task test:race)
  • Markdown changed: docs generation/link checks (task docs)
  • User docs/user-facing behavior changed: site build (task site:build)
  • Guarded engine API affected: compatibility check (task api:check): the engine is unchanged
  • Intentional engine API change: task api:update + engine/CHANGELOG.md: not applicable

Contract tests (internal/identitybroker/conformance)

Every implementation now loads conformance.Definitions(). New and changed cases:

  • an unknown definition, another revision, another source, a missing revision, and a name-only reference are refused, and the agent then registers with a loaded one;
  • registering again with another definition or revision is ALREADY_EXISTS, and the agent is unchanged;
  • an agent's SPIFFE ID contains no incarnation, host session, broker session, definition, or owner;
  • each agent has its own ag_ identifier, and its SPIFFE ID is both its subject and its actor ID;
  • the existing cases for a closed session, repeated registration, reopened sessions, and owner, host session, and parent takeovers still pass.

Other tests

  • Broker core: a re-registration keeps its definition after the broker stops loading it (D4); racing first registrations get one identity; CheckRegistration rejects malformed IDs and a credential naming another agent.
  • Credential holder: a malformed agent ID, a credential naming another agent, and a well-formed but different agent are all refused.
  • Server: identityAgentDefinition picks the loaded built-in or global reference, sends an unloaded name by name only, and never matches a name to a built-in; a session running an unloaded definition is refused and logged, with a positive control.
  • Composition: startup loads the built-ins and a global definition and logs a bad file without its contents; a missing agents directory fails startup, with a positive control; a session created through the real wiring registers its main agent with the loaded built-in; under a harness policy only the built-in references reach the server.
  • AuthorizeCall refuses an agent registered to another session of the same broker without an ID-JAG exchange, with a positive control in the agent's own session.

Changes

File Change
internal/identitybroker/agents.go, credential.go, sessions.go, broker.go Per-instance identity, checks 3 and 7, race retry, CheckRegistration
internal/identitybroker/service.go, definition.go Contract and comment updates
internal/identitybroker/conformance/* Loaded definition set; new cases
internal/agentcredential/holder.go Uses CheckRegistration
internal/adapter/server/identity_broker.go, service.go IdentityDefinitions; sends the loaded reference
internal/app/identitybroker.go, build.go Loads definitions at startup; passes them to the server
docs/drafts/agent-identity/agent-definitions.md Drops the flag name
user-docs/operating/mecak8s/identity-and-client-access.md Broker behavior with agent definitions
*_test.go Tests above; fixtures load definitions

API compatibility

  • Assessment. No gRPC or HTTP message, route, or field changes. Two behaviors a client or a downstream service can observe change, and only with --enable-identity-broker on:
    • session_agent_definitions. CreateSession.agent_definition_name (or POST /v1/sessions) naming an agent from a project, user, or driver source still creates the session, and still echoes resolved_agent_definition_name. Its runs, though, now fail at run entry with the existing internal error, because the broker refuses to register an agent whose definition it did not load. Before this change the shared identity registered any definition. Built-in sessions, and sessions named after an agent in the --agents-dir directories, are unchanged, except under an operator harness_context policy, where every named session is refused.
    • act.sub. The ID-JAGs AS-1 issues for the gateway carry one SPIFFE ID per agent instead of one per process. The format, spiffe://<trust domain>/agent/<ag_ identifier>, is unchanged. Production configures no gateway yet.
  • Rationale for no major bump. No client change could make the refused session correct. Which definitions can run in broker mode is the operator's deployment policy (the design's "Loading definitions"), not a contract a client can satisfy. The broker is an experimental capability, off by default, and the design calls for this refusal; Full definition loader and registration rules #2551 then accepts unloaded definitions as mecak8s reports. The act.sub change keeps its format and meaning ("the acting agent"), and is now more precise.
  • Major/feature changes: none.
  • Approval. The operator reviewed this assessment and approved shipping without a major bump. A refused session fails at its first run, after CreateSession has succeeded and echoed the definition; Full definition loader and registration rules #2551 replaces that with a refusal.
  • Stored data: none. Broker state is in memory, so identities do not survive a restart until Durable broker state and recovery #2563.
  • Merged into this branch:
  • Upgrade implications. Operators running the experimental broker who use named agents from a workspace or home directory must move them into an --agents-dir directory. Under a harness_context policy, named agents cannot run with the broker until Sessions run and register the exact definition revision #2548. A missing --agents-dir directory now stops startup. The server logs a warning naming the session and definition when it registers an agent whose definition the broker did not load.

User-facing change

Only with --enable-identity-broker:

  • each session's main agent gets its own identity;
  • a session using a named agent outside the --agents-dir directories cannot run, and under a harness_context policy no named agent can;
  • a missing --agents-dir directory stops startup.

With #2913 and #2914: each helper (subagent, parallel branch, team member) also gets its own identity under the agent that created it, and a helper naming an agent outside the --agents-dir directories cannot start. Helpers that run no named agent can call the MCP gateway's tools under their own identity.

Special notes for reviewers

  • Shortcuts kept:
  • ABORTED. RegisterAgent retries once when another first registration of the same incarnation recorded its identity while this one was signing; identities are never reassigned, so the retry succeeds. CodeAborted is reachable only if two fresh 128-bit ag_ identifiers collide in a row, and the contract says registering again succeeds.
  • Holder guarantee after a restart. The old ID ended in the incarnation, so the holder could check a registration against its request without having held anything. Opaque IDs remove that, so after a restart or lease loss the holder relies on the broker's own checks plus CheckRegistration's format check.

🤖 Generated with Claude Code

rdimitrov and others added 3 commits November 19, 2026 01:24
…st loaded definitions

Each agent instance now gets its own ag_ identifier when its incarnation
first registers, kept for good, and the SPIFFE ID
spiffe://<trust domain>/agent/<ag_ identifier>, which carries no
definition name, incarnation, or ancestry. act.sub is that ID. The
shared agent identity is removed.

A new instance must name exactly a definition the broker loaded; an
instance registering again is checked against its earlier registration,
definition included, instead of the definitions loaded now. Startup
loads the built-ins and the operator's global definitions from the
agents directories, fails when one cannot be read, and logs each
definition left out. The server registers a session's main agent with
the loaded reference. The check that a registration answers its request
moves into the broker package as CheckRegistration.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- CheckRegistration validates the trust domain with ValidateTrustDomain,
  and its tests pair each malformed ID with a credential naming it, so
  only the ID's form can fail them.
- The server's IdentityDefinitions holds references only, marked as the
  #2548 shortcut, and the server logs a warning when a session runs a
  definition the broker did not load.
- Test fixtures use the per-agent ID format; the D4 test gains a
  positive control; the mecak8s identity tests register with the loaded
  built-in main; the server test credential helper is shared.
- The service contract documents CodeAborted; the operator docs say how
  to set the agents directory under Helm.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The server maps a session's agent name to the broker's global record,
which holds only while the operator's agent directories win every name.
An operator harness_context policy can let another source, such as a
driver, win a name the broker loaded, so under a policy the server gets
only the built-in references: named sessions are refused instead of
registering another source's definition as the operator's.

Also from review: conformance.DefinitionRefs gives the server tests one
list of what the contract broker loaded, and a test checks AuthorizeCall
refuses an agent registered to another session of the same broker
without an ID-JAG exchange. The operator docs note the policy behavior.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@ChrisJBurns ChrisJBurns left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the inline comments.

Comment thread internal/adapter/server/service.go Resolved
…y broker

A server with an identity broker but no IdentityDefinitions sent every
agent's definition by name only, which the broker refuses, so every run
failed at run entry with only a warning. NewService now refuses that
configuration, and composition with an injected broker core still sends
the references of the definitions its configuration loads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rdimitrov
rdimitrov merged commit 015a755 into main Nov 20, 2026
50 checks passed
@rdimitrov
rdimitrov deleted the feat/per-agent-registration branch November 20, 2026 15:09
jhrozek added a commit that referenced this pull request Nov 21, 2026
…on test

Since per-agent identities (#2883) the broker accepts only definitions it
loaded, so registering {system, main} with no revision is refused with "the
definition is not one the broker loaded". The rotation test needs a registered
agent to obtain a credential, so register the built-in main by its loaded
reference, builtinMainRef().

Co-Authored-By: mecatl <[email protected]>
jhrozek added a commit that referenced this pull request Nov 21, 2026
The identityBroker.enabled row said each subagent, parallel branch, and team
member gets its own agent identity. No Parallel branch can run beside the
broker: Parallel forks only a local workspace, which the broker refuses. The
sentence arrived with the per-agent identities text (#2883) and became false
once it met this PR's workspace rule.

Co-Authored-By: mecatl <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — 8320c9da Deployed Nov 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Helper agents: their own registered identity and broker MCP tools Per-agent registration and identities, switched on

2 participants