feat: enforce authorization on CreateExperiment and CreateRegisteredModel#247
feat: enforce authorization on CreateExperiment and CreateRegisteredModel#247remidebette wants to merge 4 commits into
Conversation
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>
|
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. 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: |
Summary
Resurrects @nitaibezerra's original work from #195/#202, rebased onto current
mainand made workspace-aware.Currently any authenticated user can create experiments and registered models regardless of
DEFAULT_MLFLOW_PERMISSIONor group/regex permissions — there's no before-request validator onCreateExperiment/CreateRegisteredModel, only an after-request handler that grantsMANAGEto the creator after the resource already exists.This PR adds opt-in creation enforcement gated by a new
RESTRICT_RESOURCE_CREATIONconfig 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:
fix: enforce authorization on CreateExperiment and CreateRegisteredModel— addsvalidate_can_create_experimentandvalidate_can_create_registered_modelvalidators wired intoBEFORE_REQUEST_HANDLERS. Resolves permission by resource name (the resource ID doesn't exist yet at creation time) using regex/group-regex sources only.feat: add RESTRICT_RESOURCE_CREATION flag for backward compatibility— gates the new validators behind an opt-in config flag (defaultfalse).docs: add resource creation authorization documentation— documents the flag and the resolution order.fix(auth): respect workspace permissions for resource creation(new in this rebase) — extracts the existing workspace-fallback logic fromresolve_permissioninto a small helper and applies it on the creation paths. Without this, withMLFLOW_ENABLE_WORKSPACES=truea user with no workspace permission would fall through toDEFAULT_MLFLOW_PERMISSIONand could still create resources.Behaviour
When
RESTRICT_RESOURCE_CREATION=false(default): no change — anyone authenticated can create.When
RESTRICT_RESOURCE_CREATION=true:DEFAULT_MLFLOW_PERMISSIONTest 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 locallyNotes
@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