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

Fix super-admin role #516

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion packages/apps/tenant/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ description: Separated tenant namespace
icon: /logos/tenant.svg

type: application
version: 1.6.1
version: 1.6.2
130 changes: 104 additions & 26 deletions packages/apps/tenant/templates/tenant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ subjects:
- kind: ServiceAccount
name: tenant-root
namespace: tenant-root
- kind: Group
name: tenant-root-super-admin
apiGroup: rbac.authorization.k8s.io
Comment on lines -46 to -48
Copy link
Member

Choose a reason for hiding this comment

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

Super admin of one tenant should be super-admin of any sub-tenants

{{- end }}
{{- if hasPrefix "tenant-" .Release.Namespace }}
{{- $parts := splitList "-" .Release.Namespace }}
Expand All @@ -54,18 +51,12 @@ subjects:
- kind: ServiceAccount
name: {{ join "-" (slice $parts 0 (add $i 1)) }}
namespace: {{ join "-" (slice $parts 0 (add $i 1)) }}
- kind: Group
name: {{ join "-" (slice $parts 0 (add $i 1)) }}-super-admin
apiGroup: rbac.authorization.k8s.io
Comment on lines -57 to -59
Copy link
Member

Choose a reason for hiding this comment

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

Super admin of one tenant should be super-admin of any sub-tenants

{{- end }}
{{- end }}
{{- end }}
- kind: ServiceAccount
name: {{ include "tenant.name" . }}
namespace: {{ include "tenant.name" . }}
- kind: Group
name: {{ include "tenant.name" . }}-super-admin
apiGroup: rbac.authorization.k8s.io
Comment on lines -66 to -68
Copy link
Member

Choose a reason for hiding this comment

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

Super admin of one tenant should be super-admin of any sub-tenants

roleRef:
kind: Role
name: {{ include "tenant.name" . }}
Expand All @@ -84,23 +75,6 @@ rules:
resources: ["helmcharts"]
verbs: ["*"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ include "tenant.name" . }}
namespace: cozy-public
subjects:
- kind: ServiceAccount
name: {{ include "tenant.name" . }}
namespace: {{ include "tenant.name" . }}
- kind: Group
name: {{ include "tenant.name" . }}-super-admin
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: {{ include "tenant.name" . }}
apiGroup: rbac.authorization.k8s.io
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
Expand Down Expand Up @@ -361,3 +335,107 @@ roleRef:
kind: Role
name: {{ include "tenant.name" . }}-admin
apiGroup: rbac.authorization.k8s.io
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ include "tenant.name" . }}-super-admin
namespace: {{ include "tenant.name" . }}
rules:
- apiGroups: [rbac.authorization.k8s.io]
resources:
- roles
verbs:
- get
- apiGroups: [""]
resources:
- "*"
verbs:
- get
- list
- watch
- delete
- apiGroups: ["helm.toolkit.fluxcd.io"]
resources:
- helmreleases
verbs:
- get
- list
- watch
- apiGroups: ["kubevirt.io"]
resources:
- virtualmachines
verbs:
- get
- list
- apiGroups: ["subresources.kubevirt.io"]
resources:
- virtualmachineinstances/console
- virtualmachineinstances/vnc
verbs:
- get
- list
- apiGroups: ["apps.cozystack.io"]
resources:
- '*'
verbs:
- get
- list
- watch
- create
- update
- patch
- delete

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider expanding super-admin permissions for complete control

While the role provides comprehensive access to apps.cozystack.io resources, consider adding these permissions for a true super-admin role:

  • Full access to roles and rolebindings for user management
  • Full access to events and pods/log for monitoring
  • Full access to pods/exec for troubleshooting
  - apiGroups: [rbac.authorization.k8s.io]
    resources:
    - roles
+   - rolebindings
    verbs:
    - get
+   - list
+   - watch
+   - create
+   - update
+   - patch
+   - delete
  # ... existing permissions ...
+ - apiGroups: [""]
+   resources:
+   - events
+   - pods/log
+   - pods/exec
+   verbs:
+   - get
+   - list
+   - watch
+   - create
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ include "tenant.name" . }}-super-admin
namespace: {{ include "tenant.name" . }}
rules:
- apiGroups: [rbac.authorization.k8s.io]
resources:
- roles
verbs:
- get
- apiGroups: [""]
resources:
- "*"
verbs:
- get
- list
- watch
- delete
- apiGroups: ["helm.toolkit.fluxcd.io"]
resources:
- helmreleases
verbs:
- get
- list
- watch
- apiGroups: ["kubevirt.io"]
resources:
- virtualmachines
verbs:
- get
- list
- apiGroups: ["subresources.kubevirt.io"]
resources:
- virtualmachineinstances/console
- virtualmachineinstances/vnc
verbs:
- get
- list
- apiGroups: ["apps.cozystack.io"]
resources:
- '*'
verbs:
- get
- list
- watch
- create
- update
- patch
- delete
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ include "tenant.name" . }}-super-admin
namespace: {{ include "tenant.name" . }}
rules:
- apiGroups: [rbac.authorization.k8s.io]
resources:
- roles
- rolebindings
verbs:
- get
- list
- watch
- create
- update
- patch
- delete
- apiGroups: [""]
resources:
- "*"
verbs:
- get
- list
- watch
- delete
- apiGroups: [""]
resources:
- events
- pods/log
- pods/exec
verbs:
- get
- list
- watch
- create
- apiGroups: ["helm.toolkit.fluxcd.io"]
resources:
- helmreleases
verbs:
- get
- list
- watch
- apiGroups: ["kubevirt.io"]
resources:
- virtualmachines
verbs:
- get
- list
- apiGroups: ["subresources.kubevirt.io"]
resources:
- virtualmachineinstances/console
- virtualmachineinstances/vnc
verbs:
- get
- list
- apiGroups: ["apps.cozystack.io"]
resources:
- '*'
verbs:
- get
- list
- watch
- create
- update
- patch
- delete


---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ include "tenant.name" . }}-super-admin
namespace: cozy-public
rules:
- apiGroups: ["source.toolkit.fluxcd.io"]
resources: ["helmrepositories"]
verbs:
- get
- list
- apiGroups:
- source.toolkit.fluxcd.io
resources:
- helmcharts
verbs:
- get
- list
- apiGroups: ["source.toolkit.fluxcd.io"]
resources:
- helmcharts
verbs: ["*"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ include "tenant.name" . }}-super-admin
namespace: cozy-public
subjects:
- kind: Group
name: {{ include "tenant.name" . }}-super-admin
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: {{ include "tenant.name" . }}-super-admin
apiGroup: rbac.authorization.k8s.io
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ include "tenant.name" . }}-super-admin
namespace: {{ include "tenant.name" . }}
subjects:
- kind: Group
name: {{ include "tenant.name" . }}-super-admin
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: {{ include "tenant.name" . }}-super-admin
apiGroup: rbac.authorization.k8s.io
Copy link
Member

Choose a reason for hiding this comment

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

Super admin of one tenant should be super-admin of any sub-tenants

3 changes: 2 additions & 1 deletion packages/apps/versions_map
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ tenant 1.3.1 c56e5769
tenant 1.4.0 94c688f7
tenant 1.5.0 48128743
tenant 1.6.0 df448b99
tenant 1.6.1 HEAD
tenant 1.6.1 edbbb9be
tenant 1.6.2 HEAD
virtual-machine 0.1.4 f2015d6
virtual-machine 0.1.5 7cd7de7
virtual-machine 0.2.0 5ca8823
Expand Down