# Service accounts and CI sign-in

> For the complete documentation index, see [llms.txt](https://docs-stg.ringleader.dev/llms.txt).


> A service account is an identity for CI or automation that signs in to Ringleader with no stored secret.


A service account is an identity that is not a person: the thing a CI pipeline, a scheduled job or a piece of automation signs in as. It holds no password, API key or long-lived token, so there is nothing to leak or rotate. Use one when a pipeline needs to sign in to Ringleader.

## Service accounts

You create a service account, scope it with ordinary roles, audit it and revoke it. Its subject is `sa:<namespace>/<name>`, always namespace-qualified, so two teams can both have a `ci` without them being the same identity anywhere.

By default, a service account holds a **trust list** instead of a secret. The list names which external identities may become the account. A GitHub Actions job proves who it is with the identity token GitHub already issues it. Ringleader checks that proof against the trust list and returns a short-lived token. So there is no stored secret to leak, rotate or paste into a secrets store.

[ServiceAccount and IdentityProvider](https://docs-stg.ringleader.dev/reference/resources/serviceaccount/) has the fields and status values.

## Identity providers and service accounts

Signing in this way takes two objects, written at two levels:

| Object | Scope | Who writes it | What it says |
|---|---|---|---|
| `IdentityProvider` | Cluster-scoped, belongs to one organization | An organization administrator | Tokens signed by this issuer may become identities here. It is the trust anchor. |
| `ServiceAccount` | Namespaced | Anyone who can create one in the namespace | These specific external identities may become this account. |

The split matters. Registering an issuer is a decision for the whole organization. Deciding that one repository may become one particular account is a day-to-day decision inside a namespace.

Two rules apply to an `IdentityProvider`:

- Its name must be the owning organization's name, or start with it followed by a hyphen. The kind is cluster-scoped, so every organization wanting a provider called `github` would collide. Use `acmecorp-github` or `acmecorp`, never a bare `github`.
- Only an organization administrator can write one. A namespace member has no access to it at all. If you signed up on your own, you already administer your personal organization, so you can register one for yourself. [Organization and OrgDomain](https://docs-stg.ringleader.dev/reference/resources/organization/) says more.

## Identity provider profiles

A profile records one ecosystem's issuer, how audiences behave there, and the claims a trust rule must pin to name a stable identity. A rule cannot pin fewer claims than its profile requires. It may always pin more.

| Profile | A rule must pin | Notes |
|---|---|---|
| `github-actions` | `repository_owner_id` and `repository_id` | Harden further with a GitHub Environment that has required reviewers (the `environment` claim), or `job_workflow_ref` for a reusable workflow. |
| `gitlab-ci` | `namespace_path` or `project_path` | Harden with a protected environment (`environment` and `environment_protected`), or `ref_protected`. |
| `gcp` | `email` or `sub` | The caller chooses the audience on the metadata server's identity endpoint. |
| `aws` | `sub` | The audience is set on the projected service-account token. |
| `azure` | `tid`, and `oid` or `sub` | The audience is a registered resource rather than a URL of ours, so the organization registers which resource value the deployment accepts. |
| `spiffe` | `sub` (the SPIFFE ID) | Your own SPIFFE and SPIRE trust domain. You may pin `sub` by path prefix, as [Trust rules](#trust-rules) says. Harden with a narrow SPIRE registration entry: a SPIFFE ID identifies only what its entry's selectors do, and one parented on a node alias names the host rather than the workload on it. |
| `ringleader-workstation` | `sub` | A workstation assuming a service account. [Workstation identity and capabilities](https://docs-stg.ringleader.dev/organizations-teams/policies-identities/workstation-identity/) says how. |
| `custom` | Nothing built in, so `requireClaims` must name at least one claim | Also requires an explicit `issuer`. |

Run `rl serviceaccount trust --help` for the same table as your deployment sees it.

## Trust rules

Each entry of a service account's `trust` list is one external identity allowed to become the account. [ServiceAccount and IdentityProvider](https://docs-stg.ringleader.dev/reference/resources/serviceaccount/) lists its fields. The matching rules are blunt:

- Every claim in a rule must match for that rule to admit.
- Any matching rule admits, so several pipelines can share one account.
- Matching is exact string equality. There are no wildcards and no regular expressions, because an authority boundary is not a place for pattern matching. There is one exception, the SPIFFE path prefix.

Under the `spiffe` profile, `sub` may be pinned by path prefix, so one rule covers every workload beneath a SPIFFE path you control:

```yaml
spec:
  trust:
    - provider: acme-spire
      matchPrefix:
        sub: spiffe://acme.example/ns/payments
```

```bash
rl serviceaccount trust ci --provider acme-spire \
    --claim-prefix sub=spiffe://acme.example/ns/payments
```

A prefix matches on path segments, never on characters. `spiffe://d/ns/pay` admits `spiffe://d/ns/pay/api` and never `spiffe://d/ns/payroll`. A prefix must name at least one path segment below the trust domain, so you cannot pin a whole trust domain this way.

## Unused service accounts

Every service account publishes an `Unused` condition, which answers whether someone should look at the account. [Status fields](https://docs-stg.ringleader.dev/reference/resources/serviceaccount/#status-fields) lists its four reasons.

Flagging is all it does. Nothing is ever disabled or deleted automatically at any threshold, because a quarterly release pipeline is not abandoned, it is quarterly. When an account is finished, set `enabled: false` or delete it.

The window is a fixed 30 days. It is not configurable, per account or per deployment. A threshold that the owner of a forgotten account could raise until the flag stopped firing would not be worth publishing.

The condition says no use has been recorded. That is not the same as asserting none happened. Accounts that predate usage recording start out looking unused until something signs in as them.

## Suspension

A service account is suspended when the person who created it no longer has permission to create one in that namespace. It stops being usable immediately, without being deleted, and `status.authorityReason` says so in as many words. An administrator can restore the creator's access, or someone who has that access can recreate the account.

Ringleader checks this continuously rather than only at creation. That is what keeps "a service account never carries more than its creator could grant directly" true after the fact.

## Create a service account

Anyone who can create one in the namespace can.

```bash
rl serviceaccount create ci
```

Describe what the account is for in `spec.description`. It is what a reader sees months later.

## Trust a CI provider

An organization administrator registers the provider once. [ServiceAccount and IdentityProvider](https://docs-stg.ringleader.dev/reference/resources/serviceaccount/#identityprovider) has an example `IdentityProvider` and its fields.

1. Register the issuer as an `IdentityProvider`, with the profile for your ecosystem. Apply it with `rl apply -f`.
2. Add a trust rule to the service account. The rule must pin at least the claims its profile requires.

   ```bash
   rl serviceaccount trust ci --provider acmecorp-github \
       --claim repository_owner_id=1234567 \
       --claim repository_id=7654321 \
       --claim environment=production
   ```

A rule that pins too few claims for its provider's profile is refused, whether you add it with the command or write it by hand.

## Give a service account rights

A service account holds no rights of its own. Rights come from ordinary role bindings that name its subject, exactly as for a person:

```yaml
apiVersion: core.ringleader.dev/v1
kind: RoleBinding
metadata:
  name: ci-can-build
  namespace: dev
spec:
  subjects: ["sa:dev/ci"]
  roleRef:
    kind: GlobalRole
    name: namespace-member
```

You can never bind an account to more than you hold yourself. An account is bounded by its author's own access, before and after it is created. [Roles and grants](https://docs-stg.ringleader.dev/organizations-teams/accounts-access/roles-grants/) says how roles work.

## Sign in from CI

From a CI job that has an ambient workload identity, sign in with no secret at all.

1. In a GitHub Actions workflow, let the job issue its own identity token.

   ```yaml
   # .github/workflows/build.yml
   permissions:
     id-token: write     # required: this is what lets the job mint its own assertion
   ```

2. Run `rl auth login` with the service account and the provider.

   ```bash
   rl auth login https://ringleader.example.com \
       --service-account dev/ci \
       --provider acmecorp-github
   ```

The command asks the job's platform for an identity assertion, presents it, and gets a short-lived token back. Nothing is stored on disk that is worth stealing. What it keeps is the recipe, which is the origin, the provider and the account. The recipe is useless without an ambient identity that only that runner can produce.

This works only where something can prove who the process is. That means one of these:

- A GitHub Actions job with `permissions: {id-token: write}`.
- A host running a SPIRE agent that has a registration entry for the process. The [`spire-agent` devtool](https://docs-stg.ringleader.dev/reference/tools/devtools/spire-agent/) is one way to get that.
- A Ringleader workstation that holds the `sa:assume` capability, matched by a trust rule whose provider has the `ringleader-workstation` profile. [Workstation identity and capabilities](https://docs-stg.ringleader.dev/organizations-teams/policies-identities/workstation-identity/) says more.

On a laptop there is nothing to exchange, so use the ordinary [`rl auth login`](https://docs-stg.ringleader.dev/reference/cli/commands/authentication/#rl-auth-login-url).

[Authentication commands](https://docs-stg.ringleader.dev/reference/cli/commands/authentication/) lists the flags. You normally never set `--audience`, which defaults to the audience Ringleader advertises for itself. Pass it only for a migration, or a hostname your operator accepts in addition to the canonical one. Leave `--register-node` off on an ephemeral runner, because its registration would add the runner's key to every workstation the account owns and re-push their configuration. Turn it on for a long-lived robot on a fixed host.

Every rejected sign-in gets the same opaque answer, whatever went wrong: no such account, switched off, no rule matched, a claim mismatch. The endpoint is unauthenticated, and a specific message would let anyone probe another tenant for the names of their accounts. The detail you need is on the account's own status and in its events.

## Check a service account

`rl serviceaccount get` (alias `sa`) shows which identities nothing is using:

```bash
rl serviceaccount get
```

```text
NAMESPACE   NAME        LAST USED   STATUS      AGE
dev         ci          14m         Ready       62d
dev         nightly     41d         Unused      95d
dev         old-robot   NEVER       Unused      210d
dev         legacy-ci   3d          Disabled    1y
```

- **LAST USED** is how long ago something last signed in, or `NEVER`.
- **STATUS** is one word, most blocking first: `Suspended` (Ringleader withdrew it), `Disabled` (you switched it off with `enabled: false`), `Unused` (the condition is flagged), else `Ready`.

`rl serviceaccount describe ci` adds the full status, including who last assumed the account and under which rule. Sign-ins are also recorded as events in the namespace. `rl event get` shows an `Assumed` entry naming the provider and rule. It shows an `AssumptionRefused` warning when something proved a real identity from a provider your organization registered but matched none of your rules. That is usually a rule that needs updating.

## Turn off a service account

There are three levers, from narrowest to widest:

1. Delete a trust rule. That external identity can no longer become the account, and the others still can.
2. Set `spec.enabled: false` on the account. Nothing can become it, but the object and its permissions survive, ready to be switched back on.
3. Set `spec.enabled: false` on the `IdentityProvider`. Every account trusting that issuer stops working at once. This is the break-glass switch for a compromised issuer.

Deleting the account removes it entirely. All four take effect on the very next sign-in attempt, not on a cache's schedule.

## Next steps

- [ServiceAccount and IdentityProvider](https://docs-stg.ringleader.dev/reference/resources/serviceaccount/): the fields and status of the two objects.
- [Authentication commands](https://docs-stg.ringleader.dev/reference/cli/commands/authentication/): the flags of `rl auth login`.
- [Workstation identity and capabilities](https://docs-stg.ringleader.dev/organizations-teams/policies-identities/workstation-identity/): let a workstation sign in as a service account.
- [Roles and grants](https://docs-stg.ringleader.dev/organizations-teams/accounts-access/roles-grants/): the roles you bind an account to.

