Skip to content

Conversation

@tchap
Copy link
Contributor

@tchap tchap commented Nov 7, 2025

When running oc login, the insecure flag from kubeconfig is not consulted properly when calling getClientConfig.
This is now fixed.

@openshift-ci-robot openshift-ci-robot added jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Nov 7, 2025
@openshift-ci-robot
Copy link

@tchap: This pull request references Jira Issue OCPBUGS-64619, which is invalid:

  • expected the bug to target the "4.21.0" version, but no target version was set

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

When running oc login, the insecure flag from kubeconfig is not consulted properly when calling getClientConfig.
This is now fixed.

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.

@tchap tchap changed the title https://issues.redhat.com/browse/OCPBUGS-64619: oc login: Respect insecure flag from kubeconfig OCPBUGS-64619: oc login: Respect insecure flag from kubeconfig Nov 7, 2025
@coderabbitai
Copy link

coderabbitai bot commented Nov 7, 2025

Walkthrough

getClientConfig's TLS/CA resolution was refactored: CA sourcing can now fall back to a kubeconfig cluster via findCluster; Insecure handling and certificate-error branching use clientConfig.Insecure; combining insecure-skip-tls-verify with certificate-authority/-data now returns a conflict error. A unit test and an error constant were added.

Changes

Cohort / File(s) Summary
Login TLS/CA logic
pkg/cli/login/loginoptions.go
getClientConfig now prefers an explicit CAFile; if absent, it uses findCluster to populate CAFile/CAData and InsecureSkipTLSVerify. Adds an error when InsecureSkipTLSVerify is true while CAFile/CAData are provided. Certificate-related error handling now consults clientConfig.Insecure.
Cluster lookup helper
pkg/cli/login/helpers.go
Removed findExistingClientCA(...) and added findCluster(host, kubeconfig) *clientcmdapi.Cluster which returns the matching cluster or nil; CA extraction logic was moved to the caller.
Error messages
pkg/cli/login/error_translation.go
Added unexported constant insecureTransportCertificateAuthorityConflictMsg explaining that certificate-authority/certificate-authority-data are mutually exclusive with insecure-skip-tls-verify.
Tests
pkg/cli/login/loginoptions_test.go
Added TestGetClientConfig_InsecureSkipTLSVerify to exercise combinations of CLI InsecureSkipTLSVerify and kubeconfig cluster settings, including conflict and error expectations using a TLS test server.
Manifest
go.mod
Present in diff (no behavioral changes summarized).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Verify precedence and clearing/population of CAFile/CAData vs InsecureSkipTLSVerify in getClientConfig.
  • Ensure findCluster nil-handling does not leave stale CA values.
  • Review certificate-error branches to confirm they now correctly use clientConfig.Insecure.
  • Check TestGetClientConfig_InsecureSkipTLSVerify for teardown, determinism, and coverage of conflict paths.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 7c307ce and 4ba0db7.

📒 Files selected for processing (4)
  • pkg/cli/login/error_translation.go (1 hunks)
  • pkg/cli/login/helpers.go (1 hunks)
  • pkg/cli/login/loginoptions.go (2 hunks)
  • pkg/cli/login/loginoptions_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/cli/login/error_translation.go
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

-Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.

Files:

  • pkg/cli/login/loginoptions.go
  • pkg/cli/login/helpers.go
  • pkg/cli/login/loginoptions_test.go
🧬 Code graph analysis (1)
pkg/cli/login/loginoptions_test.go (1)
pkg/cli/login/loginoptions.go (1)
  • LoginOptions (62-103)
🔇 Additional comments (4)
pkg/cli/login/helpers.go (1)

33-41: LGTM! Clean refactoring to return the full cluster object.

The change from findExistingClientCA to findCluster properly provides the caller with access to both CA data and the InsecureSkipTLSVerify setting. Returning the first matching cluster is appropriate for this use case.

pkg/cli/login/loginoptions_test.go (1)

380-463: LGTM! Comprehensive test coverage for the insecure flag behavior.

The test cases properly validate:

  • Kubeconfig InsecureSkipTLSVerify is respected when no CLI flag is set
  • CLI flag takes precedence when provided
  • Conflict detection between insecure and CA settings
  • Error messages match expectations

The table-driven structure makes the test clear and maintainable.

pkg/cli/login/loginoptions.go (2)

165-181: LGTM! Correctly implements kubeconfig insecure flag resolution.

The logic properly handles the precedence and conflict scenarios:

  1. CLI --insecure-skip-tls-verify flag takes precedence (skips this block entirely)
  2. Explicit --certificate-authority flag is used if provided
  3. Otherwise, consults kubeconfig cluster for both InsecureSkipTLSVerify and CA data
  4. Enforces mutual exclusivity between insecure mode and CA settings (lines 177-179)

This fixes the reported issue where kubeconfig's insecure flag was not being respected.


