Skip to content

Commit 942223f

Browse files
authored
Fix AzureCLICredential argument quoting on Windows (#25533)
1 parent 5f413ae commit 942223f

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

sdk/azidentity/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
### Bugs Fixed
1717

18+
- `AzureCLICredential` quoted arguments incorrectly on Windows
19+
1820
### Other Changes
1921

2022
## 1.14.0-beta.1 (2025-10-07)

sdk/azidentity/developer_credential_util.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"errors"
1313
"os"
1414
"os/exec"
15-
"runtime"
1615
"strings"
1716
"time"
1817
)
@@ -30,17 +29,9 @@ var shellExec = func(ctx context.Context, credName, command string) ([]byte, err
3029
ctx, cancel = context.WithTimeout(ctx, cliTimeout)
3130
defer cancel()
3231
}
33-
var cmd *exec.Cmd
34-
if runtime.GOOS == "windows" {
35-
dir := os.Getenv("SYSTEMROOT")
36-
if dir == "" {
37-
return nil, newCredentialUnavailableError(credName, `environment variable "SYSTEMROOT" has no value`)
38-
}
39-
cmd = exec.CommandContext(ctx, "cmd.exe", "/c", command)
40-
cmd.Dir = dir
41-
} else {
42-
cmd = exec.CommandContext(ctx, "/bin/sh", "-c", command)
43-
cmd.Dir = "/bin"
32+
cmd, err := buildCmd(ctx, credName, command)
33+
if err != nil {
34+
return nil, err
4435
}
4536
cmd.Env = os.Environ()
4637
stderr := bytes.Buffer{}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
//go:build !windows
5+
6+
package azidentity
7+
8+
import (
9+
"context"
10+
"os/exec"
11+
)
12+
13+
func buildCmd(ctx context.Context, _, command string) (*exec.Cmd, error) {
14+
cmd := exec.CommandContext(ctx, "/bin/sh", "-c", command)
15+
cmd.Dir = "/bin"
16+
return cmd, nil
17+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package azidentity
5+
6+
import (
7+
"context"
8+
"os"
9+
"os/exec"
10+
"syscall"
11+
)
12+
13+
func buildCmd(ctx context.Context, credName, command string) (*exec.Cmd, error) {
14+
dir := os.Getenv("SYSTEMROOT")
15+
if dir == "" {
16+
return nil, newCredentialUnavailableError(credName, `environment variable "SYSTEMROOT" has no value`)
17+
}
18+
cmd := exec.CommandContext(ctx, "cmd.exe")
19+
cmd.Dir = dir
20+
cmd.SysProcAttr = &syscall.SysProcAttr{CmdLine: "/c " + command}
21+
return cmd, nil
22+
}

0 commit comments

Comments
 (0)