Skip to content

Commit 7d3855f

Browse files
authored
updates KMS support docs (sigstore#125)
Signed-off-by: ChrisJBurns <[email protected]>
1 parent 4f6b2f9 commit 7d3855f

File tree

1 file changed

+127
-34
lines changed

1 file changed

+127
-34
lines changed

content/en/cosign/kms_support.md

Lines changed: 127 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,85 @@ position: 119
55
---
66

77
This page contains detailed instructions on how to configure `cosign` to work with KMS providers.
8-
Right now `cosign` supports Hashicorp Vault, AWS KMS, and GCP KMS, and we are hoping to support more in the future!
8+
Right now `cosign` supports [AWS KMS](https://aws.amazon.com/kms/), [GCP KMS](https://cloud.google.com/security-key-management), [Azure Key Vault](https://azure.microsoft.com/en-gb/products/key-vault), [Hashicorp Vault](https://www.vaultproject.io/) and [Kubernetes Secrets](https://kubernetes.io/docs/concepts/configuration/secret/) with the hope to support more in the future!
99

10+
## Basic Usage
11+
12+
When referring to a key managed by a KMS provider, `cosign` takes a [go-cloud](https://gocloud.dev) style URI to refer to the specific provider.
13+
14+
For example: `awskms://`, `gcpkms://`, `azurekms://`, `hashivault://` and `k8s://`. The URI path syntax is provider specific and explained in the section for each provider.
15+
16+
### Key Generation and Management
17+
18+
To generate keys using a KMS provider, you can use the `cosign generate-key-pair` command with the `--kms` flag.
19+
For example:
20+
21+
```shell
22+
$ cosign generate-key-pair --kms <some provider>://<some key>
23+
```
24+
25+
The public key can be retrieved with:
26+
27+
```shell
28+
$ cosign public-key --key <some provider>://<some key>
29+
-----BEGIN PUBLIC KEY-----
30+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEXc+DQU8Pb7Xo2RWCjFG/f6qbdABN
31+
jnVtSyKZxNzBfNMLLtVxdu8q+AigrGCS2KPmejda9bICTcHQCRUrD5OLGQ==
32+
-----END PUBLIC KEY-----
33+
```
34+
35+
### Signing and Verification
36+
37+
For the following examples, we have:
38+
39+
```shell
40+
$ IMAGE=gcr.io/user/demo
41+
$ IMAGE_DIGEST=$IMAGE@sha256:410a07f17151ffffb513f942a01748dfdb921de915ea6427d61d60b0357c1dcd
42+
```
43+
44+
To sign and verify using a key managed by a KMS provider, you can pass a provider-specific URI to the `--key` command:
45+
46+
```shell
47+
$ cosign sign --key <some provider>://<some key> $IMAGE_DIGEST
48+
Pushing signature to: gcr.io/user/demo:sha256-410a07f17151ffffb513f942a01748dfdb921de915ea6427d61d60b0357c1dcd.cosign
49+
50+
$ cosign verify --key <some provider>://<some key> $IMAGE_DIGEST
51+
52+
Verification for gcr.io/user/demo --
53+
The following checks were performed on each of these signatures:
54+
- The cosign claims were validated
55+
- The signatures were verified against the specified public key
56+
- The code-signing certificate was verified using trusted certificate authority certificates
57+
58+
[{"critical":{"identity":{"docker-reference":"gcr.io/user/demo"},"image":{"docker-manifest-digest":"sha256:410a07f17151ffffb513f942a01748dfdb921de915ea6427d61d60b0357c1dcd"},"type":"cosign container image signature"},"optional":null}]
59+
```
60+
61+
You can also export the public key and verify against that file:
62+
63+
```shell
64+
$ cosign public-key --key <some provider>://<some key> > kms.pub
65+
$ cosign verify --key kms.pub $IMAGE_DIGEST
66+
```
1067

1168
## Providers
1269

1370
This section contains the provider-specific documentation.
1471

15-
1672
### AWS
1773

1874
AWS KMS keys can be used in `cosign` for signing and verification.
19-
The URI format for AWS KMS is:
20-
21-
`awskms://$ENDPOINT/$KEYID`
22-
23-
where ENDPOINT and KEYID are replaced with the correct values.
75+
The URI format for AWS KMS is `awskms://$ENDPOINT/$KEYID` where `$ENDPOINT` and `$KEYID` are replaced with the correct values.
2476

25-
The ENDPOINT value is left blank in most scenarios, but can be set for testing with KMS-compatible servers such as [localstack](https://localstack.cloud/).
77+
The `$ENDPOINT` value is left blank in most scenarios, but can be set for testing with KMS-compatible servers such as [localstack](https://localstack.cloud/).
2678
If omitting a custom endpoint, it is mandatory to prefix the URI with `awskms:///` (with three slashes).
2779

28-
If a custom endpoint is used, you may disable TLS verification by setting an environment variable: `AWS_TLS_INSECURE_SKIP_VERIFY=1`.
80+
If a custom endpoint is used, you may disable TLS verification by setting an environment variable `AWS_TLS_INSECURE_SKIP_VERIFY=1`.
2981

3082
AWS credentials are provided using standard configuration as [described in AWS docs](https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#specifying-credentials).
3183

32-
The KEYID value must conform to any [AWS KMS key identifier](https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id)
33-
format as described in the linked document (Key ARN, Key ID, Alias ARN, or Alias ID).
84+
The `$KEYID` value must conform to any [AWS KMS key identifier](https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id) format as described in the linked document (Key ARN, Key ID, Alias ARN, or Alias ID).
3485

35-
Note that key creation is not supported by cosign if using the Key ARN or Key ID formats, so it is recommended to use [Key Aliases](https://docs.aws.amazon.com/kms/latest/developerguide/kms-alias.html)
36-
for most situations.
86+
Note that key creation is not supported by cosign if using the Key ARN or Key ID formats, so it is recommended to use [Key Aliases](https://docs.aws.amazon.com/kms/latest/developerguide/kms-alias.html) for most situations.
3787

3888
The following URIs are valid:
3989

@@ -46,50 +96,93 @@ The following URIs are valid:
4696
- Alias ARN: `awskms:///arn:aws:kms:us-east-2:111122223333:alias/ExampleAlias`
4797
- Alias ARN with endpoint: `awskms://localhost:4566/arn:aws:kms:us-east-2:111122223333:alias/ExampleAlias`
4898

99+
Example:
100+
101+
```shell
102+
$ export AWS_REGION=us-east-1
103+
$ export AWS_CMK_ID=$(aws kms create-key
104+
--customer-master-key-spec RSA_4096 \
105+
--key-usage SIGN_VERIFY \
106+
--description "Cosign Signature Key Pair" \
107+
--query KeyMetadata.KeyId --output text)
108+
109+
$ cosign sign --key awskms:///${AWS_CMK_ID} $IMAGE_DIGEST
110+
$ cosign verify --key awskms:///${AWS_CMK_ID} $IMAGE_DIGEST | jq .
111+
```
112+
49113
### GCP
50114

51115
GCP KMS keys can be used in `cosign` for signing and verification.
52-
The URI format for GCP KMS is:
53116

54-
`gcpkms://projects/$PROJECT/locations/$LOCATION/keyRings/$KEYRING/cryptoKeys/$KEY/versions/$KEY_VERSION`
117+
The URI format for GCP KMS is:
118+
119+
```shell
120+
gcpkms://projects/$PROJECT/locations/$LOCATION/keyRings/$KEYRING/cryptoKeys/$KEY/versions/$KEY_VERSION
121+
```
55122

56-
where PROJECT, LOCATION, KEYRING, KEY and KEY_VERSION are replaced with the correct values.
123+
Where `$PROJECT`, `$LOCATION`, `$KEYRING`, `$KEY` and `$KEY_VERSION` are replaced with the correct values.
57124

58-
Cosign automatically uses GCP Application Default Credentials for authentication.
59-
See the GCP [API documentation](https://cloud.google.com/docs/authentication/production) for information on how to authenticate in different environments.
125+
Cosign automatically uses GCP Application Default Credentials for authentication. See the GCP [API documentation](https://cloud.google.com/docs/authentication/production) for information on how to authenticate in different environments.
60126

61127
The user must have the following IAM roles:
62-
* Safer KMS Viewer Role
63-
* Cloud KMS CryptoKey Signer/Verifier (`roles/cloudkms.signerVerifier`)
64128

65-
### Azure Key Vault
129+
- Safer KMS Viewer Role
130+
- Cloud KMS CryptoKey Signer/Verifier (`roles/cloudkms.signerVerifier`)
66131

67-
Azure Key Vault keys can be used in `cosign` for signing and verification.
132+
### Azure Key Vault
68133

69-
The URI format for Azure Key Vault is:
70-
`azurekms://[VAULT_NAME][VAULT_URI]/[KEY]`
134+
Azure Key Vault keys can be used in `cosign` for signing and verification. The URI format for Azure Key Vault is:
135+
`azurekms://[VAULT_NAME][VAULT_URI]/[KEY]` where `$VAULT_NAME`, `$VAULT_URI`, and `$KEY` are replaced with the correct values.
71136

72-
where VAULT_NAME, VAULT_URI, and KEY are replaced with the correct values.
137+
The following environment variables must be set to let cosign authenticate to Azure Key Vault. (see this [reference](https://devblogs.microsoft.com/azure-sdk/authentication-and-the-azure-sdk/#environment-variables) for more details about Azure SDK Authentication):
73138

74-
The following environment variables must be set to let cosign authenticate to Azure Key Vault. (see this [reference](https://devblogs.microsoft.com/azure-sdk/authentication-and-the-azure-sdk/#environment-variables) for more details about Azure SDK Authentication)
75-
- AZURE_TENANT_ID
76-
- AZURE_CLIENT_ID
77-
- AZURE_CLIENT_SECRET
139+
- `AZURE_TENANT_ID`
140+
- `AZURE_CLIENT_ID`
141+
- `AZURE_CLIENT_SECRET`
78142

79143
To create a key using `cosign generate-key-pair --kms azurekms://[VAULT_NAME][VAULT_URI]/[KEY]` you will need a user which has permissions to create keys in Key Vault. For example `Key Vault Crypto Officer` role.
80144

81-
To sign images using `cosign sign --key azurekms://[VAULT_NAME][VAULT_URI]/[KEY] [IMAGE]` you will need a user which has permissions to the sign action such as the `Key Vault Crypto User` role.
145+
To sign images using `cosign sign --key azurekms://[VAULT_NAME][VAULT_URI]/[KEY] [IMAGE_DIGEST]` you will need a user which has permissions to the sign action such as the `Key Vault Crypto User` role.
82146

83147
### Hashicorp Vault
84148

85149
Hashicorp Vault keys can be used in `cosign` for signing and verification.
86-
The URI format for Hashicorp Vault KMS is:
150+
The URI format for Hashicorp Vault KMS is: `hashivault://$keyname`
87151

88-
`hashivault://$keyname`
89-
90-
This provider requires that the standard Vault environment variables (VAULT_ADDR, VAULT_TOKEN) are set correctly.
152+
This provider requires that the standard Vault environment variables (`$VAULT_ADDR`, `$VAULT_TOKEN`) are set correctly.
91153
This provider also requires that the `transit` secret engine is enabled.
92154

155+
### Kubernetes Secret
156+
157+
Cosign can use keys stored in Kubernetes Secrets to so sign and verify signatures. In order to generate a secret you have to pass `cosign generate-key-pair` a `k8s://[NAMESPACE]/[NAME]` URI specifying the namespace and secret name:
158+
159+
```shell
160+
$ cosign generate-key-pair k8s://default/testsecret
161+
Enter password for private key: ****
162+
Enter again: ****
163+
Successfully created secret testsecret in namespace default
164+
Public key written to cosign.pub
165+
```
166+
167+
After generating the key pair, cosign will store it in a Kubernetes secret using your current context. The secret will contain the private and public keys, as well as the password to decrypt the private key.
168+
169+
The secret has the following structure:
170+
171+
```yaml
172+
apiVersion: v1
173+
kind: Secret
174+
metadata:
175+
name: testsecret
176+
namespace: default
177+
type: Opaque
178+
data:
179+
cosign.key: LS0tLS1CRUdJTiBFTkNSWVBURUQgQ09TSUdOIFBSSVZBVEUgS0VZLS0tLS[...]==
180+
cosign.password: YWJjMTIz
181+
cosign.pub: LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUZrd0V3WUhLb1pJemowQo[...]==
182+
```
183+
184+
When verifying an image signature using `cosign verify`, the key will be automatically decrypted using the password stored in the kubernetes secret under the `cosign.password` field.
185+
93186
#### Local Setup
94187

95188
For a local setup, you can run Vault yourself or use the `docker-compose` file from [sigstore/sigstore](https://github.com/sigstore/sigstore/blob/main/test/e2e/docker-compose.yml) as an example.

0 commit comments

Comments
 (0)