Skip to content

feat: enforce authorization on CreateExperiment and CreateRegisteredModel#247

Draft
remidebette wants to merge 4 commits into
mlflow-oidc:mainfrom
instadeepai:upstream/restrict-resource-creation-rebased
Draft

feat: enforce authorization on CreateExperiment and CreateRegisteredModel#247
remidebette wants to merge 4 commits into
mlflow-oidc:mainfrom
instadeepai:upstream/restrict-resource-creation-rebased

Conversation

@remidebette

Copy link
Copy Markdown
Contributor

Summary

Resurrects @nitaibezerra's original work from #195/#202, rebased onto current main and made workspace-aware.

Currently any authenticated user can create experiments and registered models regardless of DEFAULT_MLFLOW_PERMISSION or group/regex permissions — there's no before-request validator on CreateExperiment/CreateRegisteredModel, only an after-request handler that grants MANAGE to the creator after the resource already exists.

This PR adds opt-in creation enforcement gated by a new RESTRICT_RESOURCE_CREATION config flag (default: false), so existing deployments see no behaviour change unless they enable it.

Fixes #202.

Changes

Three rebased commits from @nitaibezerra plus one workspace-correctness fix:

  1. fix: enforce authorization on CreateExperiment and CreateRegisteredModel — adds validate_can_create_experiment and validate_can_create_registered_model validators wired into BEFORE_REQUEST_HANDLERS. Resolves permission by resource name (the resource ID doesn't exist yet at creation time) using regex/group-regex sources only.
  2. feat: add RESTRICT_RESOURCE_CREATION flag for backward compatibility — gates the new validators behind an opt-in config flag (default false).
  3. docs: add resource creation authorization documentation — documents the flag and the resolution order.
  4. fix(auth): respect workspace permissions for resource creation (new in this rebase) — extracts the existing workspace-fallback logic from resolve_permission into a small helper and applies it on the creation paths. Without this, with MLFLOW_ENABLE_WORKSPACES=true a user with no workspace permission would fall through to DEFAULT_MLFLOW_PERMISSION and could still create resources.

Behaviour

When RESTRICT_RESOURCE_CREATION=false (default): no change — anyone authenticated can create.

When RESTRICT_RESOURCE_CREATION=true:

Scenario Result
User has matching regex / group-regex granting EDIT+ on the requested name Allow
Workspaces disabled, no regex match Falls back to DEFAULT_MLFLOW_PERMISSION
Workspaces enabled, no regex match, user has EDIT+ on request workspace Allow
Workspaces enabled, no regex match, no workspace permission Deny

Test plan

  • pytest mlflow_oidc_auth/tests/validators/test_experiment.py mlflow_oidc_auth/tests/validators/test_registered_model.py mlflow_oidc_auth/tests/hooks/test_before_request.py mlflow_oidc_auth/tests/utils/test_permissions.py — 158/158 passing locally
  • New tests cover: regex match, regex miss with workspaces enabled and a workspace permission, regex miss with workspaces enabled and no workspace permission (deny), regex miss with workspaces disabled
  • Maintainer review

Notes

@nitaibezerra is preserved as the original author on commits 1-3. Happy to squash on merge if maintainers prefer a single-commit PR — let me know.

🤖 Generated with Claude Code

nitaibezerra and others added 4 commits May 4, 2026 15:53
Any authenticated user could create experiments and registered models
regardless of DEFAULT_MLFLOW_PERMISSION or group/regex permissions.
This happened because CreateExperiment and CreateRegisteredModel had
no before-request validator — only after-request handlers that grant
MANAGE permission to the creator after the resource was already created.

The root cause is that existing validators resolve permissions by
resource ID, which doesn't exist yet at creation time. This adds new
validators that resolve permissions by resource name (available in the
creation request), checking regex and group-regex permission sources
and falling back to DEFAULT_MLFLOW_PERMISSION.

With DEFAULT_MLFLOW_PERMISSION=NO_PERMISSIONS, experiment and model
creation is now properly blocked unless the user has a matching regex
permission granting at least EDIT access.

Fixes mlflow-oidc#202

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Gate creation validators behind an opt-in config flag (default: false)
so existing deployments upgrading won't see behavior changes. When the
flag is disabled, CreateExperiment and CreateRegisteredModel are always
allowed, matching upstream behavior.

Refs: mlflow-oidc#195, mlflow-oidc#202

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Document the RESTRICT_RESOURCE_CREATION config flag and how creation
permissions are resolved using regex/group-regex sources.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The new effective_new_experiment_permission and effective_new_registered_model_permission
introduced in the previous commit call get_permission_from_store_or_default directly,
bypassing the workspace-fallback logic in resolve_permission. With MLFLOW_ENABLE_WORKSPACES=true
a user without workspace access could still create resources because the validator fell back
to DEFAULT_MLFLOW_PERMISSION instead of the user's workspace permission.

Extracts the workspace-fallback block from resolve_permission into a small helper and applies
it on the creation paths so they match the contract enforced for existing resources.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@remidebette
remidebette marked this pull request as draft May 4, 2026 14:29
@remidebette
remidebette marked this pull request as draft May 4, 2026 14:29
@remidebette

Copy link
Copy Markdown
Contributor Author

I just noticed #245 after rebasing

The spirit behind this PR and the past one was that - pre-workspace - any experiment creation was allowed (as a bug), even the ones which subsequent access was being forbidden by a regex.
For example in my case of project based prefix <project>/<exp name> some people would be allowed some project prefix but not all.
So that if users did typos in the project name, they ended up creating experiments they would not be able to access.

This gets restricted by this PR, in the sense that a user needs experiment EDIT access to be able to create such an exp.

The issue is that with #245 and post-workspace, the responsibility of creating exps is not in the exps access rights anymore but in the workspace access rights (and should be Workspace MANAGE as per https://mlflow-oidc.github.io/mlflow-oidc-auth/#/workspaces?id=workspace-permissions

I was trying to see how to adapt the current non-workspace code for workspaces, but it seems irrelevant now.

Should we still plan on merging for the bug in: MLFLOW_ENABLE_WORKSPACES=false @kharkevich, or would you rather encourage users to switch to workspaces instead ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DEFAULT_MLFLOW_PERMISSION -> NO_PERMISSIONS takes no effect

2 participants