Skip to content

Commit 7780750

Browse files
triviajontbavelier
andauthored
[CONTINT-4924] Support for wildcards in Kind field in KSM RBAC (#2350)
* Support for wildcards in Kind field in KSM RBAC * make generate - no need to add explicit verbs to apiservices --------- Co-authored-by: Timothée Bavelier <[email protected]> Co-authored-by: Timothée Bavelier <[email protected]>
1 parent d7277db commit 7780750

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

internal/controller/datadogagent/feature/kubernetesstatecore/rbac.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ func getRBACPolicyRules(collectorOpts collectorOptions) []rbacv1.PolicyRule {
138138
if len(collectorOpts.customResources) > 0 {
139139
rbacBuilder := utils.NewRBACBuilder(commonVerbs...)
140140
for _, cr := range collectorOpts.customResources {
141+
// Don't pluralize if the kind is a wildcard
142+
if cr.GroupVersionKind.Kind == "*" {
143+
rbacBuilder.AddGroupKind(cr.GroupVersionKind.Group, "*")
144+
continue
145+
}
146+
141147
// Use the resource plural if specified, otherwise derive it from the Kind
142148
resourceName := cr.ResourcePlural
143149
if resourceName == "" {

internal/controller/datadogagent/feature/kubernetesstatecore/rbac_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,31 @@ func TestGetRBACPolicyRules(t *testing.T) {
279279
assert.True(t, hasArgo, "Should have Argo Application permissions")
280280
},
281281
},
282+
{
283+
name: "with wildcard kind",
284+
collectorOpts: collectorOptions{
285+
customResources: []v2alpha1.Resource{
286+
{
287+
GroupVersionKind: v2alpha1.GroupVersionKind{
288+
Group: "stable.example.com",
289+
Version: "v1",
290+
Kind: "*",
291+
},
292+
},
293+
},
294+
},
295+
validateFunc: func(t *testing.T, rules []rbacv1.PolicyRule) {
296+
hasStable := false
297+
for _, rule := range rules {
298+
if slices.Contains(rule.APIGroups, "stable.example.com") {
299+
hasStable = true
300+
assert.Contains(t, rule.Resources, "*")
301+
break
302+
}
303+
}
304+
assert.True(t, hasStable, "Should have stable.example.com permissions")
305+
},
306+
},
282307
}
283308

284309
for _, tc := range testCases {

0 commit comments

Comments
 (0)