Repository navigation
feat(identitybroker): add the identity broker interface and stand-in broker - #2443
Conversation
…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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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_DENIEDwith no reason, rather thansession_owned. The failure matrix gives registration under a different owner a plainPERMISSION_DENIED, andsession_ownedis the reason for refusing a session open, which mecak8s handles as a failed open.
Summary
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:*identitybroker.Errorwith a code mirroring the design's gRPC statuses and, where the design defines one, a reason.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.identitybroker/conformance, contract tests every implementation passes, following thecredentialstore/conformancepattern. Later work adds cases in its own files.internal-identitybrokerdepguard rule to the core package and givesstandinandconformancetheir 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
Test plan
Baseline checks
task lint): every module clean.task lintstops at the pre-existing darwin-only gosec G703 inenvironment/microvm/launch_ownership_darwin.go:754; the modules after it were run directly and are clean.task test): covered by the race suite below.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 outsideinternal/identitybrokerimports it, so those test binaries are identical tomain's; thecmd/and microVM failures were also reproduced on unmodifiedmainwhile preparing feat(identitybroker): add validated startup foundation for the agent identity broker #2442.go run ./cmd/mecademo): tool call, permission ask and approval, and result shown.task docs): no Markdown changes.task site:build)task api:check)task api:update+engine/CHANGELOG.mdAlso checked:
testingin the core,osandconformanceinstandin, andosandinternal/mcpbrokerinconformancewere each rejected.Tokennever prints its value: covered for%v,%+v,%#v,%s,%q,%x,%d, nested in a request, and throughjson.Marshal.Changes
internal/identitybroker/service.goService, request and result types and their validation,Owner,AgentRef, andCalleron the contextinternal/identitybroker/errors.goError,Code,Reason, andTokeninternal/identitybroker/broker.goServiceis the contract for the whole identity brokerinternal/identitybroker/standin/internal/identitybroker/conformance/.golangci.ymlstandinandconformancerules addedUser-facing change
None.
Special notes for reviewers
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.PERMISSION_DENIEDanddenied.session_owned, the design's reason for a session that belongs to someone else.owner_mismatchis AS-1's reason for a token paired with the wrong owner.ALREADY_EXISTS. The design does not cover this case; this is a proposed choice.WithCaller/CallerFrom), never as a request field, per the modulith constraints. Checking it will be addressed later.AuthorizeCall.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.