Skip to content

Commit bc17755

Browse files
committed
feat(helm): bind the credential provider's Secret reader per namespace
The k8s-credential-provider-secret-reader ClusterRole is bound with a ClusterRoleBinding, so the provider can read every Secret in the cluster. credentialProvider.rbac.namespaces binds the ClusterRole by RoleBinding in each listed namespace instead. Empty, the default, keeps the ClusterRoleBinding. The ClusterRole is always rendered so other namespaces can bind it. Signed-off-by: QuentinBisson <quentin@giantswarm.io>
1 parent d8021f1 commit bc17755

4 files changed

Lines changed: 116 additions & 0 deletions

File tree

‎charts/substrate/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ See `values.yaml` for the full set; the important keys:
9797
| `atelet.nodeSelector` | `{}` | Node labels atelet pods must match; must cover the nodes of every WorkerPool |
9898
| `atelet.imageCredentialProviderBinDir` | `""` | Host path to the kubelet credential provider binaries; both paths are mounted read-only |
9999
| `credentialProvider.enabled` | `true` | Deploy the Kubernetes Secret provider and route `k8s.io` credential URIs to it. With no provider, every credential injection fails closed |
100+
| `credentialProvider.rbac.namespaces` | `[]` | Namespaces the provider reads Secrets in. Empty, its Secret reader ClusterRole (`k8s-credential-provider-secret-reader`, prefixed with the release name unless the release is `substrate`) is bound cluster-wide; set, it is bound by RoleBinding in each listed namespace only, and a namespace added later needs its own RoleBinding to it |
100101
| `credentialProvider.namespacePolicies` | `[]` | Default-deny atespace-to-namespace grants; the chart includes get-only Secret RBAC for the provider |
101102
| `ateApi.actorJWTIssuer` | `https://<idp-service>.<namespace>.svc` | Issuer placed in actor JWTs; set a stable URL reachable by relying parties |
102103
| `objectStorePlugin.extraEnv` | `[]` | Object storage credentials/settings shared by both object-store plugins |

‎charts/substrate/templates/k8s-credential-provider.yaml‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ rules:
3434
- apiGroups: [""]
3535
resources: ["secrets"]
3636
verbs: ["get"]
37+
{{- /* Without credentialProvider.rbac.namespaces the reader is bound
38+
cluster-wide. With it, the reader is bound by RoleBinding in each listed
39+
namespace only. */}}
40+
{{- $readerNamespaces := dig "rbac" "namespaces" list .Values.credentialProvider | uniq }}
41+
{{- if not $readerNamespaces }}
3742
---
3843
apiVersion: rbac.authorization.k8s.io/v1
3944
kind: ClusterRoleBinding
@@ -47,6 +52,24 @@ subjects:
4752
- kind: ServiceAccount
4853
name: {{ include "substrate.fullname" (list "k8s-credential-provider" .) }}
4954
namespace: {{ .Release.Namespace }}
55+
{{- else }}
56+
{{- range $ns := $readerNamespaces }}
57+
---
58+
apiVersion: rbac.authorization.k8s.io/v1
59+
kind: RoleBinding
60+
metadata:
61+
name: {{ include "substrate.fullname" (list "k8s-credential-provider-secret-reader" $) }}
62+
namespace: {{ $ns }}
63+
roleRef:
64+
apiGroup: rbac.authorization.k8s.io
65+
kind: ClusterRole
66+
name: {{ include "substrate.fullname" (list "k8s-credential-provider-secret-reader" $) }}
67+
subjects:
68+
- kind: ServiceAccount
69+
name: {{ include "substrate.fullname" (list "k8s-credential-provider" $) }}
70+
namespace: {{ $.Release.Namespace }}
71+
{{- end }}
72+
{{- end }}
5073
---
5174
apiVersion: apps/v1
5275
kind: Deployment
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
suite: k8s credential provider Secret reader binding
16+
templates:
17+
- k8s-credential-provider.yaml
18+
release:
19+
name: substrate
20+
namespace: ate-system
21+
tests:
22+
- it: binds the reader cluster-wide by default
23+
asserts:
24+
- containsDocument:
25+
kind: ClusterRoleBinding
26+
apiVersion: rbac.authorization.k8s.io/v1
27+
name: k8s-credential-provider-secret-reader
28+
any: true
29+
- containsDocument:
30+
kind: RoleBinding
31+
apiVersion: rbac.authorization.k8s.io/v1
32+
not: true
33+
34+
- it: binds the reader only in the listed namespaces
35+
set:
36+
credentialProvider.rbac.namespaces: [kagent, agents-acme-x1]
37+
asserts:
38+
- containsDocument:
39+
kind: ClusterRoleBinding
40+
apiVersion: rbac.authorization.k8s.io/v1
41+
not: true
42+
- containsDocument:
43+
kind: ClusterRole
44+
apiVersion: rbac.authorization.k8s.io/v1
45+
name: k8s-credential-provider-secret-reader
46+
any: true
47+
- containsDocument:
48+
kind: RoleBinding
49+
apiVersion: rbac.authorization.k8s.io/v1
50+
name: k8s-credential-provider-secret-reader
51+
namespace: kagent
52+
any: true
53+
- containsDocument:
54+
kind: RoleBinding
55+
apiVersion: rbac.authorization.k8s.io/v1
56+
name: k8s-credential-provider-secret-reader
57+
namespace: agents-acme-x1
58+
any: true
59+
60+
- it: the RoleBindings name the reader and the provider's ServiceAccount
61+
set:
62+
credentialProvider.rbac.namespaces: [kagent]
63+
documentSelector:
64+
path: kind
65+
value: RoleBinding
66+
asserts:
67+
- equal:
68+
path: roleRef
69+
value: {apiGroup: rbac.authorization.k8s.io, kind: ClusterRole, name: k8s-credential-provider-secret-reader}
70+
- equal:
71+
path: subjects
72+
value: [{kind: ServiceAccount, name: k8s-credential-provider, namespace: ate-system}]
73+
74+
- it: binds the reader cluster-wide with an empty list
75+
set:
76+
credentialProvider.rbac.namespaces: []
77+
asserts:
78+
- containsDocument:
79+
kind: ClusterRoleBinding
80+
apiVersion: rbac.authorization.k8s.io/v1
81+
name: k8s-credential-provider-secret-reader
82+
any: true
83+
- containsDocument:
84+
kind: RoleBinding
85+
apiVersion: rbac.authorization.k8s.io/v1
86+
not: true

‎charts/substrate/values.yaml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ atenetEgress:
191191
credentialProvider:
192192
# Deploy the Kubernetes Secret provider and route k8s.io credential URIs to it.
193193
enabled: true
194+
rbac:
195+
# Namespaces the provider reads Secrets in. Empty (the default), its
196+
# Secret reader ClusterRole is bound cluster-wide. Set, the ClusterRole is
197+
# bound by RoleBinding in each listed namespace only; a namespace added
198+
# later needs its own RoleBinding to it.
199+
namespaces: []
194200
namespacePolicies: []
195201
# - atespace: team-a
196202
# allowedNamespaces: [team-a-secrets]

0 commit comments

Comments
 (0)