

# Sign container images in Signer
<a name="container-workflow"></a>

This section describes procedures for signing container images stored in an Open Container Initiative (OCI) compliant container registry. Before you begin, make sure you have completed the prerequisites listed in [Get started with AWS Signer](getting-started.md).

**Note**  
If you're coming here from the Amazon ECR image signing documentation, be aware that you must fulfill all of the requirements related to Amazon ECR before beginning these AWS Signer procedures. For more information, see [Signing an image](https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-signing.htm) in the *Amazon Elastic Container Registry User Guide*.

**Topics**
+ [Prerequisites for signing container images](image-signing-prerequisites.md)
+ [Sign an image](image-signing-steps.md)
+ [Locally verify an image after signing](image-verification.md)
+ [Verify an image during in Amazon EKS or Kubernetes clusters](kubernetes-verification.md)

# Prerequisites for signing container images
<a name="image-signing-prerequisites"></a>

Before you begin signing, you need to set up an environment that bridges AWS Signer with Amazon ECR. Complete the following steps.

**To prepare your signing environment**

1. **Prepare the AWS CLI**

   Install and configure the latest version of the AWS CLI. For more information, see [Installing or updating the latest version of the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) in the *AWS Command Line Interface User Guide*.

1. **Prepare Amazon ECR**

   Have an existing container image stored in an Amazon ECR private repository to sign. For more information, see [Pushing an image](https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-push.html) in the *Amazon Elastic Container Registry User Guide*.

