# See who has read a secret

Read a secret's access log, and see where its value comes from, every place it is wired to, and which version each one last read.

Replace _5b8c1d2e-3f4a-4b6c-8d7e-9f0a1b2c3d4e_ with the secret's id.

## Prerequisites

- For the access log, `secrets:GetSecretAccessLog` on the secret. Every call that reaches the
  permission check is recorded in the audit log, allowed or refused.
- For the flow, `secrets:GetSecret`; its last reads also need `secrets:GetSecretAccessLog`.
- In the console, also `secrets:ListSecrets` to open **Secrets**; without it the page says "You do
  not have permission to list secrets."

## Read the access log

**Console**
1. Open **Secrets** and choose the secret.
2. In its panel, read **Last read**: the version, the consumer or how it was read, and the time.

Without the permission, the section says "The access log needs secrets:GetSecretAccessLog."

**CLI**
```sh
dcloud secrets secrets access-log 5b8c1d2e-3f4a-4b6c-8d7e-9f0a1b2c3d4e
```

**API**
```http
GET /secrets/api/secrets/5b8c1d2e-3f4a-4b6c-8d7e-9f0a1b2c3d4e/access
```

The API returns the 20 latest reads, newest first: `version`, `consumer` (`null` for a person's
read), `iamUserId`, `context`, `resource` (the reader's resource name) and `at`. The console shows
the 8 latest.

## See where a secret goes

**Console**
In the secret's panel, read **Flow**.

**CLI**
```sh
dcloud secrets secrets flow 5b8c1d2e-3f4a-4b6c-8d7e-9f0a1b2c3d4e
```

**API**
```http
GET /secrets/api/secrets/5b8c1d2e-3f4a-4b6c-8d7e-9f0a1b2c3d4e/flow
```

The flow shows, from left to right:

1. Where the value comes from: our store, or the source and reference it syncs from, with the
   sync status.
2. The secret: its active version and the key it is encrypted under.
3. What it is wired to: an app's environment variable, database, cache or registry binding, or
   Error Tracking binding; a workflow grant, per repository; a database's or cache's own password;
   a source's credential. Each shows the version it last read and when. One that last read an
   older version than the active one is stale until its next rollout or run.

Function bindings and pull-through cache logins are not drawn as wiring: their reads appear in
the list below it, "Also read by, though no longer wired to it", with every other read by a
resource not drawn. Without `secrets:GetSecretAccessLog`, the wiring is shown and the reads are
hidden (`reads: "hidden"`).

## See the secrets an app uses

`GET /secrets/api/apps/{appId}/flow` (`dcloud secrets secrets app-flow <appId>`, needs
`deploy:DescribeApp`) lists each secret the app uses, how, where it comes from and the version the
app last read. Secrets you may not describe are left out; an unknown app answers an empty list.

## Related

- [Reveal a secret's value](reveal-a-value.md)
- `secrets.secrets.access-log` · `secrets.secrets.flow`
