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_ENABLEDenvironment variable is the stringtrue. With it on, an allowlisted service account can call the routes that admit it. -
Change: on the management and GitLab APIs, an
Authorization: Bearertoken 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
npmonly. Every other route answers a peer403. -
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_authconfiguration block (audience, defaultartifact-registry;trust_domain;allowed_spiffe_ids;discovery_url) and theAR_KUBERNETES_AUTH_ENABLEDswitch. The switch is parsed strictly: unset, empty orfalseis off,trueis on, and anything else fails the boot;truewith no block fails the boot too. A configured block is validated at every load, on or off.discovery_urlmust 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 indocs/dev/configuration-reference.mdanddocs/dev/kubernetes-auth.md. - Failure: a token naming the cluster's issuer that fails verification answers
401with no fallback, a SPIFFE ID off the allowlist403, and unreachable OIDC keys503. An unreachable discovery document at boot fails the boot. A route that does not admit peers, or a package route on another format, answers403. - 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.PeerMiddlewareroutes a token by issuer and verifies it, on the management and GitLab API surfaces only.auth.AdmitKubernetesPeersandauth.RefuseKubernetesPeersdecide per route and method.validateBindingrefuses to boot if a route admits peers off a repository-scope permission, or on a{format}route without naming one format.authz.PeerRelationshipResolversynthesizes 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)