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

Explicit cluster roles for controller/webhook, not cluster-admin #872

Merged
merged 7 commits into from
Mar 27, 2019

Conversation

vaikas
Copy link
Contributor

@vaikas vaikas commented Mar 8, 2019

Fixes #749

Proposed Changes

  • Create a service account for running webhook (eventing-webhook)
  • create 2 new cluster roles: knative-eventing-webhook, knative-eventing-controller
  • create 2 clusterrole bindings

Release Note

 * webhook now runs as: eventing-webhook service account
 * controller now runs as eventing-controller service account
 * controller and webhook run with less priviledges (was using cluster-admin) 

@vaikas vaikas added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 8, 2019
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Mar 8, 2019
@knative-prow-robot knative-prow-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 8, 2019
resources: ["channels", "clusterchannelprovisioners", "subscriptions"]
verbs: ["get", "list", "create", "watch"]
- apiGroups: ["eventing.knative.dev"]
resources: ["channels/status", "clusterchannelprovisioners/status", "subscriptions/status"]
Copy link
Contributor

Choose a reason for hiding this comment

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

My preference would be to put these into the previous list, so that after each foo, we then have foo/status. I think that will make it easier to see when one has been forgotten.

config/200-controller-clusterrole.yaml Outdated Show resolved Hide resolved
config/200-webhook-clusterrole.yaml Outdated Show resolved Hide resolved
Copy link
Contributor

@grantr grantr left a comment

Choose a reason for hiding this comment

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

Thanks so much for doing this @vaikas-google! It's embarrassing that we've had cluster-admin for so long.

How did you come up with the list of permissions for the controller SA?

verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
- apiGroups: ["apiextensions.k8s.io"]
resources: ["customresourcedefinitions"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
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 controller really need write permissions on CRDs?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do these permissions apply to CRDs or all the custom resources whose type is a CRD? If the former, why do we need any permissions on CRDs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

left over cruft, removed.

verbs: ["get", "list", "watch"]
# For manipulating certs into secrets
- apiGroups: [""]
resources: ["secrets"]
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this is a candidate for a (namespaced) Role so the webhook doesn't have access to all secrets everywhere. Seems like maybe configmaps and deployments permissions could also be namespaced.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok to make this into a separate issue and tackle that in a followup?

Copy link
Member

Choose a reason for hiding this comment

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

+1 to a followup issue.

config/200-webhook-clusterrole.yaml Show resolved Hide resolved
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 26, 2019
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 26, 2019
Copy link
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

A few more comments, but thanks for doing this.

If you want the further refinements to go into another PR, feel free to open an issue; this is already a definite improvement.

/hold
/lgtm

name: knative-eventing-controller
rules:
- apiGroups: [""]
resources: ["namespaces", "secrets", "configmaps", "services", "events", "serviceaccounts"]
Copy link
Member

Choose a reason for hiding this comment

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

Do we need list/delete/watch on events? (Or create/update/patch for namespaces, secrets or serviceaccounts?)

May not be worth pulling out separately.

resources: ["routes", "services"]
verbs: ["get", "list", "watch"]
- apiGroups: ["serving.knative.dev"]
resources: ["routes/status", "services/status"]
Copy link
Member

Choose a reason for hiding this comment

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

We merge the "foo" and "foo/status" on line 34. Do we want to do the same here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure thing, done.

- apiGroups: ["eventing.knative.dev"]
resources: ["brokers", "brokers/status", "channels", "channels/status", "clusterchannelprovisioners", "clusterchannelprovisioners/status", "subscriptions", "subscriptions/status", "triggers", "triggers/status",]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
- apiGroups: ["apps"]
Copy link
Member

Choose a reason for hiding this comment

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

It's strange to have this apiGroup down here but virtualservices on line 30.

Maybe put in a comment # Resources we create as part of our side effects

Copy link
Contributor Author

Choose a reason for hiding this comment

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

my bad :) moved...

verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
- apiGroups: ["rbac.authorization.k8s.io"]
resources: ["rolebindings"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need these permissions on rolebindings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

these are needed for triggers.

Copy link
Member

Choose a reason for hiding this comment

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

Ah -- this is actually needed for the namespace Broker auto-provisioner. https://github.com/knative/eventing/blob/master/pkg/reconciler/v1alpha1/namespace/namespace.go#L264

I wonder if we want to extract the Broker auto-provisioner at some point in the future.

verbs: ["get", "list", "watch"]
# For manipulating certs into secrets
- apiGroups: [""]
resources: ["secrets"]
Copy link
Member

Choose a reason for hiding this comment

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

+1 to a followup issue.

@knative-prow-robot knative-prow-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. labels Mar 26, 2019
@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Mar 26, 2019
Copy link
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
- apiGroups: ["rbac.authorization.k8s.io"]
resources: ["rolebindings"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
Copy link
Member

Choose a reason for hiding this comment

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

Ah -- this is actually needed for the namespace Broker auto-provisioner. https://github.com/knative/eventing/blob/master/pkg/reconciler/v1alpha1/namespace/namespace.go#L264

I wonder if we want to extract the Broker auto-provisioner at some point in the future.

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 26, 2019
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: evankanderson, vaikas-google

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:
  • OWNERS [evankanderson,vaikas-google]

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

@evankanderson
Copy link
Member

As long as this is titled "WIP", it won't merge. (FYI)

@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Mar 27, 2019
@vaikas vaikas removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Mar 27, 2019
@knative-prow-robot knative-prow-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 27, 2019
@vaikas vaikas changed the title WIP: explicit cluster roles for controller/webhook, not cluster-admin Explicit cluster roles for controller/webhook, not cluster-admin Mar 27, 2019
@knative-prow-robot knative-prow-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 27, 2019
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: eventing-webhook-admin
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename to eventing-webook, or something similar as this is no longer granting admin.

Do a similar rename to eventing-controller-admin. This will mean that it won't update the existing RBAC on upgrade, if you consider that important.

# Our own resources and statuses we care about
- apiGroups: ["eventing.knative.dev"]
resources: ["brokers", "brokers/status", "channels", "channels/status", "clusterchannelprovisioners", "clusterchannelprovisioners/status", "subscriptions", "subscriptions/status", "triggers", "triggers/status",]
verbs: ["get", "list", "create", "watch"]
Copy link
Contributor

Choose a reason for hiding this comment

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

We use create in the webhook?

@Harwayne
Copy link
Contributor

/lgtm
/hold

Holding in case you want to change in response to my comments. If not, feel free to cancel the hold yourself.

@knative-prow-robot knative-prow-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. labels Mar 27, 2019
@evankanderson
Copy link
Member

/lgtm

@vaikas
Copy link
Contributor Author

vaikas commented Mar 27, 2019

I've created:
#982
to audit the roles. I want to get this in as it's clearly an improvement and then we can improve in a follow up.

@vaikas vaikas removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 27, 2019
@knative-prow-robot knative-prow-robot merged commit 9d995bc into knative:master Mar 27, 2019
@vaikas vaikas deleted the issue-749 branch March 27, 2019 21:15
pierDipi pushed a commit to pierDipi/eventing that referenced this pull request Sep 24, 2024
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. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants