# Connect 1Password

Connect a 1Password service account as a source, so that op:// references become synced secrets.

Replace _prod-1password_ with a name for the source. Name it for what it serves; with several
sources, the name is how you choose one.

## Prerequisites

- Permission for `secrets:CreateSecretSource` and `secrets:CreateSecret` (the token is stored as a
  secret). In the console, also `secrets:ListSecretSources` to open **Sources**; without it the page
  says your policies do not grant it.
- An enabled encrypt/decrypt KMS key.
- In 1Password, a service account (Developer → Service accounts) with read access to the vaults
  your apps need. Copy its token; it starts with `ops_`.
- A free unit of the sources quota and of the secrets quota; see [Quotas](quotas.md).

## Connect the source

**Console**
1. Open **Sources** (in the Secrets navigation), and choose **Connect a source**.
2. For **Provider**, choose **1Password**.
3. For **Name**, enter prod-1password.
4. For **Service account token**, paste the token.
5. (Optional) For **Refresh every (minutes)**, enter 5 to 1440. The default is 60; 1Password limits
   how many reads a service account makes an hour.
6. (Optional) For **Encrypt the token with**, choose a key.
7. Choose **Verify & connect**.

The source appears with how many vaults the token reaches.

**CLI**
```sh
dcloud secrets sources create --name prod-1password --provider onepassword \
  --credential "$OP_SERVICE_ACCOUNT_TOKEN"
```

**API**
```http
POST /secrets/api/sources
{ "name": "prod-1password", "provider": "onepassword", "credential": "ops_EXAMPLE" }
```

**Terraform**
```hcl
resource "dcloud_secrets_source" "op" {
  name          = "prod-1password"
  provider_type = "onepassword"
  credential    = var.op_service_account_token
}
```

## Result

The token is checked against 1Password before anything is stored; a rejected token stores nothing.
An accepted one is stored as the secret `SOURCE_PROD_1PASSWORD_TOKEN` (the name in upper case,
`SOURCE_…_TOKEN`), encrypted under the key you chose or, without one, the organization's default
key (else its first enabled encrypt/decrypt key), with a
version history and an access log like any secret. Every use of the token is written to that
access log.

The name is 2 to 63 lower-case letters, digits and hyphens, unique in the organization.

## Refusals

- `422` "1Password rejected the credential: …", for example "The token is valid but no vault is
  shared with this service account".
- `409` "A source named prod-1password exists", or "A secret named SOURCE_PROD_1PASSWORD_TOKEN
  already exists".
- `409` when no enabled key can encrypt the token, or a quota is full.

## Related

- [Sync a secret from a source](sync-a-secret-from-a-source.md)
- [Manage a source](manage-a-source.md)
- `secrets.sources.create` · `dcloud_secrets_source`
