# Only deploy signed images

Refuse a new app deployment unless every image it runs is signed by a key your organization trusts.

The policy is checked by the deploy service when an app is deployed. Running apps keep running.

**Important:**
Turned on with no trusted key, it refuses every image except those Deutsche Cloud builds from your
repositories.

## Prerequisites

- Permission for `ecr:PutSigningPolicy`. To open the console's **Signing** page,
  `ecr:GetSigningPolicy`; without it the page shows a refusal.
- At least one trusted key (see [Sign an image](sign-an-image.md)).

## Turn it on

**Console**
1. Open **Container registry**, then choose **Signing**.
2. Under **Only signed images deploy**, choose **Turn on**.

**Turn off** turns it off again.

**CLI**
```sh
dcloud ecr signing put-policy --require-signed-images
```

`dcloud ecr signing delete-policy` turns it off; the trusted keys stay.

**API**
```http
PUT /ecr/api/signing-policy
{ "requireSignedImages": true }
```

**Terraform**
```hcl
resource "dcloud_ecr_signing_policy" "this" {
  require_signed_images = true
  depends_on            = [dcloud_ecr_signing_key.release]
}
```

## Result

From then on a new deployment is refused unless every image it runs passes:

- an image from your registry must carry a signature a trusted key verifies, checked at the digest
  the deployment will run; a reference with neither a tag nor a digest is refused;
- an image from another registry is refused: bring it in through a pull-through cache rule, or copy
  it into your registry and sign it there;
- in a compose app, only the services that run images of the app's bound registry repository are
  checked for signatures; a service running an image of any other repository, in your registry or
  not, is refused as an image from another registry;
- an image Deutsche Cloud builds from your repository passes, and the deployment log says "trusted by
  build provenance".

A refused deployment fails with
`Refused by the registry signature policy ("only signed images deploy"): …`, naming each refused
image and why. A passed check is written to the deployment's log. Every check is emitted on your
event bus as `ECR Image Signature Check` (`detail.result` `allowed` or `denied`).

When the policy is turned on with no trusted key, the answer's `warning` is "No signing keys are
trusted yet: every image except those Deutsche Cloud builds from source will be refused."

Kubernetes clusters and Functions do not check the policy.

## Related

- [Sign an image](sign-an-image.md)
- `ecr.signing.put-policy` · `dcloud ecr signing put-policy` · `dcloud_ecr_signing_policy`
