> ## Documentation Index
> Fetch the complete documentation index at: https://www.datum.net/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Agent home for Datum, with what it is, pricing, and how to act: https://agents.datum.net
> If you can only fetch URLs: read https://www.datum.net/docs/llms.txt in full and open the most specific page for the task. Commands, limits, and field paths are on task, operations, and limits pages, not on section overviews. Pages described as "Documentation is coming soon" are placeholders.
> If you have a shell or can save files: download https://www.datum.net/docs/llms-full.txt (every page, about 740 KB) once and search it with grep, instead of fetching pages one at a time.
> datumctl describes itself: `datumctl api-resources` lists resource types and `datumctl explain <resource>` shows a schema. To act on live resources, use Datum MCP or datumctl. To search the docs, use the Docs MCP server at https://www.datum.net/docs/mcp.

# Service accounts

> Authenticate datumctl non-interactively with a service account credentials file for CI, automation, and headless environments.

Service accounts let `datumctl` authenticate without a human at the keyboard. Instead of opening a browser, you point the CLI at a credentials file, and it signs in as the service account's machine identity. Use this for continuous integration jobs, scheduled automation, and any headless runner where an interactive login is not possible.

> [!NOTE]
>
> Service accounts are **created in the Datum Cloud portal**, which is where you generate and download the credentials file. This page covers **using** those credentials with `datumctl`. To create a service account and download its key, see the portal guide on [service accounts](https://www.datum.net/docs/projects/service-accounts.md).

## When to use a service account

Choose the authentication method that matches who — or what — is running the command:

> [card] Interactive login
>
> A person at a terminal. Run `datumctl login` to authenticate through your browser (or `datumctl login --no-browser` for a device-code flow). Credentials refresh automatically and are tied to your user identity.

> [card] Service account
>
> A pipeline, cron job, or agent with no human present. Run `datumctl login --credentials <file>` to sign in as a machine identity using a downloaded credentials file.

Service accounts are the right choice when:

* The command runs unattended, so no one can complete a browser or device prompt.
* You want a dedicated, auditable identity for automation rather than a personal account.
* You need the same credentials to work reproducibly across many runners.

## Log in with a credentials file

Once you have downloaded a credentials JSON file from the portal, authenticate by passing its path to `datumctl login`:

```bash theme={null}
datumctl login --credentials ./my-service-account.json
```

`datumctl` reads the file, requests an access token for the service account, and stores the resulting session so subsequent commands are authenticated. After login you can run any command as the service account:

```bash theme={null}
datumctl get organizations
```

> [!NOTE]
>
> Service-account login is non-interactive: it does **not** open a browser and does **not** prompt you to pick a context. Set the organization or project your commands should target explicitly — see [Contexts & scoping](https://www.datum.net/docs/datumctl/contexts-and-scoping.md) — or pass `--organization` / `--project` on each command.

### Targeting a custom environment

The credentials file is issued for a specific Datum Cloud environment. For a self-hosted or otherwise custom environment, also pass that environment's auth hostname so token discovery points at the right server:

```bash theme={null}
datumctl login --credentials ./my-service-account.json --hostname auth.example.com
```

The default `--hostname` is `auth.datum.net` (production). You normally do not need `--api-hostname` — `datumctl` derives the API server from the auth hostname — but you can override it if your environment requires a specific API endpoint.

### Confirming the active identity

To verify which identity is active, use:

```bash theme={null}
datumctl whoami
```

The service account also appears in the local account list, where its `client_email` is shown as the name:

```bash theme={null}
datumctl auth list
```

## The credentials file

The credentials file is a JSON document you download from the portal. It looks like this:

```json theme={null}
{
  "type": "datum_service_account",
  "client_email": "ci-deployer@example",
  "client_id": "1234567890",
  "private_key_id": "abc123",
  "private_key": "-----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----\n",
  "scope": "openid profile email offline_access urn:zitadel:iam:org:project:id:328728232553618699:aud"
}
```

Key fields:

| Field | Purpose |
| - | - |
| `type` | Must be `datum_service_account`. `datumctl` rejects any other value. |
| `client_id` | The service account's identity. **Required.** |
| `private_key_id` | Identifies which signing key is in use. **Required.** |
| `private_key` | PEM-encoded private key used to sign the login request. **Required.** |
| `client_email` | Human-readable identity, shown as the account name in `datumctl auth list`. |
| `scope` | OAuth scopes requested at login, including the audience scope the Datum API requires. |

> [!WARNING]
>
> The credentials file contains a **private key**. Treat it like a password: never commit it to source control, restrict its file permissions, and store it in your CI system's secret manager. Anyone with the file can authenticate as the service account.

If login fails, `datumctl` reports exactly what is wrong — a missing required field, an unreadable file, or a `type` that is not `datum_service_account` — so you can correct the file and retry. To inspect the token request in detail while troubleshooting, add `--debug`, which prints the login JWT's claims to standard error.

## Authenticate directly with the API

Prefer the downloaded credentials file with `datumctl login --credentials`. Preserve its `scope` field when integrating with another client. Generated production credentials include the scope needed for the Datum API to accept the issued token.

For a client that implements the JWT bearer flow:

1. Sign an RS256 JWT using the private key. Set the header `kid` to `private_key_id`, and set both `iss` and `sub` to `client_id`. Set `iat` to the current time and `exp` to 60 seconds later.
2. Set the assertion's `aud` to `https://auth.datum.net`, the production issuer. Do not use the API hostname or the full token endpoint URL.
3. POST a form-encoded request to `https://auth.datum.net/oauth/v2/token` with `grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer`, `assertion` set to the signed JWT, and `scope` copied from the credentials file. A user-managed key has no credentials file, so set `scope` yourself to the production value shown in the example above.
4. Use the returned `access_token` as a Bearer token when calling the project API. The service account also needs an appropriate IAM role for the operation.

To use a user-managed key with `datumctl login --credentials`, build a credentials file with the fields above, including `scope`. In production, set it to:

```text theme={null}
openid profile email offline_access urn:zitadel:iam:org:project:id:328728232553618699:aud
```

If `scope` is omitted, `datumctl` requests only `openid profile email offline_access`, and the API rejects the resulting token with 401.

The production scope includes `urn:zitadel:iam:org:project:id:328728232553618699:aud`. This selects the identity-provider project audience for the issued token; it is not the assertion's `aud` and is not your Datum project ID. Custom environments can use a different scope and issuer. Use their generated credentials and authentication configuration rather than copying production values.

## Troubleshoot authentication and authorization

Check which request failed before changing roles:

* **Token exchange fails with `invalid_grant`:** check the assertion audience, signing key, key ID, client ID, and timestamps. In production, the assertion audience is `https://auth.datum.net`.
* **Token exchange succeeds but the API returns 401:** check that the exchange preserved the complete credentials `scope`, including the project audience scope. A successful exchange alone does not establish that the API accepts the token. Also check token expiry.
* **The API returns 403:** check the service account's role bindings and the project targeted by the request. An accepted token does not grant resource access.

Do not include private keys, signed assertions, or access tokens in logs or support requests.

## Credential storage on headless runners

On a runner with no system keyring, `datumctl` falls back to an unencrypted file at `~/.datumctl/credentials.json`. For what that means and how to keep it clean, see [Credential storage on headless runners](https://www.datum.net/docs/datumctl/cicd/automating.md#credential-storage-on-headless-runners).

## Related

* [Create a service account in the portal](https://www.datum.net/docs/projects/service-accounts.md) — generate the credentials file this page consumes.
* [Automating datumctl in CI/CD](https://www.datum.net/docs/datumctl/cicd/automating.md) — wire service-account login into any pipeline, with credential helpers and structured errors.
* [GitHub Actions](https://www.datum.net/docs/datumctl/cicd/github-actions.md) — install and authenticate a service account in a GitHub workflow in one step.
* [Logging in](https://www.datum.net/docs/datumctl/auth/logging-in.md) — the interactive browser and device-code flows for humans at a terminal.
* [Managing accounts & tokens](https://www.datum.net/docs/datumctl/auth/managing-accounts.md) — list sessions, switch the active identity, and print access tokens.
* [Contexts & scoping](https://www.datum.net/docs/datumctl/contexts-and-scoping.md) — set the organization or project your automated commands target.
* [Output formats & scripting](https://www.datum.net/docs/datumctl/output-and-scripting.md) — machine-readable output and structured errors for automation.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.