Skip to content

Migrate docker handler to OIDCRegistry#84

Open
kbukum1 wants to merge 1 commit intomainfrom
kamil/oidc-migrate-docker
Open

Migrate docker handler to OIDCRegistry#84
kbukum1 wants to merge 1 commit intomainfrom
kamil/oidc-migrate-docker

Conversation

@kbukum1
Copy link
Copy Markdown
Contributor

@kbukum1 kbukum1 commented Apr 3, 2026

What

Migrate the Docker registry handler from manual OIDC credential map + mutex to the shared OIDCRegistry type introduced in #78.

Why

Part of the phased migration to fix OIDC credential collisions when multiple registries share a host (#87).

Docker already stored the raw registry value as the OIDC key, so this is a pure structural refactor with no behavior change. Single-file diff, no test changes.

Behavior changes

  • Credential selection is now deterministic. The old code iterated over a Go map (map[string]*OIDCCredential), so with multiple OIDC credentials on the same host, which one matched was nondeterministic. OIDCRegistry.TryAuth uses longest path-prefix matching, ensuring the most specific credential always wins. This is the core fix for OIDC credential collision when multiple registries share a host #87.

  • Host matching uses strings.ToLower instead of IDNA normalization. The old TryAuthOIDCRequestWithPrefix used helpers.AreHostnamesEqual (IDNA ToASCII), while OIDCRegistry.TryAuth uses lowercase comparison. This is acceptable because all real OIDC registries (Azure DevOps, JFrog, AWS CodeArtifact, Cloudsmith) use ASCII hostnames — no package registry uses internationalized domain names.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the Docker registry handler’s OIDC credential storage to use the shared oidc.OIDCRegistry type (introduced in #78) instead of a per-handler map+mutex, as part of the phased migration to prevent OIDC credential collisions (#87).

Changes:

  • Replace oidcCredentials map + RWMutex with oidcRegistry *oidc.OIDCRegistry in DockerRegistryHandler.
  • Register OIDC credentials via oidcRegistry.Register(...) during handler construction.
  • Authenticate requests via oidcRegistry.TryAuth(...) instead of TryAuthOIDCRequestWithPrefix(...).

Comment on lines 60 to 62
if _, _, ok := handler.oidcRegistry.Register(cred, []string{"registry"}, "docker registry"); ok {
continue
}
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

Register(...) success now continues the credentials loop, so OIDC-configured docker_registry entries will no longer be added to h.credentials for static auth fallback. Previously (with the inline CreateOIDCCredential block) the handler registered OIDC and still appended username/password creds, allowing fallback when OIDC token acquisition fails. If the intent is a pure refactor/no behavior change, remove this continue (or only skip static registration when no static fields are present).

Copilot uses AI. Check for mistakes.
@kbukum1 kbukum1 marked this pull request as ready for review April 3, 2026 04:39
@kbukum1 kbukum1 requested a review from Copilot April 3, 2026 04:39
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Base automatically changed from kamil/oidc-registry-generalized to main April 4, 2026 00:12
Replace manual OIDC credential map and mutex with the shared
OIDCRegistry type. Docker already used the raw registry value as
the key, so this is a pure structural refactor with no behavior
change.
@kbukum1 kbukum1 force-pushed the kamil/oidc-migrate-docker branch from 9b6cfa7 to e19c62a Compare April 4, 2026 00:20
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