Skip to content

MGMT-24693: bracket IPv6 in OAuth issuer and callback URLs - #9120

Open
andrej1991 wants to merge 1 commit into
openshift:mainfrom
andrej1991:fix-ipv6-oauth-urls
Open

MGMT-24693: bracket IPv6 in OAuth issuer and callback URLs#9120
andrej1991 wants to merge 1 commit into
openshift:mainfrom
andrej1991:fix-ipv6-oauth-urls

Conversation

@andrej1991

@andrej1991 andrej1991 commented Jul 27, 2026

Copy link
Copy Markdown

Go's url.Parse rejects unbracketed IPv6 host:port strings, which made kube-apiserver CrashLoop on NodePort OAuth metadata and left HostedControlPlane not Ready.

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes

Special notes for your reviewer:

Checklist:

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

Summary by CodeRabbit

  • Bug Fixes

    • Corrected OAuth callback and OAuth metadata endpoint URLs (issuer, authorization endpoint, and token endpoint) across IPv4, IPv6, and hostname-based setups.
    • Ensures IPv6 addresses are formatted with the required brackets for correct OAuth behavior.
  • Tests

    • Expanded OAuth metadata tests to cover IPv4, IPv6, and hostname cases, including validation of the generated endpoint URLs.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

OAuth callback URL templates and OAuth metadata URLs now construct host-port values with net.JoinHostPort, including correct IPv6 bracket formatting. OAuth metadata generation uses url.URL for issuer and derived authorization and token endpoints. Tests cover IPv4, IPv6, and hostname inputs by decoding generated metadata and comparing the resulting URLs.

Suggested reviewers: csrwng, nirshal, bryan-cox

🚥 Pre-merge checks | ✅ 4 | ❌ 7

❌ Failed checks (7 inconclusive)

Check name Status Explanation Resolution
Stable And Deterministic Test Names ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Test Structure And Quality ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Topology-Aware Scheduling Compatibility ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Ipv6 And Disconnected Network Test Compatibility ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
No-Weak-Crypto ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Container-Privileges ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
No-Sensitive-Data-In-Logs ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: bracketing IPv6 in OAuth issuer and callback URL construction.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@openshift-ci
openshift-ci Bot requested review from Nirshal and csrwng July 27, 2026 12:41
@openshift-ci openshift-ci Bot added area/control-plane-operator Indicates the PR includes changes for the control plane operator - in an OCP release and removed do-not-merge/needs-area labels Jul 27, 2026
@openshift-ci

openshift-ci Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: andrej1991
Once this PR has been reviewed and has the lgtm label, please assign sjenning for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (2)
control-plane-operator/controllers/hostedcontrolplane/v2/kas/oauth_test.go (1)

41-79: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use the required “When ... it should ...” test-name format.

Rename the three new cases to include it should, for example: When OAuth host is IPv6, it should bracket the address.

As per coding guidelines, **/*_test.go: Always use “When ... it should ...” format for describing test cases when creating unit tests.

Proposed rename
- name: "When OAuth host is IPv4, issuer URLs should not use brackets",
+ name: "When OAuth host is IPv4, it should leave issuer URLs unbracketed",

- name: "When OAuth host is IPv6, issuer URLs should bracket the address",
+ name: "When OAuth host is IPv6, it should bracket the address",

- name: "When OAuth host is a hostname, issuer URLs should remain unbracketed",
+ name: "When OAuth host is a hostname, it should leave issuer URLs unbracketed",
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@control-plane-operator/controllers/hostedcontrolplane/v2/kas/oauth_test.go`
around lines 41 - 79, Rename the three new test cases in the OAuth test table so
each follows the required “When ..., it should ...” format: the IPv4 case should
state it should not use brackets, the IPv6 case should state it should bracket
the address, and the hostname case should state it should remain unbracketed.
Keep the test logic and expectations unchanged.

Source: Coding guidelines

control-plane-operator/controllers/hostedcontrolplane/hostedcontrolplane_controller.go (1)

765-767: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add or confirm unit coverage for the callback template.

The supplied tests cover adaptOauthMetadata, but do not exercise this controller branch. Verify that an existing controller test covers an IPv6 OAuthHost; otherwise add one to prevent regressions in OAuthCallbackURLTemplate.

As per coding guidelines, **/*_test.go: Unit test any code changes and additions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@control-plane-operator/controllers/hostedcontrolplane/hostedcontrolplane_controller.go`
around lines 765 - 767, Add or update a unit test for the controller branch
assigning OAuthCallbackURLTemplate, using an IPv6 infraStatus.OAuthHost and
verifying the resulting URL brackets the host and includes the OAuth port. Reuse
existing controller test setup and confirm the expected callback path and
identity-provider placeholder.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@control-plane-operator/controllers/hostedcontrolplane/hostedcontrolplane_controller.go`:
- Around line 765-767: Add or update a unit test for the controller branch
assigning OAuthCallbackURLTemplate, using an IPv6 infraStatus.OAuthHost and
verifying the resulting URL brackets the host and includes the OAuth port. Reuse
existing controller test setup and confirm the expected callback path and
identity-provider placeholder.

