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
Merged
Show file tree
Hide file tree
Changes from 6 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
38 changes: 38 additions & 0 deletions config/200-controller-clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2019 The Knative Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
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.

verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
- apiGroups: ["serving.knative.dev"]
resources: ["routes", "routes/status", "services", "services/status"]
verbs: ["get", "list", "watch"]
- apiGroups: ["networking.istio.io"]
resources: ["virtualservices"]
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...

resources: ["deployments"]
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.

# 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", "update", "delete", "patch", "watch"]
7 changes: 7 additions & 0 deletions config/200-serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: v1
kind: ServiceAccount
metadata:
name: eventing-controller
namespace: knative-eventing
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: eventing-webhook
namespace: knative-eventing
39 changes: 39 additions & 0 deletions config/200-webhook-clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2019 The Knative Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: knative-eventing-webhook
rules:
# For watching logging configuration and getting certs
- apiGroups: [""]
resources: ["configmaps"]
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.

verbs: ["get", "create"]
# For getting our Deployment so we can decorate with ownerref
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["get"]
# For actually registering our webhook
- apiGroups: ["admissionregistration.k8s.io"]
resources: ["mutatingwebhookconfigurations"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
# 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?

15 changes: 14 additions & 1 deletion config/201-clusterrolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,18 @@ subjects:
namespace: knative-eventing
roleRef:
kind: ClusterRole
name: cluster-admin
name: knative-eventing-controller
apiGroup: rbac.authorization.k8s.io
---
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.

subjects:
- kind: ServiceAccount
name: eventing-webhook
namespace: knative-eventing
roleRef:
kind: ClusterRole
name: knative-eventing-webhook
apiGroup: rbac.authorization.k8s.io
2 changes: 1 addition & 1 deletion config/500-webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
sidecar.istio.io/inject: "false"
labels: *labels
spec:
serviceAccountName: eventing-controller
serviceAccountName: eventing-webhook
containers:
- name: webhook
terminationMessagePolicy: FallbackToLogsOnError
Expand Down