pkg/admission: block WS creation if user cannot bind to default exports - #4311
Conversation
|
hmm, unclear why the |
There was a problem hiding this comment.
Pull request overview
This PR adds an admission-time permission gate to prevent creating a Workspace from a WorkspaceType when the requesting user cannot bind to the APIExports referenced by the type’s spec.defaultAPIBindings, and factors the shared authorization logic into a reusable helper in pkg/admission/apibinding.
Changes:
- Add a default-APIBindings access check to the
WorkspaceTypeExistsadmission plugin to block workspace creation early whenbindis not permitted. - Extract common “default APIBindings bind permission” logic into
apibindingadmission.CheckDefaultAPIBindingsAccess()and reuse it from the WorkspaceType admission path. - Add unit tests covering allow/deny scenarios, including inherited bindings through extended types.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/admission/workspacetypeexists/admission.go | Adds defaultAPIBindings access enforcement during workspace create; wires LogicalCluster lookup helpers/indexers. |
| pkg/admission/workspacetypeexists/admission_test.go | Adds tests to ensure workspace creation is rejected when bind on default APIExports is missing. |
| pkg/admission/workspacetype/admission.go | Refactors existing WorkspaceType defaultAPIBindings permission logic to use the shared helper. |
| pkg/admission/apibinding/binding_permissions.go | Introduces CheckDefaultAPIBindingsAccess helper for centralized default binding authorization checks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
6594ca5 to
6d38bea
Compare
/retest |
/retest |
|
/retest |
|
CI errors seem related EDIT: NVM, it passed. |
|
/test pull-kcp-test-e2e-multiple-runs |
| notPermitted := errors.New("no permission to bind one or more of the default API bindings") | ||
| if showExportPathInErrors { | ||
| notPermitted = fmt.Errorf("no permission to bind to export %s", | ||
| logicalcluster.NewPath(ref.Path).Join(ref.Export).String()) | ||
| } | ||
|
|
There was a problem hiding this comment.
I don't know how to argue it, but I have never seen a boolean parameter to toggle the error formatting in a function, and so I was wondering if this should simply be a custom error type that contains, as one field, the workspace Path. Then the caller can decide how they want to format it.
There was a problem hiding this comment.
yep, seems better with a custom error type.
updated.
6d38bea to
449161e
Compare
| // DefaultAPIBindingAccessError indicates the user lacks the 'bind' verb on one of a | ||
| // WorkspaceType's default APIExports. | ||
| type DefaultAPIBindingAccessError struct { | ||
| // ExportPath is the fully-qualified export path. | ||
| ExportPath string | ||
| } | ||
|
|
||
| func (e *DefaultAPIBindingAccessError) Error() string { | ||
| if e.ExportPath != "" { | ||
| return fmt.Sprintf("no permission to bind to export %s", e.ExportPath) | ||
| } | ||
| return "no permission to bind one or more of the default API bindings" | ||
| } |
There was a problem hiding this comment.
i added this new error type
DefaultAPIBindingAccessError
| if err := apibindingadmission.CheckDefaultAPIBindingsAccess(ctx, a.GetUserInfo(), logicalcluster.From(alias), alias.Spec.DefaultAPIBindings, o.getLogicalCluster, newAuthorizer); err != nil { | ||
| // Do not leak the export path when creating a workspace. | ||
| if notPermitted, ok := errors.AsType[*apibindingadmission.DefaultAPIBindingAccessError](err); ok { | ||
| notPermitted.ExportPath = "" |
There was a problem hiding this comment.
here we don't want to leak the WS path to the user as they might not be the owner of the WST
|
While this might ok syntax wise, can we have e2e test (or do we have one already?) for this. As its kinda hard to know if this does what it tells it does? |
Block the creation of Workspace based on a custom WorkspaceType, if the user cannot bind to the APIExports requested on the WorkspaceType's defaultAPIBindings. Extract some common logic from pkg/admission/workspacetype/admission.go in a function apibindingadmission.CheckDefaultAPIBindingsAccess(). Include unit and e2e tests. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
449161e to
828b75a
Compare
/retest |
|
same flake |
/retest |
|
LGTM label has been added. DetailsGit tree hash: e57b559aa7c3ce63f52393f94aeb14f207f421cf |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: mjudeikis The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/retest |
Summary
Block the creation of Workspace based on a custom WorkspaceType, if the user cannot bind to the APIExports requested on the WorkspaceType's defaultAPIBindings.
Extract some common logic from pkg/admission/workspacetype/admission.go in a function apibindingadmission.CheckDefaultAPIBindingsAccess().
i have tested the creation block with a script locally and it works.
What Type of PR Is This?
/kind bug
Related Issue(s)
Fixes #4299
(second attempt)
Release Notes