Skip to content

Commit

Permalink
fix: RBACs for hub and disabled namespaced RBACs
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweaver87 committed Jul 8, 2024
1 parent 2dff203 commit 0827106
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 210 deletions.
8 changes: 8 additions & 0 deletions traefik/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,16 @@ Renders a complete tree, even values that contains template.
{{- end -}}

{{- define "imageVersion" -}}
{{/*
Traefik hub is based on v3.0 of traefik proxy, so this is a hack to avoid to much complexity in RBAC management which are
based on semverCompare
*/}}
{{- if $.Values.hub.token -}}
v3.0
{{- else -}}
{{ (split "@" (default $.Chart.AppVersion $.Values.image.tag))._0 | replace "latest-" "" | replace "experimental-" "" }}
{{- end -}}
{{- end -}}

{{/* Generate/load self-signed certificate for admission webhooks */}}
{{- define "traefik-hub.webhook_cert" -}}
Expand Down
13 changes: 10 additions & 3 deletions traefik/templates/rbac/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ rules:
- get
- list
- watch
{{- if $.Values.hub.token }}
- apiGroups:
- discovery.k8s.io
resources:
- endpointslices
verbs:
- get
- list
- watch
{{- end }}
{{- else }}
- apiGroups:
- ""
Expand All @@ -87,9 +97,6 @@ rules:
resources:
- endpointslices
verbs:
{{- if $.Values.hub.token }}
- get
{{- end }}
- list
- watch
{{- end }}
Expand Down
79 changes: 0 additions & 79 deletions traefik/templates/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ rules:
resources:
- endpointslices
verbs:
{{- if $.Values.hub.token }}
- get
{{- end }}
- list
- watch
{{- end }}
Expand Down Expand Up @@ -156,81 +153,5 @@ rules:
verbs:
- update
{{- end -}}
{{- if $.Values.hub.token }}
- apiGroups:
- hub.traefik.io
resources:
- accesscontrolpolicies
- apiaccesses
- apiportals
- apiratelimits
- apis
- apiversions
verbs:
- list
- watch
- create
- update
- patch
- delete
- get
- apiGroups:
- ""
resources:
- namespaces
- pods
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- events
verbs:
- create
- patch
- apiGroups:
- coordination.k8s.io
resources:
- leases
verbs:
- get
- list
- watch
- create
- update
- patch
- delete
- apiGroups:
- ""
resources:
- secrets
verbs:
- get
- list
- watch
- update
- create
- delete
- deletecollection
- apiGroups:
- apps
resources:
- replicasets
verbs:
- get
- list
- watch
- apiGroups:
- extensions
- networking.k8s.io
resources:
- ingresses
verbs:
- get
- list
- watch
{{- end -}}
{{- end -}}
{{- end -}}
4 changes: 4 additions & 0 deletions traefik/templates/requirements.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@
{{- if and (.Values.providers.kubernetesGateway).enabled (and (semverCompare "<3.1.0-rc3" $version) (not .Values.experimental.kubernetesGateway.enabled)) }}
{{- fail "ERROR: Before traefik v3.1.0-rc3, kubernetesGateway is experimental. Enable it by setting experimental.kubernetesGateway.enabled to true" -}}
{{- end }}

{{- if and .Values.hub.token (and .Values.rbac.enabled .Values.rbac.namespaced) }}
{{- fail "ERROR: Currently traefik-hub doesn't support namespaced RBACs" -}}
{{- end }}
131 changes: 3 additions & 128 deletions traefik/tests/rbac-config_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1141,8 +1141,8 @@ tests:
- watch

- it: should contain additional RBACS for hub
chart:
appVersion: v3.1.0
image:
tag: v3.1.0
set:
hub:
token: xxx
Expand Down Expand Up @@ -1273,132 +1273,7 @@ tests:
- get
- list
- watch
- it: should provide namespace'd RBACS for hub
chart:
appVersion: v3.1.0
set:
hub:
token: xxx
rbac:
namespaced: true
providers:
kubernetesIngress:
enabled: false
asserts:
- template: rbac/role.yaml
contains:
path: rules
content:
apiGroups:
- hub.traefik.io
resources:
- accesscontrolpolicies
- apiaccesses
- apiportals
- apiratelimits
- apis
- apiversions
verbs:
- list
- watch
- create
- update
- patch
- delete
- get
- template: rbac/role.yaml
contains:
path: rules
content:
apiGroups:
- ""
resources:
- namespaces
- pods
verbs:
- get
- list
- watch
- template: rbac/role.yaml
contains:
path: rules
content:
apiGroups:
- ""
resources:
- events
verbs:
- create
- patch
- template: rbac/role.yaml
contains:
path: rules
content:
apiGroups:
- discovery.k8s.io
resources:
- endpointslices
verbs:
- get
- list
- watch
- template: rbac/role.yaml
contains:
path: rules
content:
apiGroups:
- coordination.k8s.io
resources:
- leases
verbs:
- get
- list
- watch
- create
- update
- patch
- delete
- template: rbac/role.yaml
contains:
path: rules
content:
apiGroups:
- ""
resources:
- secrets
verbs:
- get
- list
- watch
- update
- create
- delete
- deletecollection
- template: rbac/role.yaml
contains:
path: rules
content:
apiGroups:
- apps
resources:
- replicasets
verbs:
- get
- list
- watch
- template: rbac/role.yaml
contains:
path: rules
content:
apiGroups:
- extensions
- networking.k8s.io
resources:
- ingresses
verbs:
- get
- list
- watch

- it: should provide expected namespace'd RBACS for version < v3.1
set:
image:
Expand Down
9 changes: 9 additions & 0 deletions traefik/tests/requirements-config_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,12 @@ tests:
enabled: true
asserts:
- notFailedTemplate: {}
- it: should not fail when using traefik-hub with namespaced RBACs
set:
hub:
token: xxx
rbac:
namespaced: true
asserts:
- failedTemplate:
errorMessage: "ERROR: Currently traefik-hub doesn't support namespaced RBACs"

0 comments on commit 0827106

Please sign in to comment.