Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions pkg/webhooks/regularuser/regularuser.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ import (
)

const (
WebhookName string = "regular-user-validation"
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.`
WebhookName string = "regular-user-validation"
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.`
mustGatherKind string = "MustGather"
mustGatherGroup string = "managed.openshift.io"
customDomainKind string = "CustomDomain"
customDomainGroup string = "managed.openshift.io"
)

var (
adminGroups = []string{"osd-sre-admins", "osd-sre-cluster-admins"}
ceeGroup string = "osd-devaccess"
mustGatherKind string = "MustGather"
adminGroups = []string{"osd-sre-admins", "osd-sre-cluster-admins"}
ceeGroup string = "osd-devaccess"

scope = admissionregv1.AllScopes
rules = []admissionregv1.RuleWithOperations{
Expand Down Expand Up @@ -168,18 +171,26 @@ func (s *RegularuserWebhook) authorized(request admissionctl.Request) admissionc
ret.UID = request.AdmissionRequest.UID
return ret
}
if utils.SliceContains("dedicated-admins", request.UserInfo.Groups) &&

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to also accounts for cluster-admins users?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's in the spec, yes. Let's chat Tuesday.

request.Kind.Kind == customDomainKind &&
request.Kind.Group == customDomainGroup {
ret = admissionctl.Allowed("dedicated-admins may manage Custom Domains")
ret.UID = request.AdmissionRequest.UID
return ret
}
if utils.SliceContains(ceeGroup, request.UserInfo.Groups) &&
request.Kind.Kind == mustGatherKind &&
request.Kind.Group == mustGatherGroup {
ret = admissionctl.Allowed("Members of CEE may manage MustGather CRs")
ret.UID = request.AdmissionRequest.UID
return ret
}
for _, userGroup := range request.UserInfo.Groups {
if utils.SliceContains(userGroup, adminGroups) {
ret = admissionctl.Allowed("Members of admin groups are allowed")
ret.UID = request.AdmissionRequest.UID
return ret
}

if (userGroup == ceeGroup) && (request.Kind.Kind == mustGatherKind) {
ret = admissionctl.Allowed("Members of CEE may manage MustGather CRs")
ret.UID = request.AdmissionRequest.UID
return ret
}
}

log.Info("Denying access", "request", request.AdmissionRequest)
Expand Down
62 changes: 62 additions & 0 deletions pkg/webhooks/regularuser/regularuser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,68 @@ func TestNodesSubjectPermissionsClusterVersions(t *testing.T) {
runRegularuserTests(t, tests)
}

func TestCustomDomains(t *testing.T) {
tests := []regularuserTests{
{
testID: "customdomain-unauth-user",
targetResource: "customdomains",
targetKind: "CustomDomain",
targetVersion: "v1alpha1",
targetGroup: "managed.openshift.io",
username: "system:unauthenticated",
userGroups: []string{"system:unauthenticated"},
operation: v1beta1.Create,
shouldBeAllowed: false,
},
{
testID: "customdomain-dedicated-admins",
targetResource: "customdomains",
targetKind: "CustomDomain",
targetVersion: "v1alpha1",
targetGroup: "managed.openshift.io",
username: "dedi-admin",
userGroups: []string{"system:authenticated", "system:authenticated:oauth", "dedicated-admins"},
operation: v1beta1.Create,
shouldBeAllowed: true,
},
{
testID: "customdomain-dedicated-admins-edit",
targetResource: "customdomains",
targetKind: "CustomDomain",
targetVersion: "v1alpha1",
targetGroup: "managed.openshift.io",
username: "dedi-admin",
userGroups: []string{"system:authenticated", "system:authenticated:oauth", "dedicated-admins"},
operation: v1beta1.Update,
shouldBeAllowed: true,
},
{
testID: "customdomain-dedicated-admins-delete",
targetResource: "customdomains",
targetKind: "CustomDomain",
targetVersion: "v1alpha1",
targetGroup: "managed.openshift.io",
username: "dedi-admin",
userGroups: []string{"system:authenticated", "system:authenticated:oauth", "dedicated-admins"},
operation: v1beta1.Delete,
shouldBeAllowed: true,
},
{
// shouldn't be able to create a CustomDomain from machine.openshift.io if that should come to exist
testID: "customdomain-dedicated-admins-wrong-group",
targetResource: "customdomains",
targetKind: "CustomDomain",
targetVersion: "v1alpha1",
targetGroup: "machine.openshift.io",
username: "dedi-admin",
userGroups: []string{"system:authenticated", "system:authenticated:oauth", "dedicated-admins"},
operation: v1beta1.Create,
shouldBeAllowed: false,
},
}
runRegularuserTests(t, tests)
}

func TestMustGathers(t *testing.T) {
tests := []regularuserTests{
{
Expand Down