Skip to content

feat(identitybroker): add the identity broker interface and stand-in broker - #2443

Merged
ChrisJBurns merged 3 commits into
mainfrom
feat/identitybroker-interface
Oct 21, 2026
Merged

ChrisJBurns merged 3 commits into
mainfrom
feat/identitybroker-interface

Conversation

@ChrisJBurns

@ChrisJBurns ChrisJBurns commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds identitybroker.Service, the contract for every call Mecatl makes to the identity broker, so later work plugs in behind it without rewiring Mecatl, and the broker can later move to its own service. It has five calls:
    • OpenSession / FindSession / CloseSession: the broker session for a root host session;
    • RegisterAgent: registers an agent instance and returns its reference and credential (the agent-instance JWT-SVID, credentials-and-lifecycle.md step (4));
    • AuthorizeCall: decides an MCP call for the agent presenting that credential and returns the gateway token (step (6)).
  • Requests and results are plain values owned by the package. Every error is an *identitybroker.Error with a code mirroring the design's gRPC statuses and, where the design defines one, a reason.
  • Adds identitybroker/standin, a stand-in broker used until the real one exists: sessions in memory, one fixed agent with a placeholder credential, and every call denied, so nothing reaches a gateway through it.
  • Adds identitybroker/conformance, contract tests every implementation passes, following the credentialstore/conformance pattern. Later work adds cases in its own files.
  • Narrows the internal-identitybroker depguard rule to the core package and gives standin and conformance their own rules (standard library plus the core package).

Nothing calls the interface yet; starting the stand-in in mecak8s will be addressed later.

Closes #2446

Issue relationship

Relates to #2121

Type of change

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

Test plan

Baseline checks

  • Linting (task lint): every module clean. task lint stops at the pre-existing darwin-only gosec G703 in environment/microvm/launch_ownership_darwin.go:754; the modules after it were run directly and are clean.
  • Fast offline test suite (task test): covered by the race suite below.
  • Pre-review race suite (task test:race): internal/identitybroker/... passes. Failures elsewhere (cmd/mecated, cmd/mecatui, internal/app, internal/adapter/server, helm and kind charts, microVM packages, and others) come from the local macOS environment. No package outside internal/identitybroker imports it, so those test binaries are identical to main's; the cmd/ and microVM failures were also reproduced on unmodified main while preparing feat(identitybroker): add validated startup foundation for the agent identity broker #2442.
  • Offline demo (go run ./cmd/mecademo): tool call, permission ask and approval, and result shown.
  • Markdown changed: docs generation/link checks (task docs): no Markdown changes.
  • User docs/user-facing behavior changed: site build (task site:build)
  • Guarded engine API affected: compatibility check (task api:check)
  • Intentional engine API change: task api:update + engine/CHANGELOG.md

Also checked:

  • The contract tests catch a broken implementation: with the stand-in's owner check removed, or closed sessions let through, the suite fails.
  • The lint rules fire: planted imports of testing in the core, os and conformance in standin, and os and internal/mcpbroker in conformance were each rejected.
  • Token never prints its value: covered for %v, %+v, %#v, %s, %q, %x, %d, nested in a request, and through json.Marshal.

Changes

File Change
internal/identitybroker/service.go Service, request and result types and their validation, Owner, AgentRef, and Caller on the context
internal/identitybroker/errors.go Error, Code, Reason, and Token
internal/identitybroker/broker.go Package comment: Service is the contract for the whole identity broker
internal/identitybroker/standin/ Stand-in broker and its tests
internal/identitybroker/conformance/ Contract tests: shared helpers and session cases
.golangci.yml Core rule narrowed; standin and conformance rules added

User-facing change

None.

Special notes for reviewers

  • The agent is identified by its credential, as in the design, not by a session ID or an ag_ identifier. Registration returns the credential; Mecatl's trusted harness code holds it and presents it on each call, and it never reaches the engine or the model.
  • A denial is an error, not a result field, so a caller that ignores the result cannot dispatch. It carries PERMISSION_DENIED and denied.
  • A different owner on an open host session fails with session_owned, the design's reason for a session that belongs to someone else. owner_mismatch is AS-1's reason for a token paired with the wrong owner.
  • A different incarnation on an open host session fails with ALREADY_EXISTS. The design does not cover this case; this is a proposed choice.
  • The caller travels with the context (WithCaller / CallerFrom), never as a request field, per the modulith constraints. Checking it will be addressed later.
  • A registration may name its definition only by name. Mecatl sessions don't yet know their definition's source and revision, so registration requires the name and checks the source and revision only when set. Requiring them will be addressed later; the startup snapshot stays strict.
  • Left out until something uses them: AS-1 lookups, trust-bundle publishing, the definition source, the record sink, credential renewal, and runs, run owners, and delegations on AuthorizeCall.
  • The stand-in keeps all state in one process. Session IDs are random, so they are not guessable and do not repeat after a restart. Closed sessions are kept in memory so they keep refusing calls; nothing is shared between replicas.

