Skip to content

Commit

Permalink
Merge pull request #5446 from profnandaa/fix-4901-powershell-in-path
Browse files Browse the repository at this point in the history
fix: WCOW: add powershell.exe dir to default PATH for backward compatibiliy
  • Loading branch information
tonistiigi authored Dec 16, 2024
2 parents 609aa14 + 70fb3d0 commit e51ed22
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
46 changes: 45 additions & 1 deletion frontend/dockerfile/dockerfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ var allTests = integration.TestFuncs(
testLocalCustomSessionID,
testTargetStageNameArg,
testStepNames,
testPowershellInDefaultPathOnWindows,
)

// Tests that depend on the `security.*` entitlements
Expand Down Expand Up @@ -1813,7 +1814,7 @@ COPY Dockerfile .
entrypoint []string
env []string
}{
{p: "windows/amd64", entrypoint: []string{"cmd", "/S", "/C", "foo bar"}, env: []string{"PATH=c:\\Windows\\System32;c:\\Windows"}},
{p: "windows/amd64", entrypoint: []string{"cmd", "/S", "/C", "foo bar"}, env: []string{"PATH=c:\\Windows\\System32;c:\\Windows;C:\\Windows\\System32\\WindowsPowerShell\\v1.0"}},
{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"}},
} {
t.Run(exp.p, func(t *testing.T) {
Expand Down Expand Up @@ -1950,6 +1951,49 @@ COPY --from=base /out/ /
require.Equal(t, "value:final", string(dt))
}

func testPowershellInDefaultPathOnWindows(t *testing.T, sb integration.Sandbox) {
integration.SkipOnPlatform(t, "!windows")

f := getFrontend(t, sb)

// just testing that the powershell path is in PATH
// but not testing powershell itself since it will need
// servercore image that is too bulky for just one single test.
dockerfile := []byte(`
FROM nanoserver
USER ContainerAdministrator
RUN echo %PATH% > env_path.txt
`)
dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", dockerfile, 0600),
)
c, err := client.New(sb.Context(), sb.Address())
require.NoError(t, err)
defer c.Close()

destDir := t.TempDir()
_, err = f.Solve(sb.Context(), c, client.SolveOpt{
Exports: []client.ExportEntry{
{
Type: client.ExporterLocal,
OutputDir: destDir,
},
},
LocalMounts: map[string]fsutil.FS{
dockerui.DefaultLocalNameDockerfile: dir,
dockerui.DefaultLocalNameContext: dir,
},
}, nil)
require.NoError(t, err)

dt, err := os.ReadFile(filepath.Join(destDir, "env_path.txt"))
require.NoError(t, err)

envPath := string(dt)
require.Contains(t, envPath, "C:\\Windows\\System32\\WindowsPowerShell\\v1.0")
}

func testExportMultiPlatform(t *testing.T, sb integration.Sandbox) {
integration.SkipOnPlatform(t, "windows")
workers.CheckFeatureCompat(t, sb, workers.FeatureOCIExporter, workers.FeatureMultiPlatform)
Expand Down
2 changes: 1 addition & 1 deletion util/system/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const DefaultPathEnvUnix = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/s
// DefaultPathEnvWindows is windows style list of directories to search for
// executables. Each directory is separated from the next by a colon
// ';' character .
const DefaultPathEnvWindows = "c:\\Windows\\System32;c:\\Windows"
const DefaultPathEnvWindows = "c:\\Windows\\System32;c:\\Windows;C:\\Windows\\System32\\WindowsPowerShell\\v1.0"

func DefaultPathEnv(os string) string {
if os == "windows" {
Expand Down

0 comments on commit e51ed22

Please sign in to comment.