Skip to content

Commit 3031ecc

Browse files
Merge pull request #136 from lisa/OSD-6482
OSD-6482: Dedicated-admins should be able to manage CustomDomain
2 parents 5c54b7c + 5b5808a commit 3031ecc

File tree

2 files changed

+84
-11
lines changed

2 files changed

+84
-11
lines changed

pkg/webhooks/regularuser/regularuser.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ import (
1717
)
1818

1919
const (
20-
WebhookName string = "regular-user-validation"
21-
docString string = `Managed OpenShift customers may not manage any objects in the following APIgroups %s, nor may Managed OpenShift customers alter the ClusterVersion, Node or SubjectPermission objects.`
20+
WebhookName string = "regular-user-validation"
21+
docString string = `Managed OpenShift customers may not manage any objects in the following APIgroups %s, nor may Managed OpenShift customers alter the ClusterVersion, Node or SubjectPermission objects.`
22+
mustGatherKind string = "MustGather"
23+
mustGatherGroup string = "managed.openshift.io"
24+
customDomainKind string = "CustomDomain"
25+
customDomainGroup string = "managed.openshift.io"
2226
)
2327

2428
var (
25-
adminGroups = []string{"osd-sre-admins", "osd-sre-cluster-admins"}
26-
ceeGroup string = "osd-devaccess"
27-
mustGatherKind string = "MustGather"
29+
adminGroups = []string{"osd-sre-admins", "osd-sre-cluster-admins"}
30+
ceeGroup string = "osd-devaccess"
2831

2932
scope = admissionregv1.AllScopes
3033
rules = []admissionregv1.RuleWithOperations{
@@ -168,18 +171,26 @@ func (s *RegularuserWebhook) authorized(request admissionctl.Request) admissionc
168171
ret.UID = request.AdmissionRequest.UID
169172
return ret
170173
}
174+
if utils.SliceContains("dedicated-admins", request.UserInfo.Groups) &&
175+
request.Kind.Kind == customDomainKind &&
176+
request.Kind.Group == customDomainGroup {
177+
ret = admissionctl.Allowed("dedicated-admins may manage Custom Domains")
178+
ret.UID = request.AdmissionRequest.UID
179+
return ret
180+
}
181+
if utils.SliceContains(ceeGroup, request.UserInfo.Groups) &&
182+
request.Kind.Kind == mustGatherKind &&
183+
request.Kind.Group == mustGatherGroup {
184+
ret = admissionctl.Allowed("Members of CEE may manage MustGather CRs")
185+
ret.UID = request.AdmissionRequest.UID
186+
return ret
187+
}
171188
for _, userGroup := range request.UserInfo.Groups {
172189
if utils.SliceContains(userGroup, adminGroups) {
173190
ret = admissionctl.Allowed("Members of admin groups are allowed")
174191
ret.UID = request.AdmissionRequest.UID
175192
return ret
176193
}
177-
178-
if (userGroup == ceeGroup) && (request.Kind.Kind == mustGatherKind) {
179-
ret = admissionctl.Allowed("Members of CEE may manage MustGather CRs")
180-
ret.UID = request.AdmissionRequest.UID
181-
return ret
182-
}
183194
}
184195

185196
log.Info("Denying access", "request", request.AdmissionRequest)

pkg/webhooks/regularuser/regularuser_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,68 @@ func TestNodesSubjectPermissionsClusterVersions(t *testing.T) {
329329
runRegularuserTests(t, tests)
330330
}
331331

332+
func TestCustomDomains(t *testing.T) {
333+
tests := []regularuserTests{
334+
{
335+
testID: "customdomain-unauth-user",
336+
targetResource: "customdomains",
337+
targetKind: "CustomDomain",
338+
targetVersion: "v1alpha1",
339+
targetGroup: "managed.openshift.io",
340+
username: "system:unauthenticated",
341+
userGroups: []string{"system:unauthenticated"},
342+
operation: v1beta1.Create,
343+
shouldBeAllowed: false,
344+
},
345+
{
346+
testID: "customdomain-dedicated-admins",
347+
targetResource: "customdomains",
348+
targetKind: "CustomDomain",
349+
targetVersion: "v1alpha1",
350+
targetGroup: "managed.openshift.io",
351+
username: "dedi-admin",
352+
userGroups: []string{"system:authenticated", "system:authenticated:oauth", "dedicated-admins"},
353+
operation: v1beta1.Create,
354+
shouldBeAllowed: true,
355+
},
356+
{
357+
testID: "customdomain-dedicated-admins-edit",
358+
targetResource: "customdomains",
359+
targetKind: "CustomDomain",
360+
targetVersion: "v1alpha1",
361+
targetGroup: "managed.openshift.io",
362+
username: "dedi-admin",
363+
userGroups: []string{"system:authenticated", "system:authenticated:oauth", "dedicated-admins"},
364+
operation: v1beta1.Update,
365+
shouldBeAllowed: true,
366+
},
367+
{
368+
testID: "customdomain-dedicated-admins-delete",
369+
targetResource: "customdomains",
370+
targetKind: "CustomDomain",
371+
targetVersion: "v1alpha1",
372+
targetGroup: "managed.openshift.io",
373+
username: "dedi-admin",
374+
userGroups: []string{"system:authenticated", "system:authenticated:oauth", "dedicated-admins"},
375+
operation: v1beta1.Delete,
376+
shouldBeAllowed: true,
377+
},
378+
{
379+
// shouldn't be able to create a CustomDomain from machine.openshift.io if that should come to exist
380+
testID: "customdomain-dedicated-admins-wrong-group",
381+
targetResource: "customdomains",
382+
targetKind: "CustomDomain",
383+
targetVersion: "v1alpha1",
384+
targetGroup: "machine.openshift.io",
385+
username: "dedi-admin",
386+
userGroups: []string{"system:authenticated", "system:authenticated:oauth", "dedicated-admins"},
387+
operation: v1beta1.Create,
388+
shouldBeAllowed: false,
389+
},
390+
}
391+
runRegularuserTests(t, tests)
392+
}
393+
332394
func TestMustGathers(t *testing.T) {
333395
tests := []regularuserTests{
334396
{

0 commit comments

Comments
 (0)