Repository navigation
[AKS] Fix #34091: az aks get-credentials: Fix kubelogin conversion for explicit kubeconfig paths - #34099
Conversation
…sion for explicit kubeconfig paths AI-generated by X Engineering Agent via Azure AI Foundry. Foundry-Job: 5cea4d61c0405a0d3cad2061ebf19ec75d5984a5d77936de831da998855811b1
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical and moderate issues remain in kubelogin execution and explicit-path recovery guidance.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Fixes az aks get-credentials kubelogin conversion for explicit kubeconfig paths.
Changes:
- Passes the selected kubeconfig path to kubelogin.
- Adds regression coverage for path, environment, merge, and failure scenarios.
- Preserves nonfatal conversion failures.
File summaries
| File | Summary |
|---|---|
src/azure-cli/azure/cli/command_modules/acs/custom.py |
Updates kubelogin invocation; unresolved executable-path security and explicit-path recovery issues remain. |
src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_custom.py |
Adds focused regression tests for credential conversion scenarios. |
Review details
Suppressed comments (1)
src/azure-cli/azure/cli/command_modules/acs/custom.py:1956
- For an explicit
--filepath, the fallback hint below still tells users to run conversion without--kubeconfig; with noKUBECONFIGset, kubelogin will operate on~/.kube/configinstead of the file just merged, so the devicecode kubeconfig remains unconverted. Include the effectivepathin this recovery command (and quote it for paths containing spaces).
["kubelogin", "convert-kubeconfig", "-l", "azurecli", "--kubeconfig", path],
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| subprocess.run( | ||
| ["kubelogin", "convert-kubeconfig", "-l", "azurecli"], | ||
| cwd=os.path.dirname(path), | ||
| ["kubelogin", "convert-kubeconfig", "-l", "azurecli", "--kubeconfig", path], |
There was a problem hiding this comment.
Aditya Pujara (@a0x1ab) This is a valid Windows executable-search issue and is worth addressing in this PR. The local which() helper searches PATH, but its result is discarded; launching the bare kubelogin name lets Windows CreateProcess search the caller’s current directory before PATH, so it may execute a different kubelogin.exe than the one that was checked. Please retain the resolved value and invoke os.path.abspath(kubelogin_path), matching the existing kubectl hardening in this module. This is compatible with the #34091 fix: keep cwd unset and continue passing --kubeconfig, path.
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
|
🔔 Routing this PR to @Azure/act-observability-squad. |
|
🔔 Routing this PR to @Azure/act-observability-squad. |
|
Please fix CI issues |
…4d61c040 Resolved import-only conflicts in: - src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_custom.py
Live test results —
|
There was a problem hiding this comment.
Review
The explicit kubeconfig-path fix addresses the reported empty working-directory failure, but executable selection still needs correction before human approval. All 52 upstream checks and the Agent live-test run passed on 42bcbf4e3e35b3ade81bafb0bad46de76134c523; the remaining finding is confirmed from the changed invocation, not a CI failure.
Domain edge case: invoke the resolved executable
At src/azure-cli/azure/cli/command_modules/acs/custom.py:2066-2071, which("kubelogin") is used only as a Boolean, while the changed subprocess argument at line 2070 is still the bare name kubelogin. Removing cwd makes the caller's working directory the invocation context. On Windows, CreateProcess can select a current-directory kubelogin.exe before the executable found on PATH, exposing the selected kubeconfig to an unintended process. The same file already documents and avoids this behavior for kubectl at lines 361-367 and 2339-2345.
Store the result of which, normalize a successful result with os.path.abspath(), and use that resolved path as argv[0]. Preserve --kubeconfig path, caller-relative kubeconfig semantics, stdout handling, and the existing nonfatal missing/converter-error behavior.
Update src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_custom.py: the new _run_kubelogin helper replaces argv[0] with sys.executable, and the assertions currently expect the bare name, so those tests cannot detect executable-selection regressions. Return a distinct resolved path from which, assert its absolute form is passed to subprocess, and cover a relative PATH result and Windows current-directory shadowing with a benign fixture. Keep the existing file-content, unrelated-config, and failure-path assertions. Run python -m unittest azure.cli.command_modules.acs.tests.latest.test_custom.AKSGetCredentialsTest in the development environment on Windows and POSIX, then rerun upstream validation and the authorized live-test workflow for the new head.
Test validation
- Live test: Passed. Workflow run
- Regression coverage: For
acs: 1 focused test file(s) changed. Scenario coverage is unverified; review the issue's required conditions, test setup, and assertions before approval. No linked issue was found in the PR timeline; inspect the source issue and its required scenario manually.
I inspected source issue #34091 through the sanitized issue view. The added AKSGetCredentialsTest cases exercise bare, relative, absolute, spaced, and environment-selected kubeconfig paths, and assert the merged YAML uses azurecli without modifying unrelated configurations. Those are changed-test assertions, separate from the Agent workflow result. The child-interpreter converter is a stand-in, not evidence that the real kubelogin executable was selected safely; add the focused executable-path regression above before re-review. No service request/response fields change, so these filesystem assertions do not require an ARM recording update.
Risk assessment
17/100 · Low · High confidence
- Change scope: 2 changed files, 354 changed lines (
+349/-5), including 1 production file. - Affected components:
acs - Risk drivers: public CLI behavior (+18)
- Regression evidence: Changed regression tests are included, reducing risk.
- Confidence: High because changed-line patches were available for every production file.
- Required review: Owning-squad review is recommended for
acsbefore merge.
Posted by x-engineering-agent (Reviewer)
|
Azure/azure-cli#34099 and Azure/azure-cli#34104 implement the same runtime fix; only comments and tests differ. I suggest consolidating into #34099 for its broader test coverage, carrying over useful cases from #34104. Before merging, please also address the executable-resolution feedback: invoke the absolute path returned by |
X Engineering Agent Report⏳ In progress — X Engineering Agent is reviewing this PR at |
🤖 PR Validation — ️✔️ All clear
Related command
az aks get-credentialsDescription
Fixes #34091.
Implemented by X Engineering Agent using Azure AI Foundry. This is an AI-generated change, published by the configured operator.
Testing Guide
az aks get-credentials.src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_custom.py.History Notes
[AKS]
az aks get-credentials: Fix kubelogin conversion for explicit kubeconfig pathsThis checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.