Skip to content
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

Fix Windows credential provider cannot find binary #120291

Conversation

lzhecheng
Copy link
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

Fix Windows credential provider cannot find binary. Windows credential provider binary path may have ".exe" suffix so it is better to use LookPath() to support it flexibly.

Which issue(s) this PR fixes:

Fixes #kubernetes-sigs/cloud-provider-azure#4533

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Fix Windows credential provider cannot find binary. Windows credential provider binary path may have ".exe" suffix so it is better to use LookPath() to support it flexibly.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Aug 31, 2023
@lzhecheng
Copy link
Contributor Author

/test pull-kubernetes-node-e2e-containerd

@lzhecheng
Copy link
Contributor Author

@dchen1107 @derekwaynecarr could you please take a look at the PR?Thank you.

@@ -98,7 +98,10 @@ func RegisterCredentialProviderPlugins(pluginConfigFile, pluginBinDir string) er
registerMetrics()

for _, provider := range credentialProviderConfig.Providers {
pluginBin := filepath.Join(pluginBinDir, provider.Name)
pluginBin, err := exec.LookPath(filepath.Join(pluginBinDir, provider.Name))
Copy link
Member

Choose a reason for hiding this comment

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

could you also add comments here, and also it's better having a ut coverage for this. thanks.
btw, is this a regression? does external windows credential provider never work?

Copy link
Contributor Author

@lzhecheng lzhecheng Sep 8, 2023

Choose a reason for hiding this comment

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

Sure.
Since external credential provider is relatively new feature I think (?) and it is also Windows (fewer users), I'm not sure if other clouds have started using it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a comment there. The reason that I don't add a UT is that UT tests are still run on linux, not the OS of this change.

@lzhecheng lzhecheng force-pushed the fix-credentialprovider-win-bin-path branch from 4abdc2f to bdbc87f Compare September 8, 2023 07:13
// Considering Windows binary with suffix ".exe", LookPath() helps to find the correct path.
pluginBin, err := exec.LookPath(filepath.Join(pluginBinDir, provider.Name))
if err != nil {
return fmt.Errorf("error finding binary path of plugin provider %s: %w", provider.Name, err)
Copy link
Member

Choose a reason for hiding this comment

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

original logic does not return error while this PR would returns error, and in L106, it's already returning error if pluginBin not found

Copy link
Contributor Author

@lzhecheng lzhecheng Sep 12, 2023

Choose a reason for hiding this comment

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

I combined the code with the code below because LookPath calls os.Stat

Windows credential provider binary path may have ".exe" suffix so
it is better to use LookPath() to support it flexibly.

Signed-off-by: Zhecheng Li <zhechengli@microsoft.com>
@lzhecheng lzhecheng force-pushed the fix-credentialprovider-win-bin-path branch from bdbc87f to 6102357 Compare September 12, 2023 02:48
Copy link
Member

@andyzhangx andyzhangx left a comment

Choose a reason for hiding this comment

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

/lgtm
/kind bug
/priority important-soon
/sig cloud-provider
/area provider/azure
/triage accepted

@k8s-ci-robot k8s-ci-robot added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. area/provider/azure Issues or PRs related to azure provider triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Sep 12, 2023
@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Sep 12, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: ecd127f4903ba71e2dfb5521c1e375836e1dfad9

@andyzhangx
Copy link
Member

/retest

@andyzhangx
Copy link
Member

@andrewsykim can you take a look at this PR? thanks.

@andyzhangx
Copy link
Member

btw, I think the PR title should be support credential provider on Windows node, without this PR, it won't work on windows.

@lzhecheng
Copy link
Contributor Author

@andrewsykim could you please review or refer someone to help? Thx.

@lzhecheng
Copy link
Contributor Author

@dims could you please help review?

@dims
Copy link
Member

dims commented Sep 25, 2023

/assign @nckturner @andrewsykim

@lzhecheng
Copy link
Contributor Author

@nckturner @andrewsykim could you take a look? thanks

@dims
Copy link
Member

dims commented Jan 4, 2024

/approve
/lgtm

cc @liggitt in case there were some lingering concerns around exec.LookPath (looks fine to me as this does append the full directory and the binary name itself)

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andyzhangx, dims, lzhecheng

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 4, 2024
// Considering Windows binary with suffix ".exe", LookPath() helps to find the correct path.
// LookPath() also calls os.Stat().
pluginBin, err := exec.LookPath(filepath.Join(pluginBinDir, provider.Name))
if err != nil {
if os.IsNotExist(err) {
Copy link
Member

Choose a reason for hiding this comment

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

does LookPath wrap errors? do we need to call errors.Is(err, os.ErrNotExist) instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

LookPath calls findExecutable which wraps os.Stat.
However, I think it is better to follow the suggestion in comments to use errors.Is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@k8s-ci-robot k8s-ci-robot merged commit 2efed1f into kubernetes:master Jan 4, 2024
14 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.30 milestone Jan 4, 2024
@lzhecheng lzhecheng deleted the fix-credentialprovider-win-bin-path branch January 5, 2024 05:04
@lzhecheng lzhecheng restored the fix-credentialprovider-win-bin-path branch January 5, 2024 05:04
@lzhecheng lzhecheng deleted the fix-credentialprovider-win-bin-path branch January 5, 2024 05:04
@andyzhangx
Copy link
Member

/cherrypick release-1.29

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. area/provider/azure Issues or PRs related to azure provider cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants