# ServiceAccount and IdentityProvider

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


> A non-human identity your CI or automation becomes, with no stored secret: it trusts an external issuer, not a password.


A **ServiceAccount** is an identity that is not a person: the thing a CI pipeline, a
scheduled job, or a piece of automation signs in as. You create it, scope it with
ordinary [RBAC](https://docs.ringleader.dev/reference/resources/roles/), audit it, and revoke it.

```text
apiVersion: core.ringleader.dev/v1
kind: ServiceAccount
```

Its subject is `sa:<namespace>/<name>`, always namespace-qualified.
[Service accounts and CI sign-in](https://docs.ringleader.dev/organizations-teams/policies-identities/service-accounts-ci/) explains how one works, from creating it to turning it off.

## IdentityProvider

The trust anchor. It names the external issuer and the limit on what a trust rule
can pin.

```yaml
apiVersion: core.ringleader.dev/v1
kind: IdentityProvider
metadata:
  name: acmecorp-github     # must be, or start with, the owning org's name
spec:
  org: acmecorp
  profile: github-actions
  allowClaims: ["environment", "job_workflow_ref"]
```

| Field | Type | Description |
|-------|------|-------------|
| `org` | `string` | **Required.** The owning organization. |
| `profile` | `string` | **Required.** The ecosystem this provider represents: `github-actions`, `gitlab-ci`, `gcp`, `aws`, `azure`, `spiffe`, `ringleader-workstation`, or `custom`. |
| `issuer` | `string` | The issuer URL. Required for `custom`, and for any profile whose issuer is per-tenant or per-instance (self-hosted GitLab, Azure, an EKS cluster). Fixed by the profile otherwise, and a conflicting value is refused rather than silently overridden. |
| `audience` | `string` | The audience a trust rule may name. Optional: the deployment already publishes the audience it answers to. A value here may only **narrow** within what the deployment accepts. |
| `requireClaims` | `[]string` | Extra claims **every** rule under this provider must pin, on top of the profile's own mandatory ones. It can only tighten. Required (non-empty) for `custom`. |
| `allowClaims` | `[]string` | Claims a rule **may** pin beyond the mandatory ones. It never restates the mandatory claims. |
| `enabled` | `bool` | Master switch for the whole trust anchor. Absent means enabled; `false` refuses every exchange through it. |

[Service accounts and CI sign-in](https://docs.ringleader.dev/organizations-teams/policies-identities/service-accounts-ci/) lists the profiles, with the claims a rule must pin for each, the rule for a provider's name and who may write one.

## ServiceAccount

```yaml
apiVersion: core.ringleader.dev/v1
kind: ServiceAccount
metadata:
  name: ci
  namespace: dev
spec:
  description: Builds and tests the platform repo
  trust:
    - provider: acmecorp-github
      match:
        repository_owner_id: "1234567"
        repository_id: "7654321"
        environment: production
```

| Field | Type | Description |
|-------|------|-------------|
| `description` | `string` | What this identity is for. Worth writing, since it is what a reader sees months later. |
| `enabled` | `bool` | Master switch. Absent means enabled; `false` refuses every sign-in immediately, without deleting the account or its permissions. |
| `trust` | `[]object` | The trust list. See below. |

### Trust rules

Each entry of `spec.trust` is one external identity allowed to become this account.

| Field | Type | Description |
|-------|------|-------------|
| `provider` | `string` | **Required.** The `IdentityProvider` this rule trusts. |
| `audience` | `string` | Optional. Narrows the accepted audience for this rule within what the deployment accepts. |
| `match` | `object` | The claims this rule pins, as exact values. |
| `matchPrefix` | `object` | Claims pinned by **SPIFFE ID path prefix** instead. Only the `spiffe` profile's `sub` accepts one. |

A rule must pin something: use `match` or `matchPrefix`, never both in one rule.

[Service accounts and CI sign-in](https://docs.ringleader.dev/organizations-teams/policies-identities/service-accounts-ci/) says how a rule matches, what the SPIFFE path prefix does and how to give an account rights.

## Status fields

The system writes these.

| Field | Type | Description |
|-------|------|-------------|
| `lastAssumedAt` | `string` | When something last signed in as this account. Absent if nothing ever has. |
| `lastAssumedBy` | `object` | Who did: `{provider, ruleIndex, claims}`: the trust anchor, which rule admitted them, and the identity claims worth showing. |
| `authorityReason` | `string` | Why the account has been suspended, when it has. Absent on a healthy one. |
| `conditions` | `[]object` | Carries `Unused`; see below. |

### The `Unused` condition

Every account publishes an `Unused` condition, answering "should someone look at
this?". Its reason says which of four situations it is:

| Reason | Status | Meaning |
|---|---|---|
| `RecentlyUsed` | `False` | Used within the last 30 days. Healthy. |
| `NotYetUsed` | `False` | Never used, but created within the last 30 days. A pipeline that has not run yet looks exactly like this, so it is not flagged. |
| `NotUsedRecently` | `True` | Used, but not for over 30 days. |
| `NeverUsed` | `True` | Never used at all, and created over 30 days ago. This is the most suspicious of the four: an identity nothing has ever needed, still usable. |

[Service accounts and CI sign-in](https://docs.ringleader.dev/organizations-teams/policies-identities/service-accounts-ci/) says what the condition does and does not do, when an account is suspended, how to check one and how to turn one off.

## Next steps
- [Service accounts and CI sign-in](https://docs.ringleader.dev/organizations-teams/policies-identities/service-accounts-ci/): create one, trust a CI provider, sign in and turn it off.
- [Roles and RoleBindings](https://docs.ringleader.dev/reference/resources/roles/): the roles you bind an account to.
- [Organization and OrgDomain](https://docs.ringleader.dev/reference/resources/organization/): who may register an `IdentityProvider`.
- [`rl auth`](https://docs.ringleader.dev/reference/cli/commands/authentication/): login, status, and tokens.

