docker build from a private GitHub URL fails for an organization with SAML SSO
403 Forbidden or 404 Not Found when building from https://github.com/<org>/<repo>.gitShort answer
A GitHub organization that enforces SAML SSO refuses a classic personal access token or SSH key until you authorize it for that organization. Authorize the credential in GitHub settings, then hand it to the build as a secret, not a build argument.
Fix it fast
1Find out which cause you have
Test the same credential with git outside Docker. If git fails too, the problem is GitHub's SSO authorization, not Docker.
git ls-remote https://github.com/<org>/<repo>.git2Match what you see, then jump to its fix
- 1
git ls-remote returns 403 or 404 with the same tokenThe classic token is not authorized for the organizationFix - 2
Authorize steps do not apply; the token has no entry for the organizationA fine-grained token was created without access to the organizationFix - 3
The token works in git but docker buildx build still failsThe build never receives the credentialFix
- 1
What does the error look like?
403 Forbidden or 404 Not Found when building from https://github.com/<org>/<repo>.gitdocker buildx build with a git URL cannot read a private repository
Cause 1 of 3
The classic token is not authorized for the organization
1Check
A classic personal access token must be authorized after creation before it can reach an organization that enforces SAML SSO. Without that you get 404 Not Found or 403 Forbidden.
git ls-remote https://<user>:<token>@github.com/<org>/<repo>.git2Fix
In GitHub open Settings, Developer settings, Personal access tokens, click Configure SSO next to the token and Authorize beside the organization. If the button is missing, sign in through your identity provider once first. A revoked authorization cannot be restored; create a new token.
# GitHub web UI: Settings > Developer settings > Personal access tokens > Configure SSO > Authorize3Verify
git ls-remote lists the repository refs.
git ls-remote https://github.com/<org>/<repo>.gitConfirmed by docs.github.com
Cause 2 of 3
A fine-grained token was created without access to the organization
1Check
Fine-grained tokens are authorized during creation, before access to the organization is granted, so there is no later Configure SSO step.
# GitHub web UI: Settings > Developer settings > Fine-grained tokens2Fix
Create a new fine-grained token and grant it access to the organization while you create it.
# GitHub web UI: Developer settings > Fine-grained tokens > Generate new token3Verify
git ls-remote with the new token lists refs.
git ls-remote https://github.com/<org>/<repo>.gitConfirmed by docs.github.com
Cause 3 of 3
The build never receives the credential
1Check
BuildKit does not read your git login. For a private repository over HTTPS it reads a secret named GIT_AUTH_TOKEN, and for SSH it uses the agent you forward with --ssh. Do not pass tokens with --build-arg.
echo ${GIT_AUTH_TOKEN:+token is set}2Fix
Pass the token as a secret, or use SSH with a key that is authorized for the organization.
GIT_AUTH_TOKEN=<token> docker buildx build \
--secret id=GIT_AUTH_TOKEN \
https://github.com/<org>/<repo>.git
docker buildx build --ssh default git@github.com:<org>/<repo>.git3Verify
BuildKit clones the repository and the build starts.
docker buildx build --progress=plain https://github.com/<org>/<repo>.gitConfirmed by docs.docker.com
How do I stop it coming back?
- Use a fine-grained token limited to the repositories the build needs.
- Keep the token in the CI secret store and pass it only with --secret.
- Authorize SSH keys for the organization the same way as tokens.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
apk cannot find py-pip in an Alpine Docker image
py-pip (no such package):
On current Alpine releases there is no package called py-pip.
2 causes, each with a fixServers
ng serve runs in the container but localhost:4200 does not open
The browser cannot open localhost:4200 although ng serve is running in the container
ng serve listens on localhost by default, which inside a container is the container itself.
3 causes, each with a fixServers
Angular routes return 404 from nginx when you refresh or open a link
The home page loads, but refreshing /some/route shows an nginx 404
Angular routes like /users/42 are not files, so nginx looks for them on disk and returns 404.
3 causes, each with a fixServers
AH00558: Apache in Docker cannot reliably determine its fully qualified domain name
Set the 'ServerName' directive globally to suppress this message
AH00558 is a warning, not a crash.
2 causes, each with a fixServers
Apache in a Docker container logs AH01114 when it proxies to a backend
AH01114: HTTP: failed to make connection to backend: api
Apache's proxy worker could not open a connection to the address in ProxyPass.
5 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fix