Skip to content

Commit a4e784d

Browse files
committed
Helm: add support for cluster role aggregates
Extends the Helm chart to create ClusterRole aggregates based of the resource specific viewer and editor roles.
1 parent 3ad6d40 commit a4e784d

24 files changed

+241
-2
lines changed

chart/templates/_helpers.tpl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,43 @@ globalTransformationOptions configures the manager's --global-transformation-opt
175175
{{- $opts | join "," -}}
176176
{{- end -}}
177177
{{- end -}}
178+
179+
{{/*
180+
aggregateRoleMatchLabelsViewer generates the matchLabels for the viewer cluster roles.
181+
*/}}
182+
{{- define "vso.aggregateRoleMatchLabelsViewer" -}}
183+
{{- $ret := list }}
184+
{{- with .Values.controller.rbac.clusterRoleAggregation.viewerRoles -}}
185+
{{- if eq "*" (. | first) -}}
186+
{{- $labels := dict "vso.hashicorp.com/aggregate-to-viewer" "true" -}}
187+
{{- $ret = append $ret (dict "matchLabels" $labels) }}
188+
{{- else -}}
189+
{{- range . -}}
190+
{{- $labels := dict -}}
191+
{{- $_ := set $labels "vso.hashicorp.com/role-instance" (printf "%s-viewer-role" (. | lower) ) -}}
192+
{{- $ret = append $ret (dict "matchLabels" $labels) }}
193+
{{- end -}}
194+
{{- end -}}
195+
{{- $ret | toYaml -}}
196+
{{- end -}}
197+
{{- end -}}
198+
199+
{{/*
200+
aggregateRoleMatchLabelsEditor generates the matchLabels for the editor cluster roles.
201+
*/}}
202+
{{- define "vso.aggregateRoleMatchLabelsEditor" -}}
203+
{{- $ret := list }}
204+
{{- with .Values.controller.rbac.clusterRoleAggregation.editorRoles -}}
205+
{{- if eq "*" (. | first) -}}
206+
{{- $labels := dict "vso.hashicorp.com/aggregate-to-editor" "true" -}}
207+
{{- $ret = append $ret (dict "matchLabels" $labels) }}
208+
{{- else -}}
209+
{{- range . -}}
210+
{{- $labels := dict -}}
211+
{{- $_ := set $labels "vso.hashicorp.com/role-instance" (printf "%s-editor-role" (. | lower) ) -}}
212+
{{- $ret = append $ret (dict "matchLabels" $labels) }}
213+
{{- end -}}
214+
{{- end -}}
215+
{{- $ret | toYaml -}}
216+
{{- end -}}
217+
{{- end -}}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{- if .Values.controller.rbac.clusterRoleAggregation.editorRoles -}}
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
name: {{ printf "%s-%s" (include "vso.chart.fullname" .) "aggregate-role-editor" }}
6+
labels:
7+
app.kubernetes.io/component: rbac
8+
vso.hashicorp.com/role-instance: aggregate-role-editor
9+
{{- include "vso.chart.labels" . | nindent 4 }}
10+
aggregationRule:
11+
clusterRoleSelectors:
12+
{{- include "vso.aggregateRoleMatchLabelsEditor" . | nindent 7 -}}
13+
{{- end -}}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{- if .Values.controller.rbac.clusterRoleAggregation.viewerRoles -}}
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
name: {{ printf "%s-%s" (include "vso.chart.fullname" .) "aggregate-role-viewer" }}
6+
labels:
7+
app.kubernetes.io/component: rbac
8+
vso.hashicorp.com/role-instance: aggregate-role-viewer
9+
vso.hashicorp.com/aggregate-to-editor: "true"
10+
{{- include "vso.chart.labels" . | nindent 4 }}
11+
aggregationRule:
12+
clusterRoleSelectors:
13+
{{- include "vso.aggregateRoleMatchLabelsViewer" . | nindent 7 -}}
14+
{{- end -}}

chart/templates/hcpauth_editor_role.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ metadata:
1313
app.kubernetes.io/component: rbac
1414
# allow for selecting on the canonical name
1515
vso.hashicorp.com/role-instance: hcpauth-editor-role
16+
vso.hashicorp.com/aggregate-to-editor: "true"
1617
{{- include "vso.chart.labels" . | nindent 4 }}
1718
rules:
1819
- apiGroups:

chart/templates/hcpauth_viewer_role.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ metadata:
1313
app.kubernetes.io/component: rbac
1414
# allow for selecting on the canonical name
1515
vso.hashicorp.com/role-instance: hcpauth-viewer-role
16+
vso.hashicorp.com/aggregate-to-viewer: "true"
1617
{{- include "vso.chart.labels" . | nindent 4 }}
1718
rules:
1819
- apiGroups:

chart/templates/hcpvaultsecretsapp_editor_role.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ metadata:
1313
app.kubernetes.io/component: rbac
1414
# allow for selecting on the canonical name
1515
vso.hashicorp.com/role-instance: hcpsecretsapp-editor-role
16+
vso.hashicorp.com/aggregate-to-editor: "true"
1617
{{- include "vso.chart.labels" . | nindent 4 }}
1718
rules:
1819
- apiGroups:

chart/templates/hcpvaultsecretsapp_viewer_role.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ metadata:
1313
app.kubernetes.io/component: rbac
1414
# allow for selecting on the canonical name
1515
vso.hashicorp.com/role-instance: hcpsecretsapp-viewer-role
16+
vso.hashicorp.com/aggregate-to-viewer: "true"
1617
{{- include "vso.chart.labels" . | nindent 4 }}
1718
rules:
1819
- apiGroups:

chart/templates/role.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ metadata:
1313
app.kubernetes.io/component: rbac
1414
# allow for selecting on the canonical name
1515
vso.hashicorp.com/role-instance: manager-role
16+
1617
{{- include "vso.chart.labels" . | nindent 4 }}
1718
rules:
1819
- apiGroups:

chart/templates/secrettransformation_editor_role.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ metadata:
1313
app.kubernetes.io/component: rbac
1414
# allow for selecting on the canonical name
1515
vso.hashicorp.com/role-instance: secrettransformation-editor-role
16+
vso.hashicorp.com/aggregate-to-editor: "true"
1617
{{- include "vso.chart.labels" . | nindent 4 }}
1718
rules:
1819
- apiGroups:

chart/templates/secrettransformation_viewer_role.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ metadata:
1313
app.kubernetes.io/component: rbac
1414
# allow for selecting on the canonical name
1515
vso.hashicorp.com/role-instance: secrettransformation-viewer-role
16+
vso.hashicorp.com/aggregate-to-viewer: "true"
1617
{{- include "vso.chart.labels" . | nindent 4 }}
1718
rules:
1819
- apiGroups:

0 commit comments

Comments
 (0)