Draft: feat(ac-lifecycle): authenticate pod-identity peers on the routes that admit them

Summary

  • Problem: AutoFlow, a service in the same cluster, needs to call Artifact Registry to clean up idle npm remote packages. It has no Rails token and no service token, only its Kubernetes service account.

  • Impact: nothing changes unless the AR_KUBERNETES_AUTH_ENABLED environment variable is the string true. With it on, an allowlisted service account can call the routes that admit it.

  • Change: on the management and GitLab APIs, an Authorization: Bearer token whose unverified issuer is the cluster's is verified offline against the cluster's OIDC keys, through the pod-identity module, and becomes a Kubernetes peer identified by its SPIFFE ID. Any other Bearer token takes the existing path unchanged. Each route decides whether it admits a peer. Today four do:

    • GET /api/v1/{slug}/repositories/{repository_name}, as Artifact Manager (read_repository).
    • GET /api/v1/{slug}/repositories/{repository_name}/npm/packages, as Artifact Manager (read_artifact).
    • POST /api/v1/{slug}/repositories/{repository_name}/npm/packages/bulk_delete, as Artifact Manager (delete_artifact).
    • GET /api/gitlab/v1/namespaces/{id}.

    The package routes admit a peer on npm only. Every other route answers a peer 403.

  • Downsides: a peer names no organization, so on the admitted routes it is Artifact Manager in every organization: the SPIFFE ID allowlist is the whole trust boundary. This is an accepted gap while the path is a work in progress and off by default; organization scoping is ADR-020 future work. With authorization unenforced, an admitted route checks no permission.

Note

This is the reference MR for the change and stays in Draft. It is not merged as is: the ADR, spec and code changes ship as separate MRs extracted from it. It adds 1,942 lines of Go (588 production, 1,354 tests, generated code excluded).

Checklist

  • Ran it: not yet. Only the unit tests: no run against a cluster with a real projected token.
  • Interfaces and data: adds the optional kubernetes_auth configuration block (audience, default artifact-registry; trust_domain; allowed_spiffe_ids; discovery_url) and the AR_KUBERNETES_AUTH_ENABLED switch. The switch is parsed strictly: unset, empty or false is off, true is on, and anything else fails the boot; true with no block fails the boot too. A configured block is validated at every load, on or off. discovery_url must be readable without credentials: the service sends no bearer. No API, schema or storage change for any other caller. Specified in S08 (authentication) and S09 (authorization), which owns the admitted-routes table; documented in docs/dev/configuration-reference.md and docs/dev/kubernetes-auth.md.
  • Failure: a token naming the cluster's issuer that fails verification answers 401 with no fallback, a SPIFFE ID off the allowlist 403, and unreachable OIDC keys 503. An unreachable discovery document at boot fails the boot. A route that does not admit peers, or a package route on another format, answers 403.
  • Rollout: off unless the variable is set, so a mixed deploy behaves as today.
  • Hot path: with the switch off, nothing is constructed. With it on, a management or GitLab API request with a Bearer token pays one unverified decode of the token's payload to read its issuer.
  • Database: n/a, no migration or query.
  • Security: yes, this adds an authentication path that skips IAM. A peer is checked in three places:
    • auth.PeerMiddleware routes a token by issuer and verifies it, on the management and GitLab API surfaces only.
    • auth.AdmitKubernetesPeers and auth.RefuseKubernetesPeers decide per route and method. validateBinding refuses to boot if a route admits peers off a repository-scope permission, or on a {format} route without naming one format.
    • authz.PeerRelationshipResolver synthesizes Artifact Manager tuples for a peer with no IAM read, so GLAZ still decides against the route's permission.
  • ADRs: ADR-020 (authentication flow) and ADR-021 (authorization) are amended for in-cluster service callers in gitlab-com/content-sites/handbook!21755 (merged), merged.
  • E2E: none yet. Rows for the admitted routes, the refused routes and the switch are planned with their tests.
  • Simplicity: rejected one central allowlist in PeerMiddleware: smaller, but it repeats each route's path. Each route opts in where it is registered instead.

Related to #1751 (closed) Related to gitlab-com/content-sites/handbook!21755 (merged)

Edited by David Fernandez

Merge request reports

Loading
Loading