Skip to content

Add flask routes to auth validators#18486

Merged
BenWilson2 merged 4 commits intomlflow:masterfrom
BenWilson2:artifact-security
Nov 13, 2025
Merged

Add flask routes to auth validators#18486
BenWilson2 merged 4 commits intomlflow:masterfrom
BenWilson2:artifact-security

Conversation

@BenWilson2
Copy link
Member

@BenWilson2 BenWilson2 commented Oct 23, 2025

🛠 DevTools 🛠

Open in GitHub Codespaces

Install mlflow from this PR

# mlflow
pip install git+https://github.com/mlflow/mlflow.git@refs/pull/18486/merge
# mlflow-skinny
pip install git+https://github.com/mlflow/mlflow.git@refs/pull/18486/merge#subdirectory=libs/skinny

For Databricks, use the following command:

%sh curl -LsSf https://raw.githubusercontent.com/mlflow/mlflow/HEAD/dev/install-skinny.sh | sh -s pull/18486/merge

Related Issues/PRs

#xxx

What 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?

  • Existing unit/integration tests
  • New unit/integration tests
  • Manual tests

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?

  • No. You can skip the rest of this section.
  • Yes. I've updated:
    • Examples
    • API references
    • Instructions

Release Notes

Is this a user-facing change?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release notes for MLflow users.

What component(s), interfaces, languages, and integrations does this PR affect?

Components

  • area/tracking: Tracking Service, tracking client APIs, autologging
  • area/models: MLmodel format, model serialization/deserialization, flavors
  • area/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registry
  • area/scoring: MLflow Model server, model deployment tools, Spark UDFs
  • area/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflows
  • area/gateway: MLflow AI Gateway client APIs, server, and third-party integrations
  • area/prompts: MLflow prompt engineering features, prompt templates, and prompt management
  • area/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionality
  • area/projects: MLproject format, project running backends
  • area/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev server
  • area/build: Build and test infrastructure for MLflow
  • area/docs: MLflow documentation pages

How 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" section
  • rn/breaking-change - The PR will be mentioned in the "Breaking Changes" section
  • rn/feature - A new user-facing feature worth mentioning in the release notes
  • rn/bug-fix - A user-facing bug fix worth mentioning in the release notes
  • rn/documentation - A user-facing documentation change worth mentioning in the release notes

Should this PR be included in the next patch release?

Yes should be selected for bug fixes, documentation updates, and other small changes. No should 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?
  • Minor release: a release that increments the second part of the version number (e.g., 1.2.0 -> 1.3.0).
    Bug fixes, doc updates and new features usually go into minor releases.
  • Patch release: a release that increments the third part of the version number (e.g., 1.2.0 -> 1.2.1).
    Bug fixes and doc updates usually go into patch releases.
  • Yes (this PR will be cherry-picked and included in the next patch release)
  • No (this PR will be included in the next minor release)

Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com>
@BenWilson2 BenWilson2 added the team-review Trigger a team review request label Oct 23, 2025
@github-actions github-actions bot added v3.5.2 area/tracking Tracking service, tracking client APIs, autologging rn/bug-fix Mention under Bug Fixes in Changelogs. labels Oct 23, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 23, 2025

Documentation preview for c0af4e1 is available at:

More info
  • Ignore this comment if this PR does not change the documentation.
  • The preview is updated when a new commit is pushed to this PR.
  • This comment was created by this workflow run.
  • The documentation was built by this workflow run.

