Repository navigation
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7215 +/- ##
==========================================
- Coverage 81.64% 81.62% -0.03%
==========================================
Files 898 902 +4
Lines 91621 91735 +114
==========================================
+ Hits 74805 74878 +73
- Misses 16811 16852 +41
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
rdimitrov
left a comment
There was a problem hiding this comment.
Comment: the code is clean and nothing breaks on upgrade (no callers yet), but several trust-semantics decisions should be settled here, because #6887 will build on these interfaces and they are hard to change afterwards.
Design: Adding leaf packages (pkg/auth/subject, pkg/auth/actor) with depguard rules, and the resolver in pkg/authserver next to storage.UserStorage, is the right placement. The weak spots are where identity is scoped. The actor allowlist and the resolver both treat issuer and subject more loosely than the iss#sub identity implies. There is also now a third act parser and a second actor-authorization dialect (actor.claims here vs claims in ActorMatcher) with no stated plan to converge them.
Findings:
-
pkg/auth/actor/policy.go:112-119: the issuer and subject allowlists are two independent sets. With issuers{A, B}and subjects{agent-1}, actorB#agent-1passes even though onlyA#agent-1was meant. Subjects are only unique within an issuer. Fix: allow(issuer, subject)pairs (e.g.map[issuer][]subject), or document clearly that the subject list applies to every allowed issuer. -
pkg/auth/actor/policy.go:112,actor.go:49-60:Request.TokenIssueris never used.Effectivetakesact.issfrom the token body, so a token from issuer A carryingact:{iss:"B", sub:"x"}passes whenever B is allowlisted, with no check that A may speak for B. Fix: requireact.iss == TokenIssuerunless the operator lists explicit(tokenIssuer, actorIssuer)pairs. -
pkg/authserver/subjectresolver/resolver.go:61-79,:92:Newaccepts two issuers with the same providerNameand the same claim. Both then look upGetProviderIdentity(name, value)in one namespace (the storage key has no issuer component), so issuer B'ssub=123resolves to the local user linked to issuer A'ssub=123. Fix: reject sharedNameinNewunless the claims differ and are known to be in the same value space, or require one issuer perName. -
pkg/auth/subject/subject.go:14,resolver.go:92:Ref.Claimduplicates resolver configuration. The resolver is configured with a claim per issuer and then rejects aRefwhoseClaimdiffers, so callers must know the configured claim and a mismatch silently becomesErrUnknown. Fix: let the resolver extract the claim itself (Resolve(ctx, issuer, claims)) or exposeBindingClaim(issuer); ifRef.Claimstays, drop the equality check. -
pkg/auth/subject/binding_claim.go:18:ValidateBindingClaimis a denylist of four names (email,preferred_username,upn,unique_name).mail,name,nickname,username,login,phone_numberand namespaced email claims pass, while the package doc promises mutable claims are refused. Fix: extend the list or soften the doc to "known mutable claims". -
pkg/auth/actor/policy.go:118-146: a third CEL harness bypassingcelcore.Engine(for interrupt support), and actor CEL with different semantics fromActorMatcher. Fix: add interrupt and bool-output options totoolhive-core/celand use it from all sites, or state in the PR how #6887 and #7159 will reconcileactor_matcherwithPolicy. -
pkg/auth/actor/policy.go:122-132:Evaluatetrusts the exportedActorfields. An embedder building anActordirectly can passClaimscontaining a nestedact, orSource: "client"with claims, so CEL can be driven by a prior actor despite the type docs. Fix: ignoreClaims["act"]and ignoreClaimsfor client-sourced actors, or add a constructor.
Test gap: no test exercises a CEL runtime error through a live Policy call site; #6887 needs to know whether it maps to 5xx or refusal.
🤖 Reviewed with Claude Code
Tokens name a user by a claim from an issuer, and the token exchange, the vMCP and embedders must all map that claim to the same local user. Put the lookup key, the Resolver interface and its three failure modes in a leaf package under pkg/authserver, next to pkg/authserver/identity, so the authorization server does not depend on pkg/auth and other callers can import it without pulling in the rest of the server. ErrUnknown refuses the token, ErrAmbiguous lets directory-backed resolvers refuse an identity that matches two users, and ErrUnavailable tells callers to answer with a server error rather than invalid_grant so the client can retry. Closes #7157 Co-authored-by: Mecatl <noreply@mecatl.dev>
Delegated-access redemption needs to turn an identity-provider subject into the local user it belongs to. Add a subject.Resolver for the standalone authorization server that reads the provider-identity rows it already keeps (see the "Subject resolver" part of the delegated access issue). The resolver is built from a map of issuer to (provider name, subject claim). An unknown issuer, a claim other than the provider's subject claim, a missing row, or a row whose user is missing is ErrUnknown; any other storage error is ErrUnavailable. It never returns an empty user with a nil error. Rows exist only for the identity-provider sign-in leg, so later legs never resolve. A row alone does not prove the user exists: Redis deletes the user record before it cleans up the user's rows, best effort, so a stale row can outlive its user. Like the sign-in path, the resolver also loads the user and treats a missing one as ErrUnknown. Mapping an issuer to a provider asserts that the issuer's subject claim values are the subjects that provider's sign-in stores; a wrong mapping resolves to the wrong user. New accepts several issuers for one provider, but configuring that belongs to the third-party issuers work. Not wired into the server yet. Closes #7157 Co-authored-by: Mecatl <noreply@mecatl.dev>
The token-exchange handlers, the vMCP and embedders must reach the same answer on whether the agent named by a delegated token may act. Add the leaf package pkg/authserver/actor for it, from "Delegated access: subject resolver and actor policy packages" (#7157). Effective takes raw claims and returns the outermost act as the actor. An act without iss takes the token's iss, and a token without act is refused under the default source. Under the source "client", Effective names the client as the actor. Policy and Decision carry stable Reason strings, and Decision records the actor's source for audit. The default policy is bound to one token issuer and allows an actor whose issuer is that issuer or one configured to act through it, so a token from one issuer cannot name an actor issuer allowed only for another. The actor's issuer need not equal the token issuer: a ToolHive authorization server names its agents under their own issuer. A denial is a Decision; a Policy error means the policy could not decide, and callers answer with a server error. The actor's claims are a deep copy of the outermost act without its nested act, so a Policy that reads them cannot be driven by a prior actor or by a later change to the caller's claims. An actor with no issuer or subject is treated as no actor. Closes #7157 Co-authored-by: Mecatl <noreply@mecatl.dev>
The subject a delegated token maps to must come from a claim that stays stable for a user. email, preferred_username, upn, unique_name (where Entra v1 tokens carry the UPN) and the other profile claims such as name, phone_number, mail and username are mutable, so using them would let a changed address or display name resolve to a different local user. Refusing them here, in one exported function, lets the authorization server and the virtual MCP server share the rule. The list covers known names only, so a claim that passes is not proven stable. Okta custom authorization servers issue sub in access tokens that may not match the sign-in subject, so sub gets a warning there. The function returns the warning instead of logging it, so this leaf package stays free of logging and the caller decides how to report it. subjectresolver.New runs the same check on each provider's subject claim, so a resolver cannot be built over a mutable claim. It drops the Okta warning; callers that want it call ValidateBindingClaim themselves. Closes #7157 Co-authored-by: Mecatl <noreply@mecatl.dev>
Callers of the subject and actor packages need to fake the Resolver and Policy interfaces in their tests. Generate the gomock mocks, with the go:generate lines that produce them. Closes #7157 Co-authored-by: Mecatl <noreply@mecatl.dev>
9b293de to
24cfd3b
Compare
|
Thanks, this was useful. Going through them in order: 1, 6 and 7: I dropped the CEL expression and the subject allowlist from DefaultPolicy. Neither the subject mapping at redemption (#6887) nor the third-party issuers work (#7159) configures them, so they were a second actor CEL dialect next to the actor matcher with nobody using it. That removes the independent issuer/subject sets, the separate CEL harness and the "Evaluate trusts Actor.Claims" problem in one go. If someone needs richer actor rules later, they can come back as another Policy implementation on celcore once we know which dialect to standardise on. Policy stays an interface, so embedders can already plug in their own. 2: Agreed that nothing tied the actor issuer to the token issuer. I didn't go with act.iss == TokenIssuer as the default, though, because that breaks every ToolHive AS-1: its act.iss is the agent's issuer (for Mecatl a SPIFFE trust domain), and validateActIssuer even refuses an actor issuer equal to the server's own issuer. Instead a DefaultPolicy is now bound to one token issuer, NewDefaultPolicy(tokenIssuer, actorIssuers), and allows act.iss only from {tokenIssuer} plus the issuers configured to act through it. A request for another token issuer is an error. So it's your pairs model, one policy per token issuer, which is also how #6887 builds it. 3: The storage key is only (upstream name, subject), but the only thing that writes rows under a name is that upstream's own sign-in, and upstream names are unique, so rows from two issuers never mix by accident. Issuer B can only reach A's users if the operator maps B to A's name, and that mapping is exactly the cross-issuer feature: it says "B's claim values are A's stored subjects". Rejecting a repeated (name, claim) pair would block real cases where that holds, like Entra's v1 and v2 issuers for one tenant, which carry the same oid, and requiring different claims wouldn't stop a wrong mapping either. So I left New as is, made the Provider and New docs say plainly what the mapping asserts, and added a test for the Okta uid case. In #6887 the map only ever holds the identity provider's own issuer anyway, because of its startup check. 4: The claim is in Ref on purpose. In #6887 the value doesn't come from the identity provider's token: AS-1 vouches upstream_subject = {iss, claim, value}, so there's no claims map to hand the resolver. And a directory resolver should be able to look up (issuer, claim, value), say Okta uid or Entra oid, without knowing ToolHive's config, which BindingClaim(issuer) would force on it. The caller checks claim against binding_claim and refuses with invalid_assertion before it calls Resolve, so the resolver's check is a backstop. I kept it, because without it a Ref naming email would look up an email address as if it were a stored sub, and added a line to the Resolve doc saying so. 5: Agreed. The list now also has name, nickname, given_name, family_name, phone_number, mail, login and username, and the docs say "known mutable claim names", since a claim that passes isn't proven stable. Test gap: there's no live call site in this PR, so that one belongs to #6887. What's settled here is the contract: a denial is always a Decision, and a Policy error means it couldn't decide, so callers answer server_error, the same as the resolver's ErrUnavailable. I've put that in #6887's refusal table. On the third act parser: Effective's doc now says it's the strict parser for decisions, unlike the lenient audit.ParseDelegationChain, which never fails. A few other changes while I was at it, and a heads-up that I force-pushed with the fixes folded into the original commits. The two packages moved from pkg/auth to pkg/authserver/subject and pkg/authserver/actor, next to pkg/authserver/identity, so the authorization server doesn't pick up new pkg/auth imports. I dropped the depguard rule, because they import nothing else from ToolHive and the compiler catches cycles anyway. Decision now carries the actor's source for audit. And the actor and subject docs now point at tokenexchange.ActorTokenValidator and UpstreamIdentity, so it's clear which step each covers and that Ref is the same lookup key. |
rdimitrov
left a comment
There was a problem hiding this comment.
Re-review of 24cfd3b: approve. The earlier findings are resolved or withdrawn, and the new shape is simpler.
- Independent issuer/subject allowlists: resolved. The subject allowlist and the CEL expression are gone, so there are no separate sets left to cross-match.
TokenIssuerunused, no tie toact.iss: resolved with a different fix.NewDefaultPolicy(tokenIssuer, actorIssuers)binds one policy to one token issuer andEvaluaterejects any other. Your argument against requiringact.iss == TokenIssueris right, because agents with their own issuer (e.g. a SPIFFE trust domain) would break.- Shared provider
Nameacross issuers: withdrawn. Rows are only written by that upstream's own sign-in, and Entra v1/v2 issuers sharing oneoidis a real case that rejecting repeated names would block. The new docs and the Oktauidtest cover it. Ref.Claimduplicating resolver configuration: withdrawn. AS-1 vouches{iss, claim, value}, so the resolver check is a backstop, and theResolvedoc now says that.- Four-name denylist: resolved. It now has 12 names, matched case-insensitively, and the docs say "known mutable claim names".
- Third CEL harness / second actor dialect: resolved. CEL is removed and
Policystays an interface. Evaluatetrusting exportedActorfields: resolved for this PR.Effectivedeep-copiesClaimsandDefaultPolicynever reads them.- CEL runtime-error test: withdrawn, as there is no CEL left. The denial-versus-error contract is documented.
Two points to address in this PR or a follow-up. Neither blocks the merge:
pkg/authserver/actor/policy.go:62-70:DefaultPolicyis an issuer-only check. ForSourceClientthe actor issuer is always the token issuer, so it allows every client ID at that issuer. Anactwith noissfalls back to the token issuer and is allowed for anysub. If that is the intent, state in theDefaultPolicydoc that it does not restrict actors per subject or per client, and that anything finer needs anotherPolicy.Evaluatedoes not validateActor.Source, and forSourceClientit does not checkActor.Subject == req.ClientID. Both are cheap to add and would makeEvaluatesafe for a hand-builtActortoo, not only for the output ofEffective.
Design: unchanged in shape. The subject resolver, the standalone resolver and the actor Policy with Effective are still the pieces, now under pkg/authserver/{subject,actor} with one policy per token issuer. Nothing outside these packages imports them yet, so there is no upgrade impact.
🤖 Reviewed with Claude Code
Summary
Delegated access needs two answers for every delegated token: which local user it acts for, and whether the agent acting for that user is allowed. ID-JAG redemption at the gateway's authorization server, the vMCP's direct route and, later, token exchange all have to reach the same answers for the same token, and embedders need to be able to plug in their own user directory. This PR adds those answers as shared packages. Nothing calls them yet; "Delegated access: subject mapping at ID-JAG redemption" (#6887) is the first caller.
pkg/authserver/subject:Ref{Issuer, Claim, Value}, theResolverinterface and its three errors.ErrUnknownrefuses the token,ErrAmbiguousis for directory-backed resolvers that find two users, andErrUnavailabletells callers to answer with a server error so the client can retry.ValidateBindingClaimrefuses known mutable claim names (email,preferred_username,upn,unique_name, and profile claims such asname,phone_number,mailandusername) and warns onsubfor Okta custom authorization servers.pkg/authserver/subjectresolver: the standalone resolver. It maps an issuer to a configured provider and subject claim, reads the provider-identity row, and then loads the user, so a row that outlived its user (Redis deletes the user before cleaning up the rows) resolves toErrUnknown.Newrefuses mutable binding claims. It adds no storage method.pkg/authserver/actor:Effectivereturns the actor from the outermostact(anactwithoutisstakes the token's issuer, as Okta needs), or the client under theclientsource, with no fallback between the two.DefaultPolicyis bound to one token issuer and allows an actor whose issuer is that issuer or one configured to act through it, so a token from one issuer cannot name an actor issuer allowed only for another. Decisions carry stable reason strings for callers to map to reason codes, and the actor's source for audit. A denial is aDecision; aPolicyerror means it could not decide, and callers answer with a server error.ResolverandPolicy.Closes #7157
Type of change
Test plan
task test)task test-e2e)task lint-fix)Unit tests ran with the race detector on the three new packages at each commit, and
golangci-lintandgo vetreport no issues on them.Changes
pkg/authserver/subject/subject.goRef,Resolver,ErrUnknown,ErrAmbiguous,ErrUnavailablepkg/authserver/subject/binding_claim.goValidateBindingClaimpkg/authserver/subjectresolver/resolver.gopkg/authserver/actor/actor.goActor,Request,Decision,Policy,Effectivepkg/authserver/actor/policy.goDefaultPolicyand its reason stringspkg/authserver/{subject,actor}/mocks/Does this introduce a user-facing change?
No. The packages have no callers yet.
Special notes for reviewers
subjectresolver.Newchecks the binding claim but drops the Oktasubwarning on purpose. Configuration code that wants to report it callsValidateBindingClaimitself, so the leaf packages stay free of logging.Policyis an interface, so richer rules can be added as another implementation.validateActIssuereven refuses an actor issuer equal to the server's own issuer. Binding each policy to one token issuer gives the same protection.subjectresolver.Newasserts that the issuer's subject claim values are that provider's stored subjects. Rows are only written by that provider's own sign-in, so nothing mixes unless an operator maps an issuer to it; the docs say a wrong mapping resolves to the wrong user.subjectandactorlive underpkg/authserver, likepkg/authserver/identity, rather than underpkg/auth, so the authorization server gains nopkg/authimports. They import nothing else from ToolHive, so the vMCP and embedders can use them without the rest of the server.subject.Refis{Issuer, Claim, Value}, the shape of theupstream_subjectclaim. It is the lookup-key part oftokenexchange.UpstreamIdentity({Issuer, StableClaim, StableValue}, without the rawsub). Both docs now say so. No conversion helper yet; that comes with the redemption wiring, which is the first code that needs one.actorauthorizes theactclaim of a presented token;tokenexchange.ActorTokenValidatorchecks the actor's credential before an ID-JAG is issued. The two package docs point at each other.