Skip to content

daemon: do not append defaults if insecure-registries are configured - #53868

Merged
thaJeztah merged 2 commits into
moby:masterfrom
thaJeztah:no_insecure_registries
Nov 12, 2026
Merged

thaJeztah merged 2 commits into
moby:masterfrom
thaJeztah:no_insecure_registries

Conversation

@thaJeztah

@thaJeztah thaJeztah commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

daemon: align localhost registry handling with Docker configuration

Containerd implicitly allows HTTP for localhost registries based on their hostname or loopback IP address, independently of Docker's insecure registry configuration.

Docker also considers DNS resolution when determining whether a registry is insecure, and may explicitly configure localhost as secure.

Override containerd's implicit HTTP fallback when Docker considers the registry secure, while preserving explicit containerd host configuration.

daemon: do not append defaults if insecure-registries are configured

Previously, the daemon unconditionally added localhost ("::1/128", "127.0.0.0/8") addresses as insecure registries, even if insecure registries were configured by the user.

This patch changes the behavior to only configure the defaults if not configured. This makes sure that only the configured addresses are set as "insecure", and allows opting-out of the defaults by setting an empty slice in daemon.json ({"insecure-registries":[]}).

Note that disabling insecure registries through the command-line (--insecure-registry) flags is currently not possible, as these flags do not accept an empty value.

Summary

Release notes (optional)

Stop automatically treating loopback registries as insecure when `insecure-registries` is explicitly configured, and allow disabling the default insecure registries by setting `"insecure-registries": []` in `daemon.json`.

A picture of a cute animal (not mandatory but encouraged)

@github-actions github-actions Bot added the area/daemon Core Engine label Oct 6, 2026
@thaJeztah
thaJeztah force-pushed the no_insecure_registries branch from 78ca29c to 1cabdd2 Compare October 6, 2026 18:14
@thaJeztah
thaJeztah force-pushed the no_insecure_registries branch 2 times, most recently from ac78ae3 to 824ef7c Compare October 7, 2026 13:03
@thaJeztah
thaJeztah marked this pull request as ready for review October 7, 2026 18:21
Comment on lines +111 to +137
t.Run("defaults", func(t *testing.T) {
t.Parallel()
d := daemon.New(t)
defer d.Stop(t)
d.Start(t, "--iptables=false", "--ip6tables=false")
info := d.Info(t)

expectedCIDRS := []netip.Prefix{
netip.MustParsePrefix("127.0.0.0/8"),
netip.MustParsePrefix("::1/128"),
}
assert.DeepEqual(t, info.RegistryConfig.InsecureRegistryCIDRs, expectedCIDRS, cmpopts.EquateComparable(netip.Prefix{}))
})

