Skip to content

feat: enforce filterRules restrictions on workspace create and update - #1364

Draft
Snehadas2005 wants to merge 1 commit into
kubeflow:notebooks-v2from
Snehadas2005:task-enforce-filterrules
Draft

feat: enforce filterRules restrictions on workspace create and update#1364
Snehadas2005 wants to merge 1 commit into
kubeflow:notebooks-v2from
Snehadas2005:task-enforce-filterrules

Conversation

@Snehadas2005

Copy link
Copy Markdown
Member

This PR implements server-side enforcement of WorkspaceKind.spec.filterRules[] restrictions during Workspace creation (POST /workspaces) and update (PUT /workspaces/:name). Even if the frontend UI restricts or disables invalid options, the backend independently validates selected imageConfig and podConfig options against defined filter rules using the workspace's target namespace context to prevent direct API misuse.

Specifically:

  • On Workspace create: Evaluates filterRules for both selected imageConfig and podConfig options using the target namespace context.
  • On Workspace update: Only re-evaluates filterRules if imageConfig and/or podConfig are actually modified. This prevents existing workloads from breaking on unrelated workspace updates (e.g. updating labels/display name) when an administrator adds a new deny rule post-creation.
  • Deny error response: Rejects invalid requests with HTTP 422 Unprocessable Entity containing the matched filter rule's denyMessage.text within cause.validation_errors[].

Key Changes

  1. Workspace Repository (internal/repositories/workspaces/repo.go)

    • enforceFilterRuleRestrictions: Helper function that retrieves the referenced WorkspaceKind, resolves target namespace labels via resolveNamespaceLabels, and invokes the shared filterrules.Evaluate() engine for the selected imageConfig and podConfig.
    • CreateWorkspace: Invokes enforceFilterRuleRestrictions upfront before creating the Kubernetes resource.
    • UpdateWorkspace: Checks if newOptions.ImageConfig != currentOptions.ImageConfig or newOptions.PodConfig != currentOptions.PodConfig before validating, ensuring unchanged options are not re-checked.
    • Error Surface: Uses helper.NewInternalValidationError(filterErrs) to map denied options directly into the existing cause.validation_errors[] field error structure without requiring changes to the handler layer (workspaces_handler.go).
  2. Unit & Integration Tests (api/workspaces_handler_test.go)
    Added an Ordered test context Enforcing filterRule restrictions on Workspace create/update covering:

    • Create rejection (imageConfig): Workspace create fails when selected imageConfig matches a deny rule.
    • Create rejection (podConfig): Workspace create fails when selected podConfig matches a deny rule.
    • Create success: Workspace create succeeds when all options are allowed.
    • Update rejection: Workspace update fails when changing to a restricted imageConfig.
    • Update success: Workspace update succeeds when options remain unchanged.

Verification

  • Static Analysis & Linting: Ran go vet ./... and go fmt ./... across the backend with 0 errors/warnings.
  • Build Verification: Verified binary compilation using go build ./cmd/main.go.
  • Unit Tests: Verified all Ginkgo + envtest specifications pass via make test.

Notes for Reviewers

  • The issue specifies returning HTTP 403 or 422. This implementation uses 422 Unprocessable Entity as it seamlessly reuses the existing InternalValidationErrorfailedValidationResponse pipeline already established for PVC/Secret mountability validation.

closes: #1206
related: #682

@github-project-automation github-project-automation Bot moved this to Needs Triage in Kubeflow Notebooks Aug 29, 2026
@google-oss-prow google-oss-prow Bot added the area/backend area - related to backend components label Aug 29, 2026
@google-oss-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign andyatmiami for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow google-oss-prow Bot added area/v2 area - version - kubeflow notebooks v2 size/L labels Aug 29, 2026
@Snehadas2005 Snehadas2005 changed the title fix: filter hidden options and display restrictions popover enforce WorkspaceKind filterRules on Workspace create and update Aug 29, 2026
@Snehadas2005 Snehadas2005 changed the title enforce WorkspaceKind filterRules on Workspace create and update feat: enforce filterRules restrictions on workspace create and update Aug 29, 2026
Signed-off-by: Sneha Das <154408198+Snehadas2005@users.noreply.github.com>
@Snehadas2005
Snehadas2005 force-pushed the task-enforce-filterrules branch from 785b769 to cfcf26a Compare August 29, 2026 05:47
@Snehadas2005
Snehadas2005 marked this pull request as draft August 29, 2026 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/backend area - related to backend components area/v2 area - version - kubeflow notebooks v2 do-not-merge/work-in-progress size/L

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

1 participant