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

🐛 Reduce permission for cluster manager and klusterlet #325

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
5 changes: 4 additions & 1 deletion deploy/cluster-manager/config/rbac/cluster_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ metadata:
rules:
# Allow the registration-operator to create workload
- apiGroups: [""]
resources: ["configmaps", "namespaces", "serviceaccounts", "services", "pods"]
resources: ["configmaps", "namespaces", "serviceaccounts", "services"]
verbs: ["create", "get", "list", "update", "watch", "patch", "delete", "deletecollection"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["get"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "list", "watch", "update", "patch", "delete"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ metadata:
categories: Integration & Delivery,OpenShift Optional
certified: "false"
containerImage: quay.io/open-cluster-management/registration-operator:latest
createdAt: "2023-11-28T10:34:20Z"
createdAt: "2023-11-30T07:06:56Z"
description: Manages the installation and upgrade of the ClusterManager.
operators.operatorframework.io/builder: operator-sdk-v1.32.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
Expand Down Expand Up @@ -118,7 +118,6 @@ spec:
- namespaces
- serviceaccounts
- services
- pods
verbs:
- create
- get
Expand All @@ -128,6 +127,12 @@ spec:
- patch
- delete
- deletecollection
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- apiGroups:
- ""
resourceNames:
Expand Down
16 changes: 15 additions & 1 deletion deploy/klusterlet/config/rbac/cluster_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,22 @@ metadata:
rules:
# Allow the registration-operator to create workload
- apiGroups: [""]
resources: ["secrets", "configmaps", "serviceaccounts"]
resources: ["configmaps", "serviceaccounts"]
verbs: ["create", "get", "list", "update", "watch", "patch", "delete"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["create"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["update", "get", "list", "watch", "delete"]
resourceNames:
- "open-cluster-management-image-pull-credentials"
- "bootstrap-hub-kubeconfig"
- "hub-kubeconfig-secret"
- "external-managed-kubeconfig"
- "external-managed-kubeconfig-work"
- "external-managed-kubeconfig-registration"
- "external-managed-kubeconfig-agent"
# get pods and replicasets is for event creation
- apiGroups: [""]
resources: ["pods"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ metadata:
categories: Integration & Delivery,OpenShift Optional
certified: "false"
containerImage: quay.io/open-cluster-management/registration-operator:latest
createdAt: "2023-11-28T10:34:20Z"
createdAt: "2023-11-30T08:06:17Z"
description: Manages the installation and upgrade of the Klusterlet.
operators.operatorframework.io/builder: operator-sdk-v1.32.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
Expand Down Expand Up @@ -93,7 +93,6 @@ spec:
- apiGroups:
- ""
resources:
- secrets
- configmaps
- serviceaccounts
verbs:
Expand All @@ -104,6 +103,30 @@ spec:
- watch
- patch
- delete
- apiGroups:
- ""
resources:
- secrets
verbs:
- create
- apiGroups:
- ""
resourceNames:
- open-cluster-management-image-pull-credentials
- bootstrap-hub-kubeconfig
- hub-kubeconfig-secret
- external-managed-kubeconfig
- external-managed-kubeconfig-work
- external-managed-kubeconfig-registration
- external-managed-kubeconfig-agent
resources:
- secrets
verbs:
- update
- get
- list
- watch
- delete
- apiGroups:
- ""
resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ metadata:
rules:
# Allow controller to get/list/watch/create/delete configmaps/events
- apiGroups: [""]
resources: ["configmaps", "events", "pods"]
resources: ["configmaps", "events"]
verbs: ["get", "list", "watch", "create", "update", "delete", "deletecollection", "patch"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["get"]
- apiGroups: ["apps"]
resources: ["replicasets"]
verbs: ["get"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ metadata:
name: open-cluster-management:{{ .ClusterManagerName }}-work:controller
rules:
- apiGroups: [ "" ]
resources: [ "configmaps", "pods"]
resources: [ "configmaps"]
verbs: [ "get", "list", "watch"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["get"]
# Allow create subjectaccessreviews
- apiGroups: ["authorization.k8s.io"]
resources: ["subjectaccessreviews"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ metadata:
rules:
# Allow controller to get/list/watch/create/delete configmaps
- apiGroups: [""]
resources: ["configmaps", "pods"]
resources: ["configmaps"]
verbs: ["get", "list", "watch", "create", "delete", "update"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["get"]
- apiGroups: ["apps"]
resources: ["replicasets"]
verbs: ["get"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ rules:
verbs: ["update"]
# Allow hub to get/list/watch/create/delete namespace and service account
- apiGroups: [""]
resources: ["namespaces", "serviceaccounts", "configmaps", "pods"]
resources: ["namespaces", "serviceaccounts", "configmaps"]
verbs: ["get", "list", "watch", "create", "delete", "update"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["get"]
- apiGroups: ["", "events.k8s.io"]
resources: ["events"]
verbs: ["create", "patch", "update"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get"]
- apiGroups: ["apps"]
resources: ["replicasets"]
verbs: ["get"]
- apiGroups: ["coordination.k8s.io"]
resources: ["leases"]
verbs: ["create", "get", "list", "update", "watch", "patch"]
Expand Down
6 changes: 6 additions & 0 deletions manifests/klusterlet/management/klusterlet-work-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ rules:
- apiGroups: ["", "events.k8s.io"]
resources: ["events"]
verbs: ["create", "patch", "update"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["get"]
- apiGroups: ["apps"]
resources: ["replicasets"]
verbs: ["get"]
6 changes: 3 additions & 3 deletions pkg/operator/operators/klusterlet/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package klusterlet

import (
"context"
"io/ioutil"
"os"
"time"

"github.com/openshift/library-go/pkg/controller/controllercmd"
Expand Down Expand Up @@ -65,7 +65,7 @@ func (o *Options) RunKlusterletOperator(ctx context.Context, controllerContext *

hubConfigSecretInformer := newOneTermInformer(helpers.HubKubeConfig)
bootstrapConfigSecretInformer := newOneTermInformer(helpers.BootstrapHubKubeConfig)
externalConfigSecretInformer := newOneTermInformer(helpers.WorkWebhookSecret)
externalConfigSecretInformer := newOneTermInformer(helpers.ExternalManagedKubeConfig)

secretInformers := map[string]corev1informers.SecretInformer{
helpers.HubKubeConfig: hubConfigSecretInformer.Core().V1().Secrets(),
Expand All @@ -92,7 +92,7 @@ func (o *Options) RunKlusterletOperator(ctx context.Context, controllerContext *

// Read component namespace
operatorNamespace := defaultComponentNamespace
nsBytes, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
nsBytes, err := os.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
if err == nil {
operatorNamespace = string(nsBytes)
}
Expand Down
Loading