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
5 changes: 4 additions & 1 deletion pkg/resources/core/v1/namespace/projectannotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,13 @@ func (p *projectNamespaceAdmitter) Admit(request *admission.Request) (*admission
return response, nil
}

constructedReason := fmt.Sprintf("User %q does not have permission %q on project %q",
request.UserInfo.Username, manageNSVerb, projectName)

response.Allowed = false
response.Result = &metav1.Status{
Status: "Failure",
Message: sarResponse.Status.Reason,
Message: constructedReason,
Reason: metav1.StatusReasonUnauthorized,
Code: http.StatusForbidden,
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/resources/core/v1/namespace/projectannotations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestValidateProjectNamespaceAnnotations(t *testing.T) {
includeProjectAnnotation bool
targetProject string
userCanAccessProject bool
rejectMessage string
sarError bool
wantError bool
wantAllowed bool
Expand Down Expand Up @@ -72,6 +73,7 @@ func TestValidateProjectNamespaceAnnotations(t *testing.T) {
includeProjectAnnotation: true,
targetProject: "p-123xyz",
userCanAccessProject: false,
rejectMessage: "User \"test-user\" does not have permission \"manage-namespaces\" on project \"p-123xyz\"",
sarError: false,
wantError: false,
wantAllowed: false,
Expand Down Expand Up @@ -220,6 +222,9 @@ func TestValidateProjectNamespaceAnnotations(t *testing.T) {
} else {
assert.NoError(t, err)
assert.Equal(t, test.wantAllowed, response.Allowed)
if test.rejectMessage != "" {
assert.Equal(t, test.rejectMessage, response.Result.Message)
}
}
})
}
Expand Down