Skip to content

fix(rbac): restore secretResourceNames for namespaced Role - #1972

Open
HarnageaGabriel wants to merge 2 commits into
traefik:masterfrom
HarnageaGabriel:fix-1745-secretResourceNames-namespaced
Open

fix(rbac): restore secretResourceNames for namespaced Role#1972
HarnageaGabriel wants to merge 2 commits into
traefik:masterfrom
HarnageaGabriel:fix-1745-secretResourceNames-namespaced

Conversation

@HarnageaGabriel

Copy link
Copy Markdown

What

Restores rbac.secretResourceNames, but scoped only to the namespaced Role case (rbac.namespaced: true). templates/rbac/clusterrole.yaml is left untouched.

Why

#1683 removed rbac.secretResourceNames entirely to fix a real bug: Kubernetes RBAC does not support resourceNames on a ClusterRole's list/watch rules, so setting it broke Traefik's secret informer when rbac.namespaced: false.

That fix over-removed the value: when rbac.namespaced: true, Traefik only gets a namespaced Role (not a ClusterRole), and resourceNames on a Role works correctly. Restricting it to one secret (e.g. Traefik's own TLS certificate) instead of every secret in the namespace is a legitimate, useful restriction that #1683 removed as collateral damage.

The maintainer confirmed this direction in the issue: re-implement a version of secretResourceNames tailored for the namespaced use case.

Changes

  • traefik/templates/rbac/role.yaml: re-add the conditional resourceNames block for the secrets rule (same logic fix: remove rbac.secretResourceNames #1683 removed).
  • traefik/templates/rbac/clusterrole.yaml: unchanged — cluster-scoped RBAC keeps unrestricted secret access, per fix: remove rbac.secretResourceNames #1683.
  • traefik/values.yaml: re-add rbac.secretResourceNames: [], with an updated doc comment clarifying it only applies when rbac.namespaced: true.
  • traefik/values.schema.json, traefik/VALUES.md: regenerated via helm schema / helm-docs.
  • traefik/tests/rbac-config_test.yaml: re-add only the two Role-scoped test cases from fix: remove rbac.secretResourceNames #1683's removed tests (empty vs. set secretResourceNames under rbac.namespaced: true). No ClusterRole test cases are re-added.

Test plan

  • helm unittest -f tests/rbac-config_test.yaml traefik — 41/41 pass, including the 2 new Role cases.
  • helm unittest ./traefik (full suite) — same 47 pre-existing, unrelated failures as on master (tracing/otlp arg formatting), zero regressions from this change (708 passed vs. 706 on master, the +2 being the new tests).
  • Confirmed templates/rbac/clusterrole.yaml renders identically to master (no resourceNames for secrets in ClusterRole, regardless of secretResourceNames).

Fixes #1745

PR traefik#1683 removed rbac.secretResourceNames entirely because Kubernetes
RBAC does not support resourceNames on a ClusterRole's list/watch
rules, which broke Traefik's secret informer when rbac.namespaced is
false. That removal also dropped the value for the namespaced (Role)
case, where resourceNames on a Role works correctly and lets users
restrict Traefik's secret access to a single secret (e.g. its TLS
certificate) instead of every secret in the namespace.

Restore rbac.secretResourceNames, applied only to templates/rbac/role.yaml.
templates/rbac/clusterrole.yaml is untouched so cluster-scoped RBAC
keeps unrestricted secret access as fixed by traefik#1683.

Fixes traefik#1745

Signed-off-by: HarnageaGabriel <gabriel.harnagea06@gmail.com>
Comment thread traefik/VALUES.md
| rbac.aggregateTo | list | `[]` | Enable user-facing roles https://kubernetes.io/docs/reference/access-authn-authz/rbac/#user-facing-roles |
| rbac.enabled | bool | `true` | Whether Role Based Access Control objects like roles and rolebindings should be created |
| rbac.namespaced | bool | `false` | When set to true: <br /> 1. It switches respectively the use of `ClusterRole` and `ClusterRoleBinding` to `Role` and `RoleBinding`.<br /> 2. It adds `disableClusterScopeResources` on Ingress and CRD (Kubernetes) providers<br /> **NOTE**: `IngressClass`, `NodePortLB` and **Gateway** provider cannot be used with namespaced RBAC. <br /> See [upstream documentation](https://doc.traefik.io/traefik/reference/install-configuration/providers/kubernetes/kubernetes-ingress/#opt-providers-kubernetesIngress-disableClusterScopeResources) for more details. |
| rbac.secretResourceNames | list | `[]` | List of Kubernetes secrets that are accessible for Traefik when `rbac.namespaced` is true. If empty, then access is granted to every secret. Ignored when `rbac.namespaced` is false (ClusterRole), since Kubernetes RBAC does not support `resourceNames` on cluster-scoped list/watch rules. |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignored when rbac.namespaced is false (ClusterRole), since Kubernetes RBAC does not support resourceNames on cluster-scoped list/watch rules.

Would you please add a fail-fast check in requirements.yaml for better UserXP?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added — see 4acafff: requirements.yaml now fails template rendering when rbac.secretResourceNames is set while rbac.namespaced is false, with message ERROR: rbac.secretResourceNames requires rbac.namespaced to be true. Kubernetes RBAC does not support resourceNames on cluster-scoped list/watch rules. Follows the same fail pattern as the other checks in that file. Covered by new tests in requirements-config_test.yaml (invalid combo fails, valid combo passes).

…ed RBAC

rbac.secretResourceNames was silently ignored when rbac.namespaced is
false, since Kubernetes RBAC does not support resourceNames on
cluster-scoped list/watch rules. Add a requirements.yaml check to
surface this at template/install time instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rbac.secretResourceNames support removed even for namespaced deployments

2 participants