(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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this for ? the validator always return True

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Purely for consistency so that we have all server routes listed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we remove them? It's confusing since it does nothing, will it cause CVE?

Copy link
Collaborator

@WeichenXu123 WeichenXu123 Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: can we make the request failing if no validator is found for a request path ? ( in

def _find_validator(req: Request) -> Callable[[], bool] | None:
)

@WeichenXu123
Copy link
Collaborator

One idea (does not block this PR):

Current approach is to add validator for each endpoint path, which is easy to cause omissions,
The following way might be better.

when a request comes, put the request username in a thread-local variable,
then in SqlAlchemyStore.get_run / SqlAlchemyStore.get_experiment method, we can validate the related experiment permission setting with the username set in the thread-local variable, if validation fails, raise permission error.

@serena-ruan
Copy link
Collaborator

serena-ruan commented Oct 29, 2025

/review


🚀 Review workflow started


✅ Review completed.

Review Output

Perfect! I've successfully reviewed PR #18486 and added 12 review comments. The review found:

Style Guide Issues:

  • Multiple redundant docstrings that merely repeat function names (violations of MLflow's Python style guide)
  • Several functions with docstrings that could be more concise or converted to regular comments

Potential Bug:

  • The validate_gateway_proxy() function has a docstring that mentions "Returns empty list" but the function returns a boolean True, suggesting a documentation error

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.

Comment on lines +409 to +411
"""
Get permission for Flask routes that use either run_id or run_uuid parameter.
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
"""
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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah could we remove these useless docstrings?

Comment on lines +436 to +440
def _get_permission_from_model_version() -> Permission:
"""
Get permission for model version artifacts.
Model versions inherit permissions from their registered model.
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Comment on lines +458 to +462
def _get_permission_from_trace_request_id() -> Permission:
"""
Get permission for trace artifacts.
Traces inherit permissions from their parent run/experiment.
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Comment on lines +426 to +428
def validate_can_read_run_artifact():
"""Validator for /get-artifact Flask route"""
return _get_permission_from_run_id_or_uuid().can_read
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the Python style guide, this docstring merely repeats what the function name already indicates. Consider removing it.

Suggested change
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

Comment on lines +431 to +432
def validate_can_update_run_artifact():
"""Validator for /upload-artifact Flask route"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the Python style guide, this docstring merely repeats what the function name already indicates. Consider removing it.

Suggested change
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

Comment on lines +453 to +455
def validate_can_read_model_version_artifact():
"""Validator for /model-versions/get-artifact Flask route"""
return _get_permission_from_model_version().can_read
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the Python style guide, this docstring merely repeats what the function name already indicates. Consider removing it.

Suggested change
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

Comment on lines +478 to +480
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the Python style guide, this docstring merely repeats what the function name already indicates. Consider removing it.

Suggested change
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

Comment on lines +483 to +487
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.
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Comment on lines +511 to +516
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the Python style guide, this docstring is redundant. The function call itself shows it has the same logic.

Suggested change
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

Comment on lines +519 to +523
def validate_can_search_datasets():
"""
Validator for /ajax-api/2.0/mlflow/experiments/search-datasets Flask route.
Checks READ permission on the experiment.
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the Python style guide, consider making this docstring more concise. The "Checks READ permission on the experiment" part is the valuable context.

Suggested change
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

Comment on lines +549 to +552
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).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the Python style guide, consider making this docstring more concise. The key information is the UPDATE permission requirement.

Suggested change
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

Comment on lines +569 to +578
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com>
(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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insteresting, is this still valid?

Copy link
Collaborator

@WeichenXu123 WeichenXu123 Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be valid, these endpoints all exist

Copy link
Member Author

@BenWilson2 BenWilson2 Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point! I'll verify if this has any issues before merging.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirmed the route still exists and is viable.

Copy link
Collaborator

@serena-ruan serena-ruan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :)

Copy link
Collaborator

@WeichenXu123 WeichenXu123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@BenWilson2 BenWilson2 added v3.6.1 and removed v3.5.2 labels Nov 13, 2025
@BenWilson2 BenWilson2 enabled auto-merge November 13, 2025 05:01
@BenWilson2 BenWilson2 added this pull request to the merge queue Nov 13, 2025
Merged via the queue into mlflow:master with commit ca9ab39 Nov 13, 2025
50 of 51 checks passed
@BenWilson2 BenWilson2 deleted the artifact-security branch November 13, 2025 05:43
Tian-Sky-Lan pushed a commit to Tian-Sky-Lan/mlflow that referenced this pull request Nov 24, 2025
Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com>
Signed-off-by: Tian Lan <sky.blue266000@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/tracking Tracking service, tracking client APIs, autologging rn/bug-fix Mention under Bug Fixes in Changelogs. team-review Trigger a team review request v3.6.1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants