-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Bazel 5.2 Google Cloud's Workload identity federation auth seems broken #15639
Comments
@coeuvre I see you made the cherry-pick adding the related PR to Bazel 5.2 in the first place. Maybe you have a clue about what is wrong? |
@bazaglia I'd like to look into this, but reproducing it seems to be quite involved. Do you have a repro that does not require setting up a GitHub action? I wonder if a fake credentials file (i.e., with sensitive data replaced by random strings) is sufficient to trigger the issue. |
@tjgq if you're interested I can set you up a GH repository to reproduce this pretty easily. |
I was also able to reproduce this today as well on my production repo. I believe my instructions from #14278 will still reproduce it with minimal effort. |
The difficult part for me isn't setting up the GitHub repository, it's configuring the GCP workload identity provider: the google.com GCP org policy forbids me from using I do have a working theory, though: in #15176 we upgraded @kylekurz Are you able to build Bazel with PR #16082 and let me know if you can still repro? |
@tjgq I will give this a shot. Might not get to it until tomorrow though. |
@tjgq sorry for the delay, been fighting migraines for a week. It doesn't look like that branch fixes this:
Let me know if I can get you more information. I built off the tip of your branch this morning. EDIT: I did do a second run and dumped the credentials file, so I'm not passing a broken path to Bazel. |
HttpHeaders.putAll uses reflective access. Well-known headers such as Content-Type or Authentication have dedicated fields of type List<String>, while remaining headers go into a Map<String, Object> grab bag. The IdentityPoolCredentials#getSubjectTokenFromMetadataServer method attempts to set every header to a String, which causes a crash for well-known headers. See bazelbuild/bazel#15639 for where this issue was first noticed.
I was able to repro this today. It looks like there's a bug in the |
IdentityPoolCredentials#getSubjectTokenFromMetadataServer calls HttpHeaders.putAll to set request headers. The latter sets its fields through reflective access: well-known headers such as Content-Type or Authentication have dedicated fields of type List<String>, while remaining headers go into a Map<String, Object> grab bag. However, we attempt to set every header to a String, which causes a crash for well-known headers. See bazelbuild/bazel#15639 for where this issue was first noticed.
IdentityPoolCredentials#getSubjectTokenFromMetadataServer calls HttpHeaders.putAll to set request headers. The latter sets its fields through reflective access: well-known headers such as Content-Type or Authentication have dedicated fields of type List<String>, while remaining headers go into a Map<String, Object> grab bag. However, we attempt to set every header to a String, which causes a crash for well-known headers. See bazelbuild/bazel#15639 for where this issue was first noticed.
IdentityPoolCredentials#getSubjectTokenFromMetadataServer calls HttpHeaders.putAll to set request headers. The latter sets its fields through reflective access: well-known headers such as Content-Type or Authentication have dedicated fields of type List<String>, while remaining headers go into a Map<String, Object> grab bag. However, we attempt to set every header to a String, which causes a crash for well-known headers. See bazelbuild/bazel#15639 for where this issue was first noticed.
IdentityPoolCredentials#getSubjectTokenFromMetadataServer calls HttpHeaders.putAll to set request headers. The latter sets its fields through reflective access: well-known headers such as Content-Type or Authentication have dedicated fields of type List<String>, while remaining headers go into a Map<String, Object> grab bag. However, we attempt to set every header to a String, which causes a crash for well-known headers. See bazelbuild/bazel#15639 for where this issue was first noticed.
I'm no longer convinced there's a bug in google-auth-library-oauth2-http. The test case I added in googleapis/google-auth-library-java#984 passes even without the fix (as the maintainer pointed out). I'm fairly sure PR #16082 was the right fix all along. I've just managed to run a GitHub action successfully with WIF using a Bazel built at that PR. |
In bazelbuild#15176 we upgraded google-auth-library-oauth2-http to 1.6.0, but didn't upgrade its dependencies accordingly; Maven claims 1.41.4 is needed [1]. In turn, a new transitive dependency on opencensus-contrib-http-util 0.31.0 also becomes necessary [2]. Fixes bazelbuild#15639. [1] https://mvnrepository.com/artifact/com.google.auth/google-auth-library-oauth2-http/1.6.0 [2] https://mvnrepository.com/artifact/com.google.http-client/google-http-client/1.41.4
@tjgq does that mean my build of your branch was wrong? I definitely didn't get a successful WIF run using that, but I can try again if you'd like. |
How exactly are you building and running Bazel? In particular, how does the built Bazel make it into the GitHub action execution environment? |
I have a GHA runner I manage in GCP so I can have local cache for some runs, so I just built the binary (on that machine) and called it directly from there instead of using the bazelisk wrapper. |
Ok, so here's how I verified that it works for me:
I've also confirmed that I get the reported crash if I check in a Bazel binary built without the changes in my PR. One thing you might want to try is grab the credentials JSON file and run the Bazel binary locally (to take some complexity out of the equation). I'm not sure that these credentials can be reused across build requests, but at least you seem to get Bazel to report a different error (I got something like a |
Is this going to be included in a release soon? |
It will definitely be included in 6.0, but I'm reluctant about backporting it to 5.3.1. There's a lot of complexity in the interaction between Bazel and the OAuth2 support libraries, and we could very easily introduce other bugs. |
@tjgq so I'm still not entirely sure what I did wrong building your branch, but I think I agree that your fix works. I took the binary in your test repo and put it on my CI machine, then ran a job that used it and it worked perfectly. Thanks for your research here, I will be watching for when this hits a released version of Bazel! |
In bazelbuild#15176 we upgraded google-auth-library-oauth2-http to 1.6.0, but didn't upgrade its dependencies accordingly; Maven claims 1.41.4 is needed [1]. In turn, a new transitive dependency on opencensus-contrib-http-util 0.31.0 also becomes necessary [2]. Fixes bazelbuild#15639. [1] https://mvnrepository.com/artifact/com.google.auth/google-auth-library-oauth2-http/1.6.0 [2] https://mvnrepository.com/artifact/com.google.http-client/google-http-client/1.41.4 Partial commit for third_party/*, see bazelbuild#16082. Signed-off-by: Sunil Gowroji <[email protected]>
In bazelbuild#15176 we upgraded google-auth-library-oauth2-http to 1.6.0, but didn't upgrade its dependencies accordingly; Maven claims 1.41.4 is needed [1]. In turn, a new transitive dependency on opencensus-contrib-http-util 0.31.0 also becomes necessary [2]. Fixes bazelbuild#15639. [1] https://mvnrepository.com/artifact/com.google.auth/google-auth-library-oauth2-http/1.6.0 [2] https://mvnrepository.com/artifact/com.google.http-client/google-http-client/1.41.4 Partial commit for third_party/*, see bazelbuild#16082. Signed-off-by: Sunil Gowroji <[email protected]>
FYI, I'm going to backport this into 5.4.0 because I got a report of another user running into an issue related to this. |
In #15176 we upgraded google-auth-library-oauth2-http to 1.6.0, but didn't upgrade its dependencies accordingly; Maven claims 1.41.4 is needed [1]. In turn, a new transitive dependency on opencensus-contrib-http-util 0.31.0 also becomes necessary [2]. Fixes #15639. [1] https://mvnrepository.com/artifact/com.google.auth/google-auth-library-oauth2-http/1.6.0 [2] https://mvnrepository.com/artifact/com.google.http-client/google-http-client/1.41.4 Partial commit for third_party/*, see #16082. Signed-off-by: Sunil Gowroji <[email protected]> Signed-off-by: Sunil Gowroji <[email protected]>
Description of the bug:
Bazel 5.2 updated to the Google Auth library, which supports Workload identity federation, useful for keyless authentication from pipelines. This can be verified in #15383. However, when providing the credentials file through the
google_credentials
flag:Bazel just throws an error:
What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Which operating system are you running Bazel on?
Linux on Github Actions
What is the output of
bazel info release
?5.2.0
If
bazel info release
returnsdevelopment version
or(@non-git)
, tell us how you built Bazel.No response
What's the output of
git remote get-url origin; git rev-parse master; git rev-parse HEAD
?No response
Have you found anything relevant by searching the web?
#14278
Any other information, logs, or outputs that you want to share?
No response
The text was updated successfully, but these errors were encountered: