Skip to content

Commit 5713b97

Browse files
authored
fix(foundationdb): let tenant roles read the connection ConfigMap (#4148)
A tenant cannot connect to its own FoundationDB: the fdb-kubernetes-operator writes the cluster file into the `<release>-config` ConfigMap, but tenant subjects have no RBAC to read it and the dashboard resource map does not expose it, so there is no way to obtain the connection string without cluster-admin access. This PR: - adds `<release>-config` to the dashboard resource map; - adds a Role/RoleBinding granting get/list/watch on exactly that ConfigMap to the tenant `use` access level (via the existing cozy-lib helper); - adds helm unittest coverage (`make test`, 6 tests). Out of scope: FoundationDB currently exposes no Service, so clients still need in-cluster reachability to the coordinator pod IPs from the cluster file — that is a separate topic. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added the FoundationDB configuration resource to the dashboard resource map. * Added read-only access for authorized tenant users and service accounts to view the configuration resource. * **Bug Fixes** * Ensured configuration access and resource visibility remain available when monitoring is disabled. * **Tests** * Added coverage to verify resource mapping, access permissions, and rendered chart output. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents bd38922 + 9ee2a23 commit 5713b97

3 files changed

Lines changed: 117 additions & 2 deletions

File tree

‎packages/apps/foundationdb/Makefile‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ include ../../../hack/package.mk
22

33
generate:
44
cozyvalues-gen -m 'foundationdb' -v values.yaml -s values.schema.json -r README.md -g ../../../api/apps/v1alpha1/foundationdb/types.go
5-
../../../hack/update-crd.sh
5+
../../../hack/update-crd.sh
6+
7+
test:
8+
helm unittest .

‎packages/apps/foundationdb/templates/dashboard-resourcemap.yaml‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ metadata:
1111
app.cozystack.io/type: dashboard-resourcemap
1212
data:
1313
resources: |
14+
- apiVersion: v1
15+
kind: ConfigMap
16+
name: {{ .Release.Name }}-config
1417
- apiVersion: apps.foundationdb.org/v1beta2
1518
kind: FoundationDBCluster
1619
name: {{ .Release.Name }}
@@ -19,4 +22,28 @@ data:
1922
kind: FoundationDBBackup
2023
name: {{ .Release.Name }}-backup
2124
{{- end }}
22-
{{- end }}
25+
{{- end }}
26+
---
27+
apiVersion: rbac.authorization.k8s.io/v1
28+
kind: Role
29+
metadata:
30+
name: {{ .Release.Name }}-dashboard-resources
31+
rules:
32+
- apiGroups:
33+
- ""
34+
resources:
35+
- configmaps
36+
resourceNames:
37+
- {{ .Release.Name }}-config
38+
verbs: ["get", "list", "watch"]
39+
---
40+
kind: RoleBinding
41+
apiVersion: rbac.authorization.k8s.io/v1
42+
metadata:
43+
name: {{ .Release.Name }}-dashboard-resources
44+
subjects:
45+
{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "use" .Release.Namespace) }}
46+
roleRef:
47+
kind: Role
48+
name: {{ .Release.Name }}-dashboard-resources
49+
apiGroup: rbac.authorization.k8s.io
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
suite: foundationdb tenant configuration access
2+
templates:
3+
- templates/dashboard-resourcemap.yaml
4+
release:
5+
name: foundationdb-example
6+
namespace: tenant-example
7+
tests:
8+
- it: grants read access only to this cluster configuration
9+
documentSelector: &role
10+
path: kind
11+
value: Role
12+
asserts: &configAccess
13+
- equal:
14+
path: rules
15+
value:
16+
- apiGroups: [""]
17+
resources: [configmaps]
18+
resourceNames: [foundationdb-example-config]
19+
verbs: [get, list, watch]
20+
21+
- it: keeps configuration accessible with monitoring disabled
22+
set:
23+
monitoring.enabled: false
24+
documentSelector: *role
25+
asserts: *configAccess
26+
27+
- it: binds the configuration role to tenant users and administrators
28+
documentSelector:
29+
path: kind
30+
value: RoleBinding
31+
asserts:
32+
- equal:
33+
path: roleRef
34+
value:
35+
kind: Role
36+
name: foundationdb-example-dashboard-resources
37+
apiGroup: rbac.authorization.k8s.io
38+
- equal:
39+
path: subjects
40+
value:
41+
- kind: ServiceAccount
42+
name: tenant-example
43+
namespace: tenant-example
44+
- kind: Group
45+
name: tenant-example-admin
46+
apiGroup: rbac.authorization.k8s.io
47+
- kind: Group
48+
name: tenant-example-super-admin
49+
apiGroup: rbac.authorization.k8s.io
50+
- kind: Group
51+
name: tenant-example-use
52+
apiGroup: rbac.authorization.k8s.io
53+
- kind: ServiceAccount
54+
name: tenant-root
55+
namespace: tenant-root
56+
- kind: Group
57+
name: tenant-root-admin
58+
apiGroup: rbac.authorization.k8s.io
59+
- kind: Group
60+
name: tenant-root-super-admin
61+
apiGroup: rbac.authorization.k8s.io
62+
- kind: Group
63+
name: tenant-root-use
64+
apiGroup: rbac.authorization.k8s.io
65+
66+
- it: includes the configuration in the existing resource map
67+
documentSelector:
68+
path: kind
69+
value: ConfigMap
70+
asserts:
71+
- matchRegex:
72+
path: data.resources
73+
pattern: "apiVersion: v1\n kind: ConfigMap\n name: foundationdb-example-config"
74+
75+
- it: renders only the existing map and the two access objects
76+
asserts:
77+
- hasDocuments:
78+
count: 3
79+
80+
- it: renders only the access objects with monitoring disabled
81+
set:
82+
monitoring.enabled: false
83+
asserts:
84+
- hasDocuments:
85+
count: 2

0 commit comments

Comments
 (0)