Skip to content

feat: infer upstream registry from containerd ns= query parameter#1792

Merged
gaius-qi merged 2 commits intodragonflyoss:mainfrom
bumarcell:feat/ns-query-param-registry
Apr 15, 2026
Merged

feat: infer upstream registry from containerd ns= query parameter#1792
gaius-qi merged 2 commits intodragonflyoss:mainfrom
bumarcell:feat/ns-query-param-registry

Conversation

@bumarcell
Copy link
Copy Markdown
Contributor

@bumarcell bumarcell commented Apr 14, 2026

Summary

When containerd uses registry mirrors, it appends a ?ns=<registry> query parameter to indicate the original upstream registry (e.g., GET /v2/library/nginx/manifests/latest?ns=docker.io). Currently, the dfdaemon proxy only checks the X-Dragonfly-Registry header and falls back to the static proxy.registry_mirror.addr config.

This PR adds support for extracting the ns query parameter as a second fallback, making the registry mirror work correctly with containerd's mirror protocol without requiring the X-Dragonfly-Registry header to be set.

Changes

  • Added get_ns_from_query() helper function that extracts the ns query parameter from the request URI and prepends https:// if no scheme is present
  • Refactored make_registry_mirror_request() to use a three-level fallback:
    1. X-Dragonfly-Registry header (explicit override)
    2. ns query parameter (set by containerd when using registry mirrors)
    3. Static config value (proxy.registry_mirror.addr)
  • Removed a redundant no-op call to header::get_registry()
  • Added unit tests for the new get_ns_from_query() function

Backward Compatibility

This change is fully backward compatible. Existing header-based and config-based flows are unaffected — the ns parameter is only checked when no header is present.

#1791

Signed-off-by: Jamal Allogie jamal.allogie@gmail.com

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 14, 2026

Codecov Report

❌ Patch coverage is 74.54545% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.21%. Comparing base (678ee48) to head (403db01).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
dragonfly-client/src/proxy/mod.rs 0.00% 14 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1792      +/-   ##
==========================================
+ Coverage   43.11%   43.21%   +0.10%     
==========================================
  Files          91       92       +1     
  Lines       26839    26868      +29     
==========================================
+ Hits        11571    11612      +41     
+ Misses      15268    15256      -12     
Files with missing lines Coverage Δ
dragonfly-client/src/proxy/query.rs 100.00% <100.00%> (ø)
dragonfly-client/src/proxy/mod.rs 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

When containerd uses registry mirrors, it appends a `?ns=<registry>`
query parameter to indicate the original upstream registry (e.g.,
`GET /v2/library/nginx/manifests/latest?ns=docker.io`).

This change adds support for extracting the `ns` query parameter as
a fallback when the `X-Dragonfly-Registry` header is not present.
The fallback order is now:
1. X-Dragonfly-Registry header (explicit override)
2. ns query parameter (set by containerd)
3. Static config (proxy.registry_mirror.addr)

This is fully backward compatible — existing header-based and
config-based flows are unaffected.

Fixes dragonflyoss#1791

Signed-off-by: Jamal Allogie <jamal.allogie@gmail.com>
@bumarcell bumarcell force-pushed the feat/ns-query-param-registry branch from 38735b4 to 4f44e35 Compare April 14, 2026 09:55
@bumarcell
Copy link
Copy Markdown
Contributor Author

Could a maintainer please add the enhancement label? The Classify PR check requires it and I don't have permission to add labels from my fork.

@gaius-qi gaius-qi added the enhancement New feature or request label Apr 15, 2026
@gaius-qi gaius-qi enabled auto-merge (squash) April 15, 2026 03:01
Copy link
Copy Markdown
Member

@EvanCley EvanCley left a comment

Choose a reason for hiding this comment

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

LGTM

@gaius-qi gaius-qi merged commit f54846b into dragonflyoss:main Apr 15, 2026
7 checks passed
bumarcell added a commit to bumarcell/client that referenced this pull request Apr 20, 2026
Add a new dfinit containerd configuration option, proxyAllRegistries
(default: true), that writes a catch-all `_default/hosts.toml` under the
containerd config_path so registries not explicitly listed in
`registries:` are still proxied through dfdaemon.

The `_default` fallback omits both the top-level `server` field and the
`X-Dragonfly-Registry` header; dfdaemon infers the upstream registry
from the `ns=` query parameter that containerd appends when resolving
via `_default` (support added in dragonflyoss#1792). Explicitly configured
registries keep their own `hosts.toml` and take precedence over the
catch-all.

Closes dragonflyoss#1791.

Signed-off-by: Jamal Allogie <jamal.allogie@gmail.com>
bumarcell added a commit to bumarcell/client that referenced this pull request Apr 21, 2026
Add a new dfinit containerd configuration option, proxyAllRegistries
(default: true), that writes a catch-all `_default/hosts.toml` under the
containerd config_path so registries not explicitly listed in
`registries:` are still proxied through dfdaemon.

The `_default` fallback omits both the top-level `server` field and the
`X-Dragonfly-Registry` header; dfdaemon infers the upstream registry
from the `ns=` query parameter that containerd appends when resolving
via `_default` (support added in dragonflyoss#1792). Explicitly configured
registries keep their own `hosts.toml` and take precedence over the
catch-all.

Closes dragonflyoss#1791.

Signed-off-by: Jamal Allogie <jamal.allogie@gmail.com>
bumarcell added a commit to bumarcell/client that referenced this pull request Apr 21, 2026
Add a new dfinit containerd configuration option, proxyAllRegistries
(default: true), that writes a catch-all `_default/hosts.toml` under the
containerd config_path so registries not explicitly listed in
`registries:` are still proxied through dfdaemon.

The `_default` fallback omits both the top-level `server` field and the
`X-Dragonfly-Registry` header; dfdaemon infers the upstream registry
from the `ns=` query parameter that containerd appends when resolving
via `_default` (support added in dragonflyoss#1792). Explicitly configured
registries keep their own `hosts.toml` and take precedence over the
catch-all.

Closes dragonflyoss#1791.

Signed-off-by: Jamal Allogie <jamal.allogie@gmail.com>
gaius-qi added a commit that referenced this pull request Apr 22, 2026
)

* feat: add proxy_all_registries option to dfinit containerd module

Add a new dfinit containerd configuration option, proxyAllRegistries
(default: true), that writes a catch-all `_default/hosts.toml` under the
containerd config_path so registries not explicitly listed in
`registries:` are still proxied through dfdaemon.

The `_default` fallback omits both the top-level `server` field and the
`X-Dragonfly-Registry` header; dfdaemon infers the upstream registry
from the `ns=` query parameter that containerd appends when resolving
via `_default` (support added in #1792). Explicitly configured
registries keep their own `hosts.toml` and take precedence over the
catch-all.

Closes #1791.

Signed-off-by: Jamal Allogie <jamal.allogie@gmail.com>

* fix(containerd): rename add_default_mirror to add_default_registry

Signed-off-by: Gaius <gaius.qi@gmail.com>

* chore: bump workspace version to 1.3.6

Signed-off-by: Gaius <gaius.qi@gmail.com>

---------

Signed-off-by: Jamal Allogie <jamal.allogie@gmail.com>
Signed-off-by: Gaius <gaius.qi@gmail.com>
Co-authored-by: Gaius <gaius.qi@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants