-
Notifications
You must be signed in to change notification settings - Fork 159
Improve deployment scripts, make service account JSON configurable by directory, not name #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,26 @@ | ||
#!/bin/bash | ||
|
||
# This script will setup the given project with a Service Account that has the correct | ||
# restricted permissions to run the gcp_compute_persistent_disk_csi_driver and download | ||
# the keys to a specified directory | ||
|
||
# WARNING: This script will delete and recreate the service accounts, bindings, and keys | ||
# associated with ${GCE_PD_SA_NAME}. Great care must be taken to not run the script | ||
# with a service account that is currently in use. | ||
|
||
# Args: | ||
# PROJECT: GCP project | ||
# GCE_PD_SA_NAME: Name of the service account to create | ||
# GCE_PD_SA_DIR: Directory to save the service account key | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there defaults set? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should there be defaults? I think these are all important enough that there shouldn't be any defaults. I have |
||
|
||
|
||
set -o nounset | ||
set -o errexit | ||
|
||
readonly PKGDIR="${GOPATH}/src/sigs.k8s.io/gcp-compute-persistent-disk-csi-driver" | ||
readonly KUBEDEPLOY="${PKGDIR}/deploy/kubernetes" | ||
|
||
BIND_ROLES="roles/compute.storageAdmin roles/iam.serviceAccountUser projects/${PROJECT}/roles/gcp_compute_persistent_disk_csi_driver_custom_role" | ||
IAM_NAME="${GCEPD_SA_NAME}@${PROJECT}.iam.gserviceaccount.com" | ||
readonly BIND_ROLES="roles/compute.storageAdmin roles/iam.serviceAccountUser projects/${PROJECT}/roles/gcp_compute_persistent_disk_csi_driver_custom_role" | ||
readonly IAM_NAME="${GCE_PD_SA_NAME}@${PROJECT}.iam.gserviceaccount.com" | ||
|
||
# Create or Update Custom Role | ||
if gcloud iam roles describe gcp_compute_persistent_disk_csi_driver_custom_role --project "${PROJECT}"; | ||
|
@@ -22,8 +35,8 @@ else | |
fi | ||
|
||
# Delete Service Account Key | ||
if [ -f $SA_FILE ]; then | ||
rm "$SA_FILE" | ||
if [ -f "${GCE_PD_SA_DIR}/cloud-sa.json" ]; then | ||
rm "${GCE_PD_SA_DIR}/cloud-sa.json" | ||
fi | ||
# Delete ALL EXISTING Bindings | ||
gcloud projects get-iam-policy "${PROJECT}" --format json > "${PKGDIR}/deploy/iam.json" | ||
|
@@ -34,9 +47,9 @@ rm -f "${PKGDIR}/deploy/iam.json" | |
gcloud iam service-accounts delete "${IAM_NAME}" --project "${PROJECT}" --quiet || true | ||
|
||
# Create new Service Account and Keys | ||
gcloud iam service-accounts create "${GCEPD_SA_NAME}" --project "${PROJECT}" | ||
gcloud iam service-accounts create "${GCE_PD_SA_NAME}" --project "${PROJECT}" | ||
for role in ${BIND_ROLES} | ||
do | ||
gcloud projects add-iam-policy-binding "${PROJECT}" --member serviceAccount:"${IAM_NAME}" --role ${role} | ||
done | ||
gcloud iam service-accounts keys create "${SA_FILE}" --iam-account "${IAM_NAME}" --project "${PROJECT}" | ||
gcloud iam service-accounts keys create "${GCE_PD_SA_DIR}/cloud-sa.json" --iam-account "${IAM_NAME}" --project "${PROJECT}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put this note in the readme right up top