Skip to content

Agent Mesh

api,node,control-plane: type the OAuth metadata documents

Antonio Ojeada156045572d
diff --git a/api/network.go b/api/network.go
index c80536c5..e5315104 100644
--- a/api/network.go
+++ b/api/network.go
@@ -204,6 +204,31 @@ const (
TokenTypeAccessToken = "urn:ietf:params:oauth:token-type:access_token"
)
+// OAuthAuthorizationServerMetadata is the RFC 8414 document a token endpoint
+// serves at /.well-known/oauth-authorization-server. Only the fields Agent Mesh
+// populates are present; omitted RFC 8414 fields are optional there too.
+type OAuthAuthorizationServerMetadata struct {
+ Issuer string `json:"issuer"`
+ AuthorizationEndpoint string `json:"authorization_endpoint,omitempty"`
+ TokenEndpoint string `json:"token_endpoint"`
+ RevocationEndpoint string `json:"revocation_endpoint,omitempty"`
+ JWKSURI string `json:"jwks_uri,omitempty"`
+ ResponseTypesSupported []string `json:"response_types_supported"`
+ GrantTypesSupported []string `json:"grant_types_supported,omitempty"`
+ TokenEndpointAuthMethodsSupported []string `json:"token_endpoint_auth_methods_supported,omitempty"`
+ RevocationEndpointAuthMethodsSupported []string `json:"revocation_endpoint_auth_methods_supported,omitempty"`
+ CodeChallengeMethodsSupported []string `json:"code_challenge_methods_supported,omitempty"`
+}
+
+// OAuthProtectedResourceMetadata is the RFC 9728 document a resource server
+// serves at /.well-known/oauth-protected-resource.
+type OAuthProtectedResourceMetadata struct {
+ Resource string `json:"resource"`
+ AuthorizationServers []string `json:"authorization_servers,omitempty"`
+ BearerMethodsSupported []string `json:"bearer_methods_supported,omitempty"`
+ ScopesSupported []string `json:"scopes_supported,omitempty"`
+}
+
// ============================================================================
// Agent Mesh Custom HTTP Headers
// ============================================================================
diff --git a/internal/controlplane/sts.go b/internal/controlplane/sts.go
index 63c566eb..740e4757 100644
--- a/internal/controlplane/sts.go
+++ b/internal/controlplane/sts.go
@@ -377,15 +377,15 @@ func (s *Server) HandleOAuthAuthorizationServer(w http.ResponseWriter, r *http.R
return
}
issuer := s.oidcIssuerURL(r)
- doc := map[string]any{
- "issuer": issuer,
- "authorization_endpoint": issuer + "/oauth/authorize",
- "token_endpoint": issuer + "/oauth/token",
- "jwks_uri": issuer + "/jwks",
- "response_types_supported": []string{"code"},
- "grant_types_supported": []string{api.GrantTypeAuthorizationCode, api.GrantTypeTokenExchange},
- "code_challenge_methods_supported": []string{"S256"},
- "token_endpoint_auth_methods_supported": []string{
+ doc := api.OAuthAuthorizationServerMetadata{
+ Issuer: issuer,
+ AuthorizationEndpoint: issuer + "/oauth/authorize",
+ TokenEndpoint: issuer + "/oauth/token",
+ JWKSURI: issuer + "/jwks",
+ ResponseTypesSupported: []string{"code"},
+ GrantTypesSupported: []string{api.GrantTypeAuthorizationCode, api.GrantTypeTokenExchange},
+ CodeChallengeMethodsSupported: []string{"S256"},
+ TokenEndpointAuthMethodsSupported: []string{
"none",
"client_secret_post",
"private_key_jwt",
diff --git a/internal/node/sts.go b/internal/node/sts.go
index 2075ea61..6adbdb1e 100644
--- a/internal/node/sts.go
+++ b/internal/node/sts.go
@@ -786,10 +786,14 @@ func clientAssertionFromForm(form url.Values) (string, bool, error) {
if assertion == "" && assertionType == "" {
return "", false, nil
}
+ if assertion == "" {
+ return "", false, errors.New("client_assertion is required with client_assertion_type")
+ }
+ if assertionType == "" {
+ return "", false, errors.New("client_assertion_type is required with client_assertion")
+ }
switch assertionType {
case api.ClientAssertionTypeJWTBearer, api.ClientAssertionTypeJWTSPIFFE:
- case "":
- return "", false, errors.New("client_assertion_type is required with client_assertion")
default:
return "", false, fmt.Errorf("unsupported client_assertion_type %q; use %s or %s", assertionType, api.ClientAssertionTypeJWTBearer, api.ClientAssertionTypeJWTSPIFFE)
}
@@ -829,11 +833,11 @@ func handleOAuthProtectedResource(node *AgentMeshNode, w http.ResponseWriter, r
authServers = append(authServers, cpURL)
}
}
- meta := map[string]any{
- "resource": nodeBaseURL(node, r) + "/mcp",
- "authorization_servers": authServers,
- "bearer_methods_supported": []string{"header"},
- "scopes_supported": []string{"mcp", "inference", "egress", "a2a"},
+ meta := api.OAuthProtectedResourceMetadata{
+ Resource: nodeBaseURL(node, r) + "/mcp",
+ AuthorizationServers: authServers,
+ BearerMethodsSupported: []string{"header"},
+ ScopesSupported: []string{"mcp", "inference", "egress", "a2a"},
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(meta)
@@ -849,14 +853,14 @@ func handleOAuthAuthorizationServer(node *AgentMeshNode, w http.ResponseWriter,
return
}
issuer := nodeBaseURL(node, r)
- meta := map[string]any{
- "issuer": issuer,
- "token_endpoint": issuer + "/oauth/token",
- "revocation_endpoint": issuer + "/oauth/revoke",
- "response_types_supported": []string{},
- "grant_types_supported": nodeOAuthGrantTypes,
- "token_endpoint_auth_methods_supported": nodeOAuthClientAuthMethods,
- "revocation_endpoint_auth_methods_supported": nodeOAuthClientAuthMethods,
+ meta := api.OAuthAuthorizationServerMetadata{
+ Issuer: issuer,
+ TokenEndpoint: issuer + "/oauth/token",
+ RevocationEndpoint: issuer + "/oauth/revoke",
+ ResponseTypesSupported: []string{},
+ GrantTypesSupported: nodeOAuthGrantTypes,
+ TokenEndpointAuthMethodsSupported: nodeOAuthClientAuthMethods,
+ RevocationEndpointAuthMethodsSupported: nodeOAuthClientAuthMethods,
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(meta)
diff --git a/internal/node/sts_test.go b/internal/node/sts_test.go
index 46018ecf..ace3730d 100644
--- a/internal/node/sts_test.go
+++ b/internal/node/sts_test.go
@@ -659,6 +659,15 @@ func TestNodeOAuthTokenClientAssertionGrants(t *testing.T) {
status: http.StatusUnauthorized,
code: "invalid_client",
},
+ {
+ name: "client_assertion_type without client_assertion",
+ form: url.Values{
+ "grant_type": {api.GrantTypeClientCredentials},
+ "client_assertion_type": {api.ClientAssertionTypeJWTSPIFFE},
+ },
+ status: http.StatusUnauthorized,
+ code: "invalid_client",
+ },
{
name: "jwt-bearer without assertion",
form: url.Values{"grant_type": {api.GrantTypeJWTBearer}},
@@ -693,12 +702,7 @@ func TestNodeOAuthTokenClientAssertionGrants(t *testing.T) {
if rec.Code != http.StatusOK {
t.Fatalf("status %d", rec.Code)
}
- var meta struct {
- Issuer string `json:"issuer"`
- TokenEndpoint string `json:"token_endpoint"`
- GrantTypes []string `json:"grant_types_supported"`
- AuthMethods []string `json:"token_endpoint_auth_methods_supported"`
- }
+ var meta api.OAuthAuthorizationServerMetadata
if err := json.Unmarshal(rec.Body.Bytes(), &meta); err != nil {
t.Fatalf("json: %v", err)
}
@@ -706,12 +710,15 @@ func TestNodeOAuthTokenClientAssertionGrants(t *testing.T) {
t.Fatalf("issuer/token_endpoint = %q / %q", meta.Issuer, meta.TokenEndpoint)
}
for _, want := range []string{api.GrantTypeTokenExchange, api.GrantTypeClientCredentials, api.GrantTypeJWTBearer} {
- if !slices.Contains(meta.GrantTypes, want) {
- t.Fatalf("grant_types_supported %v lacks %s", meta.GrantTypes, want)
+ if !slices.Contains(meta.GrantTypesSupported, want) {
+ t.Fatalf("grant_types_supported %v lacks %s", meta.GrantTypesSupported, want)
}
}
- if !slices.Contains(meta.AuthMethods, "spiffe_jwt") || !slices.Contains(meta.AuthMethods, "private_key_jwt") {
- t.Fatalf("token_endpoint_auth_methods_supported = %v", meta.AuthMethods)
+ if !slices.Contains(meta.TokenEndpointAuthMethodsSupported, "spiffe_jwt") || !slices.Contains(meta.TokenEndpointAuthMethodsSupported, "private_key_jwt") {
+ t.Fatalf("token_endpoint_auth_methods_supported = %v", meta.TokenEndpointAuthMethodsSupported)
+ }
+ if !strings.Contains(rec.Body.String(), `"response_types_supported":[]`) {
+ t.Fatalf("response_types_supported must be an empty array, not null: %s", rec.Body.String())
}
})
}
diff --git a/tests/integration/sts_cuj_test.go b/tests/integration/sts_cuj_test.go
index fdae8970..01df7c93 100644
--- a/tests/integration/sts_cuj_test.go
+++ b/tests/integration/sts_cuj_test.go
@@ -446,16 +446,12 @@ egress:
if err != nil {
t.Fatalf("GET authorization server metadata: %v", err)
}
- var asMeta struct {
- TokenEndpoint string `json:"token_endpoint"`
- GrantTypes []string `json:"grant_types_supported"`
- AuthMethods []string `json:"token_endpoint_auth_methods_supported"`
- }
+ var asMeta api.OAuthAuthorizationServerMetadata
if err := json.NewDecoder(meta.Body).Decode(&asMeta); err != nil {
t.Fatalf("decode authorization server metadata: %v", err)
}
_ = meta.Body.Close()
- if !slices.Contains(asMeta.GrantTypes, api.GrantTypeClientCredentials) || !slices.Contains(asMeta.AuthMethods, "spiffe_jwt") {
+ if !slices.Contains(asMeta.GrantTypesSupported, api.GrantTypeClientCredentials) || !slices.Contains(asMeta.TokenEndpointAuthMethodsSupported, "spiffe_jwt") {
t.Fatalf("metadata does not advertise client_credentials/spiffe_jwt: %+v", asMeta)
}