Skip to content

feat(agent): pull through a registry mirror, then the source registry (MK8S-553) - #81

Draft
ezekiel-alexrod wants to merge 2 commits into
improvement/MK8S-451-scope-plain-httpfrom
improvement/MK8S-553-registry-mirror
Draft

ezekiel-alexrod wants to merge 2 commits into
improvement/MK8S-451-scope-plain-httpfrom
improvement/MK8S-553-registry-mirror

Conversation

@ezekiel-alexrod

@ezekiel-alexrod ezekiel-alexrod commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #77 (MK8S-451): the mirror goes through its plain HTTP list. I'll rebase on main once #77 merges.

Component

agent, docs

Problem

go-containerregistry has no mirror support. So today an ImageCache source has to carry the registry address, like <ip>:5000/metalk8s-<ver>/..., while containerd pulls ghcr.io/scality/... and lets its mirror config redirect it. We want the same canonical name in the ImageCache resources.

Fix

  • Agent and imagecachectl import: a --mirror=<host[:port]> flag. A source ghcr.io/scality/x:1.0 is pulled from <mirror>/v2/scality/x/...?ns=ghcr.io first, as containerd does, then from ghcr.io if the mirror fails. When both fail, the error carries both causes.
  • Rewritten reference, not a rewritten host: the puller builds <mirror>/<repository>:<tag> (or @<digest>) and a small RoundTripper (withNamespace) only adds ns. So the library picks the scheme for the real mirror host, --ca-file and --plain-http-registry apply to it like to any registry, and errors name the mirror. Swapping the host in the transport would keep the HTTPS scheme of ghcr.io and break with a plain HTTP mirror.
  • The fallback is decided when the manifest and config are resolved. Layers stream from whichever answered, so a mirror lost mid-stream fails the pull and the next pass resolves again.
  • imagecachectl: with --mirror, --plain-http goes to the mirror, not to the source's registry. On a node the mirror is the local registry without TLS, and the source names a real one that keeps HTTPS.
  • Docker Hub goes as ns=docker.io, like containerd. A source that already names the mirror is pulled once, with no ns.

Design: scality/citadel#399, section "Registry mirror".

The interesting part is open and withNamespace in agent/internal/puller/puller.go. I'd like feedback on the approach and on the imagecachectl --plain-http choice.

Test

Check Result
make -C agent test, make -C agent lint OK
go test -race on puller and cli OK
Unit: mirror first with ns=<registry>, fallback, both failures in the error, digest reference, Docker Hub ns, source on the mirror itself, CA applied to the mirror, unlisted mirror kept HTTPS only, invalid mirror refused OK
make -C agent test-e2e on kind: source only on the mirror is synced, then the mirror is stopped and a second ImageCache is synced from the registry 7/7 specs OK

Out of scope

  • One mirror per registry.
  • Switching the MetalK8s Salt states to the canonical source and passing --mirror (follow-up in metalk8s).
  • A mirror that drops packets costs a dial timeout on every resolve, and nothing is logged while the registry answers. Not handled here.

  • Docs updated: README.md, agent/README.md, agent/DESIGN.md.
  • Cache layout change. Not applicable.

Relates-to: MK8S-553

--plain-http marked every registry insecure, so go-containerregistry
raced HTTPS and HTTP for all of them: a registry serving HTTPS no longer
failed on a bad certificate, and anyone on the path could answer the
HTTP attempt. It also excluded --ca-file, leaving a site with one plain
HTTP registry and one signed by a private CA with no working setting.

Replace it on the agent with --plain-http-registry=<host[:port]>,
repeatable. Only a source whose registry matches an entry exactly is
marked insecure; every other registry stays HTTPS only. Entries are
validated and normalized at startup and logged with a warning. The list
goes with --ca-file and still excludes --insecure-skip-tls-verify.

Marking a registry is not the only way the library reaches for HTTP: it
also races HTTP on its own for a private or loopback IP address and for
a localhost name, whatever the list says, and nothing turns that off.
Every pull therefore goes through a transport that refuses a plain HTTP
request to an unlisted registry before it leaves, so only the HTTPS
attempt is left and a bad certificate fails the pull again. Without it,
a registry on a private address, the usual case on premises, would be
reached over plain HTTP listed or not.

imagecachectl import keeps its --plain-http switch, now scoped to the
registry of its single source, and goes through the same transport.

BREAKING CHANGE: the agent no longer accepts --plain-http and refuses to
start with it. Pass --plain-http-registry with the registry the
ImageCache sources name instead. A plain HTTP registry on a private or
loopback IP address or a localhost name, which the library used to reach
over HTTP unlisted, must now be listed too, and imagecachectl import
needs --plain-http for it.
The library has no mirror support, so a source had to name the registry
address. With --mirror, a source keeps its real name, like
ghcr.io/scality/x:1.0, and is pulled from <mirror>/scality/x:1.0 with
ns=ghcr.io first, as containerd does. When the mirror fails, the
registry the source names is tried, and the error carries both causes.

The reference is rewritten rather than the host of each request, so
--ca-file and --plain-http-registry apply to the mirror like to any
registry. imagecachectl takes the same flag, and its --plain-http then
goes to the mirror.

Refs: MK8S-553
@ezekiel-alexrod
ezekiel-alexrod force-pushed the improvement/MK8S-553-registry-mirror branch from 3534b53 to 2a7c6b1 Compare November 23, 2026 14:02
@riadelhajjaji-scality
riadelhajjaji-scality force-pushed the improvement/MK8S-451-scope-plain-http branch from f108e11 to 5bb8cd5 Compare November 24, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants