# Manage keys and service accounts

Source: https://docs.graphops.xyz/platform/cli/api-keys

Create a key for each application and pipeline, and replace or revoke it from your terminal without
opening the platform. `graphops api-keys` lists, creates, changes, renames, rotates and revokes your
organization's [API keys](/platform/api-keys).
`graphops service-accounts` creates [service accounts](/platform/service-accounts),
changes their permissions, deletes them, and creates their keys. Run a command with `--help` to see
its options.

To keep one key on your own machine for development, store it instead: see
[Developer workflow](/platform/cli/developer-workflow).

## Prerequisites

* The owner or developer role.
* A sign-in from the last 12 hours to create or change credentials. If the CLI asks you to sign in
again, run `graphops auth login`.

## Create a key

A new key's secret is shown once. Pass `--reveal` to print it, alone on its line, so you can pipe it
straight into your CI system's secret store. Or pass `--secret-file <file>` to write it to a new
file that only you can read. The command requires one of the two, or `--store`, which keeps the key
in your credential store for `graphops exec` instead.

`graphops api-keys create` without `--product` grants every data service your organization can use;
at a terminal, it asks which. Pass `--product rpc` (repeat for several) to grant only some.

## Find and change a key

* **Name a key by its name or ID.** `show`, `update`, `rename`, `rotate` and `revoke` take either,
as `graphops api-keys list` shows them. When several keys share a name, the command lists their
IDs for you to choose from. `graphops api-keys show` prints each product with its limits, such as
networks, Endpoint Aliases, origins and Managed Subgraphs.
* **Replacing access names what changes.** `graphops api-keys update <key> --product <product>`
replaces every product. The command prints what it added and removed and which limits changed.
When the change removes a product or changes a limit, which can break an application or widen
what the key reaches, repeat the key's name or ID with `--confirm`.

## Replace or revoke a key

* **Replace a key without downtime.** `graphops api-keys rotate` stops the old key at once. To
avoid an outage, run `graphops api-keys create --like <key> --secret-file <file>`, which creates
a key with the same products and limits, deploy the new secret to your application, and then
revoke the old key with `graphops api-keys revoke <key> --confirm <key>`.
* **Rotating your stored key can store its replacement.** `graphops api-keys rotate <key> --confirm <key> --store` stores the new key for `graphops exec` and prints only its ID. If you rotate or
revoke the stored key another way, the CLI warns that it no longer works; store another with
`graphops api-keys store` or `graphops api-keys create --store --replace`.
* **Rotating and revoking ask you to confirm.** Repeat the key's name or ID with `--confirm`.
Revoking cannot be undone.

## Manage service accounts

A service account is your organization's identity for automation, such as a release pipeline.
[Run the CLI in CI](/platform/cli/automation#run-the-cli-in-ci) shows how a job signs in with one
of its keys.

* **Changing a service account's permissions keeps the others.**
`graphops service-accounts update <account> --add-grant <permission>` adds a permission and
`--remove-grant` removes one. The command prints what changed and every permission the account
then holds, with its limits. Adding a permission the account already holds keeps that
permission's limits.
* **Replacing every permission names what changes.** Pass `--grants <file>` with the full list. In a
`--grants` file, for service accounts or query keys, limit a permission to Managed Subgraphs by
name or ID. When the change removes a permission or changes a limit, repeat the account's name or
ID with `--confirm`.
* **Deleting asks you to confirm.** Repeat the service account's name or ID with `--confirm`.

`--confirm` guards against acting on the wrong resource through a typo. It is not your approval: a
coding agent must have your agreement before it runs one of these commands.

## Next steps

* [Developer workflow](/platform/cli/developer-workflow): Store a key for local development and run your code with it.
* [Scripts, CI and coding agents](/platform/cli/automation): Sign in a pipeline as a service account.
* [API keys](/platform/api-keys): Choose products and limits for each key.