feat(oc-mirror): authenticate to ACR with a Go binary - #6668
Draft
Wenqi He (weherdh) wants to merge 1 commit into
Draft
feat(oc-mirror): authenticate to ACR with a Go binary#6668Wenqi He (weherdh) wants to merge 1 commit into
Wenqi He (weherdh) wants to merge 1 commit into
Conversation
mirror.sh authenticated by running 'az acr login' with DOCKER_COMMAND pointed at a shim script, so az's internal 'docker login' call was intercepted and the credential scraped out of its arguments. That broke silently when azure-cli 2.88.0 switched to --password-stdin: the job kept reporting success while mirroring nothing. The shim's jq rewrite also overwrote auth.json, discarding the registry.redhat.io credentials the init container had written there. Replace it with the acrauth binary, which exchanges the managed identity's Entra token for an ACR refresh token and upserts a single registry key into the auth file. az is no longer on the authentication path, so a CLI upgrade cannot change our behaviour. AZURE_CLIENT_ID is now optional, which lets the local dry-run targets fall back to the ambient az credential; previously 'set -u' made them fail outright.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: weherdh The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Skipping CI for Draft Pull Request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Warning
Draft — blocked on Azure/ARO-Tools#321.
tooling/acrauth/go.modcarries a temporaryreplacepointing at a localARO-Tools checkout. That must be swapped for a published pseudo-version
before this can merge.
Why
mirror.shauthenticated to ACR like this:DOCKER_COMMAND=/usr/local/bin/docker-login.sh az acr login -n "${REGISTRY}"az acr loginalways persists credentials by exec'ingdocker login, so we pointedDOCKER_COMMANDat a shim that intercepted that call and scraped the credential out ofits arguments.
That coupling broke when azure-cli 2.88.0 (2026-07-07) switched to
--password-stdin.The shim's positional parsing shifted, it wrote a garbage credential, and the job kept
reporting success while mirroring nothing. The image is built from a single digest
shared by all environments, so every environment was affected simultaneously. It went
unnoticed until STG's registries were emptied for an unrelated reason and there was no
longer a stale-but-present catalog masking it.
Separately, the shim's
jqrewrite replacedauth.jsonwholesale, discarding theregistry.redhat.iocredentials thedecodesecretsinit container had already writtento that same file.
The root problem is that our authentication depended on the internal argv layout of a CLI
we deliberately do not pin —
tdnf update -yis required by thesecure supply chain policy.
That is not a contract we can rely on.
What
Do the exchange directly.
acrauth logintrades the managed identity's Entra token for anACR refresh token and upserts a single registry key into the auth file, leaving other
registries and unmodelled fields (
email,identitytoken) intact./usr/local/bin/acrauth login \ --registry "${REGISTRY_URL}" \ --auth-file "${XDG_RUNTIME_DIR}/containers/auth.json" \ --client-id "${AZURE_CLIENT_ID:-}"azis no longer on the authentication path, so a CLI upgrade cannot change our behaviour.Also in here:
AZURE_CLIENT_IDis now optional. The oldaz login --identity --client-id "${AZURE_CLIENT_ID}"underset -umeant the local*-dry-runtargets could never run. Empty now falls back to the ambient credential, which the Makefile already mounts via-v ${HOME}/.azure:/root/.azure.frontend/Dockerfileand friends) so the Go module can be compiled in.docker-login.shis deleted.Testing
Verified against the live
arohcpocpdevregistry:oras repo ls --registry-config <our auth.json>registry.redhat.ioentry (incl.email) preserved0600--dry-run)✓ 1 / 1 additional images mirrored successfullyThe last row is end-to-end:
oc-mirrorauthenticated to the ACR and pushed an image usingonly the credential this binary wrote.
Two bugs were caught by that testing and are already fixed:
CGO_ENABLED=0compiles on stock Go but fails on the Microsoft FIPS toolchain this repo uses — nowCGO_ENABLED=1 GOFIPS140=latest, matchingfrontend/Dockerfile.rename(2)over a bind-mountedauth.jsonreturnsEBUSY, which the dry-run targets hit; handled in ARO-Tools#321.Notes for reviewers
config/config.yamlstill needs bumping once this builds.