Skip to content
TesseraDocs
MenuWorkload identity

Workload identity

How a CI job, a pod or a cloud service gets a short-lived Tessera token with no client secret, by proving where it runs.

View as Markdown

On this page

How a CI job, a pod or a cloud service gets a short-lived Tessera token with no client secret, by proving where it runs.

The workload holds an identity token that its platform issues (GitHub Actions, Kubernetes, AWS, Google Cloud, Azure, or any OIDC issuer). It posts that token to Tessera as a JWT bearer assertion (RFC 7523). You decide once, with a federation policy, which workloads are allowed and exactly what token they receive.

How it works

  1. A realm administrator registers the platform as a trusted issuer: its issuer URL, its JWKS URL and the audience its tokens must carry. Use the realm's issuer URL as that audience.
  2. The administrator writes a federation policy on that issuer: conditions on the token's claims, plus the scopes, resources and maximum lifetime the workload gets.
  3. The workload asks its platform for an identity token with the realm's issuer URL as audience, and posts it to $ISSUER/token with no client_id and no secret.
  4. Tessera checks the signature, the claims and the policy, and returns an access token.
curl -sS "$ISSUER/token" \
  -d grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer \
  --data-urlencode "assertion=$IDENTITY_TOKEN" \
  -d resource=https://api.acme.example \
  -d scope=deploy
{
  "access_token": "eyJhbGciOi...",
  "token_type": "Bearer",
  "expires_in": 900,
  "scope": "deploy"
}

Each identity token can be exchanged once. Fetch a fresh one for every exchange, and keep the Tessera token until shortly before it expires.

GitHub Actions

A realm administrator allows one repository and branch. Look first with --dry-run, then run it again without:

tessera workload-federation add github --realm acme \
  --repo acme/web --ref refs/heads/main \
  --repository-id 123456789 --owner-id 987654321 \
  --scope deploy --resource https://api.acme.example \
  --dry-run

--repository-id and --owner-id are the numeric ids in the token (gh api repos/acme/web --jq '.id, .owner.id'). They survive renames, so a deleted and re-created repository does not inherit access. The command refuses to continue without --ref or --environment, and refuses a wildcard repository. If your realm has its own login domain, add --audience https://login.acme.example.

In the workflow:

permissions:
  id-token: write
  contents: read
env:
  TESSERA_ISSUER: https://login.kurthlabs.com/realms/acme
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Get a Tessera token
        run: |
          set -euo pipefail
          audience=$(jq -rn --arg a "$TESSERA_ISSUER" '$a|@uri')
          identity=$(curl -sSf -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
            "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=$audience" | jq -r .value)
          echo "::add-mask::$identity"
          token=$(curl -sSf "$TESSERA_ISSUER/token" \
            -d grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer \
            --data-urlencode "assertion=$identity" \
            -d resource=https://api.acme.example -d scope=deploy | jq -r .access_token)
          echo "::add-mask::$token"
          echo "TESSERA_TOKEN=$token" >> "$GITHUB_ENV"

More than one branch: --ref 'refs/heads/release/**' or --ref 'refs/tags/v*'. A pull request job has the ref refs/pull/<n>/merge, which none of these admit. For a whole organization, pin it to a protected environment: --org acme --environment production.

Kubernetes

tessera workload-federation add kubernetes --realm acme \
  --oidc-issuer https://oidc.cluster.example \
  --namespace payments --service-account worker \
  --scope read --resource https://api.acme.example

This matches kubernetes.io/namespace and kubernetes.io/serviceaccount/name, both exactly. Tessera must be able to reach the cluster's JWKS URL (default <issuer>/openid/v1/jwks; pass --jwks-uri if it differs). In an ordinary realm that URL must be public https; a cluster API server on a private network is refused (destination_not_public), so expose its JWKS publicly or through a tunnel. If the cluster's tokens carry no jti, add --no-jti. In the pod, project a token whose audience is the realm's issuer URL:

spec:
  serviceAccountName: worker
  containers:
    - name: app
      volumeMounts:
        - {name: tessera-sat, mountPath: /var/run/secrets/tessera, readOnly: true}
  volumes:
    - name: tessera-sat
      projected:
        sources:
          - serviceAccountToken:
              path: token
              audience: https://login.kurthlabs.com/realms/acme
              expirationSeconds: 600

Then exchange $(cat /var/run/secrets/tessera/token) as the assertion, as above.

Clouds

Preset Required flags Matches
gcp --service-account-email email and email_verified
azure --tenant-id, --object-id tid and oid
aws --oidc-issuer, --jwks-uri, --role-arn sub equal to the role ARN

All presets also take --scope, --resource, --name, --audience, --no-jti, --max-token-lifetime and --named. Google and Azure tokens carry no jti and last up to an hour, so their presets set that up for you. Decode one real token first and compare its iss, sub and jti with what you registered.

Any other OIDC issuer

Register the issuer, then write the policy yourself:

curl -sS -X POST "$ADMIN/trusted-jwt-issuers" \
  -H "Authorization: Bearer $ADMIN_TOKEN" -H "Content-Type: application/json" \
  -d '{
    "issuer": "https://idp.customer.example",
    "jwks_uri": "https://idp.customer.example/.well-known/jwks.json",
    "audience": "https://login.kurthlabs.com/realms/acme",
    "subject_type": "workload",
    "allowed_grants": ["jwt-bearer"],
    "require_jti": true,
    "max_assertion_lifetime_seconds": 300
  }'
