Skip to content

Commit

Permalink
traefik: reduce rbac scope if one namespace is handled (helm#16111)
Browse files Browse the repository at this point in the history
Signed-off-by: Nandor Kracser <bonifaido@gmail.com>
  • Loading branch information
bonifaido authored and kengou committed Sep 18, 2019
1 parent 4464ebb commit 09d8eac
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion stable/traefik/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v1
name: traefik
version: 1.77.2
version: 1.77.3
appVersion: 1.7.14
description: A Traefik based Kubernetes ingress controller with Let's Encrypt support
keywords:
Expand Down
15 changes: 15 additions & 0 deletions stable/traefik/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ Helper for containerPort (http)
{{- end -}}
{{- end -}}

{{/*
Helper for RBAC Scope
If Kubernetes namespace selection is defined and the (one) selected
namespace is the release namespace Cluster scope is unnecessary.
*/}}
{{- define "traefik.rbac.scope" -}}
{{- if .Values.kubernetes -}}
{{- if not (eq (.Values.kubernetes.namespaces | default (list) | toString) (list .Release.Namespace | toString)) -}}
Cluster
{{- end -}}
{{- else -}}
Cluster
{{- end -}}
{{- end -}}

{{/*
Helper for containerPort (https)
*/}}
Expand Down
6 changes: 3 additions & 3 deletions stable/traefik/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: v1
metadata:
name: {{ template "traefik.fullname" . }}
---
kind: ClusterRole
kind: {{ include "traefik.rbac.scope" . | printf "%sRole" }}
{{- if semverCompare "^1.8-0" .Capabilities.KubeVersion.GitVersion }}
apiVersion: rbac.authorization.k8s.io/v1
{{- else }}
Expand Down Expand Up @@ -39,7 +39,7 @@ rules:
verbs:
- update
---
kind: ClusterRoleBinding
kind: {{ include "traefik.rbac.scope" . | printf "%sRoleBinding" }}
{{- if semverCompare "^1.8-0" .Capabilities.KubeVersion.GitVersion }}
apiVersion: rbac.authorization.k8s.io/v1
{{- else }}
Expand All @@ -49,7 +49,7 @@ metadata:
name: {{ template "traefik.fullname" . }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
kind: {{ include "traefik.rbac.scope" . | printf "%sRole" }}
name: {{ template "traefik.fullname" . }}
subjects:
- kind: ServiceAccount
Expand Down

0 comments on commit 09d8eac

Please sign in to comment.