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

Enable broker support on Linux for WSL #766

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from

Conversation

DharshanBJ
Copy link
Contributor

No description provided.

@DharshanBJ DharshanBJ requested a review from a team as a code owner November 7, 2024 00:34
@DharshanBJ
Copy link
Contributor Author

/azp run MSAL-Python-SDL-CI

Copy link
Contributor

@fengga fengga left a comment

Choose a reason for hiding this comment

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

Thanks, this PR looks good to me. And please make sure get an approval from Ray.

@@ -200,6 +200,7 @@ def _build_app(cls,
http_client=http_client or MinimalHttpClient(),
enable_broker_on_windows=broker_available,
enable_broker_on_mac=broker_available,
enable_broker_on_linux=broker_available,
Copy link
Collaborator

Choose a reason for hiding this comment

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

praise: Thanks for finding this test file!

suggestion: If you haven't already, please also do python -m unittest tests.test_e2e and make sure we won't run into any issue. Note that you will need to setup an .env first, whose content is described at the beginning of this test_e2e.py file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't support POP and ssh-cert flows for linux yet, tested the other e2e flows.

Copy link
Collaborator

@rayluo rayluo left a comment

Choose a reason for hiding this comment

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

Thanks for a clean PR! Implementation wise, it looks good. I added some suggestions above, mostly in terms of our workflow. Please make corresponding changes and then wait for the PyMsalRuntime release.

Copy link
Collaborator

@rayluo rayluo left a comment

Choose a reason for hiding this comment

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

@DharshanBJ
Copy link
Contributor Author

We will also need to change the precise dependency version error message here and a approximate version hint there

updated

@DharshanBJ DharshanBJ changed the title Enable broker support on Linux Enable broker support on Linux for WSL Jan 14, 2025
@thomasaarholt
Copy link

thomasaarholt commented Feb 17, 2025

@DharshanBJ, I would love to see this wrapped up.

I arrived here after trying to debug errors with using msal on WSL. This PR worked "as-advertised" and made my life a whole lot easier.

Before your PR, the following snippet kept returning a browser window with The redirect URI 'http://localhost:<some port number>' specified in the request does not match the redirect URIs configured for the application.

Testing with enable_broker_on_linux=True "just worked". 🚀

    app = PublicClientApplication(
        <client_id>,
        authority=<authority>,
        enable_broker_on_linux=True,
    )
    app.acquire_token_interactive(...)

@thomasaarholt
Copy link

This work enables Data Scientists at Microsoft to develop and debug their pipelines better. Some of our models are deployed on linux environments. We believe that it is crucial to develop and test our work on the same environment that we deploy on, which is why I highly approve of this PR 😊

@rayluo any chance you could take a look at the state of this PR when you have the time?

@thomasaarholt
Copy link

I have one oddity. When using the broker on Linux, I get the following text printed "{{\"ping\",\"success\"}}}"
image

This does not happen on Windows:
image

@DharshanBJ
Copy link
Contributor Author

I have one oddity. When using the broker on Linux, I get the following text printed "{{\"ping\",\"success\"}}}" image

This does not happen on Windows: image

The "{{"ping","success"}}}" message is expected on WSL, it's from initializing the msal.wsl.proxy execuatble which is needed to talk to the windows broker on WSL.
On pure windows, msal.wsl.proxy is not needed and hence we dont see "{{"ping","success"}}}"

@@ -704,7 +704,7 @@ def _decide_broker(self, allow_broker, enable_pii_log):

def is_pop_supported(self):
"""Returns True if this client supports Proof-of-Possession Access Token."""
return self._enable_broker
return self._enable_broker and sys.platform != "linux"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Avoid using logic like "if var != one_thing", because you never know what the rest of things are. In this case, sys.platform has much more values than we should use.

Change this to sys.platform in ("win32", "darwin"). Same applies to other occurrences. Define a new internal helper when appropriate.

Comment on lines +1579 to +1582
is_ssh_cert_or_pop_request = (
data.get("token_type") == "ssh-cert" or
data.get("token_type") == "pop" or
isinstance(auth_scheme, msal.auth_scheme.PopAuthScheme))
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are two same snippets in this PR. How about refactoring it into an internal helper like this?

def _is_ssh_cert_or_pop_request(token_type, auth_scheme) -> bool:
    ...

@rayluo
Copy link
Collaborator

rayluo commented Feb 20, 2025

I have one oddity. When using the broker on Linux, I get the following text printed "{{\"ping\",\"success\"}}}"

The "{{"ping","success"}}}" message is expected on WSL, it's from initializing the msal.wsl.proxy execuatble which is needed to talk to the windows broker on WSL. On pure windows, msal.wsl.proxy is not needed and hence we dont see "{{"ping","success"}}}"

@DharshanBJ , that feels like some sort of debug log. Could it be turned off or removed from that "msal.wsl.proxy"?

CC: @jiasli

"""
if client_credential is not None:
raise ValueError("Public Client should not possess credentials")
# Using kwargs notation for now. We will switch to keyword-only arguments.
enable_broker_on_windows = kwargs.pop("enable_broker_on_windows", False)
enable_broker_on_mac = kwargs.pop("enable_broker_on_mac", False)
enable_broker_on_linux = kwargs.pop("enable_broker_on_linux", False)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The dev branch has received new changes. Please merge that into your branch, and then remove this line and add the new parameter into __init__().

@@ -2162,7 +2180,9 @@ def acquire_token_interactive(
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

One more thing. MSAL Python's caller (such as Azure CLI) can specify a parameter app.acquire_token_interactive(..., prompt="select_account") which will in turn call pymsalruntime.signin_interactively(). On Windows, that function will pop up the account selector, as requested. But on WSL, it does not pop any UI, and seemingly just return a token for the current user.

Is that expected, @DharshanBJ ? (Note that az login usually expects an account picker.) CC: @jiasli

@rayluo
Copy link
Collaborator

rayluo commented Feb 21, 2025

it is crucial to develop and test our work on the same environment that we deploy on, which is why I highly approve of this PR 😊

@thomasaarholt , we agree with that part. Is your work going to be deployed on WSL or on standalone Linux (which may or may not have Intune installed)?

Keep in mind that this PR is mainly targeting WSL. On standalone Linux, unless Intune is installed, MSAL Python will still fall back to browser-based UI. If your work after deployment will mainly run on standalone Linux without Intune, you might want to still focus testing the browser-based experience, for the same reason that you mentioned above.

FWIW, the default browser-based experience unfortunately deteriorates on WSL but technically still functions. In a freshly installed WSL ubuntu, it would end up with a message like this on the console "gio: http://localhost:1234/...: Operation not supported", but the app developer on WSL can still click on that url to bring up a browser page and completes the sign-in there. (Those are known issues here and there.) If your end user is mainly on standalone Linux, the browser will typically automatically pop up without issue.

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.

5 participants