Skip to content

Commit e51ed22

Browse files
authored
Merge pull request moby#5446 from profnandaa/fix-4901-powershell-in-path
fix: WCOW: add powershell.exe dir to default PATH for backward compatibiliy
2 parents 609aa14 + 70fb3d0 commit e51ed22

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

frontend/dockerfile/dockerfile_test.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ var allTests = integration.TestFuncs(
213213
testLocalCustomSessionID,
214214
testTargetStageNameArg,
215215
testStepNames,
216+
testPowershellInDefaultPathOnWindows,
216217
)
217218

218219
// Tests that depend on the `security.*` entitlements
@@ -1813,7 +1814,7 @@ COPY Dockerfile .
18131814
entrypoint []string
18141815
env []string
18151816
}{
1816-
{p: "windows/amd64", entrypoint: []string{"cmd", "/S", "/C", "foo bar"}, env: []string{"PATH=c:\\Windows\\System32;c:\\Windows"}},
1817+
{p: "windows/amd64", entrypoint: []string{"cmd", "/S", "/C", "foo bar"}, env: []string{"PATH=c:\\Windows\\System32;c:\\Windows;C:\\Windows\\System32\\WindowsPowerShell\\v1.0"}},
18171818
{p: "linux/amd64", entrypoint: []string{"/bin/sh", "-c", "foo bar"}, env: []string{"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"}},
18181819
} {
18191820
t.Run(exp.p, func(t *testing.T) {
@@ -1950,6 +1951,49 @@ COPY --from=base /out/ /
19501951
require.Equal(t, "value:final", string(dt))
19511952
}
19521953

1954+
func testPowershellInDefaultPathOnWindows(t *testing.T, sb integration.Sandbox) {
1955+
integration.SkipOnPlatform(t, "!windows")
1956+
1957+
f := getFrontend(t, sb)
1958+
1959+
// just testing that the powershell path is in PATH
1960+
// but not testing powershell itself since it will need
1961+
// servercore image that is too bulky for just one single test.
1962+
dockerfile := []byte(`
1963+
FROM nanoserver
1964+
USER ContainerAdministrator
1965+
RUN echo %PATH% > env_path.txt
1966+
`)
1967+
dir := integration.Tmpdir(
1968+
t,
1969+
fstest.CreateFile("Dockerfile", dockerfile, 0600),
1970+
)
1971+
c, err := client.New(sb.Context(), sb.Address())
1972+
require.NoError(t, err)
1973+
defer c.Close()
1974+
1975+
destDir := t.TempDir()
1976+
_, err = f.Solve(sb.Context(), c, client.SolveOpt{
1977+
Exports: []client.ExportEntry{
1978+
{
1979+
Type: client.ExporterLocal,
1980+
OutputDir: destDir,
1981+
},
1982+
},
1983+
LocalMounts: map[string]fsutil.FS{
1984+
dockerui.DefaultLocalNameDockerfile: dir,
1985+
dockerui.DefaultLocalNameContext: dir,
1986+
},
1987+
}, nil)
1988+
require.NoError(t, err)
1989+
1990+
dt, err := os.ReadFile(filepath.Join(destDir, "env_path.txt"))
1991+
require.NoError(t, err)
1992+
1993+
envPath := string(dt)
1994+
require.Contains(t, envPath, "C:\\Windows\\System32\\WindowsPowerShell\\v1.0")
1995+
}
1996+
19531997
func testExportMultiPlatform(t *testing.T, sb integration.Sandbox) {
19541998
integration.SkipOnPlatform(t, "windows")
19551999
workers.CheckFeatureCompat(t, sb, workers.FeatureOCIExporter, workers.FeatureMultiPlatform)

util/system/path.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const DefaultPathEnvUnix = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/s
1616
// DefaultPathEnvWindows is windows style list of directories to search for
1717
// executables. Each directory is separated from the next by a colon
1818
// ';' character .
19-
const DefaultPathEnvWindows = "c:\\Windows\\System32;c:\\Windows"
19+
const DefaultPathEnvWindows = "c:\\Windows\\System32;c:\\Windows;C:\\Windows\\System32\\WindowsPowerShell\\v1.0"
2020

2121
func DefaultPathEnv(os string) string {
2222
if os == "windows" {

0 commit comments

Comments
 (0)