1. **Download the container-signing tools** 

   Two software packages need to be installed in your local environment for you to sign images:
   + The open source supply chain security program Notation, developed by the [Notary Project](https://notaryproject.dev/)
   + The AWS Signer plugin for Notation. You can either use our plugin binary, or our open source library.

------
#### [ Plugin binary ]

   The AWS Signer installer installs both the Notation client and the AWS Signer plugin for Notation. Separate binaries are available to install only the AWS Signer plugin.

   The installer includes the following.
   + Notation binary and third party license.
   + AWS Signer plugin binary and third party license.
   + Notation license.
   + Trust store set up with AWS Signer's Notation signing [root certificate](https://d2hvyiie56hcat.cloudfront.net/aws-signer-notation-root.cert).
   + GovCloud trust store and [root certificate](https://d2hvyiie56hcat.cloudfront.net/aws-us-gov-signer-notation-root.cert), for use in the AWS GovCloud (US) Region.
   + A configurable trust policy. For information about configuring the trust policy, see [Locally verify an image after signing](image-verification.md).

   The following table provides the installer and related files for each supported operating system and architecture. You can download our latest [CHANGELOG](https://d2hvyiie56hcat.cloudfront.net/CHANGELOG) to see the versions of the Notation CLI and plugin included in each installer release.  
**Notation binary and AWS Signer Plugin installer files**    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/signer/latest/developerguide/image-signing-prerequisites.html)

------
#### [ Open source library ]

   The open source Signer plugin is available as a library for use with your toolchain to generate and verify container artifacts signatures. Access the source code and instructions to build the Signer plugin in the [Signer Notation plugin Github repository](https://github.com/aws/aws-signer-notation-plugin).

------

1. **(Optional) Verify signed packages.**

   For instructions to complete this step, select the tab for your platform.

------
#### [ Linux ]

   1. Download the public key.

      ```
      $ ​wget https://d2hvyiie56hcat.cloudfront.net/linux/public.key
      ```

   1. Import the public key into your keyring. If you're using the unzip the AWS Signer plugin, first unzip downloaded file and then run command against the binary file within the zip file.

      ```
      $  gpg --import public.key
      gpg: key A3B52DA65461CF90: public key "AWS Signer Notation" imported
      gpg: Total number processed: 1
      gpg:               imported: 1
      ```

      ​Make a note of the key value, as you need it in the next step. In the preceding example, the key value is `A3B52DA65461CF90`.

   1. Verify the fingerprint by running the following command, replacing **key-value** with the value from the preceding step:

      ```
      $  gpg --fingerprint key-value
      pub   rsa3072 2023-04-24 [SC]
          E84A F8A2 A9B5 2F1F 4435  AE71 A3B5 2DA6 5461 CF90
      uid           [ unknown] AWS Signer Notation​
      ```

      The fingerprint string should be `E84A F8A2 A9B5 2F1F 4435 AE71 A3B5 2DA6 5461 CF90`.

      If the fingerprint string doesn't match, don't run the installer. Contact Amazon Web Services.

      After you have verified the fingerprint, you can use it to verify the signature of the AWS Signer Notation package.

   1. Download the package signature file using **wget**. To determine the correct signature file, see the preceding table.

      ```
      $ ​wget signature-file-link
      ```

   1. To verify the signature, run gpg --verify:

      ```
      $  gpg --verify sig-filename downloaded-filename
      gpg: Signature made Mon May 22 16:16:34 2023 PDT
      gpg:                using RSA key A3B52DA65461CF90
      gpg: Good signature from "AWS Signer Notation" [unknown]
      gpg: WARNING: This key is not certified with a trusted signature!
      gpg:          There is no indication that the signature belongs to the owner.
      Primary key fingerprint: E84A F8A2 A9B5 2F1F 4435  AE71 A3B5 2DA6 5461 CF90​
      ```

      If the output includes the phrase *BAD signature*, check whether you performed the procedure correctly. If you continue to get this response, contact Amazon Web Services and avoid using the downloaded file.​ 

      Note the warning about *trust*. A key is trusted only if you or someone who you trust has signed it. This doesn't mean that the signature is invalid, only that you have not verified the public key.

------
#### [ Windows ]

   To verify the signature of the MSI installer or the plugin EXE file, using Windows PowerShell run the following command:

   ```
   C:\> ​Get-AuthenticodeSignature filename
   ```

   You can also verify the signature by right-clicking on the file in an Explorer window, choosing **Properties**, and then choosing **Digital Signatures**.

   ​You should see a result similar to the following:​

   ```
   SignerCertificate                         Status             Path
   -----------------                         ------             ----
   [40-character hexamecimal number]         Valid              downloaded-file​​
   ```

------
#### [ MacOS  ]

   1. To verify the signature of the PKG installer, run the following command. This example uses the amd64 package, but the signature of the arm64 package can be verified similarly.

      ```
      $ ​pkgutil --check-signature ​aws-signer-notation-cli_amd64.pkg
      ```

      You should see a result similar to the following:

      ```
      ​Package "aws-signer-notation-cli_amd64.pkg":
          Status: signed by a developer certificate issued by Apple for distribution
          Notarization: trusted by the Apple notary service
          Signed with a trusted timestamp on: 2023-05-19 15:17:15 +0000
          Certificate Chain:
           1. Developer ID Installer: AMZN Mobile LLC (94KV3E626L)
               Expires: 2027-06-28 22:57:06 +0000
               SHA256 Fingerprint:
                    49 68 39 4A BA 83 3B F0 CC 5E 98 3B E7 C1 72 AC 85 97 65 18 B9 4C  
                    BA 34 62 BF E9 23 76 98 C5 DA
               ------------------------------------------------------------------------
           2. Developer ID Certification Authority
               Expires: 2031-09-17 00:00:00 +0000
               SHA256 Fingerprint:
                    F1 6C D3 C5 4C 7F 83 CE A4 BF 1A 3E 6A 08 19 C8 AA A8 E4 A1 52 8F
                    D1 44 71 5F 35 06 43 D2 DF 3A
               ------------------------------------------------------------------------
           3. Apple Root CA
               Expires: 2035-02-09 21:40:36 +0000
               SHA256 Fingerprint:
                    B0 B1 73 0E CB C7 FF 45 05 14 2C 49 F1 29 5E 6E DA 6B CA ED 7E 2C
                    68 C5 BE 91 B5 A1 10 01 F0 24​
      ```

   1. To verify the signature of the AWS Signer Notation plugin executable, run the following command.

      ```
      $ ​codesign -dv --verbose=4 ./notation-com.amazonaws.signer.notation.plugin 
      ```

      ​You should see a result similar to the following.

      ```
      Executable=/path/to/notation-com.amazonaws.signer.notation.plugin
      Identifier=notation-com.amazonaws.signer.notation.plugin_darwin_arm64
      Format=Mach-O thin (arm64)
      CodeDirectory v=20500 size=74278 flags=0x10000(runtime) hashes=2314+2 location=embedded
      VersionPlatform=1
      VersionMin=720896
      VersionSDK=720896
      Hash type=sha256 size=32
      CandidateCDHash sha256=e4000dbdf4e6243be9d290b1520d95bf9027a5e4
      CandidateCDHashFull sha256=e4000dbdf4e6243be9d290b1520d95bf9027a5e42b699a354fc39ac0f498477f
      Hash choices=sha256
      CMSDigest=e4000dbdf4e6243be9d290b1520d95bf9027a5e42b699a354fc39ac0f498477f
      CMSDigestType=2
      Executable Segment base=0
      Executable Segment limit=3571712
      Executable Segment flags=0x1
      Page size=4096Launch Constraints:None
      CDHash=e4000dbdf4e6243be9d290b1520d95bf9027a5e4
      Signature size=9070
      Authority=Developer ID Application: AMZN Mobile LLC (94KV3E626L)
      Authority=Developer ID Certification Authority
      Authority=Apple Root CATimestamp=May 19, 2023 at 7:51:07 AM
      Info.plist=not bound
      TeamIdentifier=94KV3E626L
      Runtime Version=11.0.0
      Sealed Resources=none
      Internal requirements count=1 size=220
      ```

------

1. **Install the packages**

   For instructions to complete this step, select the tab for your platform.

------
#### [ Linux (RPM) ]

   If you downloaded an RPM package on a Linux server, change to the directory containing the package and enter the following:

   ```
   $ ​sudo rpm -U filename
   ```

------
#### [ Linux (DEB) ]

   If you downloaded a DEB package on a Linux server, change to the directory containing the package and enter the following:

   ```
   $ ​sudo dpkg -i -E filename
   ```

------
#### [ Windows ]

   Install the package with the following command.

   ```
   C:\> msiexec /i filename
   ```

   This command also works from within PowerShell. For more information, see [Microsoft Standard Installer command-line options ](https://learn.microsoft.com/en-us/windows/win32/msi/standard-installer-command-line-options)in the Microsoft Windows documentation.

------
#### [ MacOS ]

   If you downloaded a PKG package on a macOS server, change to the directory containing the package and enter the following:

   ```
   $ ​sudo installer -pkg filename -target /
   ```

------

1. **Verify the package installation**

   After downloading and installing the package, to verify the installation was successful, do the following.

   1. Verify that the Notation directory structure for your operating system was created. 

   1. Use the following command to display the Notation client version.

      ```
      notation version
      ```

   1. Use the following command to list the installed plugins for the Notation client and verify that you see the `com.amazonaws.signer.notation.plugin` plugin.

      ```
      notation plugin ls
      ```

## Required AWS Identity and Access Management permissions to sign and verify a container image
<a name="signer-iam-policy"></a>

 To sign and verify an image present in Amazon Elastic Container Registry, you need an AWS Identity and Access Management policy that allows Notation to interact with Amazon ECR and Signer. 

The following is an example of a user managed policy that allows Notation to interact with Amazon ECR and Signer:

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "ManageRepositoryContents",
            "Effect": "Allow",
            "Action": [
                "ecr:GetDownloadUrlForLayer",
                "ecr:BatchGetImage",
                "ecr:CompleteLayerUpload",
                "ecr:DescribeRepositories",
                "ecr:UploadLayerPart",
                "ecr:InitiateLayerUpload",
                "ecr:BatchCheckLayerAvailability",
                "ecr:PutImage"
            ],
            "Resource": "arn:aws:ecr:us-east-1:111122223333:repository/my-repo"
        },
        {
            "Sid": "GetAuthorizationToken",
            "Effect": "Allow",
            "Action": [
                "ecr:GetAuthorizationToken"
            ],
            "Resource": "*"
        },
        {
            "Sid": "SignAndRevocationCheck",
            "Effect": "Allow",
            "Action": [
                "signer:PutSigningProfile",
                "signer:SignPayload",
                "signer:GetRevocationStatus"
            ],
            "Resource": "*"
        }
    ]
}
```

------

# Sign an image
<a name="image-signing-steps"></a>

The procedures on this page show you how create a signing profile, install a helper program, and sign a container image.

## Step 1: Create a AWS Signer Notation signing profile
<a name="w2aab9c13c11b5"></a>

Create an AWS Signer Notation signing profile. If using the AWS Command Line Interface, API, AWS CloudFormation, or AWS SDKs set the platform ID to `Notation-OCI-SHA384-ECDSA`. In the console, for **signing platform** choose **Notation for container registries**. For more information on creating a signing profile, see [Create a Signer signing profile](signing-profiles.md).

## Step 2: Install a helper program
<a name="w2aab9c13c11b7"></a>

Notation requires you to include a helper program in the client's host path in order to interact with the credential store. You can use either the [Amazon Elastic Container Registry Docker credential helper](https://github.com/awslabs/amazon-ecr-credential-helper) or the [Docker credential helper](https://github.com/docker/docker-credential-helpers) to manage your credentials. We recommend using the Amazon ECR Docker credential helper, as it includes a credentials store and handles authentication for you. The Amazon ECR Docker Credential Helper not only stores and uses credentials when signing and verifying images in Amazon ECR, but also eliminates the need to use the Notation CLI notation login command or write custom logic to refresh authentication tokens and provide transparent access to your Amazon ECR repositories.

### Amazon ECR Docker credential helper
<a name="ecr-helper"></a>

Download the [Amazon Elastic Container Registry Docker credential helper](https://github.com/awslabs/amazon-ecr-credential-helper). Configure `config.json` for use with Amazon ECR.

### Docker credential helper
<a name="docker-helper"></a>

The following procedure explains how to install and configure the Docker credential helper.

**To use the Docker credential helper**

1.  First set up a credentials store. Notation relies on a credentials store for secure storage and retrieval of credentials from Amazon ECR. Most operating systems come with a default credentials store, such as osxkeychain for macOS, or wincred for Windows. If you have the Docker CLI installed on the same host where Notation is installed, Notation uses the credentials store configuration that you set up for the Docker CLI. 

   Alternatively, you can install a third-party credentials store such as [pass](https://www.passwordstore.org). You can pass these credentials to Notation as environment variables. For more information about environment variables, see [Configure environment variables to authenticate to an OCI-compliant registry](https://notaryproject.dev/docs/user-guides/how-to/registry-authentication/#configure-environment-variables-to-authenticate-to-an-oci-compliant-registry) in the Notary Project user guide.

1. Download the [Docker credential helper](https://github.com/docker/docker-credential-helpers). Set the `credsStore` option in `config.json` to the suffix of the program that you want to use.

1. Manually configure Notation client authentication. Because the Notation CLI doesn't support standard AWS authentication methods, you must manually configure Notation client authentication so that Amazon ECR knows who's requesting to sign (push signature) or verify (pull signature) an image. You can accomplish this with the Notation CLI `notation login` command, which authenticates to an Amazon ECR registry and provides an authorization token that's valid for 12 hours. Or, if you’re using the AWS Command Line Interface, you can use the `get-login-password` command which retrieves the token, decodes it, and converts into a `notation login` command for you.

   The following command allows Notation to get credentials for authenticating with Amazon ECR:

   ```
   aws ecr get-login-password --region us-west-1 | notation login --username AWS --password-stdin 111122223333.dkr.ecr.us-west-1.amazonaws.com
   ```

## Step 3: Sign the image using the Notation CLI
<a name="w2aab9c13c11b9"></a>

Use the Notation CLI to sign the image, specifying the image using the repository name and the SHA256 digest. This creates the signature and pushes it to the same Amazon ECR private repository that the image being signed is in.

**Note**  
You can specify the AWS Region and credentials profile that the Notation plugin uses for interactions with AWS Signer either by setting values for the `AWS_DEFAULT_REGION` and `AWS_PROFILE` environment variables or by providing the arguments **--plugin-config aws-region=\$1\$1*Region*\$1** and **--plugin-config aws-profile=\$1\$1*profile-name*\$1**

In the following example, we're signing an image in the `curl` repository with SHA digest `sha256:ca78e5f730f9a789ef8c63bb55275ac12dfb9e8099e6EXAMPLE`.

```
notation sign 111122223333.dkr.ecr.Region.amazonaws.com/curl@sha256:ca78e5f730f9a789ef8c63bb55275ac12dfb9e8099e6EXAMPLE --plugin "com.amazonaws.signer.notation.plugin" --id "arn:aws:signer:Region:111122223333:/signing-profiles/ecrSigningProfileName"
```

## Step 4: Verify image
<a name="w2aab9c13c11c11"></a>

After you have signed your container image, you can verify the signature locally or during an Amazon EKS deployment and further manage the signature with Amazon ECR.
+ [Locally verify an image after signing](image-verification.md)
+ [Verify an image during in Amazon EKS or Kubernetes clusters](kubernetes-verification.md)
+ [Manage your signature in your Amazon ECR repository](https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-signing.html) in the *Amazon Elastic Container Registry User Guide*.

# Locally verify an image after signing
<a name="image-verification"></a>

After you sign a container image using AWS Signer and Notation, you or an authorized member of your team can verify the origin and integrity of the image by cryptographic means. 

Complete the following steps to verify that an image is valid with Notation.

**To verify an image**

1. A trust store is required for verification. If you used the installer for the AWS Signer plugin and Notation, a trust store for both AWS commercial and AWS GovCloud (US) Regions was set up automatically and provisioned with a root certificate. For more information, see [Prerequisites for signing container images](image-signing-prerequisites.md).

1. Set up a trust policy that includes the trust store for your partition.

   The following example includes trust stores for both the AWS commercial and AWS GovCloud (US) Region. You can choose to include one or both in your trust policy depending on where you are verifying your signed images. To verify images signed in AWS commercial Regions, set `signingAuthority` to `aws-signer-ts`. To verify images signed in AWS GovCloud (US) Region, set `signingAuthority` to `aws-us-gov-signer-ts`.
**Important**  
Signatures are isolated to AWS partitions. Calls to [GetRevocationStatus](https://docs.aws.amazon.com/signer/latest/api/API_GetRevocationStatus.html) with a cross-partition signature will return a validation exception error.

   ```
   {
      "version":"1.0",
      "trustPolicies":[
         {
            "name":"aws-signer-tp",
            "registryScopes":[
               "*"
            ],
            "signatureVerification":{
               "level":"strict"
            },
            "trustStores":[
               "signingAuthority:aws-signer-ts",
               "signingAuthority:aws-us-gov-signer-ts"
            ],
            "trustedIdentities":[
               "arn:aws:signer:Region:111122223333:/signing-profiles/ecr_signing_profile",
               "arn:aws:signer:Region:111122223333:/signing-profiles/ecr_signing_profile2"
            ]
         }
      ]
   }
   ```

1. Import the policy into Notation.

   ```
   $ notation policy import mypolicy.json
   ```

   Output:

   ```
   Existing trust policy configuration found, do you 
   want to overwrite it? [y/N] y
                       
   Trust policy configuration imported successfully.
   ```

1. Verify the signature, specifying the signature using the repository name and the SHA digest.
**Note**  
You can specify the AWS Region and credentials profile that the Notation plugin uses to interact with AWS Signer by assigning a value to the `AWS_PROFILE` environment variable, or by passing the **--plugin-config aws-profile=\$1\$1*profile-name*\$1** argument to the Notation **verify** command.

   ```
   $ notation verify 111122223333.dkr.ecr.region.amazonaws.com/curl@SHA256_digest
   ```

   Output:

   ```
   Successfully verified signature for 111122223333.dkr.ecr.us-west-2.amazonaws.com/curl@SHA256_digest
   ```

# Verify an image during in Amazon EKS or Kubernetes clusters
<a name="kubernetes-verification"></a>

For AWS Signer customers wishing to verify signed container images at the time of deployment, there are various open-source solutions such as the following.
+ [Deis Labs Gatekeeper and Ratify](https://ratify.dev/docs/quickstarts/ratify-on-aws) – Use Gatekeeper as the admission controller and Ratify configured with an AWS Signer plug-in as a web hook for validating signatures.
+ [Kyverno](https://github.com/nirmata/kyverno-notation-aws) – A Kubernetes policy engine configured with a AWS Signer plugin for validating signatures.

**Note**  
Before verifying container-image signatures, customers must configure the Notation trust store and trust policy as required by their selected admission controller.