Skip to content

fix(identitybroker): map ToolHive v0.66.0 actor reasons from AS-1 - #2823

Merged
ChrisJBurns merged 3 commits into
mainfrom
fix/identitybroker-as1-actor-reasons
Nov 17, 2026
Merged

ChrisJBurns merged 3 commits into
mainfrom
fix/identitybroker-as1-actor-reasons

Conversation

@jhrozek

@jhrozek jhrozek commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Why: ToolHive v0.66.0 shipped ID-JAG issuance and the pluggable actor-token validator, and its refusal reasons are not the ones our design and broker assumed.
    • AS-1 refuses an expired actor token with actor_token_expired, not svid_expired.
    • It adds approval_required.
    • At ID-JAG issuance it adds upstream_subject_missing, sub_id_missing, dpop_not_supported and bound_elapsed.
    • The broker treated all six as unknown. So against a real v0.66.0 AS-1, an expired agent credential would fail the call as a configuration fault instead of renewing the SVID and retrying once, and approval_required would look like a broker bug.
    • Our identity harness answered svid_expired, so our own tests agreed with the wrong string.
  • Broker:
    • knownReasons gains the six reasons.
    • idjagError maps actor_token_expired to svid_expired and approval_required to denied.
    • The four issuance reasons stay configuration faults, now reported by name.
    • AS-1's legacy svid_expired still passes through.
  • Harness: the fake AS-1 answers an expired actor with actor_token_expired, as ToolHive does.
  • Design (credentials-and-lifecycle.md, implementation.md):

The stacklok/toolhive pin stays at v0.65.0; the bump belongs to #2654. This change only makes the broker ready for the reasons it will receive.

Issue relationship

Relates to #2543
Relates to #2654

Type of change

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

Test plan

Baseline checks

  • Linting (task lint)
  • Fast offline test suite (task test)
  • Pre-review race suite (task test:race): run by CI (the Test (race) job), passing
  • Offline demo (go run ./cmd/mecademo): not affected; the change is in the broker's AS-1 refusal mapping
  • Markdown changed: docs generation/link checks (task docs), including docs:check --strict
  • User docs/user-facing behavior changed: site build (task site:build): not applicable
  • Guarded engine API affected: compatibility check (task api:check): not applicable
  • Intentional engine API change: task api:update + engine/CHANGELOG.md: not applicable

Focused race tests pass: go test -race ./internal/identitybroker/... ./internal/testutil/identityharness/... ./internal/adapter/server/....

New table rows cover:

  • AS-1 actor_token_expired gives UNAUTHENTICATED with svid_expired;
  • the legacy svid_expired gives the same;
  • approval_required gives PERMISSION_DENIED with denied;
  • each issuance reason gives INTERNAL, and the error names the reason instead of "unknown".

Changes

File Change
internal/identitybroker/serverrefusal.go Six reasons in knownReasons; the four issuance reasons in configurationFaultReasons
internal/identitybroker/authorize.go, service.go idjagError maps actor_token_expired and approval_required; comments
internal/testutil/identityharness/idjag.go The fake AS-1 answers actor_token_expired
*_test.go (5 files) Rows for the new reasons
docs/drafts/agent-identity/credentials-and-lifecycle.md Reasons, failure tables (refusal order), failure matrix, in-flight ID-JAG rule, #6973 and #7030 notes
docs/drafts/agent-identity/implementation.md ToolHive work-list rows rechecked against v0.66.0; the single-level act row stays partly done

User-facing change

None today: Mecatl still pins ToolHive v0.65.0. After the bump, an expired agent credential is renewed and the call retried, instead of failing.

Special notes for reviewers

  • approval_required is reported as denied, because Mecatl has no per-agent approval flow yet. If we want the broker to keep it distinct, that needs a new broker reason.
  • bound_elapsed (the grant expired while the actor validator ran) is classified as a configuration fault, like grant_invalid. It is closer to a race than a fault. The broker checks the stored expiry first, so it should not happen in practice.
  • The in-flight ID-JAG rule is already implemented. The broker checks that the session is still open after the exchange and again after redemption (internal/identitybroker/authorize.go, stillOpen), so the doc now describes existing behaviour.
  • Refusal order. upstream_subject_missing and sub_id_missing come while AS-1 decides the request, and dpop_not_supported right after (ToolHive server/handlers/token.go), all before the actor validator. Only bound_elapsed comes after it.
  • act.iss is still open. v0.66.0 refuses a validator issuer equal to its own, so the design's act.iss = AS-1 cannot be configured. The work-list row is back to "Partly"; the new value and the step (7) text are for a separate design change.
  • Source of the reasons. Each reason was read from ToolHive main after v0.66.0: server/tokenexchange/actor_validator.go, id_jag_mint.go, refresh_token_handler.go. ToolHive's in-process flow test (in progress) pins the same strings over HTTP.

