Skip to content

Commit

Permalink
Merge pull request #29 from buildpacks/fix/userns
Browse files Browse the repository at this point in the history
Run build containers with updated settings
  • Loading branch information
natalieparellano authored Jul 10, 2024
2 parents cbc880a + 2049ae2 commit dded2a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/build/phase_config_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ type PhaseConfigProvider struct {
}

func NewPhaseConfigProvider(name string, lifecycleExec *LifecycleExecution, ops ...PhaseConfigProviderOperation) *PhaseConfigProvider {
hostConf := new(container.HostConfig)
hostConf.UsernsMode = "host"
if lifecycleExec.os != "windows" {
hostConf.SecurityOpt = []string{"no-new-privileges=true"}
}
provider := &PhaseConfigProvider{
ctrConf: new(container.Config),
hostConf: new(container.HostConfig),
hostConf: hostConf,
name: name,
os: lifecycleExec.os,
infoWriter: logging.GetWriterForLevel(lifecycleExec.logger, logging.InfoLevel),
Expand Down
3 changes: 3 additions & 0 deletions internal/build/phase_config_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ func testPhaseConfigProvider(t *testing.T, when spec.G, it spec.S) {
h.AssertSliceContainsMatch(t, phaseConfigProvider.HostConfig().Binds, "pack-app-.*:/workspace")

h.AssertEq(t, phaseConfigProvider.HostConfig().Isolation, container.IsolationEmpty)
h.AssertEq(t, phaseConfigProvider.HostConfig().UsernsMode, container.UsernsMode("host"))
h.AssertSliceContains(t, phaseConfigProvider.HostConfig().SecurityOpt, "no-new-privileges=true")
})

when("building for Windows", func() {
Expand All @@ -72,6 +74,7 @@ func testPhaseConfigProvider(t *testing.T, when spec.G, it spec.S) {
phaseConfigProvider := build.NewPhaseConfigProvider("some-name", lifecycle)

h.AssertEq(t, phaseConfigProvider.HostConfig().Isolation, container.IsolationProcess)
h.AssertSliceNotContains(t, phaseConfigProvider.HostConfig().SecurityOpt, "no-new-privileges=true")
})
})

Expand Down

0 comments on commit dded2a0

Please sign in to comment.