Skip to content

Migrate terraform handler to OIDCRegistry#83

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

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

Conversation

@kbukum1
Copy link
Copy Markdown
Contributor

@kbukum1 kbukum1 commented Apr 3, 2026

What

Migrate the Terraform 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).

Terraform was storing OIDC credentials keyed by hostname only via cred.Host(). The OIDCRegistry now preserves the full URL (via url field, with cred.Host() fallback), fixing potential collisions.

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

Migrates the Terraform registry handler to use the shared oidc.OIDCRegistry so OIDC credentials can be matched collision-free (host bucket + longest path-prefix match), aligning Terraform with the registry-wide OIDC credential storage approach introduced in #78 / fixing #87 scenarios.

Changes:

  • Replaced Terraform’s per-handler OIDC credential map + RWMutex with oidc.OIDCRegistry.
  • Updated Terraform OIDC registration to use the credential’s url field as the primary key (preserving path), with host fallback.
  • Adjusted OIDC handling tests to expect Terraform registration logs to include the full URL key.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/handlers/terraform_registry.go Switches Terraform OIDC auth to OIDCRegistry and removes handler-level mutex/map storage.
internal/handlers/oidc_handling_test.go Updates expected Terraform OIDC registration log lines to match new URL-based keys.

@kbukum1 kbukum1 force-pushed the kamil/oidc-migrate-terraform branch from 8bec9a4 to 46ef1d8 Compare April 3, 2026 04:14
@kbukum1 kbukum1 requested a review from Copilot April 3, 2026 04:15
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 2 out of 2 changed files in this pull request and generated no new comments.

@kbukum1 kbukum1 requested a review from Copilot April 3, 2026 04:38
@kbukum1 kbukum1 marked this pull request as ready for review April 3, 2026 04:38
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 2 out of 2 changed files in this pull request and generated no new comments.

@kbukum1 kbukum1 force-pushed the kamil/oidc-migrate-terraform branch from 46ef1d8 to e8fd91c Compare April 3, 2026 05:17
@kbukum1 kbukum1 requested a review from Copilot April 3, 2026 05:17
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 2 out of 2 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 2 out of 2 changed files in this pull request and generated 1 comment.

Comment on lines +30 to 32
// OIDC credentials are not used as static credentials.
if oidcCred, _, _ := handler.oidcRegistry.Register(credential, []string{"url"}, "terraform registry"); oidcCred != nil {
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.

The result of oidcRegistry.Register includes a boolean indicating whether the OIDC credential was actually registered (i.e., a usable URL/host key was resolved and parsed). The current check only looks at oidcCred != nil, so an OIDC-configured credential that fails registration will still be skipped for static token setup, leaving it unusable with no handler-level signal. Consider checking the returned registered flag (and logging when it’s false), and only continue when registration succeeds.

Copilot uses AI. Check for mistakes.
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. OIDC key changes from hostname-only to full URL
(via url field, with cred.Host() fallback), fixing credential
collisions when multiple Terraform registries share a host.
@kbukum1 kbukum1 force-pushed the kamil/oidc-migrate-terraform branch from e8fd91c to d6b157f 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