13
13
# PROJECT: GCP project
14
14
# GCE_PD_SA_NAME: Name of the service account to create
15
15
# GCE_PD_SA_DIR: Directory to save the service account key
16
- # ENABLE_KMS: If true, it will enable Cloud KMS and configure IAM ACLs.
16
+ # ENABLE_KMS: Enable Cloud KMS and configure IAM ACLs.
17
+ # ENABLE_KMS_ADMIN: Add service account permissions to destroy Cloud KMS keys.
17
18
# CREATE_SA_KEY: (Optional) If true, creates a new service account key and
18
19
# exports it if creating a new service account
19
20
@@ -27,6 +28,7 @@ source "${PKGDIR}/deploy/common.sh"
27
28
ensure_var PROJECT
28
29
ensure_var GCE_PD_SA_NAME
29
30
ensure_var ENABLE_KMS
31
+ ensure_var ENABLE_KMS_ADMIN
30
32
31
33
# Allow the user to pass CREATE_SA_KEY=false to skip the SA key creation
32
34
# Ensure the SA directory set, if we're creating the SA_KEY
@@ -35,9 +37,8 @@ if [ "${CREATE_SA_KEY}" = true ]; then
35
37
ensure_var GCE_PD_SA_DIR
36
38
fi
37
39
38
- # If the project id includes the org name in the format "org-name:project", the
39
- # gCloud api will format the project part of the iam email domain as
40
- # "project.org-name"
40
+ # If the project ID includes the org name in the format "org-name:project",
41
+ # gcloud will format the project in the IAM email domain as "project.org-name"
41
42
if [[ $PROJECT == * " :" * ]]; then
42
43
IFS=' :' read -ra SPLIT <<< " $PROJECT"
43
44
readonly IAM_PROJECT=" ${SPLIT[1]} .${SPLIT[0]} "
90
91
# Create or Update Custom Role
91
92
if gcloud iam roles describe gcp_compute_persistent_disk_csi_driver_custom_role --project " ${PROJECT} " ;
92
93
then
93
- gcloud iam roles update gcp_compute_persistent_disk_csi_driver_custom_role --quiet \
94
- --project " ${PROJECT} " \
95
- --file " ${PKGDIR} /deploy/gcp-compute-persistent-disk-csi-driver-custom-role.yaml"
94
+ action=update
96
95
else
97
- gcloud iam roles create gcp_compute_persistent_disk_csi_driver_custom_role --quiet \
98
- --project " ${PROJECT} " \
99
- --file " ${PKGDIR} /deploy/gcp-compute-persistent-disk-csi-driver-custom-role.yaml"
96
+ action=create
100
97
fi
98
+ gcloud iam roles $action gcp_compute_persistent_disk_csi_driver_custom_role --quiet \
99
+ --project " ${PROJECT} " \
100
+ --file " ${PKGDIR} /deploy/gcp-compute-persistent-disk-csi-driver-custom-role.yaml"
101
101
102
102
# Bind service account to roles
103
103
for role in ${BIND_ROLES}
@@ -113,6 +113,13 @@ then
113
113
gcloud projects add-iam-policy-binding " ${PROJECT} " --member serviceAccount:" service-${PROJECT_NUMBER} @compute-system.iam.gserviceaccount.com" --role " roles/cloudkms.cryptoKeyEncrypterDecrypter"
114
114
fi
115
115
116
+ # Authorize SA to destroy Cloud KMS encryption keys.
117
+ if [ " ${ENABLE_KMS_ADMIN} " = true ];
118
+ then
119
+ gcloud services enable cloudkms.googleapis.com --project=" ${PROJECT} "
120
+ gcloud projects add-iam-policy-binding " ${PROJECT} " --member serviceAccount:" ${IAM_NAME} " --role " roles/cloudkms.admin"
121
+ fi
122
+
116
123
# Export key if needed
117
124
if [ " ${CREATE_SA} " = true ] && [ " ${CREATE_SA_KEY} " = true ];
118
125
then
0 commit comments