|
| 1 | +# Workload Identity Authentication |
| 2 | + |
| 3 | +A CI job can authenticate to Pulp with a short-lived OIDC token from a third-party provider (for |
| 4 | +example GitHub Actions) instead of a stored username and password. The token is verified against the |
| 5 | +provider's public keys, its claims are matched against a set of rules, and the request is granted |
| 6 | +roles for that request only. No user is created and nothing is written to the role tables. |
| 7 | + |
| 8 | +This suits supply-chain workflows where a pipeline pushes content and you want its permissions scoped |
| 9 | +to specific repositories without long-lived secrets. |
| 10 | + |
| 11 | +!!! note |
| 12 | + The token is an OIDC token, but this is unrelated to the user-facing SSO login covered in |
| 13 | + [Using external service](external.md). It identifies a workload, not a person. |
| 14 | + |
| 15 | +## How it works |
| 16 | + |
| 17 | +On each request the token is read from the `Authorization` header, either as a `Bearer` token or as |
| 18 | +the password of a `Basic` header (the way `docker login` sends a token). The `iss` claim selects a |
| 19 | +configured provider, the signature is verified against the provider's JWKS, and `iss`, `aud` and |
| 20 | +`exp` are checked. The remaining claims are matched against the provider's rules to compute the roles |
| 21 | +and scopes for the request. A token that matches no rule is rejected with a 401. |
| 22 | + |
| 23 | +## Enabling |
| 24 | + |
| 25 | +Add the authentication class to `DEFAULT_AUTHENTICATION_CLASSES`, before `BasicAuthentication` so the |
| 26 | +`docker login` path reaches it, then populate `WORKLOAD_IDENTITY`: |
| 27 | + |
| 28 | +```python title="settings.py" |
| 29 | +REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"] = [ |
| 30 | + "pulpcore.app.workload_identity.authentication.WorkloadIdentityAuthentication", |
| 31 | + "pulpcore.app.authentication.BasicAuthentication", |
| 32 | + "rest_framework.authentication.SessionAuthentication", |
| 33 | +] |
| 34 | +``` |
| 35 | + |
| 36 | +No change to `AUTHENTICATION_BACKENDS` is needed. The feature stays off while `WORKLOAD_IDENTITY` is |
| 37 | +empty, so adding the class alone changes nothing. |
| 38 | + |
| 39 | +With the example below, a push from the `main` branch of `my-org/app` is granted the |
| 40 | +`file.filerepository_owner` role on the repository named `prod`, and nothing else. See the |
| 41 | +configuration reference at the end for every option. |
| 42 | + |
| 43 | +## Roles for asynchronous tasks |
| 44 | + |
| 45 | +Operations that dispatch a task, such as a sync, return a task the client polls. A workload identity |
| 46 | +request is not a database user, so it is not automatically granted a role on the tasks it creates. |
| 47 | +Grant a role carrying `core.view_task` when the CI needs to read its own tasks. |
| 48 | + |
| 49 | +## Configuration reference |
| 50 | + |
| 51 | +Every option of the `WORKLOAD_IDENTITY` setting, annotated: |
| 52 | + |
| 53 | +```python title="settings.py" |
| 54 | +WORKLOAD_IDENTITY = { |
| 55 | + # How matching rules combine. |
| 56 | + # "union" (default) collects the grants of every matching rule. |
| 57 | + # "first-match" stops at the first matching rule. |
| 58 | + "strategy": "union", |
| 59 | + |
| 60 | + # One entry per trusted provider. The key is a name for your own reference. |
| 61 | + "providers": { |
| 62 | + "github": { |
| 63 | + # Required. Expected "iss" claim. Selects the provider and is verified while decoding. |
| 64 | + "issuer": "https://token.actions.githubusercontent.com", |
| 65 | + |
| 66 | + # Required. URL of the provider's JWKS. Keys are fetched and cached. |
| 67 | + "jwks_url": "https://token.actions.githubusercontent.com/.well-known/jwks", |
| 68 | + |
| 69 | + # Required. Expected "aud" claim. |
| 70 | + "audience": "https://pulp.example.com", |
| 71 | + |
| 72 | + # Optional. Allowed signing algorithms. Default: ["RS256"]. |
| 73 | + "algorithms": ["RS256"], |
| 74 | + |
| 75 | + # Rules are evaluated in order. Each maps claims to grants. |
| 76 | + "rules": [ |
| 77 | + { |
| 78 | + # Claim name to expected value. Values support "*" globbing. |
| 79 | + # Every entry must match (AND). A missing claim never matches. |
| 80 | + "match": {"repository": "my-org/app", "ref": "refs/heads/main"}, |
| 81 | + |
| 82 | + # Grants awarded when the rule matches. |
| 83 | + "grants": [ |
| 84 | + { |
| 85 | + # Required. Name of a role that already exists in Pulp. |
| 86 | + # A role that does not exist confers no permission. |
| 87 | + "role": "file.filerepository_owner", |
| 88 | + |
| 89 | + # Required. Where the role applies. One of: |
| 90 | + # {"type": "global"} everywhere |
| 91 | + # {"type": "domain", "domain": "<name>"} objects in a domain |
| 92 | + # {"type": "object", "name": "<name>"} one object by name |
| 93 | + # {"type": "object", "prn": "<prn>"} one object by PRN |
| 94 | + "scope": {"type": "object", "name": "prod"}, |
| 95 | + }, |
| 96 | + ], |
| 97 | + }, |
| 98 | + ], |
| 99 | + }, |
| 100 | + }, |
| 101 | +} |
| 102 | +``` |
0 commit comments