Skip to content

Commit

Permalink
feat: Reduce permissions for system-upgrade-controller serviceaccount
Browse files Browse the repository at this point in the history
This patch drastically cuts down the permissions of the
system-upgrades-controller from the previous cluster-admin permissions
to a tailored set of permissions for the controller.
  • Loading branch information
SISheogorath committed Feb 28, 2024
1 parent 3ffd4a3 commit ba5c781
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 13 deletions.
2 changes: 2 additions & 0 deletions kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- manifests/clusterrole.yaml
- manifests/clusterrolebinding.yaml
- manifests/system-upgrade-controller.yaml
images:
- name: rancher/system-upgrade-controller
Expand Down
108 changes: 108 additions & 0 deletions manifests/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: system-upgrade-controller
rules:
- apiGroups:
- batch
resources:
- jobs
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- namespaces
- nodes
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- nodes
verbs:
- update
- apiGroups:
- upgrade.cattle.io
resources:
- plans
- plans/status
verbs:
- get
- list
- watch
- create
- patch
- update
- delete
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: system-upgrade-controller
rules:
- apiGroups:
- batch
resources:
- jobs
verbs:
- create
- delete
- deletecollection
- patch
- update
- get
- list
- watch
- apiGroups:
- ""
resources:
- secrets
verbs:
- get
- list
- watch
---
# Borrowed from https://stackoverflow.com/a/63553032
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: system-upgrade-controller-drainer
rules:
# Needed to evict pods
- apiGroups:
- ""
resources:
- "pods/eviction"
verbs:
- "create"
# Needed to list pods by Node
- apiGroups:
- ""
resources:
- "pods"
verbs:
- "get"
- "list"
# Needed to cordon Nodes
- apiGroups:
- ""
resources:
- "nodes"
verbs:
- "get"
- "patch"
# Needed to determine Pod owners
- apiGroups:
- "apps"
resources:
- "statefulsets"
- "daemonsets"
- "replicasets"
verbs:
- "get"
- "list"
36 changes: 36 additions & 0 deletions manifests/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: system-upgrade-drainer
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system-upgrade-controller-drainer
subjects:
- kind: ServiceAccount
name: system-upgrade
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: system-upgrade
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system-upgrade-controller
subjects:
- kind: ServiceAccount
name: system-upgrade
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: system-upgrade
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: system-upgrade-controller
subjects:
- kind: ServiceAccount
name: system-upgrade
13 changes: 0 additions & 13 deletions manifests/system-upgrade-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,6 @@ metadata:
name: system-upgrade
namespace: system-upgrade
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: system-upgrade
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: system-upgrade
namespace: system-upgrade
---
apiVersion: v1
kind: ConfigMap
metadata:
Expand Down

0 comments on commit ba5c781

Please sign in to comment.