Add flask routes to auth validators#18486
Conversation
Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com>
|
Documentation preview for c0af4e1 is available at: More info
|
| (SEARCH_DATASETS, "POST"): validate_can_search_datasets, | ||
| (CREATE_PROMPTLAB_RUN, "POST"): validate_can_create_promptlab_run, | ||
| (GATEWAY_PROXY, "GET"): validate_gateway_proxy, | ||
| (GATEWAY_PROXY, "POST"): validate_gateway_proxy, |
There was a problem hiding this comment.
what's this for ? the validator always return True
There was a problem hiding this comment.
Purely for consistency so that we have all server routes listed.
There was a problem hiding this comment.
Could we remove them? It's confusing since it does nothing, will it cause CVE?
There was a problem hiding this comment.
I think Ben's purpose is to force every path has a validator, an empty validator can be a placeholder (so that we won't missing permission validation for any endpoint path)
There was a problem hiding this comment.
Q: can we make the request failing if no validator is found for a request path ? ( in
mlflow/mlflow/server/auth/__init__.py
Line 583 in 27c95c3
|
One idea (does not block this PR): Current approach is to add validator for each endpoint path, which is easy to cause omissions, when a request comes, put the request |
|
/review ✅ Review completed. Review OutputPerfect! I've successfully reviewed PR #18486 and added 12 review comments. The review found: Style Guide Issues:
Potential Bug:
All comments have been posted to the PR with clickable suggestion blocks where applicable, making it easy for maintainers to apply the fixes with one click. |
| """ | ||
| Get permission for Flask routes that use either run_id or run_uuid parameter. | ||
| """ |
There was a problem hiding this comment.
Per the Python style guide, this docstring is redundant - the function name already clearly indicates it gets permission from run_id or run_uuid parameter. Consider removing it.
| """ | |
| Get permission for Flask routes that use either run_id or run_uuid parameter. | |
| """ | |
| def _get_permission_from_run_id_or_uuid() -> Permission: |
🤖 Generated with Claude Code
There was a problem hiding this comment.
Yeah could we remove these useless docstrings?
| def _get_permission_from_model_version() -> Permission: | ||
| """ | ||
| Get permission for model version artifacts. | ||
| Model versions inherit permissions from their registered model. | ||
| """ |
There was a problem hiding this comment.
Per the Python style guide, this docstring is redundant. The function name already conveys what it does, and the inheritance comment can be moved to a regular comment if needed.
| def _get_permission_from_model_version() -> Permission: | |
| """ | |
| Get permission for model version artifacts. | |
| Model versions inherit permissions from their registered model. | |
| """ | |
| def _get_permission_from_model_version() -> Permission: | |
| # Model versions inherit permissions from their registered model. |
🤖 Generated with Claude Code
| def _get_permission_from_trace_request_id() -> Permission: | ||
| """ | ||
| Get permission for trace artifacts. | ||
| Traces inherit permissions from their parent run/experiment. | ||
| """ |
There was a problem hiding this comment.
Per the Python style guide, this docstring is redundant. The function name is self-documenting, and the inheritance comment can be a regular comment if needed.
| def _get_permission_from_trace_request_id() -> Permission: | |
| """ | |
| Get permission for trace artifacts. | |
| Traces inherit permissions from their parent run/experiment. | |
| """ | |
| def _get_permission_from_trace_request_id() -> Permission: | |
| # Traces inherit permissions from their parent run/experiment. |
🤖 Generated with Claude Code
| def validate_can_read_run_artifact(): | ||
| """Validator for /get-artifact Flask route""" | ||
| return _get_permission_from_run_id_or_uuid().can_read |
There was a problem hiding this comment.
Per the Python style guide, this docstring merely repeats what the function name already indicates. Consider removing it.
| def validate_can_read_run_artifact(): | |
| """Validator for /get-artifact Flask route""" | |
| return _get_permission_from_run_id_or_uuid().can_read | |
| def validate_can_read_run_artifact(): | |
| return _get_permission_from_run_id_or_uuid().can_read |
🤖 Generated with Claude Code
mlflow/server/auth/__init__.py
Outdated
| def validate_can_update_run_artifact(): | ||
| """Validator for /upload-artifact Flask route""" |
There was a problem hiding this comment.
Per the Python style guide, this docstring merely repeats what the function name already indicates. Consider removing it.
| def validate_can_update_run_artifact(): | |
| """Validator for /upload-artifact Flask route""" | |
| def validate_can_update_run_artifact(): | |
| return _get_permission_from_run_id_or_uuid().can_update |
🤖 Generated with Claude Code
| def validate_can_read_model_version_artifact(): | ||
| """Validator for /model-versions/get-artifact Flask route""" | ||
| return _get_permission_from_model_version().can_read |
There was a problem hiding this comment.
Per the Python style guide, this docstring merely repeats what the function name already indicates. Consider removing it.
| def validate_can_read_model_version_artifact(): | |
| """Validator for /model-versions/get-artifact Flask route""" | |
| return _get_permission_from_model_version().can_read | |
| def validate_can_read_model_version_artifact(): | |
| return _get_permission_from_model_version().can_read |
🤖 Generated with Claude Code
| def validate_can_read_trace_artifact(): | ||
| """Validator for /ajax-api/2.0/mlflow/get-trace-artifact Flask route""" | ||
| return _get_permission_from_trace_request_id().can_read |
There was a problem hiding this comment.
Per the Python style guide, this docstring merely repeats what the function name already indicates. Consider removing it.
| def validate_can_read_trace_artifact(): | |
| """Validator for /ajax-api/2.0/mlflow/get-trace-artifact Flask route""" | |
| return _get_permission_from_trace_request_id().can_read | |
| def validate_can_read_trace_artifact(): | |
| return _get_permission_from_trace_request_id().can_read |
🤖 Generated with Claude Code
mlflow/server/auth/__init__.py
Outdated
| def validate_can_read_metric_history_bulk(): | ||
| """ | ||
| Validator for /ajax-api/2.0/mlflow/metrics/get-history-bulk Flask route. | ||
| Checks READ permission on all requested runs. | ||
| """ |
There was a problem hiding this comment.
Per the Python style guide, consider making this docstring more concise or removing it if the function name is self-explanatory. The "Checks READ permission on all requested runs" part is valuable context though.
| def validate_can_read_metric_history_bulk(): | |
| """ | |
| Validator for /ajax-api/2.0/mlflow/metrics/get-history-bulk Flask route. | |
| Checks READ permission on all requested runs. | |
| """ | |
| def validate_can_read_metric_history_bulk(): | |
| """Checks READ permission on all requested runs.""" |
🤖 Generated with Claude Code
| def validate_can_read_metric_history_bulk_interval(): | ||
| """ | ||
| Validator for /ajax-api/2.0/mlflow/metrics/get-history-bulk-interval Flask route. | ||
| Same logic as bulk metrics endpoint. | ||
| """ | ||
| return validate_can_read_metric_history_bulk() |
There was a problem hiding this comment.
Per the Python style guide, this docstring is redundant. The function call itself shows it has the same logic.
| def validate_can_read_metric_history_bulk_interval(): | |
| """ | |
| Validator for /ajax-api/2.0/mlflow/metrics/get-history-bulk-interval Flask route. | |
| Same logic as bulk metrics endpoint. | |
| """ | |
| return validate_can_read_metric_history_bulk() | |
| def validate_can_read_metric_history_bulk_interval(): | |
| # Same logic as bulk metrics endpoint | |
| return validate_can_read_metric_history_bulk() |
🤖 Generated with Claude Code
mlflow/server/auth/__init__.py
Outdated
| def validate_can_search_datasets(): | ||
| """ | ||
| Validator for /ajax-api/2.0/mlflow/experiments/search-datasets Flask route. | ||
| Checks READ permission on the experiment. | ||
| """ |
There was a problem hiding this comment.
Per the Python style guide, consider making this docstring more concise. The "Checks READ permission on the experiment" part is the valuable context.
| def validate_can_search_datasets(): | |
| """ | |
| Validator for /ajax-api/2.0/mlflow/experiments/search-datasets Flask route. | |
| Checks READ permission on the experiment. | |
| """ | |
| def validate_can_search_datasets(): | |
| """Checks READ permission on the experiment.""" |
🤖 Generated with Claude Code
mlflow/server/auth/__init__.py
Outdated
| def validate_can_create_promptlab_run(): | ||
| """ | ||
| Validator for /ajax-api/2.0/mlflow/runs/create-promptlab-run Flask route. | ||
| Checks UPDATE permission on the experiment (same as CreateRun). |
There was a problem hiding this comment.
Per the Python style guide, consider making this docstring more concise. The key information is the UPDATE permission requirement.
| def validate_can_create_promptlab_run(): | |
| """ | |
| Validator for /ajax-api/2.0/mlflow/runs/create-promptlab-run Flask route. | |
| Checks UPDATE permission on the experiment (same as CreateRun). | |
| def validate_can_create_promptlab_run(): | |
| """Checks UPDATE permission on the experiment (same as CreateRun).""" |
🤖 Generated with Claude Code
| def validate_gateway_proxy(): | ||
| """ | ||
| Validator for /ajax-api/2.0/mlflow/gateway-proxy Flask route. | ||
|
|
||
| This endpoint proxies requests to MLflow Deployments (AI Gateway) external services. | ||
| Returns empty list if MLFLOW_DEPLOYMENTS_TARGET is not configured. | ||
| No MLflow resource permissions are checked since this proxies to external services | ||
| that handle their own authorization. | ||
| """ | ||
| return True |
There was a problem hiding this comment.
This docstring provides valuable context explaining why the function returns True and the security model. This is appropriate to keep as it explains non-obvious behavior.
However, there's a potential issue: the docstring mentions "Returns empty list if MLFLOW_DEPLOYMENTS_TARGET is not configured" but the function returns True (a boolean), not a list. This seems like a copy-paste error in the docstring. Consider clarifying what this function's behavior actually is.
🤖 Generated with Claude Code
| (GET_METRIC_HISTORY_BULK, "GET"): validate_can_read_metric_history_bulk, | ||
| (GET_METRIC_HISTORY_BULK_INTERVAL, "GET"): validate_can_read_metric_history_bulk_interval, | ||
| (SEARCH_DATASETS, "POST"): validate_can_search_datasets, | ||
| (CREATE_PROMPTLAB_RUN, "POST"): validate_can_create_promptlab_run, |
There was a problem hiding this comment.
Insteresting, is this still valid?
There was a problem hiding this comment.
should be valid, these endpoints all exist
There was a problem hiding this comment.
good point! I'll verify if this has any issues before merging.
There was a problem hiding this comment.
confirmed the route still exists and is viable.
serena-ruan
left a comment
There was a problem hiding this comment.
LGTM once https://github.com/mlflow/mlflow/pull/18486/files#r2520933037 is addressed/answered! If it's for consistency only then I think we don't need it :)
Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com> Signed-off-by: Tian Lan <sky.blue266000@gmail.com>
🛠 DevTools 🛠
Install mlflow from this PR
For Databricks, use the following command:
Related Issues/PRs
#xxxWhat changes are proposed in this pull request?
Adds auth validation to flask routes that do not have corresponding proto definitions (server local routes)
How is this PR tested?
Due to the nature of this fix, ask me if you want to see the repro and fix validation.
Does this PR require documentation update?
Release Notes
Is this a user-facing change?
What component(s), interfaces, languages, and integrations does this PR affect?
Components
area/tracking: Tracking Service, tracking client APIs, autologgingarea/models: MLmodel format, model serialization/deserialization, flavorsarea/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registryarea/scoring: MLflow Model server, model deployment tools, Spark UDFsarea/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflowsarea/gateway: MLflow AI Gateway client APIs, server, and third-party integrationsarea/prompts: MLflow prompt engineering features, prompt templates, and prompt managementarea/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionalityarea/projects: MLproject format, project running backendsarea/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev serverarea/build: Build and test infrastructure for MLflowarea/docs: MLflow documentation pagesHow should the PR be classified in the release notes? Choose one:
rn/none- No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" sectionrn/breaking-change- The PR will be mentioned in the "Breaking Changes" sectionrn/feature- A new user-facing feature worth mentioning in the release notesrn/bug-fix- A user-facing bug fix worth mentioning in the release notesrn/documentation- A user-facing documentation change worth mentioning in the release notesShould this PR be included in the next patch release?
Yesshould be selected for bug fixes, documentation updates, and other small changes.Noshould be selected for new features and larger changes. If you're unsure about the release classification of this PR, leave this unchecked to let the maintainers decide.What is a minor/patch release?
Bug fixes, doc updates and new features usually go into minor releases.
Bug fixes and doc updates usually go into patch releases.