Skip to content

Commit cc30fbb

Browse files
authored
feat: Add submodule for creating a binary authentication attestor (#530)
1 parent 2dab7af commit cc30fbb

File tree

4 files changed

+212
-0
lines changed

4 files changed

+212
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Binary Authorization Infrastructure
2+
3+
This module creates the infrastructure and Attestors necessary to generate attestations on image digests.
4+
5+
## Compatibility/Requirements
6+
7+
* GCP Project ID where the project has an active billing account associated with it
8+
* Terraform version 0.12+
9+
* Google Kubernetes Engine cluster with "Binary Authorization" enabled
10+
11+
## Usage
12+
13+
```tf
14+
# Create a Key Ring
15+
resource "google_kms_key_ring" "keyring" {
16+
name = "my-example-attestor-key-ring"
17+
location = var.keyring-region
18+
lifecycle {
19+
prevent_destroy = false
20+
}
21+
}
22+
23+
# Create Quality Assurance attestor
24+
module "quality-attestor" {
25+
source = "terraform-google-modules/kubernetes-engine/google//modules/binary-authorization"
26+
27+
attestor-name = "quality-assurance"
28+
keyring-id = google_kms_key_ring.keyring.id
29+
}
30+
31+
```
32+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
33+
## Inputs
34+
35+
| Name | Description | Type | Default | Required |
36+
|------|-------------|:----:|:-----:|:-----:|
37+
| attestor-name | Name of the attestor | string | n/a | yes |
38+
| project\_id | Project ID to apply services into | string | n/a | yes |
39+
40+
## Outputs
41+
42+
| Name | Description |
43+
|------|-------------|
44+
| attestor | Name of the built attestor |
45+
| key | Name of the Key created for the attestor |
46+
47+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
48+
49+
## Next Steps
50+
51+
After building the Attestors, Attestations can be associated with image digests.
52+
53+
This module does not include a Binary Authorization policy for a cluster. A sample policy implemented as Dry-Run/Log-Only using our "quality-assurance" Attestor could look like this:
54+
55+
```tf
56+
resource "google_binary_authorization_policy" "policy" {
57+
58+
admission_whitelist_patterns {
59+
name_pattern = "gcr.io/${var.project_id}/*" # Enable local project GCR
60+
}
61+
62+
global_policy_evaluation_mode = "ENABLE"
63+
64+
# Production ready (all attestors required)
65+
default_admission_rule {
66+
evaluation_mode = "REQUIRE_ATTESTATION"
67+
enforcement_mode = "DRYRUN_AUDIT_LOG_ONLY"
68+
require_attestations_by = [
69+
module.quality-attestor.attestor # Our Attestor
70+
]
71+
}
72+
}
73+
```
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
locals {
18+
required_enabled_apis = [
19+
"containeranalysis.googleapis.com",
20+
"binaryauthorization.googleapis.com",
21+
"container.googleapis.com",
22+
"cloudkms.googleapis.com"
23+
]
24+
}
25+
26+
module "project-services" {
27+
source = "terraform-google-modules/project-factory/google//modules/project_services"
28+
version = "~> 8.0"
29+
30+
project_id = var.project_id
31+
32+
activate_apis = local.required_enabled_apis
33+
}
34+
35+
resource "google_binary_authorization_attestor" "attestor" {
36+
project = var.project_id
37+
name = "${var.attestor-name}-attestor"
38+
attestation_authority_note {
39+
note_reference = google_container_analysis_note.build-note.name
40+
public_keys {
41+
id = data.google_kms_crypto_key_version.version.id
42+
pkix_public_key {
43+
public_key_pem = data.google_kms_crypto_key_version.version.public_key[0].pem
44+
signature_algorithm = data.google_kms_crypto_key_version.version.public_key[0].algorithm
45+
}
46+
}
47+
}
48+
}
49+
50+
resource "google_container_analysis_note" "build-note" {
51+
project = var.project_id
52+
name = "${var.attestor-name}-attestor-note"
53+
attestation_authority {
54+
hint {
55+
human_readable_name = "${var.attestor-name} Attestor"
56+
}
57+
}
58+
}
59+
60+
# KEYS
61+
62+
data "google_kms_crypto_key_version" "version" {
63+
crypto_key = google_kms_crypto_key.crypto-key.id
64+
}
65+
66+
resource "google_kms_crypto_key" "crypto-key" {
67+
name = "${var.attestor-name}-attestor-key"
68+
key_ring = var.keyring-id
69+
purpose = "ASYMMETRIC_SIGN"
70+
71+
version_template {
72+
algorithm = var.crypto-algorithm
73+
}
74+
75+
lifecycle {
76+
prevent_destroy = false
77+
}
78+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
output "key" {
18+
value = google_kms_crypto_key.crypto-key.name
19+
description = "Name of the Key created for the attestor"
20+
}
21+
22+
output "attestor" {
23+
value = google_binary_authorization_attestor.attestor.name
24+
description = "Name of the built attestor"
25+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
variable "project_id" {
18+
type = string
19+
description = "Project ID to apply services into"
20+
}
21+
22+
variable "attestor-name" {
23+
type = string
24+
description = "Name of the attestor"
25+
}
26+
27+
variable keyring-id {
28+
type = string
29+
description = "Keyring ID to attach attestor keys"
30+
}
31+
32+
variable crypto-algorithm {
33+
type = string
34+
default = "RSA_SIGN_PKCS1_4096_SHA512"
35+
description = "Algorithm used for the async signing keys"
36+
}

0 commit comments

Comments
 (0)