jhrozek and others added 2 commits November 16, 2026 23:33
ToolHive v0.66.0 refuses an expired actor token at ID-JAG issuance with
actor_token_expired, not svid_expired, adds approval_required, and adds
the issuance reasons upstream_subject_missing, sub_id_missing,
dpop_not_supported, and bound_elapsed. The broker treated all six as
unknown, so an expired agent credential failed the call as a
configuration fault instead of renewing the SVID and retrying once.

Map actor_token_expired to svid_expired and approval_required to
denied, report the other four by name, and make the identity harness
answer an expired actor as ToolHive does.

Co-authored-by: Mecatl <[email protected]>
ToolHive v0.66.0 shipped ID-JAG issuance and the actor validator, and
its refusals differ from what the design assumed. AS-1 refuses an
expired actor token with actor_token_expired, not svid_expired, adds
approval_required, and adds upstream_subject_missing, sub_id_missing,
dpop_not_supported, and bound_elapsed. A schedule grant presented for
an ID-JAG is not_issuable, which the failure matrix called denied.

Record the mapping the broker applies, and say what the broker does
with an ID-JAG that returns after its session closed: AS-1 does not
read the grant again after the validator, so the broker checks the
session before using it. Note that replay-revoke
(stacklok/toolhive#6973) and AS-2's reason codes
(stacklok/toolhive#7030) are not built yet, and update the ToolHive
work list rows that v0.62.0 and v0.66.0 completed.

Co-authored-by: Mecatl <[email protected]>
@ChrisJBurns

Copy link
Copy Markdown
Contributor

Two things from the #2654 readiness check, both checked against ToolHive v0.66.0:

  • act.iss row in implementation.md. The single-level act row is now marked "Yes" but still says "with act.iss set to AS-1's issuer". ToolHive refuses that at startup: validateActIssuer in pkg/authserver/config.go rejects an ActIssuer equal to the server's own issuer. credentials-and-lifecycle.md step (7) ("act.iss names AS-1") and the "Test ID-JAG issuance" bullet in implementation.md say the same. The value still has to be chosen (it's the open item on Register Mecatl's actor-token validator at hosted AS-1 #2654), but this row shouldn't read as done for AS-1's issuer.
  • Order of sub_id_missing / upstream_subject_missing. The step (7) table puts them "After 6". In v0.66.0 the required-subject-claim check (selectSubjectClaims in refresh_token_id_jag.go) runs when the request is decided, before issueIDJAG calls the actor validator. So they come before check 6, and a validator never sees a grant missing a claim the target requires.

@ChrisJBurns

ChrisJBurns commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

@jhrozek a design question this PR touches, which #2654 needs answered before it starts: what should act.iss be?

ToolHive v0.66.0 refuses AS-1's own issuer as an ActIssuer, but step (7) says act.iss names AS-1. AS-2 and the vMCP identify an agent by (act.iss, act.sub), so changing the value later renames every agent. Options, all of which pass ToolHive's checks:

  • A. The agent trust domain, spiffe://<trust domain>. It names the namespace the agent credentials are issued in, and it's already per-deployment configuration.
  • B. The broker's own identifier (its audience URI). It names the registry that allocates ag_ identifiers.
  • C. AS-1's issuer plus a path, e.g. <AS-1 issuer>/agents. It keeps the value attributable to AS-1.

I'd go with A. Would you add it to step (7) and the implementation.md rows here, or would you rather we settle it in a separate design PR?


Review of the rest of the PR, checked against ToolHive v0.66.0's source and against #2818:

  1. Order of the issuance refusals (credentials-and-lifecycle.md, step (7) failure table). Three of the four rows say "After 6", but in ToolHive upstream_subject_missing and sub_id_missing are refused while deciding the ID-JAG, before the actor validator runs, and dpop_not_supported is refused at the token endpoint before anything else. Only bound_elapsed comes after the validator. Register Mecatl's actor-token validator at hosted AS-1 #2654 already says sub_id_missing comes before the validator, so the two disagree.
  2. act.iss row in the ToolHive work list (implementation.md). It marks "act.iss set to AS-1's issuer" as done in v0.66.0, but ToolHive sets act.iss to the issuer registered for the client's validator, never AS-1's own. That's the open question above, so the row should stay open until it's settled.
  3. "The in-flight ID-JAG rule is design only" (PR description). The broker already does this: it checks the session is still open before redeeming the ID-JAG and again before returning the gateway token, with tests (internal/identitybroker/authorize.go). Register Mecatl's actor-token validator at hosted AS-1 #2654's matching requirement can point at the existing behaviour.
  4. Renewal window. AS-1 answers actor_token_expired only within 60 s of expiry; after that it's server_error, which callers see as unavailable, with no renewal. The broker's 30 s allowance is fine today; worth a line wherever that allowance becomes configurable (Keys and gateway entries for the identity broker #2538).

With #2818: no conflicts, and the focused tests plus the cmd/mecak8s slice test pass on the two merged together. actor_token_expired → svid_expired drives #2818's renew-and-retry-once, and approval_required → denied shows the model "denied", which fits while AS-1 gives no link. #2818 now logs the broker error's code, reason and detail on a failed gateway call, so the four issuance reasons, which the model only sees as internal, can be diagnosed from Mecatl's logs.

@jhrozek

jhrozek commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

The 60s thing is ToolHive checking the validator's answer, not the SVID. If the validator refuses an expired SVID itself with actor_token_expired, which is what the validator contract asks for, the broker gets that reason however old the SVID is. server_error only happens if a validator accepts something that expired over a minute ago, and that's a validator bug. So I'd rather put a line in #2654 that our validator has to check expiry and refuse with actor_token_expired, than anything in #2538.

Fine with A for act.iss. Since it'll never match the ID-JAG's iss, the embedded AS-2 needs the trust domain in its allowed actor issuers, so let's write that down next to it. I'll fix the refusal order and the act.iss row here.

The "until #7030 lands" note on step 8 stays for now. I've got a follow-up on top of this PR that moves AS-2 to access_denied for valid ID-JAGs it won't take.

ToolHive v0.66.0 refuses upstream_subject_missing and sub_id_missing
while it decides the request, and dpop_not_supported right after that,
both before it calls the actor validator. Only bound_elapsed comes
after it. Move the two rows above check 6 in the step (7) failure
table.

The ToolHive work list marked the single-level act row done with
act.iss set to AS-1's issuer, but v0.66.0 refuses a validator issuer
equal to its own. Mark the row partly done until the act.iss value is
settled.

Co-authored-by: Mecatl <[email protected]>
@jhrozek

jhrozek commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks Chris, all fair.

On act.iss I went with your A, with one change. If act.iss is the trust domain, act.sub has to be a SPIFFE ID in it too. Otherwise we put a plain ag_ under a spiffe:// namespace it doesn't belong to, and ToolHive says it may start refusing that. So the SVID's sub itself becomes opaque, spiffe:///agent/ag_..., and the lineage stays in the registry only. act ends up as {iss: spiffe://agents.example.com, sub: spiffe://agents.example.com/agent/ag_7hq2x9}. The gateway still learns nothing about the lineage, and it's the shape the actor profile draft gives for a JWT-SVID actor token. One catch: trust domain names aren't unique (every interim install uses agents.mecatl.invalid), so the step 9 approval has to key on the ID-JAG iss plus act.iss, not act.iss alone. I'd rather do that in its own design PR. On main the code side is mostly re-keying the agent registry per instance and dropping the /inst/ suffix check in identity_broker.go.

Ordering: pushed 6145870. One small correction to the first cut though: dpop_not_supported isn't first. ToolHive checks the DPoP header after the request is decided (client, grant, subject claims) and before it calls the validator. So the order is the checks up to 4, then the subject claim reasons, then DPoP, then the validator, then bound_elapsed. I moved the subject claim and DPoP rows above 6 in the step (7) table.

Row 155 is back to "Partly" until act.iss is settled.

In-flight: yes, authorize.go already does it (stillOpen, after the exchange and after redemption). I fixed the PR description, which said it was design only.

Renewal window: agreed. It also means our production validator has to reject an expired SVID itself with actor_token_expired. Otherwise anything more than 60s past expiry comes back as a 500, which looks retryable but never succeeds.

@ChrisJBurns

ChrisJBurns commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

@jhrozek I've raised #2834, stacked on this PR, with what we agreed above:

  • act.iss is the agent trust domain, spiffe://<trust domain>, and AS-2 lists it among the actor issuers it accepts from AS-1.
  • act.sub is the instance's SPIFFE ID, spiffe://<trust domain>/agent/<ag_ identifier>.
  • Opaque SVID sub, as you proposed: the SVID's subject is that same SPIFFE ID, and definition, incarnation, and ancestry move to the registry, keyed by incarnation. Step (4), the instance-identity reference, agent-definitions.md, audit.md, and the implementation.md rows and test bullets are updated to match. The act row goes to "Yes".

The PR description lists the open tickets that need a small edit afterwards (#2527, #2552, #2553, #2555).

Approval keying (ID-JAG iss plus act.iss at step (8) check 9) is in #2835, stacked on #2834, so you don't need to write it. It overlaps #2825 on one test bullet in implementation.md, so whichever lands second needs a one-line rebase.

@ChrisJBurns
ChrisJBurns merged commit 9f1c044 into main Nov 17, 2026
78 checks passed
@ChrisJBurns
ChrisJBurns deleted the fix/identitybroker-as1-actor-reasons branch November 17, 2026 17:36
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Nov 18, 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.

2 participants