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

Docker CI jobs fail with "failed to fetch oauth token: ... 401 Unauthorized" #4234

Closed
teor2345 opened this issue Apr 28, 2022 · 10 comments · Fixed by #4254, #4298 or #4370
Closed

Docker CI jobs fail with "failed to fetch oauth token: ... 401 Unauthorized" #4234

teor2345 opened this issue Apr 28, 2022 · 10 comments · Fixed by #4254, #4298 or #4370
Labels
A-devops Area: Pipelines, CI/CD and Dockerfiles C-bug Category: This is a bug I-integration-fail Continuous integration fails, including build and test failures

Comments

@teor2345
Copy link
Contributor

Motivation

Some Docker CI jobs fail with:

error: failed to solve: failed to fetch oauth token: unexpected status: 401 Unauthorized
Error: buildx failed with: error: failed to solve: failed to fetch oauth token: unexpected status: 401 Unauthorized

The failures don't seem to have a consistent pattern.

Potential Fixes

TODO: work out how to fix this

@teor2345 teor2345 added C-bug Category: This is a bug A-devops Area: Pipelines, CI/CD and Dockerfiles S-needs-triage Status: A bug report needs triage P-Medium ⚡ I-integration-fail Continuous integration fails, including build and test failures labels Apr 28, 2022
@gustavovalverde
Copy link
Member

I'll have to research further as this error might be misleading docker/build-push-action#586

@gustavovalverde
Copy link
Member

More insight: google-github-actions/auth#160

Might be an issue with GCP

@teor2345
Copy link
Contributor Author

teor2345 commented May 3, 2022

This is still happening on the main branch, even after the Konlet fix:
https://github.com/ZcashFoundation/zebra/runs/6267974240?check_suite_focus=true

@gustavovalverde
Copy link
Member

gustavovalverde commented May 3, 2022

@gustavovalverde
Copy link
Member

Adding more information, as changing to GitHub Registry didn't solve the problem:

@ftm1000 ftm1000 removed the S-needs-triage Status: A bug report needs triage label May 5, 2022
@conradoplg conradoplg mentioned this issue May 6, 2022
27 tasks
@teor2345
Copy link
Contributor Author

teor2345 commented May 9, 2022

Let me know if there is anything I can do to help with this.

@dougdonohoe
Copy link

dougdonohoe commented Jul 11, 2022

FYI to other internet seekers: I stumbled across this issue because I'm seeing a similar issue on GCP Cloud Build pushing to GCP Artifact Registry when the build is longer than an hour. I filed docker/buildx#1205 with the details.

There is a workaround (build without --push, stop builder, build again). Full details with reproducible example can be found at dougdonohoe/build-timeout.

@gustavovalverde
Copy link
Member

@dougdonohoe if it helps you, OIDC tokens expire after an hour...so you'll end up with an expired token when the push is happening. Our workaround was increasing this limit for OAuth tokens

Here's the specific change we applied to fix this https://github.com/ZcashFoundation/zebra/pull/4370/files#diff-5b40193e09025fd041de92d38c976d0b469e3ee85bef45a71d05d8b5078b1ee8R91

@dougdonohoe
Copy link

@dougdonohoe if it helps you, OIDC tokens expire after an hour...so you'll end up with an expired token when the push is happening. Our workaround was increasing this limit for OAuth tokens

Here's the specific change we applied to fix this https://github.com/ZcashFoundation/zebra/pull/4370/files#diff-5b40193e09025fd041de92d38c976d0b469e3ee85bef45a71d05d8b5078b1ee8R91

Thanks @gustavovalverde - I did see your fix. I haven't found a similar way to extend timeouts in GCP Cloud Build yet, but I'm looking for it and am asking Google for help too.

@guyLee687
Copy link

I believe you can also extend the timeout for cloud build using:

gcloud auth print-access-token --impersonate-service-account=<SERVICE_ACCOUNT> --lifetime=12h | docker login -u oauth2accesstoken --password-stdin https://us-docker.pkg.dev
docker-credential-gcr configure-docker --registries="us-docker.pkg.dev"

and having the cloud build service account impersonate a separate service account with extended credentials.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-devops Area: Pipelines, CI/CD and Dockerfiles C-bug Category: This is a bug I-integration-fail Continuous integration fails, including build and test failures
Projects
None yet
5 participants