Skip to content

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

Merged
merged 1 commit into from
Aug 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ this drive in a production environment in its current state.

DISCLAIMER: This is not an officially supported Google product

Kubernetes Note: setup-cluster.yaml depends on the existence of cluster-roles
system:csi-external-attacher and system:csi-external-provisioner which are in
Kubernetes version 1.10.5+

# GCP Compute Persistent Disk CSI Driver

The GCP Compute Persistent Disk CSI Driver is a
Expand Down
3 changes: 3 additions & 0 deletions deploy/kubernetes/delete-driver.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

# This script will remove the GCP Compute Persistent Disk CSI Driver from the
# currently available Kubernetes cluster

set -o nounset
set -o errexit

Expand Down
12 changes: 11 additions & 1 deletion deploy/kubernetes/deploy-driver.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/bin/bash

# This script will deploy the GCP Compute Persistent Disk CSI Driver to the
# currently available Kubernetes cluster

# Note: setup-cluster.yaml depends on the existence of cluster-roles
# system:csi-external-attacher and system:csi-external-provisioner
# which are in Kubernetes version 1.10.5+
Copy link
Contributor

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


# Args:
# GCE_PD_SA_DIR: Directory the service account key has been saved in (generated by setup-project.sh)

set -o nounset
set -o errexit

Expand All @@ -8,7 +18,7 @@ readonly KUBEDEPLOY="${PKGDIR}/deploy/kubernetes"

if ! kubectl get secret cloud-sa;
then
kubectl create secret generic cloud-sa --from-file="${SA_FILE}"
kubectl create secret generic cloud-sa --from-file="${GCE_PD_SA_DIR}/cloud-sa.json"
fi

# GKE Required Setup
Expand Down
27 changes: 20 additions & 7 deletions deploy/setup-project.sh
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there defaults set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 so it throws an error if the vars are unset when the script runs



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}";
Expand All @@ -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"
Expand All @@ -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}"