-
Notifications
You must be signed in to change notification settings - Fork 421
OCPBUGS-64619: oc login: Respect insecure flag from kubeconfig #2134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@tchap: This pull request references Jira Issue OCPBUGS-64619, which is invalid:
Comment The bug has been updated to refer to the pull request using the external bug tracker. In response to this:
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. |
WalkthroughCentralizes the insecure TLS decision by computing Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–30 minutes
✨ Finishing touches
🧪 Generate unit tests (beta)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. Comment |
|
/jira refresh |
|
@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
The bug has been updated to refer to the pull request using the external bug tracker. In response to this:
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. |
|
This one #2131 is also trying to fix same bug I suppose |
|
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 :). |
|
/retest |
ardaguclu
left a comment
There was a problem hiding this 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.
| }, | ||
| "both command and kubeconfig flag set": { | ||
| insecureFlag: true, | ||
| insecureKubeconfig: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expect insecureFlag and insecureKubeconfig values differ and we explicitly state which one we should choose. Flags are higher priority than implicit assignments (kubeconfig)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the logic is that there is no priority, but setting insecure anywhere just makes the whole thing accept insecure connection. In other words, insecure=false flag does not overwrite kubeconfig with insecure=true. Otherwise we would need to explicitly check whether the CLI flag was actually set and use that value in any case, in other words, treat default flag value and explicitly set flag value to false differently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My suggestion basically is to assure whatever the expected outcome if they differ. So that in the future if that test fails, we will be notified something has changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if assigning one of them is true makes the outcome as true, let's reflect it to the test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is reflected in the test 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume the ones you pointed out is line:394 and line:398. They exercise, for example, oc login (with insecure in kubeconfig), vs. But they do not exercise oc login --insecure-tls-verify=false (with insecure in kubeconfig).
I'm totally aware that they are identical. But we need to test this case too, because from user point of view oc login and oc login --insecure-tls-verify are not identical (former means run this with whatever value, latter means run this command with my explicit definition). So in my opinion, adding 2 additional tests would make sense to me not in terms of functionality but in terms of semantically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand, test does not have notion of explicit, implicit flag. So we can leave the tests as is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate adding unit tests every time. Thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the way :mandalorian:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is not so great is that the tests are passing even when I roll back the change 😅
|
/lgtm |
|
I believe that it is better to perform pre-merge tests. cc: @zhouying7780 |
When running oc login, the insecure flag from kubeconfig is not consulted properly when calling getClientConfig(). This is now fixed. Assisted-by: Claude Code
17ab6e4 to
0215a6c
Compare
There was a problem hiding this 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: CentralizingInsecurehandling looks good; consider guardingStartingKubeConfigusage.Using
clientConfig.Insecureas the single source of truth (OR ofo.InsecureTLSandhasExistingInsecureCluster) 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 whethero.StartingKubeConfigis guaranteed non‑nil on all call sites: the newhasExistingInsecureCluster(*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 toclientConfig.Insecure = o.InsecureTLSwhenStartingKubeConfig == nilwould 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
insecuresources and assert the resultingclientConfig.Insecure. One tiny readability nit: in the branch whereexpectedInsecureClientConfigis 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
📒 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.gopkg/cli/login/loginoptions.go
|
@tchap: all tests passed! Full PR test history. Your PR dashboard. 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. |
| if o.InsecureTLS || | ||
| hasExistingInsecureCluster(*clientConfig, *o.StartingKubeConfig) || | ||
| promptForInsecureTLS(o.In, o.Out, err) { | ||
| if clientConfig.Insecure || promptForInsecureTLS(o.In, o.Out, err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the leftover line that caused an issue in previous version. I'm wondering why did I miss it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The one right below was removed:
clientConfig.Insecure = true
|
/lgtm |
|
[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
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Basically this PR still requires to be tested to merge it. |
When running oc login, the insecure flag from kubeconfig is not consulted properly when calling
getClientConfig.This is now fixed.