Skip to content

Commit 06be9fb

Browse files
committed
fix(cozystack-basics): narrow trustedCaller to explicit cozystack group list
Address review feedback from kitsunoff on packages/system/cozystack-basics/templates/gateway-hostname-policy.yaml:120: startsWith("system:serviceaccount:cozy-") without a trailing colon trusted any ServiceAccount in any namespace whose name begins with cozy- — including a hypothetical attacker-controlled cozy-evil namespace. Creating such a namespace requires cluster-admin today, so this is not an active escalation path, but it is an unnecessarily wide trust boundary for a defense-in-depth check. Switch both tenant-host-policy and namespace-host-label-policy to a group-based check that matches the exact system:serviceaccounts:<ns> group for cozy-system, cozy-cert-manager, flux-system and kube-system. Every SA in those namespaces is a member of that group automatically, so there is no behaviour regression for cozystack's own controllers. Assisted-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent b49ee24 commit 06be9fb

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

‎packages/system/cozystack-basics/templates/gateway-hostname-policy.yaml‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,12 @@ spec:
117117
(has(oldObject) && has(oldObject.spec) && "host" in oldObject.spec && oldObject.spec.host == object.spec.host) ? false : true
118118
- name: trustedCaller
119119
expression: >-
120-
(has(request.userInfo.groups) && request.userInfo.groups.exists(g, g == "system:masters")) ||
121-
request.userInfo.username.startsWith("system:serviceaccount:cozy-") ||
122-
request.userInfo.username.startsWith("system:serviceaccount:flux-system:") ||
123-
request.userInfo.username.startsWith("system:serviceaccount:kube-system:")
120+
has(request.userInfo.groups) && request.userInfo.groups.exists(g,
121+
g == "system:masters" ||
122+
g == "system:serviceaccounts:cozy-system" ||
123+
g == "system:serviceaccounts:cozy-cert-manager" ||
124+
g == "system:serviceaccounts:flux-system" ||
125+
g == "system:serviceaccounts:kube-system")
124126
validations:
125127
- expression: "!variables.hostChanged || variables.trustedCaller"
126128
messageExpression: >-
@@ -165,10 +167,12 @@ spec:
165167
: ""
166168
- name: trustedCaller
167169
expression: >-
168-
(has(request.userInfo.groups) && request.userInfo.groups.exists(g, g == "system:masters")) ||
169-
request.userInfo.username.startsWith("system:serviceaccount:cozy-") ||
170-
request.userInfo.username.startsWith("system:serviceaccount:flux-system:") ||
171-
request.userInfo.username.startsWith("system:serviceaccount:kube-system:")
170+
has(request.userInfo.groups) && request.userInfo.groups.exists(g,
171+
g == "system:masters" ||
172+
g == "system:serviceaccounts:cozy-system" ||
173+
g == "system:serviceaccounts:cozy-cert-manager" ||
174+
g == "system:serviceaccounts:flux-system" ||
175+
g == "system:serviceaccounts:kube-system")
172176
validations:
173177
- expression: "variables.newHost == variables.oldHost || variables.trustedCaller"
174178
messageExpression: >-

0 commit comments

Comments
 (0)