Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Never skip Project requests #120

Merged
merged 1 commit into from
Aug 29, 2024
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
7 changes: 6 additions & 1 deletion webhooks/namespace_project_organization_mutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (m *NamespaceProjectOrganizationMutator) Handle(ctx context.Context, req ad
ctx = log.IntoContext(ctx, log.FromContext(ctx).
WithName("webhook.namespace-project-organization-mutator.appuio.io").
WithValues("id", req.UID, "user", req.UserInfo.Username).
WithValues("operation", req.Operation).
WithValues("namespace", req.Namespace, "name", req.Name,
"group", req.Kind.Group, "version", req.Kind.Version, "kind", req.Kind.Kind))

Expand All @@ -69,7 +70,11 @@ func (m *NamespaceProjectOrganizationMutator) handle(ctx context.Context, req ad
if err != nil {
return admission.Errored(http.StatusInternalServerError, fmt.Errorf("error while checking skipper: %w", err))
}
if skip {
if skip && req.Kind.Kind == "Project" {
// Project requests come from internal openshift components with annotations for user info.
// Do not allow them but check the annotations later in the code.
log.FromContext(ctx).Info("`Project` requests will not be skipped")
} else if skip {
return admission.Allowed("skipped")
}

Expand Down
19 changes: 18 additions & 1 deletion webhooks/namespace_project_organization_mutator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func Test_NamespaceProjectOrganizationMutator_Handle(t *testing.T) {

allowed bool
orgPatch string

skip bool
}{
{
name: "Project: request with org label set",
Expand Down Expand Up @@ -111,6 +113,21 @@ func Test_NamespaceProjectOrganizationMutator_Handle(t *testing.T) {
user: "user",
allowed: false,
},
{
name: "Project: project requests should not be skipped",

object: newProjectRequest("project", map[string]string{orgLabel: "other-org"}, nil),
additionalObjects: func(*testing.T) []client.Object {
return []client.Object{
newUser("user", ""),
newGroup("other-org"),
}
},

skip: true,
user: "user",
allowed: false,
},
{
name: "Namespace: request with org label set, user not in org",

Expand Down Expand Up @@ -358,7 +375,7 @@ func Test_NamespaceProjectOrganizationMutator_Handle(t *testing.T) {
subject := NamespaceProjectOrganizationMutator{
Decoder: decoder,
Client: c,
Skipper: skipper.StaticSkipper{},
Skipper: skipper.StaticSkipper{ShouldSkip: tc.skip},

OrganizationLabel: orgLabel,
UserDefaultOrganizationAnnotation: testDefaultOrgAnnotation,
Expand Down
Loading