Skip to content

Commit 77f397b

Browse files
feat(cf-common): add cluster wide rbac (#26)
* feat(cf-common): add cluster wide rbac
1 parent 66b5955 commit 77f397b

File tree

7 files changed

+46
-6
lines changed

7 files changed

+46
-6
lines changed

charts/cf-common-test/tests/rbac/metadata_test.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ tests:
5959
enabled: true
6060
rbac:
6161
enabled: true
62+
namespaced: true
6263
rules:
6364
- apiGroups:
6465
- ""
@@ -98,6 +99,7 @@ tests:
9899
enabled: true
99100
rbac:
100101
enabled: true
102+
namespaced: true
101103
rules:
102104
- apiGroups:
103105
- ""
@@ -129,3 +131,35 @@ tests:
129131
path: metadata.name
130132
value: RELEASE-NAME-cf-common-test
131133
documentIndex: 2
134+
135+
- it: Test cluster role and binding are created when rbac.namespaced=false
136+
template: templates/rbac.yaml
137+
values:
138+
- values.yaml
139+
set:
140+
rbac:
141+
namespaced: false
142+
asserts:
143+
- hasDocuments:
144+
count: 3
145+
- isKind:
146+
of: ServiceAccount
147+
documentIndex: 0
148+
- isKind:
149+
of: ClusterRole
150+
documentIndex: 1
151+
- isKind:
152+
of: ClusterRoleBinding
153+
documentIndex: 2
154+
- equal:
155+
path: metadata.labels
156+
value:
157+
app.kubernetes.io/instance: RELEASE-NAME
158+
app.kubernetes.io/managed-by: Helm
159+
app.kubernetes.io/name: cf-common-test
160+
helm.sh/chart: cf-common-test-0.0.0
161+
documentIndex: 1
162+
- equal:
163+
path: metadata.name
164+
value: RELEASE-NAME-cf-common-test
165+
documentIndex: 1

charts/cf-common-test/tests/rbac/spec_test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ tests:
3535
enabled: true
3636
rbac:
3737
enabled: true
38+
namespaced: true
3839
rules:
3940
- apiGroups:
4041
- ""
@@ -63,6 +64,7 @@ tests:
6364
enabled: true
6465
rbac:
6566
enabled: true
67+
namespaced: true
6668
rules:
6769
- apiGroups:
6870
- ""

charts/cf-common-test/tests/rbac/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ serviceAccount:
1818
enabled: true
1919
rbac:
2020
enabled: true
21+
namespaced: true

charts/cf-common/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
appVersion: v0.0.0
33
description: Codefresh library chart
44
name: cf-common
5-
version: 0.0.23
5+
version: 0.0.24
66
type: library
77
keywords:
88
- codefresh

charts/cf-common/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Codefresh library chart
44

5-
![Version: 0.0.23](https://img.shields.io/badge/Version-0.0.23-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) ![AppVersion: v0.0.0](https://img.shields.io/badge/AppVersion-v0.0.0-informational?style=flat-square)
5+
![Version: 0.0.24](https://img.shields.io/badge/Version-0.0.24-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) ![AppVersion: v0.0.0](https://img.shields.io/badge/AppVersion-v0.0.0-informational?style=flat-square)
66

77
## Installing the Chart
88

@@ -18,7 +18,7 @@ Include this chart as a dependency in your `Chart.yaml` e.g.
1818
# Chart.yaml
1919
dependencies:
2020
- name: cf-common
21-
version: 0.0.23
21+
version: 0.0.24
2222
repository: https://chartmuseum.codefresh.io/cf-common
2323
```
2424
@@ -126,6 +126,7 @@ dependencies:
126126
| podSecurityContext | object | `{}` | Set security context for the pod |
127127
| rbac | object | See below | Configure RBAC parameters |
128128
| rbac.enabled | bool | `false` | Enable RBAC resources |
129+
| rbac.namespaced | bool | `true` | Restrict RBAC in a single namespace instead of cluster-wide scope |
129130
| rbac.rules | list | `[]` | Create custom rules |
130131
| secrets.secret | object | `{"annotation":{},"data":{},"enabled":false,"labels":{},"stringData":{},"type":"Opaque"}` | Secret name. Make sure to use the same name in `volumes` and `container.volumeMounts` |
131132
| secrets.secret.annotation | object | `{}` | Add additional annotations to the secret |

charts/cf-common/templates/render/_rbac.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ secrets:
2424
{{- if and .Values.serviceAccount.enabled .Values.rbac.enabled }}
2525
---
2626
apiVersion: rbac.authorization.k8s.io/v1
27-
kind: Role
27+
kind: {{ .Values.rbac.namespaced | ternary "Role" "ClusterRole" }}
2828
metadata:
2929
name: {{ include "cf-common.names.fullname" $ }}
3030
labels: {{ include "cf-common.labels.standard" . | nindent 4 }}
3131
rules: {{ include "cf-common.tplrender" (dict "Values" .Values.rbac.rules "context" $) | nindent 2 }}
3232
---
3333
apiVersion: rbac.authorization.k8s.io/v1
34-
kind: RoleBinding
34+
kind: {{ .Values.rbac.namespaced | ternary "RoleBinding" "ClusterRoleBinding" }}
3535
metadata:
3636
name: {{ include "cf-common.names.fullname" $ }}
3737
labels: {{ include "cf-common.labels.standard" . | nindent 4 }}
3838
roleRef:
39-
kind: Role
39+
kind: {{ .Values.rbac.namespaced | ternary "Role" "ClusterRole" }}
4040
name: {{ include "cf-common.names.fullname" $ }}
4141
apiGroup: rbac.authorization.k8s.io
4242
subjects:

charts/cf-common/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,8 @@ serviceAccount:
543543
rbac:
544544
# -- Enable RBAC resources
545545
enabled: false
546+
# -- Restrict RBAC in a single namespace instead of cluster-wide scope
547+
namespaced: true
546548
# -- Create custom rules
547549
rules: []
548550
# E.g.

0 commit comments

Comments
 (0)