Skip to content

Remove old policy bindings so that setup-project is reentrant #73

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

Conversation

davidz627
Copy link
Contributor

@davidz627 davidz627 commented Jul 18, 2018

Have the setup-project.sh script remove old policy bindings so that they can be recreated successfully.

Part of: #73

/assign @msau42

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: davidz627

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jul 18, 2018
@@ -10,10 +10,11 @@ if [ -f $SA_FILE ]; then
rm "$SA_FILE"
fi
gcloud iam service-accounts delete "$IAM_NAME" --quiet || true
# TODO: Delete ALL policy bindings
gcloud projects remove-iam-policy-binding "${PROJECT}" --member serviceAccount:"${IAM_NAME}" --role roles/compute.admin --quiet || true
Copy link
Contributor

Choose a reason for hiding this comment

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

With this change, can we reduce the compute.admin role?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, I will look into it

@davidz627 davidz627 force-pushed the fix/projectBindingDelete branch from 42d93f1 to b5a0f14 Compare July 18, 2018 21:41
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jul 18, 2018
role scopes and added custom role for necessary extras
@davidz627 davidz627 force-pushed the fix/projectBindingDelete branch from b5a0f14 to 3499c3a Compare July 18, 2018 21:45
@davidz627
Copy link
Contributor Author

@msau42 updated so that roles are fairly minimal

# Create or Update Custom Role
if gcloud iam roles describe gcp_compute_persistent_disk_csi_driver_custom_role --project "${PROJECT}";
then
yes | gcloud iam roles update gcp_compute_persistent_disk_csi_driver_custom_role \
Copy link
Contributor

Choose a reason for hiding this comment

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

does the -q option not work for suppressing interactive mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

brainfarted


# Create new Service Account and Keys
gcloud iam service-accounts create "${GCEPD_SA_NAME}"
gcloud iam service-accounts keys create "${SA_FILE}" --iam-account "${IAM_NAME}"
gcloud projects add-iam-policy-binding "${PROJECT}" --member serviceAccount:"${IAM_NAME}" --role roles/compute.admin
Copy link
Contributor

Choose a reason for hiding this comment

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

your role-binding teardown logic will not be backwards compatible anymore. maybe it needs to somehow iterate through all the rolebindings the SA has, and delete them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

resolved

done
# Delete ALL EXISTING Bindings
gcloud projects get-iam-policy "${PROJECT}" --format json > "${PKGDIR}/deploy/iam.json"
sed -i "/${IAM_NAME}/d" "${PKGDIR}/deploy/iam.json"
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this accidentally match a substring of the IAM_NAME?

Say you had something called "foobar", and your IAM_NAME was "bar"

Copy link
Contributor Author

@davidz627 davidz627 Jul 18, 2018

Choose a reason for hiding this comment

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

good catch, amended with prefix serviceAccount:

@davidz627 davidz627 force-pushed the fix/projectBindingDelete branch from d3f87c8 to 6ad9a4b Compare July 18, 2018 22:38
# Delete ALL EXISTING Bindings
gcloud projects get-iam-policy "${PROJECT}" --format json > "${PKGDIR}/deploy/iam.json"
sed -i "/serviceAccount:${IAM_NAME}/d" "${PKGDIR}/deploy/iam.json"
gcloud projects set-iam-policy "${PROJECT}" "${PKGDIR}/deploy/iam.json"
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm although in general I find this kind of scary because it sets all the rolebindings in your entire project to the .json, not just this particular service account. If someone is also modifying the iam policies at the same time, this could override their changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

theres an etag that is used for consistency. gcloud projects set-iam-policy will fail if the etag is out of date. I haven't written in any failure handling logic. It shouldn't be too difficult to just run the script again.

@msau42
Copy link
Contributor

msau42 commented Jul 19, 2018

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 19, 2018
@k8s-ci-robot k8s-ci-robot merged commit 15cff3a into kubernetes-sigs:master Jul 19, 2018
@davidz627 davidz627 deleted the fix/projectBindingDelete branch July 19, 2018 21:15
@davidz627 davidz627 mentioned this pull request Aug 10, 2018
3 tasks
jsafrane pushed a commit to jsafrane/gcp-compute-persistent-disk-csi-driver that referenced this pull request Apr 16, 2025
…ncy-openshift-4.19-ose-gcp-pd-csi-driver

OCPBUGS-45567: Updating ose-gcp-pd-csi-driver-container image to be consistent with ART for 4.19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants