---
title: "Scan an image from a private registry"
sidebarTitle: "Scan a private registry image"
description: "Store a registry credential for a host, confirm the registry accepts it, scan an image from it, and rotate or disable the credential later."
keywords: ["private registry", "registry credential", "ECR", "ACR", "Artifact Registry", "GHCR", "Harbor", "assume role", "rotate"]
---

An image in a registry that requires a login needs a credential stored against
that registry's **host**. You never name the credential on a scan: TRUSTIVAN
selects it by the host of the image being scanned.

Before you start:

- You need the `admin` role. Storing or changing a credential needs
  `credentials:manage`, which cannot be granted to an API key.
- Your plan must include private registries (`private_registries`). Storing a
  credential without it is refused with `402`. Rotating, disabling and
  deleting are never gated on the plan, so a secret you gave TRUSTIVAN can
  always be replaced or withdrawn.

## 1. Choose how to authenticate

| `scheme` | Accepted for | `username` holds | `secret` holds |
|---|---|---|---|
| `basic` | Any registry | The username | The password or token |
| `token` | Any registry | Nothing | The token |
| `assume_role` | Amazon ECR hosts | The role ARN | Not accepted |
| `aws_access_key` | Amazon ECR hosts | The access key ID | The secret access key |
| `azure_service_principal` | `*.azurecr.io` | `<tenant-id>/<client-id>` | The client secret |
| `gcp_service_account` | Artifact Registry and GCR hosts | Nothing | The service account key JSON |

The four cloud schemes are exchanged for a short-lived registry login at scan
time. No long-lived registry password is derived from them or stored.

A scheme that does not fit the host (`azure_service_principal` against
`ghcr.io`, for example) is refused when you save it, not when a scan first
fails.

## 2. Store the credential

**Settings → Registries and repos → Registry credentials**, or:

```bash
curl -s -X POST https://app.trustivan.com/api/v1/registry-credentials \
  -H 'Content-Type: application/json' \
  -b cookies.txt \
  -H "X-CSRF-Token: $(grep trustivan_csrf cookies.txt | awk '{print $7}')" \
  -d '{
        "name": "Acme production Harbor",
        "registry": "registry.acme.com:5000",
        "scheme": "basic",
        "username": "svc-trustivan",
        "secret": "…"
      }'
```

`registry` is the host, with a port if it has one. It is the matching key.
`name` is for people and is not used for matching.

The response carries the credential's `status` and never the secret. There is
no endpoint that reads a stored secret back, at any role. One host has one
credential: a second for the same host is `409`, and you rotate the existing
one instead.

### With an AWS role

`assume_role` stores no secret at all. The response returns an `external_id`,
and the role's trust policy must require that value as its `sts:ExternalId`.
The external ID is what stops another organization naming the same role.

## 3. Confirm the registry accepts it

A credential is stored first and checked afterwards, so a registry that is
briefly unreachable does not stop you saving it. Read `status`:

| `status` | Meaning |
|---|---|
| `unverified` | It has never authenticated |
| `active` | It last authenticated successfully |
| `invalid` | The registry rejected it. `status_reason` carries the reason |
| `disabled` | An administrator switched it off |

To test it again on demand:

```bash
curl -s -X POST "https://app.trustivan.com/api/v1/registry-credentials/$CREDENTIAL_ID/verify" \
  -b cookies.txt \
  -H "X-CSRF-Token: $(grep trustivan_csrf cookies.txt | awk '{print $7}')" \
  | jq '{status, status_reason, last_verified_at}'
```

Only a registry that actively **rejects** the credential marks it `invalid`. A
timeout or an unreachable host leaves the status as it was.

## 4. Scan

Request the scan exactly as you would for a public image. Nothing in the
request names the credential:

```bash
curl -s -X POST https://app.trustivan.com/api/v1/scans \
  -H "Authorization: Bearer $TRUSTIVAN_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"image": "registry.acme.com:5000/payments/api:1.8.2"}'
```

`last_used_at` on the credential records when it was last presented. If the
scan fails to pull, see [Scan failures](/troubleshooting/scans).

## Discover repositories and scan new tags

A stored registry credential can also **discover**: once an hour TRUSTIVAN lists
the registry's repositories (its `/v2/_catalog`) and their tags, and queues a
scan of every tag that appeared since the last run.

In the dashboard: **Settings → Registries and repos → Registry discovery →
Watch a registry**. Pick the credential, name the repositories (required for
Amazon ECR, GitHub Container Registry and Docker Hub), and choose whether new
tags are scanned. Each watched registry shows its last run, its last error, and
its most recently found tags with the status of the scan each started, linked to
the scan. **Edit** changes the repositories; **Stop watching** turns discovery
off and keeps what it found, so watching it again does not rescan old tags. Or
over the API:

```bash
curl -X PUT "$TRUSTIVAN_URL/api/v1/registry-credentials/$CREDENTIAL_ID/discovery" \
  -H "Authorization: Bearer $TRUSTIVAN_API_KEY" -H "Content-Type: application/json" \
  -d '{"enabled": true, "repositories": [], "scan_new_tags": true}'
```

- **`repositories`**: empty lists the catalog. Amazon ECR, GitHub and Docker Hub
  do not serve a catalog: name the repositories (`["acme/api", "acme/worker"]`);
  the run records *this registry does not list its repositories* otherwise.
- **The first run records and scans nothing**, so a registry with years of tags
  is not a backlog; from the second run each new tag is scanned (at most 50 a
  run), through the ordinary scan path and its allowance.
- Bounds: 200 repositories and the last 100 tags of each per run.
- `GET` the same address for the last run, its error, and the 50 most recently
  found tags with the scan each started and that scan's `scan_status`. Setting it needs `credentials:manage`
  and a person; reading needs `credentials:read`.

Every image a [cluster or cloud collection](/configuration/code-to-cloud) finds
running, that no scan covers, is also queued for a scan once a day.

## Rotate, disable or delete

| To | Request | Effect |
|---|---|---|
| Replace the secret | `PUT /api/v1/registry-credentials/{id}/secret` with `{"secret": "…"}` | In place: every scan of that host uses the new value. The status returns to `unverified`. The host cannot be changed |
| Stop using it now, decide later | `PUT /api/v1/registry-credentials/{id}/enabled` with `{"enabled": false}` | Reversible. Re-enabling returns it to `unverified`, not `active` |
| Withdraw it | `DELETE /api/v1/registry-credentials/{id}` | A hard delete. The stored value is gone |

## See also

- [Scan a private repository](/how-to/scan-a-private-repository): the
  equivalent for source code. Git credentials are a separate store, because
  one host can serve both and the tokens differ.
- [Credential handling](/security/credentials): how stored secrets are
  protected.
- [Request a scan](/how-to/request-a-scan)
