# Service accounts

URL: https://stack.logicaltech.it/docs/team/service-accounts/

Create LogiStack service accounts for CI pipelines and AI agents, give them a role, issue API keys they own, and keep automation working when people leave.

A service account is a machine identity for CI or an agent. It never signs in; it acts only through the API keys it owns. Use one whenever automation should outlive the person who set it up: a key owned by a member stops working the day that member is removed, while a key owned by a service account keeps going.

You need the **Owner** or **Admin** role to create, change or delete service accounts.

## Create a service account [#create-a-service-account]

<Steps>
<Step>
### Open API keys [#open-api-keys]

In the sidebar, under **Settings**, select **API keys**. Service accounts have their own panel below **Keys**.

![The API keys page, with the Service accounts panel listing GitHub Actions as a Viewer with 1 key](/screens/settings-api-keys.webp)
</Step>
<Step>
### Start a new one [#start-a-new-one]

In the **Service accounts** panel, select **New service account**.
</Step>
<Step>
### Name it [#name-it]

In **Name**, say what uses it, for example `GitHub Actions` or `Claude Code`.
</Step>
<Step>
### Pick its organization role [#pick-its-organization-role]

In **Organization role**, pick its access everywhere. **Owner** isn't offered. Start small: **Viewer** plus a scoped grant is usually enough for CI.
</Step>
<Step>
### Create it [#create-it]

Select **Create service account**. It appears in the panel with its role and key count, for example `Viewer · 0 keys`.
</Step>
</Steps>

## Give it a key [#give-it-a-key]

A service account does nothing until it has a key.

1. On **Settings › API keys**, select **Create API key**.
2. Name the key, for example `storefront-ci`.
3. In **Owner**, pick the service account. It's tagged **Service account** in the list.
4. Choose **Access**, **Expiry** and select **Create key**, as described in [API keys](./api-keys.mdx#create-a-key).
5. Copy the secret into your CI's secret store.

In the **Keys** table, the owner column shows the service account with a robot icon. In the [audit log](./audit-log.mdx), its actions show with the actor kind **Service account** (or **API key** for the key itself).

## Give it access to one project [#give-it-access-to-one-project]

The **Organization role** applies everywhere. For least privilege, give the service account **Viewer** on the organization and a stronger role only where it deploys. You can do this in two ways:

- **Narrow the key.** When you create the key, choose **Limit to scopes** and pick, for example, **Developer** on project **Storefront**. The key can then do no more than that, whatever the account's own roles. This is the simplest option.
- **Grant the account a scoped role** through the API. Service accounts aren't listed on **Settings › Members**, so use `POST /api/grants` with the service account's id as `userId`:

```bash title="Developer on one project for a service account"
curl -X POST https://stack.example.com/api/grants \
  -H "Authorization: Bearer $LOGISTACK_ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "userId": "usr_sa_github",
    "role": "developer",
    "scope": { "kind": "project", "id": "prj_storefront" }
  }'
```

`GET /api/service-accounts` lists service accounts with their ids. `PATCH /api/service-accounts/{id}` with `{"name": "...", "role": "..."}` renames one or changes its organization role.

## Example: GitHub Actions [#example-github-actions]

1. Create the service account `GitHub Actions` with **Viewer**.
2. Create the key `storefront-ci`, owner **GitHub Actions**, **Limit to scopes**: **Developer** on project **Storefront**, expiry **90 days**.
3. In GitHub, add the secret `LOGISTACK_KEY` under **Settings › Secrets and variables › Actions**.
4. Call the API from the workflow:

```yaml title=".github/workflows/deploy.yml"
name: Deploy
on:
  push:
    branches: [main]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Deploy storefront-web
        run: |
          curl -fsS -X POST \
            "https://stack.example.com/api/services/svc_storefront_web/deploy" \
            -H "Authorization: Bearer ${{ secrets.LOGISTACK_KEY }}"
```

5. [Rotate](./api-keys.mdx#rotate-a-key) the key before the 90 days run out and update the secret.

## Two-factor and SSO [#two-factor-and-sso]

Service accounts and their keys keep working when the organization [requires two-factor authentication](./two-factor-and-passkeys.mdx#require-two-factor-for-the-whole-organization). They don't sign in through SSO either.

## Delete a service account [#delete-a-service-account]

1. In the **Service accounts** panel, select the trash button on its row.
2. Read the dialog and select **Delete service account**.

<Callout type="warn">
Deleting a service account deletes every key it owns too, and anything using them stops working at once. Its grants are removed with it.
</Callout>
