Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement auth client to manage permissions #8548

Merged
merged 20 commits into from
May 31, 2023

Conversation

gabrielfu
Copy link
Collaborator

@gabrielfu gabrielfu commented May 27, 2023

Related Issues/PRs

#724 #8286

What changes are proposed in this pull request?

Add a client to manage permissions

How is this patch tested?

  • Existing unit/integration tests
  • New unit/integration tests
  • Manual tests (describe details, including test results, below)

Does this PR change the documentation?

  • No. You can skip the rest of this section.
  • Yes. Make sure the changed pages / sections render correctly in the documentation preview.

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.

Add a client to create, get, update or delete users, experiment permissions and registered model permissions.

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

Components

  • area/artifacts: Artifact stores and artifact logging
  • area/build: Build and test infrastructure for MLflow
  • area/docs: MLflow documentation pages
  • area/examples: Example code
  • area/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registry
  • area/models: MLmodel format, model serialization/deserialization, flavors
  • area/recipes: Recipes, Recipe APIs, Recipe configs, Recipe Templates
  • area/projects: MLproject format, project running backends
  • area/scoring: MLflow Model server, model deployment tools, Spark UDFs
  • area/server-infra: MLflow Tracking server backend
  • area/tracking: Tracking Service, tracking client APIs, autologging

Interface

  • area/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev server
  • area/docker: Docker use across MLflow's components, such as MLflow Projects and MLflow Models
  • area/sqlalchemy: Use of SQLAlchemy in the Tracking Service or Model Registry
  • area/windows: Windows support

Language

  • language/r: R APIs and clients
  • language/java: Java APIs and clients
  • language/new: Proposals for new client languages

Integrations

  • integrations/azure: Azure and Azure ML integrations
  • integrations/sagemaker: SageMaker integrations
  • integrations/databricks: Databricks integrations

How should the PR be classified in the release notes? Choose one:

  • rn/breaking-change - The PR will be mentioned in the "Breaking Changes" section
  • 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/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

Signed-off-by: Gabriel Fu <hfu.gabriel@gmail.com>
Signed-off-by: Gabriel Fu <hfu.gabriel@gmail.com>
Signed-off-by: Gabriel Fu <hfu.gabriel@gmail.com>
Signed-off-by: Gabriel Fu <hfu.gabriel@gmail.com>
Signed-off-by: Gabriel Fu <hfu.gabriel@gmail.com>
Signed-off-by: Gabriel Fu <hfu.gabriel@gmail.com>
Signed-off-by: Gabriel Fu <hfu.gabriel@gmail.com>
Signed-off-by: Gabriel Fu <hfu.gabriel@gmail.com>
Signed-off-by: Gabriel Fu <hfu.gabriel@gmail.com>
@github-actions github-actions bot added area/tracking Tracking service, tracking client APIs, autologging rn/documentation Mention under Documentation Changes in Changelogs. labels May 27, 2023
@mlflow-automation
Copy link
Collaborator

mlflow-automation commented May 27, 2023

Documentation preview for f9799f5 will be available here when this CircleCI job completes successfully.

More info

Comment on lines +127 to +138
def get_app_client(app_name: str, *args, **kwargs):
clients = importlib.metadata.entry_points().get("mlflow.app.client", [])
for client in clients:
if client.name == app_name:
cls = client.load()
return cls(*args, **kwargs)

raise MlflowException(
f"Failed to find client for '{app_name}'. Available clients: {[c.name for c in clients]}"
)


Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Signed-off-by: Gabriel Fu <hfu.gabriel@gmail.com>

@pytest.fixture
def mock_session():
with mock.patch("mlflow.utils.rest_utils._get_request_session") as mock_session:
Copy link
Member

Choose a reason for hiding this comment

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

Can we patch requests.Session.request instead?

Copy link
Member

@harupy harupy May 30, 2023

Choose a reason for hiding this comment

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

Instead of using mock, can we run a server in the background using subprocess and make requests against it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure, I'm updated the tests!

gabrielfu and others added 4 commits May 31, 2023 10:57
Co-authored-by: Harutaka Kawamura <hkawamura0130@gmail.com>
Signed-off-by: Gabriel Fu <hfu.gabriel@gmail.com>
# Conflicts:
#	mlflow/server/auth/__init__.py
Signed-off-by: Gabriel Fu <hfu.gabriel@gmail.com>
Signed-off-by: Gabriel Fu <hfu.gabriel@gmail.com>
@gabrielfu gabrielfu requested a review from harupy May 31, 2023 04:08
Signed-off-by: Gabriel Fu <hfu.gabriel@gmail.com>
Signed-off-by: Gabriel Fu <hfu.gabriel@gmail.com>
Signed-off-by: Gabriel Fu <hfu.gabriel@gmail.com>
Signed-off-by: Gabriel Fu <hfu.gabriel@gmail.com>
Signed-off-by: Gabriel Fu <hfu.gabriel@gmail.com>
@gabrielfu
Copy link
Collaborator Author

Sorry @harupy , I realized the client and test cases are incomplete, so I pushed a few new commits here

view_func=get_user,
methods=["POST"],
methods=["GET"],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

using GET here should be more appropriate

Copy link
Member

Choose a reason for hiding this comment

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

makes a perfect sense



@pytest.fixture
def client(tmp_path):
Copy link
Member

Choose a reason for hiding this comment

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

Awesome!

Comment on lines 53 to 56
def assert_unauthenticated(function):
with pytest.raises(MlflowException, match=r"You are not authenticated.") as exception_context:
function()
assert exception_context.value.error_code == ErrorCode.Name(UNAUTHENTICATED)
Copy link
Member

@harupy harupy May 31, 2023

Choose a reason for hiding this comment

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

Can we make this function context manager and remove lambda?

from contextlib import contextmanager

@contextmanager
def assert_unauthenticated():
    with pytest.raises(MlflowException, match=r"You are not authenticated.") as exception_context:
        yield
    assert exception_context.value.error_code == ErrorCode.Name(UNAUTHENTICATED)

didn't test this, but should work

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good idea! I'll change it!

Comment on lines 59 to 62
def assert_unauthorized(function):
with pytest.raises(MlflowException, match=r"Permission denied.") as exception_context:
function()
assert exception_context.value.error_code == ErrorCode.Name(PERMISSION_DENIED)
Copy link
Member

Choose a reason for hiding this comment

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

Signed-off-by: Gabriel Fu <hfu.gabriel@gmail.com>
Copy link
Member

@harupy harupy left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@harupy harupy left a comment

Choose a reason for hiding this comment

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

LGTM!

@harupy harupy merged commit 0098d23 into mlflow:master May 31, 2023
25 of 26 checks passed
@gabrielfu gabrielfu deleted the feat/auth-client branch June 29, 2023 02:45
@harupy harupy added the auth label Dec 22, 2023
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 auth rn/documentation Mention under Documentation Changes in Changelogs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants