Skip to content

Commit e87044f

Browse files
chore: Attach KMS Key in Safer IAP GKE cluster (#1614)
Co-authored-by: Bharath KKB <[email protected]>
1 parent 05159ec commit e87044f

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

examples/safer_cluster_iap_bastion/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This end to end example aims to showcase access patterns to a [Safer Cluster](..
44

55
Additionally we deploy a [tinyproxy](https://tinyproxy.github.io/) daemon which allows `kubectl` commands to be piped through the bastion host allowing ease of development from a local machine with the security of GKE Private Clusters.
66

7+
GKE Autopilot clusters are deployed with Application-layer Secrets Encryption that protects your secrets in etcd with a key you manage in [Cloud KMS](https://github.com/terraform-google-modules/terraform-google-kms/blob/master/README.md).
8+
79
## Setup
810

911
To deploy this example:
@@ -59,6 +61,9 @@ To deploy this example:
5961
| cluster\_name | Cluster name |
6062
| endpoint | Cluster endpoint |
6163
| get\_credentials\_command | gcloud get-credentials command to generate kubeconfig for the private cluster |
64+
| keyring | The name of the keyring. |
65+
| keyring\_resource | The location of the keyring. |
66+
| keys | Map of key name => key self link. |
6267
| location | Cluster location (region if regional cluster, zone if zonal cluster) |
6368
| master\_authorized\_networks\_config | Networks from which access to master is permitted |
6469
| network\_name | The name of the VPC being created |

examples/safer_cluster_iap_bastion/apis.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ module "enabled_google_apis" {
2020

2121
project_id = var.project_id
2222
disable_services_on_destroy = false
23+
activate_api_identities = [{
24+
api = "container.googleapis.com",
25+
roles = ["roles/cloudkms.cryptoKeyDecrypter",
26+
"roles/cloudkms.cryptoKeyEncrypter"],
27+
}]
2328

2429
activate_apis = [
2530
"serviceusage.googleapis.com",
@@ -32,5 +37,6 @@ module "enabled_google_apis" {
3237
"binaryauthorization.googleapis.com",
3338
"stackdriver.googleapis.com",
3439
"iap.googleapis.com",
40+
"cloudkms.googleapis.com",
3541
]
3642
}

examples/safer_cluster_iap_bastion/cluster.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ module "gke" {
2929
cidr_block = "${module.bastion.ip_address}/32"
3030
display_name = "Bastion Host"
3131
}]
32+
database_encryption = [
33+
{
34+
"key_name" : module.kms.keys["gke-key"],
35+
"state" : "ENCRYPTED"
36+
}
37+
]
3238
grant_registry_access = true
3339
node_pools = [
3440
{
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright 2022 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+
module "kms" {
18+
source = "terraform-google-modules/kms/google"
19+
version = "~> 2.2.1"
20+
project_id = var.project_id
21+
location = var.region
22+
keyring = "gke-keyring"
23+
keys = ["gke-key"]
24+
prevent_destroy = false
25+
}

examples/safer_cluster_iap_bastion/outputs.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,18 @@ output "bastion_kubectl_command" {
8585
description = "kubectl command using the local proxy once the bastion_ssh command is running"
8686
value = "HTTPS_PROXY=localhost:8888 kubectl get pods --all-namespaces"
8787
}
88+
89+
output "keyring" {
90+
description = "The name of the keyring."
91+
value = module.kms.keyring
92+
}
93+
94+
output "keyring_resource" {
95+
description = "The location of the keyring."
96+
value = module.kms.keyring_resource
97+
}
98+
99+
output "keys" {
100+
description = "Map of key name => key self link."
101+
value = module.kms.keys
102+
}

0 commit comments

Comments
 (0)