curl -sS -X POST "$ADMIN/federation-policies" \
  -H "Authorization: Bearer $ADMIN_TOKEN" -H "Content-Type: application/json" \
  -d '{
    "trusted_issuer_id": "<id from the first call>",
    "name": "partner-batch",
    "match": [
      {"claim": "sub", "op": "equals", "value": "svc:batch"},
      {"claim": "groups", "op": "in", "values": ["batch", "etl"]}
    ],
    "allowed_scopes": ["read"],
    "allowed_resources": ["https://api.acme.example"],
    "max_token_lifetime_seconds": 600
  }'

Issuer options: require_jti (default true; set false for platforms whose tokens have none, and Tessera then refuses a repeat by issuer, subject, audiences, iat and exp, and the token lives at most 5 minutes) and max_assertion_lifetime_seconds (60 to 3600, default 300). The jwks_uri must pass Tessera's outbound URL check. In an ordinary realm that means a public https URL: a private or internal address is refused with destination_not_public. Only the operator's own realms may reach private names.

Policy rules

A policy has 1 to 16 conditions and all must hold. Each is {claim, op, value} or {claim, op, values}.

op Holds when
equals The claim is exactly value
in The claim is one of values (1 to 50)
glob The claim matches value: * is any characters except /, ** is any characters, ? is one character except /
  • A claim path uses / between levels (kubernetes.io/serviceaccount/name). Write a key that itself contains / with ~1.
  • Matching is case sensitive. A missing, empty, object or over-long claim never matches. An array claim matches when any string element does. Nothing in a claim is treated as pattern syntax, and a glob must contain literal text (** alone is refused).
  • allowed_scopes never contain tessera: entries. allowed_resources (1 to 20) never include tessera-admin or tessera-account-ui. Lifetime is 60 to 3600 seconds, default 900.
  • When several policies match, the most specific wins: an exact value beats a list, a list beats a glob, a longer literal beats a shorter one. Equal policies that would issue different tokens are refused, never guessed. Creation order does not matter.
  • GET, PATCH and DELETE work on $ADMIN/federation-policies/<id>. Disable a policy with {"enabled": false}: new exchanges stop at once, tokens already issued run out their short life.

What the token carries

  • sub is workload:<issuer-id>:<subject>, so each branch, environment or service account is its own principal. With "principal": "named" (--named), every workload the policy admits shares one identity, agent:<issuer-id>:federation-policy:<policy-id>.
  • client_id is federation:<policy-id>. scope is what you asked for within the policy (default: all of it). aud is the requested resources within the policy. Its lifetime is the least of the realm's, the policy's and, for issuers without jti, 5 minutes.
  • Roles: bind them to the workload principal, for example tessera access bind --role api/deployer --workload <issuer-id>:repo:acme/web:ref:refs/heads/main. They appear as roles and permissions claims, never as scopes.

Test a policy

Decode the identity token's payload (never send the token), save it as claims.json and ask Tessera which policy admits it. Nothing is issued:

tessera workload-federation test --realm acme --claims-file claims.json \
  --resource https://api.acme.example --scope deploy

The answer is matched, no_match or ambiguous, the winning policy with the sub its token would carry, and for every other policy the first condition that failed.

Refusals

Answer Likely cause and fix
invalid_grant, not admitted by a policy No enabled policy matches, or two equally specific ones differ. Run the test above
invalid_grant, issuer or audience not trusted The audience the job asked for is not the one you registered
invalid_grant, lifetime too long The platform's token outlives max_assertion_lifetime_seconds; raise it (up to 3600)
invalid_grant, jti already used The same identity token was sent twice; fetch a new one
invalid_scope, invalid_target The request is outside the policy; ask for a subset
429 too_many_requests Many refused exchanges from one address for this issuer; wait for Retry-After

The audit log records jwt_bearer.issued (with the policy id) and jwt_bearer.refused (with a reason such as no_policy).

With a client instead

You can also give the workload a confidential client that allows the urn:ietf:params:oauth:grant-type:jwt-bearer grant and send -u "$CLIENT_ID:$CLIENT_SECRET" with the same request. The token's sub is the same workload:<issuer-id>:<subject>, the resources default to the client's, and the workload principal holds the roles. Use this only when you need a client; the policy path needs no secret. Reserved names are always refused: an assertion sub starting workload:, agent: or federation-policy:, and the resources tessera-admin and tessera-account-ui.