Add OAuth 2 scopes

Merged
LU
6mo ago
+1988-290

Add explicit read/write scope pairs for each product API resource so
OAuth clients can request granular access. Validation and implied-scope
helpers live next to the existing standard OAuth2 scopes.


Summary by cubic

Adds granular OAuth2 v1 API scopes and enforces a scope→action gate before IAM policy. Discovery now advertises API scopes and RFC 9728 protected-resource metadata; the consent screen shows readable names with fallbacks, and existing tokens are backfilled so clients keep working.

Coredata +71 -26

  • Relaxed scope persistence; OIDC scope validation moved to pkg/iam/oauth2.
  • Migration backfills existing access tokens with all API scopes.

Service +1061 -75

  • Added pkg/iam/oauth2 with OIDC scopes, API scope registry, protected-resource metadata, and request-scope context.
  • Authorizer gates actions via ScopeSet; returns ErrInsufficientOAuth2Scope before policy eval.
  • Registered scope sets for IAM, probo, accessreview, and agentrun; wired into services and probod.
  • Introduced API scope constants across probo, iam, accessreview, and agentrun.
  • Moved access-review driver catalog policy/action into accessreview; added core:connector:get.

GraphQL API +128 -105

  • Access-token middleware attaches token scopes to context; authz uses typed iam.Action.
  • Map insufficient-scope errors to 403 in GraphQL and Files API.
  • Expose /.well-known/oauth-protected-resource; discovery includes API scopes and protected resources.
  • Renamed connector CIMD handler; updated imports to pkg/iam/oauth2.

MCP +8 -0

  • Return “insufficient scope” when OAuth scopes are missing.

App: console +15 -5

  • Consent shows a key icon and falls back to raw names for unknown API scopes.

Agents +31 -0

  • Documented API scope format, discovery endpoints, and protected-resource metadata.

Tests +674 -79

  • E2E for API-scoped clients, discovery, and protected-resource metadata.
  • Bearer GraphQL helper and API-scoped client factory.
  • Unit tests for scope gate, ScopeSet, and OAuth2 metadata.