In `@control-plane-operator/controllers/hostedcontrolplane/v2/kas/oauth_test.go`:
- Around line 41-79: Rename the three new test cases in the OAuth test table so
each follows the required “When ..., it should ...” format: the IPv4 case should
state it should not use brackets, the IPv6 case should state it should bracket
the address, and the hostname case should state it should remain unbracketed.
Keep the test logic and expectations unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: ec9e07c8-82f1-41f6-af9f-c5c171a31fe8

📥 Commits

Reviewing files that changed from the base of the PR and between 02c0659 and 53fc430.

📒 Files selected for processing (3)
  • control-plane-operator/controllers/hostedcontrolplane/hostedcontrolplane_controller.go
  • control-plane-operator/controllers/hostedcontrolplane/v2/kas/oauth.go
  • control-plane-operator/controllers/hostedcontrolplane/v2/kas/oauth_test.go

@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 44.53%. Comparing base (872a7e8) to head (3615091).
⚠️ Report is 19 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9120      +/-   ##
==========================================
+ Coverage   44.51%   44.53%   +0.01%     
==========================================
  Files         774      774              
  Lines       96997    97008      +11     
==========================================
+ Hits        43179    43198      +19     
+ Misses      50830    50821       -9     
- Partials     2988     2989       +1     
Files with missing lines Coverage Δ
...ostedcontrolplane/hostedcontrolplane_controller.go 46.06% <100.00%> (+0.04%) ⬆️
...tor/controllers/hostedcontrolplane/v2/kas/oauth.go 19.76% <100.00%> (+12.53%) ⬆️

... and 2 files with indirect coverage changes

Flag Coverage Δ
cmd-support 38.39% <ø> (ø)
cpo-hostedcontrolplane 47.28% <100.00%> (+0.06%) ⬆️
cpo-other 45.25% <ø> (ø)
hypershift-operator 54.46% <ø> (+0.01%) ⬆️
other 32.64% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Go's url.Parse rejects unbracketed IPv6 host:port strings, which made
kube-apiserver CrashLoop on NodePort OAuth metadata and left HostedControlPlane not Ready.

Co-authored-by: Cursor <cursoragent@cursor.com>
@andrej1991
andrej1991 force-pushed the fix-ipv6-oauth-urls branch from 53fc430 to 3615091 Compare July 27, 2026 13:31
@openshift-ci

openshift-ci Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

@andrej1991: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@andrej1991 andrej1991 changed the title fix(cpo): bracket IPv6 in OAuth issuer and callback URLs NO-ISSUE: bracket IPv6 in OAuth issuer and callback URLs Jul 28, 2026
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jul 28, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@andrej1991: This pull request explicitly references no jira issue.

Details

In response to this:

Go's url.Parse rejects unbracketed IPv6 host:port strings, which made kube-apiserver CrashLoop on NodePort OAuth metadata and left HostedControlPlane not Ready.

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes

Special notes for your reviewer:

Checklist:

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

Summary by CodeRabbit

  • Bug Fixes

  • Corrected OAuth callback and OAuth metadata endpoint URLs (issuer, authorization endpoint, and token endpoint) across IPv4, IPv6, and hostname-based setups.

  • Ensures IPv6 addresses are formatted with the required brackets for correct OAuth behavior.

  • Tests

  • Expanded OAuth metadata tests to cover IPv4, IPv6, and hostname cases, including validation of the generated endpoint URLs.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@andrej1991 andrej1991 changed the title NO-ISSUE: bracket IPv6 in OAuth issuer and callback URLs MGMT-24693: bracket IPv6 in OAuth issuer and callback URLs Jul 28, 2026
@openshift-ci-robot

openshift-ci-robot commented Jul 28, 2026

Copy link
Copy Markdown

@andrej1991: This pull request references MGMT-24693 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Go's url.Parse rejects unbracketed IPv6 host:port strings, which made kube-apiserver CrashLoop on NodePort OAuth metadata and left HostedControlPlane not Ready.

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes

Special notes for your reviewer:

Checklist:

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

Summary by CodeRabbit

  • Bug Fixes

  • Corrected OAuth callback and OAuth metadata endpoint URLs (issuer, authorization endpoint, and token endpoint) across IPv4, IPv6, and hostname-based setups.

  • Ensures IPv6 addresses are formatted with the required brackets for correct OAuth behavior.

  • Tests

  • Expanded OAuth metadata tests to cover IPv4, IPv6, and hostname cases, including validation of the generated endpoint URLs.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/control-plane-operator Indicates the PR includes changes for the control plane operator - in an OCP release jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants