Repository navigation
Expose SPIFFE grant types in the operator CRD - #7175
Conversation
rdimitrov
left a comment
There was a problem hiding this comment.
Not ready to approve: the new required grantTypes field breaks existing SPIFFE MCPExternalAuthConfig resources on upgrade, and a default avoids that.
Design: Exposing the field at the CRD is the right layer. buildSPIFFEClientAuthRunConfigs is the only converter and both CRDs share it, and the Go and CEL transport rules match the runtime rule. The weak point is the upgrade story. SPIFFEClientConfig has shipped since v0.47.0 with no grantTypes (v0.66.0 explicitly says it is not exposed), and the operator always supplied token exchange.
cmd/thv-operator/api/v1beta1/mcpexternalauthconfig_types.go(theSPIFFEClientConfigCEL presence rule) andvalidateSPIFFEGrantsAndResourcesPresent: every existing SPIFFE association stored withoutgrantTypesbecomes invalid after the CRD and operator upgrade.ValidateInboundGrantsreturns "grantTypes is required", theMCPExternalAuthConfiggoesValid=false, and the servers consuming it stop reconciling until someone edits it. On clusters before Kubernetes 1.30 (no CRD validation ratcheting) even operator writes such as finalizer updates on old objects are rejected. Suggested fix: add+kubebuilder:default={"urn:ietf:params:oauth:grant-type:token-exchange"}. Defaults apply when objects are read back from etcd, so old objects keep working with no migration,client_credentialsstays opt-in, and you can drop the CEL presence rule, the Go presence check and the ratcheting caveat. If you keep the required design, tick the API Compatibility box and make the break explicit (label, release notes) rather than only mentioning it in the body.- Operator/CRD version skew: an old operator with the new CRD ignores
grantTypesand configures token exchange, so a CR that declares onlyclient_credentialsgets a grant it did not ask for. The operator-crds and operator charts are separate Helm releases, so the upgrade order indocs/arch/18is not enforced. This cannot be fixed on the old operator; put the ordering in the chart or release notes, not only in the architecture doc. - Mixed scope: the nil-registry change in
NewSPIFFEAssociationRegistry(with its comments and test) and the rewrite of the token-exchange paragraph indocs/arch/17are separate from exposing the CRD field. They are a distinct behaviour change; per the one-logical-change rule, please move them to their own PR.
Simpler alternative: with the CRD default from finding 1, what remains is the GrantTypes field with its enum and MinItems, the converter copy, and the two transport CEL rules with their Go mirror.
🤖 Reviewed with Claude Code
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7175 +/- ##
==========================================
+ Coverage 81.49% 81.55% +0.05%
==========================================
Files 894 894
Lines 91153 91164 +11
==========================================
+ Hits 74284 74346 +62
+ Misses 16864 16813 -51
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
94de838 to
9c08651
Compare
|
Thanks, agreed on all three. grantTypes now defaults to token exchange, so the CEL presence rule, the Go presence check and the grantTypes ratcheting text are gone. The envtest now checks that an association without the field reads back with token exchange. The version skew note is in the PR body's user-facing section so it lands in the release notes, and doc 18 keeps a one-line version of it. The nil-registry change and the doc 17 paragraph moved to #7177. |
rdimitrov
left a comment
There was a problem hiding this comment.
Re-review of 9c08651: the CRD default is the right fix for the earlier findings, with one gap left in the converter.
- Required
grantTypesbreaks stored associations on upgrade: resolved. It is now optional with a CRD default of the token-exchange grant, applied on read for stored objects, in all four CRD copies (including the inline VirtualMCPServer path), with an envtest case. - Old operator with new CRD: resolved in the sense that matters. An old operator behaves as before for every CR that omits the field.
- Mixed scope (
pkg/authserverchange and doc 17): resolved, both are gone from the PR.
New finding:
cmd/thv-operator/pkg/controllerutil/authserver.go:410: the converter copiesGrantTypeswith no fallback, so a nil or empty list reachesvalidateSPIFFEGrantTypes(pkg/authserver/spiffe_trust.go:735) and is rejected. Scenario: thethv-operatorchart is upgraded but the separate CRD chart is not (Helm does not upgrade CRDs). The old schema does not default or admitgrantTypes, so every stored SPIFFE association now fails at reconcile, where before this PR the converter hard-coded token exchange. The same nil reaches the converter from any caller that builds the object without the API server. The tests atauthserver_test.go:3753and:3827setGrantTypesexplicitly, so nothing covers nil. Suggested fix: inbuildSPIFFEClientAuthRunConfigs, use[]string{oauthproto.GrantTypeTokenExchange}whenlen(spiffeClient.GrantTypes) == 0, and add a converter test with nilGrantTypes. If you would rather keep the converter default-free and rely on "install CRDs first", say so and state that operators on the old CRD hard-fail; that is a deliberate trade-off I would want recorded in the PR body.
🤖 Reviewed with Claude Code
The runtime now accepts client_credentials on a SPIFFE association, but the operator hid the grant list and always injected token exchange, so no custom resource could use the new grant. Add a grantTypes field to spiffeClientAuth entries, limited to client_credentials and the token-exchange URN, one or two items, a set. It defaults to the token-exchange grant, which is what the operator configured before the field existed. The API server applies CRD defaults when it reads an object, including objects already stored, so existing associations keep their behavior with no migration and client_credentials stays opt-in. The converter copies grantTypes into the RunConfig and falls back to the same token-exchange grant when the list is empty, which happens when the operator chart is upgraded without the CRD chart and the old schema neither defaults nor keeps the field. Failing the reconcile there would break every existing SPIFFE association that the previous operator served. Now that a custom resource can list client_credentials, the CRD rules for insecureAllowHTTP and for http issuers, and ValidateInboundGrants, apply the same cleartext-transport condition as the runtime: an association counts as a confidential client only when it has spiffe_jwt in methods and client_credentials in grantTypes. Token- exchange-only JWT-SVID and X.509 associations are not affected. The rules guard the field with has(a.grantTypes). The field comments for both HTTP opt-ins name the SPIFFE case, and the loopback opt-in now says the combination is rejected at admission, with reconcile adding the loopback host check. Doc 18 describes the field and its default, and says to install the new CRDs and operator before adding client_credentials: an operator from before this change ignores grantTypes and always configures token exchange. The CRD YAMLs, deepcopy and crd-api.md are regenerated. Part of #6204. Co-authored-by: Mecatl <noreply@mecatl.dev>
9c08651 to
4c51934
Compare
|
Good catch, fixed. The converter now falls back to token exchange when grantTypes is empty, so an operator upgraded without the CRD chart keeps serving existing associations as before instead of failing reconcile. The converter test now covers nil and empty, doc 18 says the same, and the PR body records the trade-off: the converter deliberately duplicates the CRD default, and client_credentials needs the new CRDs because the old schema prunes the field. |
rdimitrov
left a comment
There was a problem hiding this comment.
Re-review of 4c51934: still right, approving. All earlier findings are resolved.
- Required
grantTypesbreaking stored associations: resolved. The field is optional with a CRD default of token exchange. - Old operator with new CRD: resolved.
- Mixed scope: resolved. The unrelated change moved to #7177.
- No converter fallback when the CRD chart lags the operator chart: resolved.
buildSPIFFEClientAuthRunConfigsnow usesspiffeGrantTypesOrDefault, which returns token exchange for a nil or empty list and otherwise returns a copy. Nil and empty cases are tested.
Design: the CRD default stays the primary mechanism. The converter fallback only covers an old CRD schema with a new operator, or an object built without the API server, and it preserves what the operator served before the field existed. An explicit empty list is still refused at admission (MinItems=1) and in RunConfig validation, so the fallback does not weaken those checks.
🤖 Reviewed with Claude Code
Summary
The auth server already accepts
client_credentialson a SPIFFE association, but the operator hid the grant list and always configured token exchange, so noMCPExternalAuthConfigorVirtualMCPServercould use the new grant.grantTypesfield tospiffeClientAuthentries:client_credentialsand/or the token-exchange URN, one or two items, a set. It defaults to the token-exchange grant, which is what the operator configured before the field existed. The API server applies the default when it reads objects, including ones already stored, so existing associations keep working with no migration andclient_credentialsstays opt-in.grantTypesinto the RunConfig and falls back to token exchange when the list is empty. The CRD default normally fills it in, but when the operator chart is upgraded without the CRD chart, the old schema prunes the field and every stored association would otherwise fail to reconcile.insecureAllowHTTPand HTTP-issuer CEL rules, and the matching Go validation, now treat an association withspiffe_jwtinmethodsandclient_credentialsingrantTypesas a confidential client, the same condition the runtime already applies.Part of #6204 (Integrate SPIFFE principals with OAuth grants and discovery).
Type of change
Test plan
go testoncmd/thv-operator/api/...,cmd/thv-operator/controllers/...,cmd/thv-operator/pkg/controllerutil/...andpkg/authserver/...cmd/thv-operator/test-integration/mcp-external-auth(Kubernetes 1.31 assets), including a new case that an association created withoutgrantTypesreads back with the token-exchange defaulttask test-e2e)task lint-fix)API Compatibility
v1beta1API, OR theapi-break-allowedlabel is applied and the migration guidance is described above.grantTypesis a new optional field with a default that matches the previous behavior. The two HTTP-transport rules only match associations that listclient_credentialsin the new field, so no existing object is affected.Changes
cmd/thv-operator/api/v1beta1/mcpexternalauthconfig_types.goGrantTypesfield with default, cleartext CEL rules and their Go mirrorcmd/thv-operator/pkg/controllerutil/authserver.gograntTypesinto the RunConfig instead of injecting token exchangedocs/arch/18-spiffe-association-declarations.mddocs/operator/crd-api.mdDoes this introduce a user-facing change?
Yes.
spiffeClientAuth[].grantTypesselectsclient_credentials, token exchange, or both; omitting it keeps token exchange.client_credentialscannot be combined withinsecureAllowHTTP, or with anhttp://issuer withoutinsecureAllowConfidentialOverLoopbackHTTP; such a CR is rejected at admission.client_credentialsto any association. An operator from before this change ignoresgrantTypesand always configures token exchange, and theoperator-crdsandoperatorcharts are separate releases, so nothing enforces this order.Special notes for reviewers
client_credentialscannot be enabled until the CRDs are upgraded, because the old schema prunesgrantTypes.