198-198: Correct use of clientConfig.Insecure in error handling.

This change ensures that if the kubeconfig specified insecure-skip-tls-verify: true, the error handling logic will respect that setting when deciding whether to proceed with an insecure connection on certificate errors.


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

@tchap
Copy link
Contributor Author

tchap commented Nov 7, 2025

/jira refresh

@openshift-ci-robot openshift-ci-robot added the jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. label Nov 7, 2025
@openshift-ci-robot
Copy link

@tchap: This pull request references Jira Issue OCPBUGS-64619, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (4.21.0) matches configured target version for branch (4.21.0)
  • bug is in the state New, which is one of the valid states (NEW, ASSIGNED, POST)

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

/jira refresh

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.

@openshift-ci-robot openshift-ci-robot removed the jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. label Nov 7, 2025
@ardaguclu
Copy link
Member

This one #2131 is also trying to fix same bug I suppose

@tchap
Copy link
Contributor Author

tchap commented Nov 7, 2025

Gosh, people don't link to Jira issues 🥲 I would personally keep this one as it also contains tests, but...

@ardaguclu
Copy link
Member

Gosh, people don't link to Jira issues 🥲 I would personally keep this one as it also contains tests, but...

The PRs that contain tests will always have higher priority :).

@tchap
Copy link
Contributor Author

tchap commented Nov 10, 2025

/retest

Copy link
Member

@ardaguclu ardaguclu left a comment

Choose a reason for hiding this comment

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

Dropped a comment about test cases. Logical changes are nice to me. Thank you for fixing this.

@ardaguclu
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Nov 10, 2025
@ardaguclu
Copy link
Member

I believe that it is better to perform pre-merge tests. cc: @zhouying7780

@tchap tchap force-pushed the login-skip-tls-validation-kubeconfig branch from 17ab6e4 to 0215a6c Compare November 17, 2025 23:10
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Nov 17, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
pkg/cli/login/loginoptions.go (1)

163-174: Centralizing Insecure handling looks good; consider guarding StartingKubeConfig usage.

Using clientConfig.Insecure as the single source of truth (OR of o.InsecureTLS and hasExistingInsecureCluster) simplifies the TLS decision and keeps the error-path logic in sync with initial config, which is a nice cleanup. The only thing I’d double‑check is whether o.StartingKubeConfig is guaranteed non‑nil on all call sites: the new hasExistingInsecureCluster(*clientConfig, *o.StartingKubeConfig) call runs unconditionally now, including when the CLI flag is set, so if that invariant is ever broken this will panic. If the invariant isn’t watertight, a small guard like falling back to clientConfig.Insecure = o.InsecureTLS when StartingKubeConfig == nil would make this safer.

Also applies to: 191-201

pkg/cli/login/loginoptions_test.go (1)

380-451: Solid coverage of flag/kubeconfig combinations; tweak failure message for clarity.

The table cases nicely exercise the combinations of CLI and kubeconfig insecure sources and assert the resulting clientConfig.Insecure. One tiny readability nit: in the branch where expectedInsecureClientConfig is false, the fatal message says “Expected to fail with insecure connection…”, which sounds opposite to what the test is asserting (we actually expect a secure connection to fail TLS validation). Renaming that part of the message would avoid confusion for future readers, especially when debugging failures.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 17ab6e4 and 0215a6c.

📒 Files selected for processing (2)
  • pkg/cli/login/loginoptions.go (2 hunks)
  • pkg/cli/login/loginoptions_test.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

-Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.

Files:

  • pkg/cli/login/loginoptions_test.go
  • pkg/cli/login/loginoptions.go

@ardaguclu
Copy link
Member

/lgtm
we will need another round of verification

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 20, 2025
@ardaguclu
Copy link
Member

Basically this PR still requires to be tested to merge it.

@zhouying7780
Copy link
Contributor

I'll do pre-merge test with the latest code tomorrow morning.

@tchap tchap force-pushed the login-skip-tls-validation-kubeconfig branch from 0215a6c to cbd832a Compare December 9, 2025 14:24
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Dec 9, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 0215a6c and cbd832a.

