Skip to content

internal/oauth: use BROWSER env var to open the login URL - #7409

Closed
GitNimay wants to merge 2 commits into
docker:masterfrom
GitNimay:6751-oauth-browser-env
Closed

GitNimay wants to merge 2 commits into
docker:masterfrom
GitNimay:6751-oauth-browser-env

Conversation

@GitNimay

Copy link
Copy Markdown
Contributor

Summary

The web-based docker login flow opens the device confirmation URL with github.com/pkg/browser. On Linux, that only tries a fixed set of launchers (xdg-open, x-www-browser, www-browser). In dev containers, none of these may be installed. Users there need a way to forward the URL to the host browser.

This PR makes the CLI use the command from the BROWSER environment variable when it's set. Other tools use the same convention, for example the GitHub CLI (go-gh).

  • The value is split on whitespace, so a command with arguments works: BROWSER="my-url-opener --flag".
  • If the command can't be started (e.g. not found), the CLI falls back to the default browser, and the error is logged at debug level.
  • If BROWSER is unset or empty, the behavior is unchanged.
$ BROWSER="my-url-opener --flag" docker login

Changes:

  • internal/oauth/manager: added openURL, which is now the default OpenBrowser implementation.
  • Added TestOpenURLWithBrowserEnv (sets BROWSER="touch -m" and checks that the command ran with the URL as its last argument).
  • docs/reference/commandline/login.md: documented the BROWSER variable for web-based login.

Release notes (optional)

`docker login` now uses the `BROWSER` environment variable, if set, to open the web-based login URL.

The web-based login flow opens the device confirmation URL with
github.com/pkg/browser, which only tries a fixed set of launchers
(xdg-open, x-www-browser, www-browser on Linux). In environments such
as dev containers, none of these may be installed, and users need a
way to forward the URL to a browser on the host.

Use the command from the BROWSER environment variable when it is set,
following the same convention as other tools such as the GitHub CLI.
If the command can't be started, fall back to the default browser.

Signed-off-by: Nimesh Kulkarni <167794819+GitNimay@users.noreply.github.com>
@GitNimay
GitNimay requested review from a team and thaJeztah as code owners October 19, 2026 09:05
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/oauth/manager/manager.go 66.66% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

The command is chosen by the user through the BROWSER environment
variable, so launching it is the intended behavior.

Signed-off-by: Nimesh Kulkarni <167794819+GitNimay@users.noreply.github.com>
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.

Support BROWSER env variable when selecting a browser to launch for oauth2

2 participants