Skip to content
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

Properly fix acquire_cluster_admin_role() #87

Merged
merged 1 commit into from
Aug 22, 2018
Merged

Properly fix acquire_cluster_admin_role() #87

merged 1 commit into from
Aug 22, 2018

Conversation

adrcunha
Copy link
Contributor

@adrcunha adrcunha commented Aug 22, 2018

kubectl 1.11 doesn't recognize the --username and --password global flags anymore. Because the prow-tests image uses kubectl 1.8, the Prow jobs are not broken (yet).

The changes in #86 don't work because the context is not changed (nor restored), but the function works as long as the current user is an owner of the GCP project (which is not the case for Prow E2E test jobs).

This change updates the context for the cluster admin, creates the role binding, then reinstates the original context. This is more secure as no ACL changes are required for the current user, nor project wide ACL changes are performed.

`kubectl` 1.11 doesn't recognize the `--username` and `--password` flags anymore. Because the `prow-tests` image uses `kubectl` 1.8, the Prow jobs are not broken (yet).

The changes in #86 don't work because the context is not changed (nor restored), but the function works as long as the current user is an owner of the GCP project (which is not the case for Prow E2E test jobs).

This change creates and uses a new context for the cluster admin, created the role binding, then switches back to the original context. This is more secure as no ACL changes are required for the current user, nor project wide ACL changes are performed.
@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 22, 2018
@knative-prow-robot knative-prow-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Aug 22, 2018
@adrcunha adrcunha requested a review from jessiezcc August 22, 2018 02:11
@steuhs
Copy link
Contributor

steuhs commented Aug 22, 2018

/approve

@knative-prow-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adrcunha, steuhs

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

kubectl config set-credentials cluster-admin --username=admin --password=${password}
kubectl config set-credentials cluster-admin \
--username=admin --password=${password}
kubectl config set-context $(kubectl config current-context) \
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the new context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The same context.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, I got "new context" from description. Looks like u already updated it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, there was indeed a mixup, and I fixed the description to reflect the implementation after I saw your comment. Originally I used a new context, but that was unnecessary and just added more complexity.

@@ -164,10 +164,16 @@ function acquire_cluster_admin_role() {
# might not have the necessary permission.
local password=$(gcloud --format="value(masterAuth.password)" \
container clusters describe $2 --zone=$3)
kubectl config set-credentials cluster-admin --username=admin --password=${password}
kubectl config set-credentials cluster-admin \
--username=admin --password=${password}
Copy link
Contributor

Choose a reason for hiding this comment

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

so this will break when prow upgrades to 1.11?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's backwards compatible.

Copy link
Contributor

Choose a reason for hiding this comment

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

in description, it says 1.11 no longer recognizes username and password. then set-credentials won't work, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. It doesn't recognize them as global flags.

Copy link
Contributor Author

@adrcunha adrcunha Aug 22, 2018

Choose a reason for hiding this comment

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

(compare the original code with the current code; updated description again)

@jessiezcc
Copy link
Contributor

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 22, 2018
@adrcunha adrcunha merged commit 4a4a682 into knative:master Aug 22, 2018
@adrcunha adrcunha deleted the fix-admin-role branch August 22, 2018 18:54
Cynocracy pushed a commit to Cynocracy/test-infra that referenced this pull request Jun 13, 2020
knative-prow-updater-robot pushed a commit to knative-prow-updater-robot/test-infra that referenced this pull request Jun 5, 2023
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. lgtm Indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants