Skip to content

Commit

Permalink
Add optional k8s role binding to application chart (#129)
Browse files Browse the repository at this point in the history
* Add optional serviceAccount.rbac to application chart

* Fix naming collision

* Increment version, add test, improve naming

---------

Co-authored-by: Florian Heubeck <[email protected]>
  • Loading branch information
blenkjon and heubeck authored Jul 17, 2024
1 parent a478ceb commit 096e733
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion chart-tests/application/ci/test-init-container-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ initContainers:
tag: 9.3
command: ['sh', '-c', 'echo $BUMP_ME_UP']
env:
BUMP_ME_UP: bump me up
BUMP_ME_UP: bump me up
securityContext:
runAsNonRoot: true
allowPrivilegeEscalation: false
Expand Down
11 changes: 11 additions & 0 deletions chart-tests/application/ci/test-role-binding-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
serviceAccount:
rbac:
- kind: RoleBinding
roleType: Role
roleName: admin
- kind: ClusterRoleBinding
roleType: ClusterRole
roleName: edit
- kind: ClusterRoleBinding
roleType: ClusterRole
roleName: view
2 changes: 1 addition & 1 deletion charts/application/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ maintainers:
- name: MediaMarktSaturn
url: https://github.com/MediaMarktSaturn
appVersion: 1.0.0
version: 1.17.0
version: 1.18.0
1 change: 1 addition & 0 deletions charts/application/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Generic application chart with common requirements of a typical workload.
| serviceAccount.secretName | string | `nil` | |
| serviceAccount.mountPath | string | `"/config/service-account"` | |
| serviceAccount.automountServiceAccountToken | bool | `false` | |
| serviceAccount.rbac | list | `[]` | |
| istio.enabled | bool | `false` | |
| istio.tlsMode | string | `"ISTIO_MUTUAL"` | |
| istio.ingress.enabled | bool | `true` | |
Expand Down
20 changes: 20 additions & 0 deletions charts/application/templates/k8s-rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{- range .Values.serviceAccount.rbac }}
{{- if or (eq .kind "RoleBinding") (eq .kind "ClusterRoleBinding") }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: {{ .kind }}
metadata:
name: {{ printf "%s-%s" $.Release.Name .roleName | quote }}
namespace: {{ $.Release.Namespace }}
labels:
{{- include "labels" $ | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: {{ .roleType }}
name: {{ .roleName }}
subjects:
- kind: ServiceAccount
name: {{ $.Release.Name }}
namespace: {{ $.Release.Namespace }}
{{- end }}
{{- end }}
5 changes: 5 additions & 0 deletions charts/application/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ serviceAccount:
mountPath: /config/service-account
# k8s ServiceAccount.automountServiceAccountToken setting
automountServiceAccountToken: false
# gives the application the defined role binding
rbac: []
# - kind: RoleBinding
# roleType: ClusterRole
# roleName: admin

# Pick one of the service mesh configs
istio:
Expand Down

0 comments on commit 096e733

Please sign in to comment.