Skip to content

[AKS] Fix #34091: az aks get-credentials: Fix kubelogin conversion for custom kubeconfig paths - #34442

Merged
xuming-ms merged 7 commits into
Azure:devfrom
FumingZhang:fix/aks-kubelogin-config-path-34091
Nov 23, 2026
Merged

xuming-ms merged 7 commits into
Azure:devfrom
FumingZhang:fix/aks-kubelogin-config-path-34091

Conversation

@FumingZhang

@FumingZhang FumingZhang commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

🤖 PR Validation — ⚠️ Review suggested

Breaking Changes Tests Suppressions
️✔️ None ️✔️ 130/130 ⚠️ 3 added

This PR adds warning or check suppressions. Fix the underlying warning where possible and justify each remaining suppression in a code comment or the PR description.

3 added suppressions
File Line Kind Code
src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_custom.py 2547 skipped test @unittest.skipIf(os.name == "nt", "Requires a POSIX executable script.")
src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_custom.py 2585 skipped test @unittest.skipIf(os.name == "nt", "Requires directory symlinks.")
src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_custom.py 2632 skipped test @unittest.skipIf(os.name == "nt", "Requires file symlinks.")

Related command

az aks get-credentials

Description

Fixes #34091.

The automatic kubelogin conversion passes os.path.dirname(path) as its working directory. For a bare relative filename such as --file config, this is an empty string, causing [Errno 2] No such file or directory: '' before kubelogin starts. Changing directories also does not select the kubeconfig to convert, so a custom output file can remain in device-code mode while another kubeconfig is modified.

  • Pass the resolved output file through --kubeconfig after merging, preserving directory-symlink/.. semantics and the existing refusal of symlink kubeconfig files.
  • Build on the merged safe executable lookup from [AKS] az aks get-credentials: Fix kubelogin executable lookup #34445 and [AKS] az aks: Fix external tool invocation #34446; this PR adds kubeconfig file selection and preserves their regression coverage.
  • Skip conversion for --file -, preserving stdout-only behavior without touching other kubeconfig files.
  • Preserve warnings for missing kubelogin and conversion failures; catch expected process-launch errors specifically.
  • Add focused regression tests, including a real subprocess fixture that converts the selected file and verifies that an inherited, unrelated kubeconfig remains unchanged.

Testing Guide

Merged-dev regressions: 80 passed, 3 Windows-only skipped; 243 subtests passed. Executed with repository sources on PYTHONPATH and isolated temporary configuration.

/usr/bin/python -m pytest -q --tb=short -p no:cacheprovider src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_custom.py src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_install_desktop.py src/azure-cli-core/azure/cli/core/tests/test_util.py::TestSafeExecutablePath -k 'install_desktop or AksExternalToolsTest or AksGetCredentialsTest or AksGetCredentialsExecutableTest or TestSafeExecutablePath'

Pylint 4.1.4 with the repository configuration: passed, 10.00/10. Production flake8, source compilation and whitespace checks passed.

The merge retains all three credential/executable/external-tool regression classes and preserves the upstream safe resolver. Native Windows and live Azure checks are not covered by these unit tests. Existing hook bootstrap could not activate its expected virtual environment; checks were run directly.

History Notes

[AKS] az aks get-credentials: Fix automatic kubelogin conversion for custom kubeconfig paths


This checklist is used to make sure that common guidelines for a pull request are followed.

Pass the merged kubeconfig explicitly to kubelogin without changing its
working directory. Reuse the resolved executable, skip stdout-only
requests and preserve conversion failure warnings.

Add regression coverage for file selection, stdout and real subprocess
conversion without touching unrelated kubeconfig files.

Fixes Azure#34091.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@x-engineering-agent

Copy link
Copy Markdown
Contributor

Hi FumingZhang,
Since the current milestone time is less than 7 days, this pr will be reviewed in the next milestone.

@yonzhan

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

FumingZhang and others added 5 commits November 19, 2026 03:37
Resolve the conversion target after credential merging so paths containing a directory symlink followed by dot-dot still select the file that was written. Preserve the existing rejection of symlink kubeconfig files.

Cover relative, absolute and KUBECONFIG-provided paths and verify unrelated files remain unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use the shared safe executable resolver for kubeconfig conversion and invoke its result directly. Avoid lexical normalization changing which executable is selected when PATH contains directory symlinks followed by dot-dot.

Cover executable path identity and working-directory decoys while preserving kubeconfig selection, symlink-file protection and conversion warnings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This reverts commit 5bd766c.

Keep executable lookup changes scoped to Azure#34445. Preserve the kubeconfig output-path fixes and directory symlink regression coverage in this PR.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Integrate the merged executable lookup fixes while keeping explicit kubeconfig selection, stdout behavior and directory symlink handling. Retain both upstream executable regression suites and the kubeconfig path tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@FumingZhang
FumingZhang marked this pull request as ready for review November 23, 2026 06:29
Copilot AI balanced review requested due to automatic review settings November 23, 2026 06:29

Copilot AI 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.

🟢 Approval recommended

No active review issues are identified for the change that directs kubelogin conversion to the selected kubeconfig.

No open issues 🎉

What changed in this PR

Fixes az aks get-credentials so automatic kubelogin conversion targets the selected kubeconfig, including custom relative paths, rather than relying on a working-directory change.

Changes:

  • Pass the resolved output path explicitly through --kubeconfig, preserving directory-symlink behavior.
  • Skip conversion for stdout output and retain warnings for missing kubelogin and expected process failures.
  • Add regression coverage for file selection, symlinks, stdout behavior, and conversion failures while preserving executable-safety tests.
File Description
src/​azure-cli/​azure/​cli/​command_modules/​acs/​tests/​latest/​test_custom.py Adds conversion regressions and updates expected subprocess arguments.
src/​azure-cli/​azure/​cli/​command_modules/​acs/​custom.py Selects the kubeconfig explicitly, skips stdout conversion, and narrows launch-error handling.

Review effort: Balanced

@xuming-ms

xuming-ms commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

There's a breaking-change error showing up here, I have rebased from dev

@xuming-ms
xuming-ms merged commit f7fa38f into Azure:dev Nov 23, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

act-observability-squad AKS az aks/acs/openshift Auto-Assign Auto assign by bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

az aks get-credentials fails with Error running kubelogin: [Errno 2] No such file or directory: '' despite kubelogin correctly installed and on PATH

6 participants