Skip to content

Commit cdb83d4

Browse files
committed
Fix KMS permissions for e2e tests
1 parent 47da7db commit cdb83d4

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

deploy/setup-project.sh

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
# PROJECT: GCP project
1414
# GCE_PD_SA_NAME: Name of the service account to create
1515
# 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.
1718
# CREATE_SA_KEY: (Optional) If true, creates a new service account key and
1819
# exports it if creating a new service account
1920

@@ -27,6 +28,7 @@ source "${PKGDIR}/deploy/common.sh"
2728
ensure_var PROJECT
2829
ensure_var GCE_PD_SA_NAME
2930
ensure_var ENABLE_KMS
31+
ensure_var ENABLE_KMS_ADMIN
3032

3133
# Allow the user to pass CREATE_SA_KEY=false to skip the SA key creation
3234
# Ensure the SA directory set, if we're creating the SA_KEY
@@ -35,9 +37,8 @@ if [ "${CREATE_SA_KEY}" = true ]; then
3537
ensure_var GCE_PD_SA_DIR
3638
fi
3739

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"
4142
if [[ $PROJECT == *":"* ]]; then
4243
IFS=':' read -ra SPLIT <<< "$PROJECT"
4344
readonly IAM_PROJECT="${SPLIT[1]}.${SPLIT[0]}"
@@ -90,14 +91,13 @@ fi
9091
# Create or Update Custom Role
9192
if gcloud iam roles describe gcp_compute_persistent_disk_csi_driver_custom_role --project "${PROJECT}";
9293
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
9695
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
10097
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"
101101

102102
# Bind service account to roles
103103
for role in ${BIND_ROLES}
@@ -113,6 +113,13 @@ then
113113
gcloud projects add-iam-policy-binding "${PROJECT}" --member serviceAccount:"service-${PROJECT_NUMBER}@compute-system.iam.gserviceaccount.com" --role "roles/cloudkms.cryptoKeyEncrypterDecrypter"
114114
fi
115115

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+
116123
# Export key if needed
117124
if [ "${CREATE_SA}" = true ] && [ "${CREATE_SA_KEY}" = true ];
118125
then

docs/kubernetes/development.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ To create a service account with correct permissions, your test project must:
4848
[Role Administrator](https://cloud.google.com/iam/docs/understanding-roles#iam.roleAdmin)
4949
IAM roles.
5050
2. Be part of an organization that allows creation of service account keys.
51-
- Google developer projects restrict SA keys and will not work for E2E
52-
testing.
51+
- For example, a Google internal developer project will not work for E2E
52+
testing because the org restricts SA key creation.
5353

5454
```sh
55-
export ENABLE_KMS=false
55+
export ENABLE_KMS=true
56+
export ENABLE_KMS_ADMIN=true
5657
./deploy/setup-project.sh
5758
```
5859

0 commit comments

Comments
 (0)