Use the notation-alibabacloud-secret-manager plugin with Alibaba Cloud Key Management Service (KMS) to sign OCI artifacts in Container Registry (ACR). Then, install and configure Ratify in your cluster to enforce signature verification. This setup prevents images that fail signature verification from being deployed, which enhances the security of your cluster.
Key concepts
notation-alibabacloud-secret-manager: A Notation plug-in that complies with the Notation project specification. It uses keys from Alibaba Cloud Key Management Service (KMS) to sign OCI artifacts in ACR.
Ratify: A binary executable verification engine that runs in a Kubernetes cluster. It validates security metadata for cloud-native artifacts, such as image signatures and SBOMs, and allows only artifacts that meet policy requirements to be deployed in the cluster.
Prerequisites
-
You have created an ACK managed cluster, ACK dedicated cluster, or ACK Serverless cluster running Kubernetes 1.20 or later. For details, see Create an ACK managed cluster, Create an ACK dedicated cluster (discontinued), and Create an ACK Serverless cluster.
-
You have created a Container Registry Enterprise Edition (Advanced Edition) instance. For details, see Create a Container Registry Enterprise Edition instance.
-
You have installed the Notation CLI.
-
You have purchased and enabled a KMS instance. For details, see Purchase and enable a KMS instance.
Step 1: Obtain a key from a KMS instance
Key Management Service (KMS) is a one-stop platform for key management and data encryption that provides simple, reliable, secure, and compliant data encryption and credential management. You can use the notation-alibabacloud-secret-manager plug-in to sign artifacts with keys created and managed by a KMS instance or with self-signed keys imported into a KMS instance.
KMS-managed key
-
Log on to the Key Management Service console. In the top navigation bar, select a region. In the left-side navigation pane, choose .
-
On the Keys page, click the Customer Master Keys tab. From the Instance ID drop-down list, select a software key management instance. Then, click Create Key.
-
In the Create Key panel, configure the parameters and click OK.
The following table describes the key parameters. For more information, see Manage keys.
Parameter
Description
Example
KMS Instance
Select the KMS instance in which you want to create the key.
kst-l*
Key Type
Select asymmetric key.
Asymmetric key
Key Specifications
The following asymmetric key specifications are supported:
-
RSA_2048
-
RSA_3072
-
EC_P256
RSA_2048
Key Usage
Select SIGN/VERIFY to generate and verify digital signatures.
SIGN/VERIFY
Key Alias
The alias for the key. Supported characters include letters, digits, underscores (_), hyphens (-), and forward slashes (/).
test-key
Tags
Tags to classify and manage the key. Each tag is a key-value pair.
None
-
-
Create an application access point.
-
In the left-side navigation pane, choose .
-
On the Application Access tab, click Create AAP. In the Create AAP panel, configure the parameters.
Parameter
Description
Mode
Select Quick Creation.
Scope (KMS Instance)
Select the KMS instance that your application needs to access.
Application Access Point Name
Enter a name for the application access point.
Authentication Method
This is set to ClientKey and cannot be changed.
Default Permission Policy
The value is
key/*secret/*and cannot be changed. This means the application can access all keys and secrets in the specified KMS instance. -
Click OK. The browser automatically downloads the ClientKey. The ClientKey includes the following files:
-
Credential (ClientKeyContent): The default filename is
clientKey_****.json. -
Credential password (ClientKeyPassword): The default filename is
clientKey_****_Password.txt.
-
-
Imported self-signed key
In addition to using keys created and managed by KMS for signing, you can also use a self-signed key by importing its key material into a KMS instance. This section provides an example of generating a private key and certificate with OpenSSL.
1. Create an asymmetric key
-
Log on to the Key Management Service console. In the top navigation bar, select a region. In the left-side navigation pane, choose .
-
On the Keys page, click the Customer Master Keys tab. From the Instance ID drop-down list, select a software key management instance. Then, click Create Key.
-
In the Create Key panel, configure the parameters and click OK.
The following table describes the key parameters. For more information, see Step 1: Create an asymmetric key with external key material.
Parameter
Description
Example
Key Type
Select asymmetric key.
Asymmetric key
Key Specifications
The following asymmetric key specifications are supported:
-
RSA_2048
-
RSA_3072
-
EC_P256
RSA_2048
Key Usage
Select SIGN/VERIFY to generate and verify digital signatures.
SIGN/VERIFY
Key Alias
The alias for the key. Supported characters include letters, digits, underscores (_), hyphens (-), and forward slashes (/).
test-key
Tags
Tags to classify and manage the key. Each tag is a key-value pair.
None
-
2. Download wrapping public key and import token
The parameters for importing key material include a wrapping public key and an import token. The wrapping public key is used to encrypt the key material and protect it during the import process. The import token is used to import the key material.
-
Find the target key and click Details in the Actions column. In the Key Material section of the key details page, click Obtain Parameters to Import Key Material.
-
In the Obtain Parameters to Import Key Material dialog box, select a Public Key Type and an Encryption Algorithm, and then click Next.
Key Management Type
KMS key spec
Wrapping key type
Encryption Algorithm
Software Key
-
RSA_2048
-
RSA_3072
-
EC_P256
-
EC_P256K
RSA_2048
RSAES_OAEP_SHA_256_AES_256_ECB_PKCS7_PAD
RSAES_OAEP_SHA_256_AES_256_ECB_PKCS7_PAD: For more information about the encryption process, see Import key material for an asymmetric key.
-
-
Download the wrapping public key and import token, and keep them safe.
-
Public Key Format:
-
DER format: The default file name is WrappingPublicKey**bin.
-
PEM format: The default file name is WrappingPublicKey**.pem.
-
-
Import Token: The default file name is ImportToken***.txt.
Important-
The import token is valid for 24 hours and can be reused within the validity period. After it expires, you must obtain a new import token and public key.
-
The wrapping public key and import token must be used as a pair. You cannot download the wrapping public key and import token twice and use the public key from one download with the import token from another.
-
-
3. Encrypt key material with the wrapping public key
Generate and encrypt the key material in your local environment. The following keys are used in this process. For more information, see the following table.
|
Key |
Purpose |
Provider |
Notation |
|
Target Asymmetric Key (TAK) |
The target asymmetric key to be imported. |
Your local environment or tools (such as an on-premises Key Management Infrastructure (KMI) or Hardware Security Module (HSM)). |
|
|
Import Wrapping Key (IWK) |
The encryption key used to import TAK. |
Alibaba Cloud KMS. |
|
|
Ephemeral Symmetric Key (ESK) |
An ephemeral symmetric key that is used to directly encrypt TAKpriv. |
Your local environment or tools. Destroy this key immediately after completing the TAK export operation. |
N/A |
-
Create a target asymmetric key private key (TAKpriv). The key specification must be the same as the one you selected when creating the asymmetric key. If you already have a TAKpriv, skip this step.
NoteTAKpriv must follow this format: RSA private keys are encoded per RFC 3447, ECC private keys are encoded per RFC 5915, and then wrapped in PKCS#8 format per RFC 5208.
-
Create an ephemeral symmetric key (ESK).
-
Use the import wrapping key public key (IWKpub) to encrypt the ephemeral symmetric key (ESK) and obtain the ESK ciphertext (Cipher(ESK)).
-
Use the ephemeral symmetric key (ESK) to encrypt the target asymmetric key private key (TAKpriv) and obtain the TAK private key ciphertext (Cipher(TAKpriv)).
-
Assemble the result data in the Cipher(ESK)||Cipher(TAKpriv) format to obtain the encrypted key material.
4. Import key material
On the key details page, click Import Key Material. In the Import Wrapped Key Material dialog box, complete the configuration and click OK.
After the key material is imported, the key status changes from Pending Import to Enabled.

-
Wrapped Key Material: Upload the key material file that you generated in Step 3. Encrypt key material with the wrapping public key.
-
Import Token: Upload the token file that you downloaded in Step 2. Download wrapping public key and import token.
-
Key Material Expired On: You can select Never Expire or specify a custom expiration time.
ImportantIf you set an expiration time for the key material, KMS deletes the expired key material after the specified time, and you can no longer use the key material. To resume use, you can import the same key material into the key again.
Step 2: Install notation-alibabacloud-secret-manager
The notation-alibabacloud-secret-manager plugin uses Alibaba Cloud KMS keys to sign ACR images in accordance with the Notation community's plugin specification.
Ensure that the notation-alibabacloud-secret-manager plugin runs in the same region and VPC as the dedicated KMS instance. For multi-VPC access, see Configure multi-VPC access to KMS instances within the same region.
-
Download the plugin for your platform. For other versions, see notation-alibabacloud-secret-manager.
-
Linux_arm64
wget https://notation-alibabacloud-secret-manager.oss-cn-hangzhou.aliyuncs.com/dist/v0.1.2/notation-alibabacloud-secret-manager_Linux_arm64.tar.gz -
Linux_x86_64
wget https://notation-alibabacloud-secret-manager.oss-cn-hangzhou.aliyuncs.com/dist/v0.1.2/notation-alibabacloud-secret-manager_Linux_x86_64.tar.gz
-
-
Create the plugin directory.
mkdir -p /root/.config/notation/plugins/alibabacloud.secretmanager.plugin/ -
Extract the archive to the plugin directory.
tar -xvf notation-alibabacloud-secret-manager_Linux_<architecture>.tar.gz -C /root/.config/notation/plugins/alibabacloud.secretmanager.plugin/ -
Configure the environment variables.
export ALIBABA_CLOUD_ACCESS_KEY_ID=<your-access-key-id> export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<your-access-key-secret> export ALIBABA_CLOUD_KMS_INSTANCE_ENDPOINT=<your-kms-endpoint> export ALIBABA_CLOUD_KMS_CLIENTKEY_FILEPATH=<your-clientkey-filepath> export ALIBABA_CLOUD_KMS_PASSWORD=<your-password> export ALIBABA_CLOUD_KMS_CA_FILEPATH=<your-ca-filepath>NoteThe notation-alibabacloud-secret-manager plugin supports multiple credential configuration methods. For more methods, see credentials.
Parameter
Description
Example
ALIBABA_CLOUD_ACCESS_KEY_ID
AccessKey ID of your Alibaba Cloud account.
XXXXXX
ALIBABA_CLOUD_ACCESS_KEY_SECRET
AccessKey secret of your Alibaba Cloud account.
XXXXXX
ALIBABA_CLOUD_KMS_INSTANCE_ENDPOINT
VPC endpoint of the dedicated KMS instance.
kst-hzxxxxxxxxxx.cryptoservice.kms.aliyuncs.comALIBABA_CLOUD_KMS_CLIENTKEY_FILEPATH
The local path to the client key file for the Application Access Point (AAP) of the dedicated KMS instance. This file should contain the content from the
clientKey_KAAP.****.jsonfile, which is downloaded in a previous step when you create the AAP./root/clientkey
ALIBABA_CLOUD_KMS_PASSWORD
Password for the Application Access Point (AAP) of the dedicated KMS instance. This password is in the clientKey_KAAP.594c78e6-7244-4187-XXX-8d59dca2ceb4_Password.txt file, downloaded in a previous step when you created the AAP.
XXXXXX
ALIBABA_CLOUD_KMS_CA_FILEPATH
The local path to the CA certificate file for the dedicated KMS instance. This file contains the content from the PrivateKmsCA_xxxxx.pem file that you downloaded in Step 4: Download the CA certificate of the KMS instance.
/root/privatekmsca
Step 3: Prepare and sign an image
1. Prepare an image in Container Registry
-
Use an Enterprise Edition instance to build an image or build and push a multi-arch image to Container Registry.
NoteContainer Registry Enterprise Edition instances support the OCI Image and Distribution Specification v1.1.0, which allows you to use client tools such as ORAS to manage and distribute OCI artifacts that are not container images. For more information, see Use the OCI v1.1.0 specification to manage and associate container images and their derivative artifacts.
-
Configure access control for your Enterprise Edition instance to connect via a VPC or the internet. For more information, see Network access control.
-
Obtain the password to log in to your Container Registry Enterprise Edition instance. If you forget or lose the password, you can reset it by configuring access credentials. For more information, see Configure access credentials.
2. Sign an image with Notation and KMS
You can use the notation-alibabacloud-secret-manager plugin to sign a specified image in Container Registry with a KMS-managed private key and certificate.notation-alibabacloud-secret-manager plugin to sign a specified image in Container Registry with a private key and certificate from Secrets Manager in Key Management Service (KMS).
To use the notation-alibabacloud-secret-manager plugin with the KMS Instance SDK (Go), you must meet specific conditions and configure custom environment variables.
-
Run the following command to log in to the image repository.
./notation login --username=tsh_ram@11380257155*** test-for-doc-registry.cn-hangzhou.cr.aliyuncs.com -
Run the following command to sign the specified image and generate a certificate. In the command,
<dirPath>specifies the path to store the generated certificate, for example, /root../notation sign --id <keyId> --plugin alibabacloud.secretmanager.plugin test-for-doc-registry.cn-hangzhou.cr.aliyuncs.com/test/nginx:2.11 --plugin-config output_cert_dir=<dirPath>Expected output:
Successfully signed test-for-doc-registry.cn-hangzhou.cr.aliyuncs.com/test/nginx@sha256:f57e1908e63538ad5159fa99443d0492d23b9d34ba7****** -
You can use the following Notation CLI command to sign an artifact.
notation sign --id <keyId> --plugin alibabacloud.secretmanager.plugin <myRegistry>/<myRepo>@<digest> --plugin-config output_cert_dir=<dirPath>Parameter
Description
idThe ID of the Key Management Service (KMS) key.
plugin-configCustom plugin parameters. The following options are supported:
-
output_cert_dir: Specifies the directory to export the X.509 certificate that is generated from the KMS key during signing. -
ca_certs: Specifies the file path to the self-signed certificate. Use this parameter when signing with a self-signed key that is imported into a KMS instance and also used to issue an X.509 certificate.
-
Step 4: Verify signatures with Ratify and Gatekeeper
1. Install Ratify and Gatekeeper
-
Enable Gatekeeper-based policy governance. For more information, see Enable security policy management.
-
Install Ratify.
-
Create the ratify namespace.
kubectl create ns ratify -
Log on to the ACK console. In the left navigation pane, click Clusters.
-
On the Clusters page, click the name of your cluster. In the left navigation pane, click .
-
On the Helm page, click Deploy. In the Basic Information section, set the following parameters, select the ratify chart, and then click Next.
Parameter
Example value
Application name
ratify
Namespace
Select ratify.
Source
The default value is Marketplace.
Chart
-
For Use scenarios, select All.
-
For Supported architecture, select amd64.
-
In the Search box, enter ratify.
-
-
On the Parameters page, select a Chart Version. To pull images by using RAM Roles for Service Accounts (RRSA), modify the parameters as shown in the Configuration example column. Then, click OK.
Parameter
Description
Default
Configuration example
ServiceAccount.createDetermines whether to create a dedicated service account for Ratify. Valid values:
-
true(default): A service account namedratify-adminis automatically created. -
false: A service account is not automatically created. If you use RRSA to pull images, you must create a service account manually before you install Ratify.
trueKeep the default value.
ServiceAccount.nameThe name of the Ratify service account.
ratify-adminKeep the default value.
ServiceAccount.annotationsCustom annotations for the service account.
{}Add the
pod-identity.alibabacloud.com/role-name: <Your-RRSA-role>annotation to enable automatic injection.NoteReplace
<Your-RRSA-role>with the name of your RRSA role.oras.authProviders.k8secretsEnabledEnables the Kubernetes Secrets Provider for image repository authentication.
falseKeep the default value.
NoteFor more information about ORAS configurations, see ORAS Store configuration example.
oras.authProviders.alibabacloudAcrBasicEnabledEnables the Alibaba Cloud ACR Provider for RRSA authentication with Container Registry instances.
falsetrueoras.cache.enabledEnables ORAS store caching for
ListReferrersandGetSubjectDescriptor.ImportantTTL-based caching might cause inconsistencies between the cache and the data source. If you require strong consistency, disable this parameter.
trueKeep the default value.
oras.cache.ttlSets the time-to-live (TTL) for the ORAS Store cache.
10Keep the default value.
alibabacloudAcrConfig.defaultInstanceIdThe default instance ID of the Container Registry instance that stores the target artifact.
Required.
Enter the ID of your Container Registry Enterprise Edition instance.
alibabacloudAcrConfig.acrInstancesConfigTo pull images from different Container Registry instances, define the
instanceNameandinstanceIdfor each instance in this list.[]
Configure this parameter as shown in the following example to connect to a private Container Registry repository.

upgradeCRDs.enabledEnables or disables the pre-install chart hook for upgrading Ratify CRDs.
trueSet this to
falseto skip upgrading the Ratify CRDs.NoteSetting this to
truetriggers apre-install hook, which may cause the installation to time out.featureFlags.RATIFY_CERT_ROTATIONEnables or disables automatic TLS certificate rotation. When enabled, Ratify automatically generates and rotates certificates.
falseSet to
trueto enable automatic certificate generation and rotation by the Ratify backend.notationCertDeprecated.
Use
notationCertsinstead to specify an array of verification certificates for the Notation verifier. The Notation verifier uses the specified certificates and certificate chain public keys to create its built-in certstore.None
Keep the default value.
notationCertsAn array of public key certificates and certificate chains for the Notation verifier's built-in certstore.
Enter the KMS verification certificate that was returned when you signed the artifact with the Notation plugin. For example:

-
-
-
In the left-side navigation pane, choose Security > Policy Governance. Click the My Policies tab and verify that the RatifyVerification policy exists.

2. Configure RRSA for private image signatures
Ratify supports authenticating with private Container Registry repositories by using RAM Roles for Service Accounts (RRSA) to pull signature data. For more information, see Use RRSA to grant RAM permissions to service accounts for pod-level access control.
-
Install the ack-pod-identity-webhook component from the Add-ons page of your cluster.
-
Create a RAM role named ratify-role. Set its trusted entity type to Identity Provider (IdP) and configure the condition fields in the trust policy. You can also use the ack-ram-tool CLI to automate the configuration.
In the
oidc:subvalue, replace<namespace>and<service_account>with the namespace and service account used for the Ratify installation.{ "Action": "sts:AssumeRole", "Condition": { "StringEquals": { "oidc:aud": "sts.aliyuncs.com", "oidc:iss": "<oidc_issuer_url>", "oidc:sub": "system:serviceaccount:<namespace>:<service_account>" } }, "Effect": "Allow", "Principal": { "Federated": [ "<oidc_provider_arn>" ] } } -
Attach the AliyunContainerRegistryFullAccess policy to the ratify-role RAM role.
-
When you deploy Ratify, create a service account and add the following annotations to both the service account and its namespace. After Ratify is deployed, the
ALIBABA_CLOUD_ROLE_ARN,ALIBABA_CLOUD_OIDC_PROVIDER_ARN, andALIBABA_CLOUD_OIDC_TOKEN_FILEenvironment variables are automatically injected into the Ratify pod template.NoteIf the service account already exists, add the
pod-identity.alibabacloud.com/role-name: ratify-roleannotation to it.--- apiVersion: v1 kind: Namespace metadata: name: ratify # The name of the namespace. labels: pod-identity.alibabacloud.com/injection: 'on' --- apiVersion: v1 kind: ServiceAccount metadata: name: ratify-admin # The name of the service account. namespace: ratify # The name of the namespace. annotations: pod-identity.alibabacloud.com/role-name: ratify-role # The name of the RAM role created earlier. ---
Step 5: Verify signing and verification
Deploy an application with a specific image in your ACK cluster to verify that the signing and verification feature works.
-
When you deploy a workload that uses an image with a valid signature, verify that the workload is successfully deployed to the target cluster.
-
When you deploy a workload that uses an unsigned image, verify that Ratify blocks the deployment. Check the workload status with
kubectlto view the blocking message. For more details, review the Ratify pod logs.kubectl get deploy ${unsigned_deploy_name} -n ${namespace} -o yaml # Replace with your deployment name and namespace.The verification log is similar to the following:

Ratify configuration
Ratify provides multiple built-in and external verifiers to process specific artifact types. To meet various signature verification needs, you can customize KeyManagementProvider (KMP) instances to define the keys or certificates used by verifiers. Ratify also provides a store to discover and retrieve metadata associated with an artifact's subject field, as defined in the OCI v1.1 specification. The following sections provide configuration examples.
Notation verifier configuration
In a verifier, you can define the name and artifactType fields to specify the artifact types it handles. Verifiers can be defined at the cluster scope or at the namespace scope by using the NamespacedVerifier kind. For more information, see the official Ratify documentation.
After you install Ratify with the default settings, a Notation verifier instance is automatically created in the cluster. You can configure the trustPolicyDoc policy as needed. The following is a sample configuration.
KMP configuration
You can define custom KeyManagementProvider (KMP) instances with inline public keys or X.509 certificates to meet various signature verification needs. During signature verification, verifiers like Notation and Cosign use an associated KMP resource. KMP resources can be defined at the cluster or namespace scope. For more information, see the official Ratify documentation. The following is a sample configuration.
ORAS store configuration
After you install Ratify, you can configure the authProvider parameter in the default ORAS store instance to connect to your private repositories in Alibaba Cloud Container Registry (ACR). The following is a sample configuration.