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

feat: add support for ClusterRole RBAC permissions #376

Merged
merged 1 commit into from
Nov 13, 2024
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
2 changes: 1 addition & 1 deletion charts/cronjob/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: cronjob
description: Run jobs on a schedule
type: application
version: 3.7.2
version: 3.8.0
maintainers:
- name: morremeyer
- name: ekeih
10 changes: 6 additions & 4 deletions charts/cronjob/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cronjob

![Version: 3.7.2](https://img.shields.io/badge/Version-3.7.2-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)
![Version: 3.8.0](https://img.shields.io/badge/Version-3.8.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)

Run jobs on a schedule

Expand Down Expand Up @@ -72,9 +72,11 @@ configMap:
| additionalVolumes | list | `[]` | |
| affinity | object | `{}` | affinity object for the pod |
| annotations | object | `{}` | |
| apiAccess | object | `{"enabled":false,"rules":[]}` | Configuration for access to the Kubernetes API |
| apiAccess.enabled | bool | `false` | When set to true, a Role and RoleBinding are deployed that give access with the rules defined in apiAccess.rules |
| apiAccess.rules | list | `[]` | Rules for the API access of the ServiceAccount used by the CronJob pods. Check [the documentation](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#role-and-clusterrole) for more information |
| apiAccess | object | `{"clusterRoleRules":[],"enabled":false,"roleRules":[],"rules":[]}` | Configuration for access to the Kubernetes API |
| apiAccess.clusterRoleRules | list | `[]` | Rules for the ClusterRole the the pods are bound to. Check [the documentation](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#role-and-clusterrole) for more information |
| apiAccess.enabled | bool | `false` | DEPRECATED, this is automatically detected by checking if `roleRules` or `clusterRoleRules` are configured. If only `rules` are set, this can be set to false to prevent deployment of the Role and RoleBinding (backwards compatibility). |
| apiAccess.roleRules | list | `[]` | Rules for the Role the the pods are bound to. Check [the documentation](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#role-and-clusterrole) for more information |
| apiAccess.rules | list | `[]` | DEPRECATED, use roleRules. Rules for the API access of the ServiceAccount used by the CronJob pods. Check [the documentation](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#role-and-clusterrole) for more information |
| args | list | `[]` | arguments to pass to the command or binary being run |
| command | list | `[]` | the command or binary to run |
| concurrencyPolicy | string | `"Allow"` | The [concurrencyPolicy](https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/#concurrency-policy) for the CronJob |
Expand Down
19 changes: 19 additions & 0 deletions charts/cronjob/ci/default-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,22 @@ hostAliases:
hostnames:
- "foo.local"
- "bar.local"

apiAccess:
# This is ignored since roleRules are set
enabled: false

rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list"]

roleRules:
- apiGroups: [""]
resources: ["deployments"]
verbs: ["get", "list"]

clusterRoleRules:
- apiGroups: [""]
resources: ["replicasets"]
verbs: ["get", "list"]
6 changes: 0 additions & 6 deletions charts/cronjob/ci/roles-values.yaml

This file was deleted.

16 changes: 16 additions & 0 deletions charts/cronjob/templates/clusterRole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if .Values.apiAccess.clusterRoleRules }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "cronjob.fullname" . }}
labels:
{{- include "cronjob.labels" . | nindent 4 }}
{{- with .Values.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
annotations:
{{- with .Values.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
rules: {{ toYaml .Values.apiAccess.clusterRoleRules | nindent 2 }}
{{- end }}
24 changes: 24 additions & 0 deletions charts/cronjob/templates/clusterRoleBinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{- if .Values.apiAccess.clusterRoleRules }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "cronjob.fullname" . }}
labels:
{{- include "cronjob.labels" . | nindent 4 }}
{{- with .Values.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
annotations:
{{- with .Values.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
subjects:
- kind: ServiceAccount
name: {{ include "cronjob.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
apiGroup: ""
roleRef:
kind: ClusterRole
name: {{ include "cronjob.fullname" . }}
apiGroup: ""
{{- end }}
4 changes: 2 additions & 2 deletions charts/cronjob/templates/role.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.apiAccess.enabled }}
{{- if or (and .Values.apiAccess.enabled .Values.apiAccess.rules) .Values.apiAccess.roleRules }}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
Expand All @@ -12,5 +12,5 @@ metadata:
{{- with .Values.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
rules: {{ toYaml .Values.apiAccess.rules | nindent 2 }}
rules: {{ toYaml (concat .Values.apiAccess.rules .Values.apiAccess.roleRules) | nindent 2 }}
{{- end }}
2 changes: 1 addition & 1 deletion charts/cronjob/templates/roleBinding.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.apiAccess.enabled }}
{{- if or .Values.apiAccess.enabled .Values.apiAccess.roleRules }}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
Expand Down
10 changes: 8 additions & 2 deletions charts/cronjob/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,17 @@ affinity: {}
# -- Configuration for access to the Kubernetes API
apiAccess:

# -- When set to true, a Role and RoleBinding are deployed that give access with the rules defined in apiAccess.rules
# -- DEPRECATED, this is automatically detected by checking if `roleRules` or `clusterRoleRules` are configured. If only `rules` are set, this can be set to false to prevent deployment of the Role and RoleBinding (backwards compatibility).
enabled: false

# -- Rules for the API access of the ServiceAccount used by the CronJob pods. Check [the documentation](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#role-and-clusterrole) for more information
# -- DEPRECATED, use roleRules. Rules for the API access of the ServiceAccount used by the CronJob pods. Check [the documentation](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#role-and-clusterrole) for more information
rules: []

# -- Rules for the Role the the pods are bound to. Check [the documentation](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#role-and-clusterrole) for more information
roleRules: []

# -- Rules for the ClusterRole the the pods are bound to. Check [the documentation](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#role-and-clusterrole) for more information
clusterRoleRules: []

# -- [Host Aliases](https://kubernetes.io/docs/tasks/network/customize-hosts-file-for-pods/#adding-additional-entries-with-hostaliases)
hostAliases: []