API compatibility: no remote-observable change. The packages are internal and not wired into any server; no protobuf, gRPC, HTTP, or engine API surface changes. No major or feature-identifier change.

ChrisJBurns and others added 3 commits October 20, 2026 20:45
…broker

Add identitybroker.Service, the contract for every call Mecatl makes to
the identity broker: open, find, and close a broker session, register
an agent and receive its credential, and authorize an MCP call by the
acting agent's credential. Requests and results are plain values owned
by the package. Every error is an *identitybroker.Error carrying a code
that mirrors the design's gRPC statuses and, where the design defines
one, a reason; a denied call is an error, so a caller that ignores the
result cannot dispatch. Token keeps credentials out of every fmt verb
and JSON. The authenticated caller travels with the context, never as a
request field; phase 1 does not check it.

Add the standin package, which keeps broker sessions in memory, returns
one fixed agent with a placeholder credential, and denies every call,
and the conformance package, the contract tests every implementation
passes, following the credentialstore conformance pattern.

Narrow the internal-identitybroker depguard rule to the core package
and give standin and conformance their own rules: standard library plus
the core package only.

Co-authored-by: Mecatl <[email protected]>
…Session request

Stand-in broker session IDs were sequential, so they were guessable and
repeated after a restart. Draw them from crypto/rand and document that
the stand-in's state, including closed sessions, lives in one process.

FindSession took a bare string and the stand-in rejected only an empty
one. Give it a FindSessionRequest validated like the other requests,
and cover malformed host session IDs in the contract tests.

Co-authored-by: Mecatl <[email protected]>
… by name

RegisterAgentRequest.Validate applied the startup snapshot's strict
definition check, which requires a source and a revision. Mecatl
sessions know their definition only by name, so every registration
would have been rejected. Require the name, check the source and
revision only when set, and leave requiring them to later work. The
startup snapshot stays strict.

Drop a comment's reference to an internal plan phase.

Co-authored-by: Mecatl <[email protected]>
// CloseSession closes a broker session with a closing reason. Closing an
// already closed session succeeds and keeps its first reason.
CloseSession(ctx context.Context, req CloseSessionRequest) error
// RegisterAgent registers an agent instance in an open broker session and

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.

Should the contract say that a registration whose HostSessionID or Owner doesn't match the session is refused?

Today the stand-in's RegisterAgent checks only that the session is open. A request that names alice's session ID with owner bob gets a credential back. With the stand-in that does no harm, because the credential is a placeholder and every call is denied. But the conformance suite has no case for it either: registerRequest copies the session's own host session and owner, so a real broker that skipped this check would still pass every case.

The design already expects the refusal. implementation.md says "Registration into a closed session, or a session bound to another workload, is refused", and that re-registering with a different host session or owner is refused.

I understand #2446 keeps registration logic out of this PR. A smaller step would be one sentence in this doc comment saying a mismatch is refused (I'd suggest PERMISSION_DENIED with session_owned), with the conformance case added by the registration ticket. Then the real broker is held to it from the start.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, agreed on the owner. #2449 adds it: the rule is documented on Service, the stand-in enforces it, and there's a contract case, so a real broker that skips it fails the suite.

Two differences from the suggestion:

  • Host session isn't compared. A child agent registers with its own host session while sharing its parent's broker session (agent-definitions.md: a subagent child has its own child session, and the tree shares one broker session). An equality check would refuse every child. The field doc says so, and a stand-in test registers a child under its own host session. How to check that a host session belongs to the tree is still open; requiring a parentless registration to use the session's root host session is one candidate.
  • PERMISSION_DENIED with no reason, rather than session_owned. The failure matrix gives registration under a different owner a plain PERMISSION_DENIED, and session_owned is the reason for refusing a session open, which mecak8s handles as a failed open.

@ChrisJBurns
ChrisJBurns merged commit b24ec74 into main Oct 21, 2026
40 of 42 checks passed
@ChrisJBurns
ChrisJBurns deleted the feat/identitybroker-interface branch October 21, 2026 11:06
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Oct 23, 2026
2 tasks
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.

Identity broker interface and stand-in broker

2 participants