Repository navigation
Description
Summary
On Windows, lstk az start-interception cannot register the LocalStack cloud in the Azure CLI when the CLI is installed in its default folder, C:\Program Files\Microsoft SDKs\Azure\CLI2.
lstk runs az cloud register --cloud-config <JSON>, az resolves to az.cmd, and cmd.exe breaks that command line at the space in C:\Program Files because of the quotes the JSON adds, so the call fails with 'C:\Program' is not recognized as an internal or external command.
Retrying does not help, so az cannot be routed to the emulator on a Windows machine with a default Azure CLI installation.
Environment
- lstk 1.4.0, installed with
npm install -g @localstack/lstk@1.4.0. The same code is in v1.4.2 and onmain(dd80374). - Windows Server 2025 on a GitHub-hosted
windows-latestrunner (image 20261021.299.1), Azure CLI 2.91.0 installed by its MSI, commands run from Git Bash. - The LocalStack for Azure emulator running in a container named
localstack-azure, whichlstk startfinds.
Steps to reproduce
- Install the Azure CLI with its MSI, which uses
C:\Program Files\Microsoft SDKs\Azure\CLI2, and install lstk. - Start the Azure emulator, for example with
lstk start --type azure. - Run
lstk az start-interception.
Actual result
Registering 'LocalStack' custom cloud...
Error: could not register 'LocalStack' cloud: az [cloud register --name LocalStack --cloud-config {"endpoints":{"activeDirectory":"https://azure.localhost.localstack.cloud:4566", ...}} --only-show-errors]: exit status 1: 'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
In the first log below, the samples' runner script retries the command 5 times, with the same result each time.
Full logs: localstack-azure-samples job (run through run-samples.sh) and aks-samples job (direct lstk az start-interception).
Expected result
The LocalStack cloud is registered and az is routed to the emulator, as on Linux and macOS.
Cause
registerLocalStackCloud(internal/azureconfig/azureconfig.go:236) passes the cloud configuration as a JSON argument:azurecli.Run(ctx, azEnv, "cloud", action, "--name", CloudName, "--cloud-config", cloudConfigJSON, "--only-show-errors").execAz(internal/azurecli/exec.go:52-61) resolvesazwithexec.LookPath, which on Windows findsaz.cmd, and starts it withexec.CommandContext.- Windows runs a batch file through
cmd.exe. Go quotes the program path, because it contains a space, and escapes the JSON's quotes with backslashes, so the command line holds many quote characters.cmd.exekeeps the quotes only when there is exactly one pair; otherwise it strips the opening quote together with the last one (cmd, Remarks), which leavesC:\Program Files\...unquoted, and the command line breaks at the space.
Probably affected too (not reproduced)
lstk setup azure registers the cloud through the same function (Setup, internal/azureconfig/azureconfig.go:197), so it most likely fails the same way.
Workaround
Put the Azure CLI on a path without spaces, first on the PATH. In PowerShell, for example:
New-Item -ItemType Junction -Path C:\azure-cli -Target "C:\Program Files\Microsoft SDKs\Azure\CLI2"
$env:PATH = "C:\azure-cli\wbin;$env:PATH"Suggested fix
Keep the JSON off the command line: write the cloud configuration to a temporary file and pass --cloud-config @<file>, which az cloud register and az cloud update accept (az cloud: "JSON encoded cloud configuration. Use @{file} to load from a file."). It works the same on every platform.
Building the command line for cmd.exe by hand (SysProcAttr.CmdLine) would also work on Windows, but it is easy to get wrong.
Activity