t.Run("insecure-registries", func(t *testing.T) {
t.Parallel()
d := daemon.New(t)
defer d.Stop(t)
d.Start(t, "--insecure-registry="+registryCIDR, "--insecure-registry="+registryHost, "--iptables=false", "--ip6tables=false")
info := d.Info(t)
d.Stop(t)

expectedCIDRS := []netip.Prefix{netip.MustParsePrefix(registryCIDR)}
assert.DeepEqual(t, info.RegistryConfig.InsecureRegistryCIDRs, expectedCIDRS, cmpopts.EquateComparable(netip.Prefix{}))
assert.DeepEqual(t, *info.RegistryConfig.IndexConfigs["docker.io"], registry.IndexInfo{Name: "docker.io", Mirrors: []string{}, Secure: true, Official: true})
assert.DeepEqual(t, *info.RegistryConfig.IndexConfigs[registryHost], registry.IndexInfo{Name: registryHost, Mirrors: []string{}, Secure: false, Official: false})
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm I think we also need a test where we test the [] empty value.

I think right now it won't work for the containerd image store because of:

moby/daemon/hosts.go

Lines 28 to 37 in 824ef7c

func (daemon *Daemon) RegistryHosts(host string) ([]docker.RegistryHost, error) {
hosts, err := hostconfig.ConfigureHosts(context.Background(), hostconfig.HostOptions{
// TODO: Also check containerd path when updating containerd to use multiple host directories
HostDir: hostconfig.HostDirFromRoot(registry.CertsDir()),
})(host)
if err == nil {
// Merge in legacy configuration if provided
if cfg := daemon.config().Config; len(cfg.Mirrors) > 0 || len(cfg.InsecureRegistries) > 0 {
hosts, err = daemon.mergeLegacyConfig(host, hosts)
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vvoland I pushed a commit to make containerd's configuration align with docker (as containerd itself indeed still has an implicit default to always consider localhost insecure (but without the DNS resolution);

} else if docker.IsLocalhost(host) {
hosts[len(hosts)-1].host = host
if options.DefaultScheme == "" {
_, port, _ := net.SplitHostPort(host)
if port == "" || port == "443" {
// If port is default or 443, only use https
hosts[len(hosts)-1].scheme = "https"
} else {
// HTTP fallback logic will be used when protocol is ambiguous
hosts[len(hosts)-1].scheme = "http"
}
// When port is 80, protocol is not ambiguous
if port != "80" {
// Skipping TLS verification for localhost
var skipVerify = true
hosts[len(hosts)-1].skipVerify = &skipVerify
}
} else {

We should probably consider making some changes in containerd to make that more easily configurable, but I think the current approach here should work?

@thaJeztah
thaJeztah force-pushed the no_insecure_registries branch 2 times, most recently from ffd8c48 to c528976 Compare October 20, 2026 09:27
@thaJeztah thaJeztah added this to the 29.10.0 milestone Oct 20, 2026
@thaJeztah
thaJeztah force-pushed the no_insecure_registries branch from c528976 to 8e9af6b Compare October 20, 2026 15:43
@thaJeztah

Copy link
Copy Markdown
Member Author
------
 > [nydus 1/2] RUN wget https://github.com/dragonflyoss/nydus/releases/download/v2.4.5/nydus-static-v2.4.5-linux-amd64.tgz:
0.074 Connecting to github.com (140.82.113.4:443)
0.405 wget: server returned error: HTTP/1.1 500 Internal Server Error
------
Dockerfile:334
--------------------
 332 |     ARG TARGETARCH
 333 |     SHELL ["/bin/bash", "-c"]
 334 | >>> RUN wget https://github.com/dragonflyoss/nydus/releases/download/$NYDUS_VERSION/nydus-static-$NYDUS_VERSION-$TARGETOS-$TARGETARCH.tgz
 335 |     RUN mkdir -p /out/nydus-static && tar xzvf nydus-static-$NYDUS_VERSION-$TARGETOS-$TARGETARCH.tgz -C /out
 336 |     
--------------------
ERROR: failed to solve: process "/bin/bash -c wget https://github.com/dragonflyoss/nydus/releases/download/$NYDUS_VERSION/nydus-static-$NYDUS_VERSION-$TARGETOS-$TARGETARCH.tgz" did not complete successfully: exit code: 1
Build references
Check build summary support
Error: buildx bake failed with: failed to solve: process "/bin/bash -c wget https://github.com/dragonflyoss/nydus/releases/download/$NYDUS_VERSION/nydus-static-$NYDUS_VERSION-$TARGETOS-$TARGETARCH.tgz" did not complete successfully: exit code: 1

@thaJeztah
thaJeztah force-pushed the no_insecure_registries branch from 8e9af6b to 975ab95 Compare October 20, 2026 16:56
@vvoland vvoland added kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. impact/changelog and removed area/testing labels Oct 28, 2026
@vvoland
vvoland requested a balanced review from Copilot October 28, 2026 18:43

This comment was marked as outdated.

Containerd implicitly allows HTTP for localhost registries based on their
hostname or loopback IP address, independently of Docker's insecure registry
configuration.

Docker also considers DNS resolution when determining whether a registry
is insecure, and may explicitly configure localhost as secure.

Override containerd's implicit HTTP fallback when Docker considers the
registry secure, while preserving explicit containerd host configuration.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah
thaJeztah force-pushed the no_insecure_registries branch 2 times, most recently from 620926f to 264faa2 Compare November 12, 2026 16:19
@thaJeztah
thaJeztah requested a balanced review from Copilot November 12, 2026 16:19

This comment was marked as resolved.

Previously, the daemon unconditionally added localhost ("::1/128", "127.0.0.0/8")
addresses as insecure registries, even if insecure registries were configured
by the user.

This patch changes the behavior to only configure the defaults if not configured.
This makes sure that only the configured addresses are set as "insecure", and
allows opting-out of the defaults by setting an empty slice in `daemon.json`
(`{"insecure-registries":[]}`).

Note that disabling insecure registries through the command-line (`--insecure-registry`)
flags is currently not possible, as these flags do not accept an empty value.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the registry security configuration changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@thaJeztah
thaJeztah requested a review from vvoland November 12, 2026 18:59
@vvoland

vvoland commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

We should also adjust docs/reference/dockerd.md section Insecure registries

@thaJeztah

Copy link
Copy Markdown
Member Author

We should also adjust docs/reference/dockerd.md section Insecure registries

Ah, dang, yes it's in this repo now 😂

(might do as a follow-up?)

@thaJeztah
thaJeztah marked this pull request as draft November 12, 2026 20:13
@thaJeztah
thaJeztah marked this pull request as ready for review November 12, 2026 20:14
@thaJeztah
thaJeztah merged commit a7df059 into moby:master Nov 12, 2026
340 of 341 checks passed
zcsizmadia added a commit to wslkit/skrog that referenced this pull request Nov 20, 2026
* deps: engine 29.10.0 (Go 1.27.4, runc 1.5.3) and docker CLI 29.10.0

* engineconfig: keep loopback in insecure-registries for engine 29.10.0

moby/moby#53868 stops dockerd adding 127.0.0.0/8 and ::1/128 to the
insecure registries once insecure-registries is set, which would cut
skrog cache (http://127.0.0.1:5000) off for anyone with a corporate
registry configured. Set/SetMany append them to any non-empty list,
and ApplyDefaults adds them to a list that predates the upgrade.

* boot-test: wait for containerd's socket, not just docker's

docker.sock can come up before dockerd's managed containerd has created
its socket. On 29.10.0 it did once, and the single ctr attempt failed the
amd64 rootfs-v29.10.0-1 release build on a healthy engine (a re-run of the
same commit passed). Retry for up to 30 s like the docker.sock wait.

* release: rootfs-v29.10.0-1 and dockercli-v29.10.0 checksums (amd64, arm64)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/daemon Core Engine docs/revisit impact/changelog kind/enhancement Enhancements are not bugs or new features but can improve usability or performance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants