Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

docker build from a private GitHub URL fails for an organization with SAML SSO

Error403 Forbidden or 404 Not Found when building from https://github.com/<org>/<repo>.git

Short 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.

  • Applies to Docker Engine 27, Docker Buildx 0.2x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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>.git
  2. 2Match what you see, then jump to its fix

    1. 1git ls-remote returns 403 or 404 with the same tokenThe classic token is not authorized for the organizationFix
    2. 2Authorize steps do not apply; the token has no entry for the organizationA fine-grained token was created without access to the organizationFix
    3. 3The token works in git but docker buildx build still failsThe build never receives the credentialFix

What does the error look like?

  • 403 Forbidden or 404 Not Found when building from https://github.com/<org>/<repo>.git
  • docker 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>.git

2Fix

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 > Authorize

3Verify

git ls-remote lists the repository refs.

git ls-remote https://github.com/<org>/<repo>.git

Confirmed by docs.github.com

Did this fix it?

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 tokens

2Fix

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 token

3Verify

git ls-remote with the new token lists refs.

git ls-remote https://github.com/<org>/<repo>.git

Confirmed by docs.github.com

Did this fix it?

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>.git

3Verify

BuildKit clones the repository and the build starts.

docker buildx build --progress=plain https://github.com/<org>/<repo>.git

Confirmed by docs.docker.com

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.