Skip to content

Commit 0e26c3e

Browse files
authored
Never skip Project requests (#120)
The requests comes from internal components of OpenShift, but has an annotation with the original user name. The user from the annotation is checked later.
1 parent 90c3196 commit 0e26c3e

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

webhooks/namespace_project_organization_mutator.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func (m *NamespaceProjectOrganizationMutator) Handle(ctx context.Context, req ad
5858
ctx = log.IntoContext(ctx, log.FromContext(ctx).
5959
WithName("webhook.namespace-project-organization-mutator.appuio.io").
6060
WithValues("id", req.UID, "user", req.UserInfo.Username).
61+
WithValues("operation", req.Operation).
6162
WithValues("namespace", req.Namespace, "name", req.Name,
6263
"group", req.Kind.Group, "version", req.Kind.Version, "kind", req.Kind.Kind))
6364

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

webhooks/namespace_project_organization_mutator_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ func Test_NamespaceProjectOrganizationMutator_Handle(t *testing.T) {
3232

3333
allowed bool
3434
orgPatch string
35+
36+
skip bool
3537
}{
3638
{
3739
name: "Project: request with org label set",
@@ -111,6 +113,21 @@ func Test_NamespaceProjectOrganizationMutator_Handle(t *testing.T) {
111113
user: "user",
112114
allowed: false,
113115
},
116+
{
117+
name: "Project: project requests should not be skipped",
118+
119+
object: newProjectRequest("project", map[string]string{orgLabel: "other-org"}, nil),
120+
additionalObjects: func(*testing.T) []client.Object {
121+
return []client.Object{
122+
newUser("user", ""),
123+
newGroup("other-org"),
124+
}
125+
},
126+
127+
skip: true,
128+
user: "user",
129+
allowed: false,
130+
},
114131
{
115132
name: "Namespace: request with org label set, user not in org",
116133

@@ -358,7 +375,7 @@ func Test_NamespaceProjectOrganizationMutator_Handle(t *testing.T) {
358375
subject := NamespaceProjectOrganizationMutator{
359376
Decoder: decoder,
360377
Client: c,
361-
Skipper: skipper.StaticSkipper{},
378+
Skipper: skipper.StaticSkipper{ShouldSkip: tc.skip},
362379

363380
OrganizationLabel: orgLabel,
364381
UserDefaultOrganizationAnnotation: testDefaultOrgAnnotation,

0 commit comments

Comments
 (0)