-
Notifications
You must be signed in to change notification settings - Fork 3k
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
az login does not work in GitHub Codespaces #20315
Comments
@jiasli for awareness |
This should be a workaround Add to devcontainer.json "forwardPorts": [
8400
], But would be nice if CLI defaulted to --use-device-code if in CODESPACES |
I hit this regularly and have to use The CLI + Codespaces correctly opens a new browser tab and I'm able to authenticate with AAD. After auth, I am redirected to If I take that localhost url that fails and run It also works if I replace My desired experience is that azure-cli would detect if I'm running it in a codespace terminal session by inspecting the |
@yonzhan - Did the redirect port change? I was able to do this before with forwardPorts, but the az cli redirect to localhost port changed recently |
Can we configure it to be a static port for the codespace scenario? |
Maybe a solution is to add |
@jongio , the port always changes. This is also the case on ssh-remote connection. The port-redirect needs to be set just before launching the browser to authenticate, as the url should contains a |
@jiasli would you be willing to accept a PR for this? GitHub CLI solved this, and this could also be solved quite easily in Azure CLI without any additional flags, as Codespaces exposes environment variables that you can use to detect:
If you're ok with that I can submit a PR for it. |
The Azure Developer CLI (azd) can only use redirect to localhost after login. The login flow would block any other redirect-url as |
@vhvb1989 Surely that should be doable to update the Azure Identity for AZ CLI to add *githubpreview.dev to the list of allowed redirects. |
@sinedied , yes, it is a little more complicated than it should... Adding a new redirect url. Azd has not direct access to add the url, it need to be a chain of requests and approvals :( |
I can reproduce this issue in my local devcontainer (WSL2, Windows 11). Adding the port manually every time does fix this issue. |
@jiasli - I'm seeing this again today and don't have a workaround. Can we look into this? |
I made a PR a while back that detects Codespaces and fall back to device code as a workaround: #27443 |
@vhvb1989 is correct. AAD blocks arbitrary
AAD will fail with
See below excerpt from https://learn.microsoft.com/en-us/entra/identity-platform/reply-url#restrictions-on-wildcards-in-redirect-uris
Related: MicrosoftDocs/azure-docs#94968 |
Hey, same problem here. We can't use device code (device authorization grant) due to internal policy. The workaround to change the URL after the redirection (from |
@dorianm , the simplest solution/workaround I know is to open the codespace with VSCode - desktop client for doing login. Then you can switch back to browser client. There is an option from bottom left corner, when you are on web-codespaces to re-open the codespace with your desktop client. This should be fixed in the long term when codespaces add support for managed identity, like an Azure VM |
@vhvb1989, @dorianm there is a simpler workaround that works inside Codespaces just use this command to simulate how az login --use-device-code This is from a tested azd template btw for terraform which requires az login to work with azd |
@john0isaac this is what I proposed in my PR, but it seems some companies disable device code usage so it does not always work 😞 Though it's good enough as a general workaround! |
I missed that some companies have these internal policies.. |
I use codespaces quite a lot, and I find that log in to Azure needs the --use-device-code flag set.
|
@jiasli for this part
As I mentioned in MicrosoftDocs/azure-docs#94968 (comment), you actually can put a wildcard in the form of |
Issue:
|
It's been 3 years and this is still a problem. If the challenge is that MSAL chooses ports at random, is the simpler solution to first make a fix to that library to enforce a static port selection so that folks can then hardcode configure a codespace with that port? P.S. for some companies, internal policiess restrict the full use and permissions of using |
I don't think that's the root issue. |
We have merged #27443 to force
Supporting redirect port selection in @vhvb1989 is correct. Auth code flow is meant to be used on the same device (where CLI is run and where the browser is launched). GitHub Codespaces is essentially another device and not |
@jgbradley1 , Have you tried this workaround:
|
Describe the bug
az login with default options doesn't work with GitHub Codespaces. It fails when trying to hit localhost on response.
To Reproduce
Open GitHub Codespaces.
run az upgrade to get to 2.30
run az login in GitHub Codespaces, the default codespace is fine.
This is printed:
**Workaround **
--use-device-code
optionCODESPACES=true
env var and callaz login
with--use-device-code
Expected behavior
It should work in GitHub Codespaces with default options.
Environment summary
GitHub Codespaces
Linux-5.4.0-1062-azure-x86_64-with-debian-bullseye-sid, Ubuntu 20.04.3 LTS
Python 3.6.10
Installer: DEB
azure-cli 2.30.0
Additional context
The text was updated successfully, but these errors were encountered: