---
question: How do I give a script or a CI job its own account and keys?
kind: task
via_web: available
via_cli: available
via_python: na
via_api: available
via_config: na
ref_web: Roles & permissions › Service accounts
ref_cli: abi iam service-account create
ref_api: POST /api/iam/admin/service-accounts
prereq: You are the platform admin. Service accounts are administered at the platform only.
next:
  - /capabilities/platform/give-someone-access
  - /capabilities/platform/review-the-audit-log
---

# Manage service accounts

A service account is a principal for a script, a CI job or a module: it signs in with a service key (`abi_sk_…`), never as a person. Like anyone, it holds nothing until a policy is attached to it. Name accounts for scripts and CI `ci/<name>`; a module's account is `module/<project>/<module id>`.

Keys are stored hashed and shown once. An account has at most five active keys. Keys of `ci/…` accounts expire after 90 days by default, module keys never. Revoking a key takes effect at its next exchange and its next broker connection; tokens it already got expire within ten minutes.

## Web UI

### Open Service accounts

Open the account menu, **Platform Settings**, then **Roles & permissions** under Access, then **Service accounts**. The table shows each account's **Name**, **Kind**, **Status** and **Active keys**.

### Create the account

Type a name, such as `ci/report-sync`, in **Name of a new service account (a script, CI)** and choose **Create**.

### Create a key

Select the account's name to open its keys. Describe what the key is for (**What the key is for (prod, ci)**) and choose **Create key**.

Copy the key from the panel ("Copy this key now. It is shown only once") with **Copy**, store it in your CI's secrets, then choose **I have copied it**.

### Give it access

Attach a policy to the account's id (`sa_…`) in **People & roles**, at the level it should act: see [Give someone access](/capabilities/platform/give-someone-access).

### Rotate or revoke a key

In the account's keys (**Key**, **Description**, **Created**, **Expires**, **Last used**, **Status**):

- **Rotate** makes a new key, shows it once, and revokes the old one;
- **Revoke** stops a key.

### Suspend or delete the account

**Suspend** refuses every call of the account at once; **Resume** restores it. **Delete** revokes its keys and detaches its policies: type its name to confirm. Built-in accounts cannot be deleted.

## CLI

`abi iam` runs as the engine from your project, outside Nexus: it needs the project's configuration and no sign-in, and tells a running engine about each change.

### Create the account and a key

```bash
abi iam service-account create ci/report-sync --key
```

It prints the account's id and name, then the key, once. Without `--key`, create one later:

```bash
abi iam key create ci/report-sync --description "nightly report" --expires-in-days 30
```

### List

```bash
abi iam service-account list
abi iam key list ci/report-sync
```

`key list` shows each key's id, state, dates and description, never its value.

### Rotate or revoke

```bash
abi iam key rotate ci/report-sync <key-id>
abi iam key revoke ci/report-sync <key-id>
```

### Delete the account

```bash
abi iam service-account delete ci/report-sync
```

An account is named by its name or its `sa_` id. The CLI does not attach policies: use the Web UI for that. See [`abi iam service-account`](/user-guide/reference/cli#abi-iam-service-account) and [`abi iam key`](/user-guide/reference/cli#abi-iam-key).

## Python

Not applicable. The SDK does not create accounts or keys. A module reads its own key from `ABI_SERVICE_KEY`.

## REST API

:::warning Session only
The routes under `/api/iam/admin/` take a signed-in session only. A personal API key (`abi_pk_…`) is refused with 403 on `/api/iam/`, so a script that holds one cannot create accounts or keys: use the CLI for automation.
:::

### Accounts

```http
POST /api/iam/admin/service-accounts
Content-Type: application/json

{"name": "ci/report-sync"}
```

`GET /api/iam/admin/service-accounts` lists them, `DELETE /api/iam/admin/service-accounts/{id}` deletes one, and `POST /api/iam/admin/principals/{id}/suspend` or `…/resume` suspends or resumes it.

### Keys

```http
POST /api/iam/admin/service-accounts/{id}/keys
Content-Type: application/json

{"description": "nightly report", "expires_in_days": 30}
```

The key's value is in this answer only. `GET …/keys` lists the keys, `POST …/keys/{key}/rotate` rotates one, and `DELETE …/keys/{key}` revokes it.

## Config

Not applicable. Service accounts and their keys live in IAM, not in `config.yaml`.

## Use the key

A service key is exchanged over the message bus, at `abi.iam.v1.token`, for a token of ten minutes at most. A module gets its key as `ABI_SERVICE_KEY` and the SDK makes that exchange, and renews the token, on its own. The account then acts with exactly the policies attached to it.

Nexus's `POST /api/iam/token` does not take a service key: it exchanges personal API keys (`abi_pk_…`) only.
