From 28f65772cdcc970be32380950a585046a5482f3c Mon Sep 17 00:00:00 2001 From: Ahmed El-Sharnoby Date: Sun, 22 Feb 2026 04:59:20 +0000 Subject: [PATCH 1/3] Add Configuration variable to allow using custom Authorization header --- README.md | 5 +++++ core/core.go | 9 +++++++++ httputil/httputil.go | 16 ++++++++++++---- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e11549da..964ced04 100644 --- a/README.md +++ b/README.md @@ -241,6 +241,11 @@ This behavior can be disabled by setting the environment variable `BAZELISK_SKIP You can control the user agent that Bazelisk sends in all HTTP requests by setting `BAZELISK_USER_AGENT` to the desired value. +You can set the Authorization header that Bazelisk sends in all HTTP requests by setting `BAZELISK_AUTH_HEADER` to the desired value. +```shell +export BAZELISK_AUTH_HEADER="bearer " +``` + # .bazeliskrc configuration file A `.bazeliskrc` file in the root directory of a workspace or the user home directory allows users to set environment variables persistently. (The Python implementation of Bazelisk doesn't check the user home directory yet, only the workspace directory.) diff --git a/core/core.go b/core/core.go index 2fcaad8e..42224bad 100644 --- a/core/core.go +++ b/core/core.go @@ -106,6 +106,7 @@ func RunBazeliskWithArgsFuncAndConfigAndOut(argsFunc ArgsFunc, repos *Repositori // repositories and config, writing its stdout and stderr to the passed writers. func RunBazeliskWithArgsFuncAndConfigAndOutAndErr(argsFunc ArgsFunc, repos *Repositories, config config.Config, stdout, stderr io.Writer) (int, error) { httputil.UserAgent = getUserAgent(config) + httputil.AuthHeader = getAuthHeader(config) // bazeliskVersion command must be the only argument if len(os.Args[1:]) == 1 && os.Args[1] == "bazeliskVersion" { @@ -324,6 +325,14 @@ func getUserAgent(config config.Config) string { return fmt.Sprintf("Bazelisk/%s", BazeliskVersion) } +func getAuthHeader(config config.Config) string { + auth_header := config.Get("BAZELISK_AUTH_HEADER") + if len(auth_header) > 0 { + return auth_header + } + return "" +} + // GetBazelVersion returns the Bazel version that should be used. func GetBazelVersion(config config.Config) (string, error) { // Check in this order: diff --git a/httputil/httputil.go b/httputil/httputil.go index 0103d29b..e12e5b32 100644 --- a/httputil/httputil.go +++ b/httputil/httputil.go @@ -28,6 +28,8 @@ var ( DefaultTransport = http.DefaultTransport // UserAgent is passed to every HTTP request as part of the 'User-Agent' header. UserAgent = "Bazelisk" + // AuthHeader is optionally set to a value that is passed as part of the 'Authorization' header in HTTP requests. + AuthHeader = "" linkPattern = regexp.MustCompile(`<(.*?)>; rel="(\w+)"`) // RetryClock is used for waiting between HTTP request retries. @@ -215,10 +217,16 @@ func DownloadBinary(originURL, destDir, destFile string, config config.Config) ( log.Printf("Downloading %s...", originURL) var auth string = "" - t, err := tryFindNetrcFileCreds(u.Host) - if err == nil { - // successfully parsed netrc for given host - auth = t + if AuthHeader != "" { + // If AuthHeader is set, use it as the Authorization header. + log.Printf("Authorization header is set using BAZELISK_AUTH_HEADER, using it for %s", u.Host) + auth = AuthHeader + } else { + t, err := tryFindNetrcFileCreds(u.Host) + if err == nil { + // successfully parsed netrc for given host + auth = t + } } resp, err := get(originURL, auth) From c859aa3a16b1abece4d44087ae998ae1a39fc672 Mon Sep 17 00:00:00 2001 From: Ahmed El-Sharnoby Date: Sun, 22 Feb 2026 04:59:20 +0000 Subject: [PATCH 2/3] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 964ced04..79cfe517 100644 --- a/README.md +++ b/README.md @@ -243,7 +243,7 @@ You can control the user agent that Bazelisk sends in all HTTP requests by setti You can set the Authorization header that Bazelisk sends in all HTTP requests by setting `BAZELISK_AUTH_HEADER` to the desired value. ```shell -export BAZELISK_AUTH_HEADER="bearer " +export BAZELISK_AUTH_HEADER="Bearer " ``` # .bazeliskrc configuration file @@ -274,6 +274,7 @@ The following variables can be set: - `BAZELISK_SHUTDOWN` - `BAZELISK_SKIP_WRAPPER` - `BAZELISK_USER_AGENT` +- `BAZELISK_AUTH_HEADER` - `BAZELISK_VERIFY_SHA256` - `USE_BAZEL_VERSION` From d11b215edeed9fe46e9ccf81345ce712b72c5d53 Mon Sep 17 00:00:00 2001 From: Ahmed El-Sharnoby Date: Sun, 22 Feb 2026 05:05:25 +0000 Subject: [PATCH 3/3] Apply Suggestion --- core/core.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/core/core.go b/core/core.go index 42224bad..a926c63b 100644 --- a/core/core.go +++ b/core/core.go @@ -326,11 +326,7 @@ func getUserAgent(config config.Config) string { } func getAuthHeader(config config.Config) string { - auth_header := config.Get("BAZELISK_AUTH_HEADER") - if len(auth_header) > 0 { - return auth_header - } - return "" + return config.Get("BAZELISK_AUTH_HEADER") } // GetBazelVersion returns the Bazel version that should be used.