📒 Files selected for processing (3)
  • pkg/cli/login/helpers.go (1 hunks)
  • pkg/cli/login/loginoptions.go (2 hunks)
  • pkg/cli/login/loginoptions_test.go (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/cli/login/loginoptions_test.go
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

-Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.

Files:

  • pkg/cli/login/loginoptions.go
  • pkg/cli/login/helpers.go
🔇 Additional comments (2)
pkg/cli/login/helpers.go (1)

33-48: LGTM!

The new findCluster and findClusterWithCA helper functions are well-designed. The generic findCluster with an optional predicate provides good flexibility, and findClusterWithCA correctly encapsulates the CA-presence check. This refactor improves reusability over the previous findExistingClientCA approach.

pkg/cli/login/loginoptions.go (1)

200-214: Core fix looks correct.

Checking clientConfig.Insecure first at line 201 ensures that if the kubeconfig already specified insecure-skip-tls-verify: true for this cluster (set at lines 172 or 176), the user won't be prompted unnecessarily. This is the essence of the bug fix.

@tchap tchap force-pushed the login-skip-tls-validation-kubeconfig branch from cbd832a to 298b544 Compare December 9, 2025 14:29
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
pkg/cli/login/loginoptions.go (1)

165-184: CA/insecure handling now correctly honors kubeconfig, with one suggested robustness tweak

The new cascade looks solid:

  • When not already insecure, you first honor an explicit CAFile, then fall back to kubeconfig via findClusterWithCA, and finally to findCluster for picking up InsecureSkipTLSVerify.
  • Using clientConfig.Insecure (instead of only o.InsecureTLS) in both the CA‑application block and the x509 error branch means kubeconfig‑driven insecure-skip-tls-verify is respected end‑to‑end.
  • Unsetting CAFile/CAData whenever clientConfig.Insecure is true avoids conflicting TLS settings during transport initialization.

One robustness suggestion: both kubeconfig lookups here dereference *o.StartingKubeConfig. That was already assumed non‑nil elsewhere, but this makes the assumption more central in the login path. If there is any code path (tests or future usages) that might call getClientConfig before initializing StartingKubeConfig, a small guard would prevent panics:

-		} else if cluster := findClusterWithCA(clientConfig.Host, *o.StartingKubeConfig); cluster != nil {
-			clientConfig.Insecure = cluster.InsecureSkipTLSVerify
-			clientConfig.CAFile = cluster.CertificateAuthority
-			clientConfig.CAData = cluster.CertificateAuthorityData
-		} else if cluster := findCluster(clientConfig.Host, *o.StartingKubeConfig, nil); cluster != nil {
-			clientConfig.Insecure = cluster.InsecureSkipTLSVerify
-		}
+		} else if o.StartingKubeConfig != nil {
+			if cluster := findClusterWithCA(clientConfig.Host, *o.StartingKubeConfig); cluster != nil {
+				clientConfig.Insecure = cluster.InsecureSkipTLSVerify
+				clientConfig.CAFile = cluster.CertificateAuthority
+				clientConfig.CAData = cluster.CertificateAuthorityData
+			} else if cluster := findCluster(clientConfig.Host, *o.StartingKubeConfig, nil); cluster != nil {
+				clientConfig.Insecure = cluster.InsecureSkipTLSVerify
+			}
+		}

If you’re confident StartingKubeConfig is always non‑nil before getClientConfig is called, this remains optional, but adding the check would make the code more future‑proof.

Also applies to: 201-201

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between cbd832a and 298b544.

📒 Files selected for processing (3)
  • pkg/cli/login/helpers.go (1 hunks)
  • pkg/cli/login/loginoptions.go (2 hunks)
  • pkg/cli/login/loginoptions_test.go (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/cli/login/loginoptions_test.go
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

-Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.

Files:

  • pkg/cli/login/loginoptions.go
  • pkg/cli/login/helpers.go
🔇 Additional comments (1)
pkg/cli/login/helpers.go (1)

33-47: Generic cluster lookup helpers look correct and improve reuse

The new findCluster/findClusterWithCA helpers correctly handle the optional predicate, return nil when no match is found, and cleanly encapsulate the CA‑presence filter. This makes the kubeconfig lookup logic more maintainable without changing the existing “first matching cluster wins” behavior.

@tchap tchap force-pushed the login-skip-tls-validation-kubeconfig branch 2 times, most recently from 09cc2b7 to 7c307ce Compare December 10, 2025 10:45
When running oc login, the insecure flag from kubeconfig is not
consulted properly when calling getClientConfig(). This is now fixed.

Assisted-by: Claude Code
@tchap tchap force-pushed the login-skip-tls-validation-kubeconfig branch from 7c307ce to 4ba0db7 Compare December 10, 2025 10:49
@ardaguclu
Copy link
Member

Thank you
/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Dec 10, 2025
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Dec 10, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ardaguclu, tchap

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

The pull request process is described 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

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Dec 10, 2025

@tchap: 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.

@openshift-bot
Copy link
Contributor

/jira refresh

The requirements for Jira bugs have changed (Jira issues linked to PRs on main branch need to target different OCP), recalculating validity.

@openshift-ci-robot openshift-ci-robot added jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. and removed jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. labels Dec 12, 2025
@openshift-ci-robot
Copy link

@openshift-bot: This pull request references Jira Issue OCPBUGS-64619, which is invalid:

  • expected the bug to target either version "4.22." or "openshift-4.22.", but it targets "4.21" instead

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

Details

In response to this:

/jira refresh

The requirements for Jira bugs have changed (Jira issues linked to PRs on main branch need to target different OCP), recalculating validity.

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

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants