|
| 1 | + |
| 2 | +# Alibaba Cloud Secret Manager plugin for Notation |
| 3 | + |
| 4 | +This repository contains the implementation of the [Alibaba Cloud Secret Manager](https://www.alibabacloud.com/help/en/kms/support/overview-6) signing plugin for [Notation](https://notaryproject.dev/). This project is still in early development status. |
| 5 | + |
| 6 | +> **Note** The Notary Project documentation is available [here](https://notaryproject.dev/docs/). You can also find the Notary Project [README](https://github.com/notaryproject/.github/blob/main/README.md) to learn about the overall Notary Project. |
| 7 | +
|
| 8 | +## Quick start |
| 9 | + |
| 10 | +This document demonstrates how to sign and verify an OCI artifact with Alibaba Cloud Secret Manager plugin for Notation. |
| 11 | + |
| 12 | + |
| 13 | +#### Plugin Spec Compatibility |
| 14 | + |
| 15 | +| Capability | Compatibility | |
| 16 | +| --------------------- | ------------------------------------------------------------ | |
| 17 | +| keySpec | `RSA-2048`, `RSA-3072`, `EC-256` | |
| 18 | +| hashAlgorithm | `SHA-256` | |
| 19 | +| signingAlgorithm | `RSASSA-PSS-SHA-256`, `ECDSA-SHA-256` | |
| 20 | +| pluginCapability | `SIGNATURE_GENERATOR.RAW`, `SIGNATURE_VERIFIER.TRUSTED_IDENTITY`, `SIGNATURE_VERIFIER.REVOCATION_CHECK` | |
| 21 | +| signingScheme | `notary.x509` | |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +## Getting Started: |
| 26 | + |
| 27 | +The following summarizes the steps to configure the notation-alibabacloud-secret-manager plugin and sign and verify a container image. The following steps are based off of the Notation hello-signing [example](https://github.com/notaryproject/notation-plugin-framework-go/tree/main/example). |
| 28 | + |
| 29 | +- Install notation [CLI](https://github.com/notaryproject/notation/releases/tag/v1.1.1). Version v1.1.1 has been tested. Note that `make install` creates the plugin directory structure based on a MacOS environment. Update the Makefile based on your OS. It then copies the plugin to the appropriate location based on the notation plugin directory structure spec. |
| 30 | + |
| 31 | +- This plugin leverages the [KMS Instance SDK](https://www.alibabacloud.com/help/en/kms/developer-reference/kms-instance-sdk-for-go/), which means you'll need to meet the pre-requisites and customize the environment as follows: |
| 32 | + |
| 33 | +| Env | Description | |
| 34 | +| --------------------- | ------------------------------------------------------------ | |
| 35 | +| ALIBABA_CLOUD_ACCESS_KEY_ID | Alibaba Cloud Account Access Key ID | |
| 36 | +| ALIBABA_CLOUD_ACCESS_KEY_SECRET | Alibaba Cloud Account Secret Access Key | |
| 37 | +| ALIBABA_CLOUD_KMS_INSTANCE_ENDPOINT | VPC Endpoint of the Dedicated KMS Instance, for example, kst-hzxxxxxxxxxx.cryptoservice.kms.aliyuncs.com | |
| 38 | +| ALIBABA_CLOUD_KMS_CLIENTKEY_FILEPATH | Local File Path of the ClientKey Credential for the Dedicated KMS Instance Application Access Point (AAP) | |
| 39 | +| ALIBABA_CLOUD_KMS_PASSWORD | Password for the Dedicated KMS Instance Application Access Point (AAP) | |
| 40 | +| ALIBABA_CLOUD_KMS_CA_FILEPATH | Local Path of the CA Certificate for the Dedicated KMS Instance | |
| 41 | + |
| 42 | +*Note: the notation-alibabacloud-secret-manager plugin supports various Credential configuration methods. For more details, please refer to [credentials](https://aliyuncontainerservice.github.io/ack-ram-tool/#credentials)* |
| 43 | + |
| 44 | + |
| 45 | +## Installation |
| 46 | + |
| 47 | +Install the notation-alibabacloud-secret-manager plugin for remote signing and verification, using the `notation plugin install` command: |
| 48 | + |
| 49 | +#### Build and Install from Source |
| 50 | + |
| 51 | +```bash |
| 52 | +git clone |
| 53 | +cd notation-alibabacloud-secret-manager |
| 54 | +make build |
| 55 | +``` |
| 56 | +## Generate and import the keypair meterial |
| 57 | + |
| 58 | +A user can bring their own private key and certificate. As a quick start, this tutorial is using openssl to generate a private key and a certificate |
| 59 | + |
| 60 | +1. Create an asymmetric key in KMS console, please refer to [step1](https://www.alibabacloud.com/help/en/kms/user-guide/import-key-material-into-an-asymmetric-key#p-qcf-3d4-pel) |
| 61 | +2. Download a wrapping public key and an import token, please refer to [step2](https://www.alibabacloud.com/help/en/kms/user-guide/import-key-material-into-an-asymmetric-key#p-f9p-n7u-88m) |
| 62 | +3. Use the wrapping public key to encrypt key material, please refer to [step3](https://www.alibabacloud.com/help/en/kms/user-guide/import-key-material-into-an-asymmetric-key#p-jar-kxa-iun) |
| 63 | +4. Import key material, please refer to [step4](https://www.alibabacloud.com/help/en/kms/user-guide/import-key-material-into-an-asymmetric-key#p-j5c-vp9-9vd) |
| 64 | +  |
| 65 | + |
| 66 | +5. Create an x509 certificate based on the private key TakPrivPkcs1.pem from step 3 above and the server_cert configuration in [openssl.cnf]((./docs/import_key.png)). |
| 67 | +```bash |
| 68 | +openssl req -x509 -new -nodes -key TakPrivPkcs1.pem -sha256 -days 3650 -out sign.crt -config openssl.cnf -extensions server_cert |
| 69 | +``` |
| 70 | + |
| 71 | + |
| 72 | +## Sign an artifact using Notation |
| 73 | +Now we've done all the configurations. Let's sign an artifact using Notation. (If you haven't done so, download notation from [here](https://github.com/notaryproject/notation/releases).) |
| 74 | +```bash |
| 75 | +notation sign --id <keyId> --plugin alibabacloud.secretmanager.plugin <myRegistry>/<myRepo>@<digest> --plugin-config ca_certs=<certPath> |
| 76 | +``` |
| 77 | +Note: the `--id` should be identical to your specific key id in Alibaba Cloud KMS Service instance and the `ca_certs` in ` --plugin-config` should be identical to the file path of the x509 certificate generated in step 5 above. |
| 78 | + |
| 79 | + |
| 80 | +## Verify the artifact using Notation |
| 81 | +1. Configure trust store. |
| 82 | + ```bash |
| 83 | + ./notation cert add -t ca -s myStore "{path-to-cert}/sign.crt" |
| 84 | + ``` |
| 85 | + where `sign.crt` is the cert generated in the previous step. |
| 86 | +2. Configure the trust policy. |
| 87 | + ```bash |
| 88 | + cat <<EOF > ./trustpolicy.json |
| 89 | + { |
| 90 | + "version": "1.0", |
| 91 | + "trustPolicies": [ |
| 92 | + { |
| 93 | + "name": "acr-hangzhou-images", |
| 94 | + "registryScopes": [ "<myRegistry>/<myRepo>" ], |
| 95 | + "signatureVerification": { |
| 96 | + "level" : "strict" |
| 97 | + }, |
| 98 | + "trustStores": [ "ca:ack.notation" ], |
| 99 | + "trustedIdentities": [ |
| 100 | + "*" |
| 101 | + ] |
| 102 | + } |
| 103 | + ] |
| 104 | + } |
| 105 | + EOF |
| 106 | + ``` |
| 107 | + ```bash |
| 108 | + ./notation policy import ./trustpolicy.json |
| 109 | + ``` |
| 110 | +3. Verify the artifact |
| 111 | + ```bash |
| 112 | + ./notation verify <myRegistry>/<myRepo>@<digest> -v |
| 113 | +
|
0 commit comments