Skip to content

Commit 93c67dd

Browse files
committed
Log when CNB_LAUNCH_UMASK is incorrect
Pass a logger down to the process launcher and log when setting the umaks is incorrect and continue. Signed-off-by: adelaney21 <[email protected]>
1 parent 4b20b35 commit 93c67dd

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

cmd/launcher/cli/launcher.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func RunLaunch() error {
4949
ExecD: launch.NewExecDRunner(),
5050
Shell: launch.DefaultShell,
5151
Setenv: os.Setenv,
52+
Logger: cmd.DefaultLogger,
5253
}
5354

5455
if err := launcher.Launch(os.Args[0], os.Args[1:]); err != nil {

launch/launcher.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/buildpacks/lifecycle/api"
1111
"github.com/buildpacks/lifecycle/env"
12+
"github.com/buildpacks/lifecycle/log"
1213
)
1314

1415
var (
@@ -26,9 +27,11 @@ type Launcher struct {
2627
ExecD ExecD
2728
Shell Shell
2829
LayersDir string
30+
Logger *log.DefaultLogger
2931
PlatformAPI *api.Version
3032
Processes []Process
3133
Setenv func(string, string) error
34+
Setumask func(Env) error
3235
}
3336

3437
type ExecFunc func(argv0 string, argv []string, envv []string) error
@@ -69,9 +72,12 @@ func (l *Launcher) LaunchProcess(self string, proc Process) error {
6972
}
7073
proc.WorkingDirectory = getProcessWorkingDirectory(proc, l.AppDir)
7174

72-
err := SetUmask(l.Env)
73-
if err != nil {
74-
return errors.Wrap(err, "umask")
75+
if l.Setumask == nil {
76+
l.Setumask = SetUmask
77+
}
78+
err := l.Setumask(l.Env)
79+
if err != nil && l.Logger != nil {
80+
l.Logger.Errorf("invalid umask: %s", err)
7581
}
7682

7783
if proc.Direct {

launch/launcher_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ func testLauncher(t *testing.T, when spec.G, it spec.S) {
124124
// set command to something on the real path so exec.LookPath succeeds
125125
process.Command = launch.NewRawCommand([]string{"sh"})
126126

127+
launcher.Setumask = func(_ launch.Env) error {
128+
return nil
129+
}
127130
mockEnv.EXPECT().Get("PATH").Return("some-path").AnyTimes()
128131
launcher.Setenv = func(k string, v string) error {
129132
if k == "PATH" {
@@ -373,6 +376,9 @@ func testLauncher(t *testing.T, when spec.G, it spec.S) {
373376
it.Before(func() {
374377
shell = &fakeShell{}
375378
launcher.Shell = shell
379+
launcher.Setumask = func(_ launch.Env) error {
380+
return nil
381+
}
376382
})
377383

378384
it("sets Caller to self", func() {

launch/umask_unix.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,33 @@
33
package launch
44

55
import (
6+
"fmt"
67
"strconv"
78
"syscall"
89

910
"github.com/pkg/errors"
1011
)
1112

13+
const (
14+
umaskEnvVar = "CNB_LAUNCH_UMASK"
15+
)
16+
1217
// SetUmask on unix systems from the value in the `UMASK` environment variable
1318
func SetUmask(env Env) error {
1419
return SetUmaskWith(env, syscall.Umask)
1520
}
1621

1722
// SetUmaskWith the injected function umaskFn
1823
func SetUmaskWith(env Env, umaskFn func(int) int) error {
19-
if umask := env.Get("UMASK"); umask != "" {
20-
u, err := strconv.ParseInt(umask, 8, 0)
21-
if err != nil {
22-
return errors.Wrap(err, "invalid umask value")
23-
}
24-
umaskFn(int(u))
24+
umask := env.Get(umaskEnvVar)
25+
if umask == "" {
26+
return nil
27+
}
28+
29+
u, err := strconv.ParseInt(umask, 8, 0)
30+
if err != nil {
31+
return errors.Wrap(err, fmt.Sprintf("invalid umask value %s", umask))
2532
}
33+
umaskFn(int(u))
2634
return nil
2735
}

launch/umask_unix_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func testUmask(t *testing.T, when spec.G, it spec.S) {
3333

3434
for _, tt := range tests {
3535
t.Run(tt.name, func(t *testing.T) {
36-
environ := env.NewLaunchEnv([]string{"UMASK=" + tt.umask}, "", "")
36+
environ := env.NewLaunchEnv([]string{"CNB_LAUNCH_UMASK=" + tt.umask}, "", "")
3737

3838
var called int
3939
spy := func(m int) int {
@@ -50,7 +50,7 @@ func testUmask(t *testing.T, when spec.G, it spec.S) {
5050
})
5151

5252
it("returns error for invalid umask", func() {
53-
environ := env.NewLaunchEnv([]string{"UMASK=invalid"}, "", "")
53+
environ := env.NewLaunchEnv([]string{"CNB_LAUNCH_UMASK=invalid"}, "", "")
5454

5555
err := launch.SetUmaskWith(environ, func(int) int { return 0 })
5656

0 commit comments

Comments
 (0)