Skip to content

Commit e28ee33

Browse files
authored
Merge pull request #1279 from sylabs/main
Merge main to 3.11 for bugfixes
2 parents 9dde5c4 + 104493f commit e28ee33

File tree

7 files changed

+65
-4
lines changed

7 files changed

+65
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# SingularityCE Changelog
22

3+
## Changes Since Last Release
4+
5+
### Bug Fixes
6+
7+
- Avoid UID / GID readonly var warnings with `--env-file`.
8+
39
## 3.11.0 Release Candidate 1 \[2023-01-11\]
410

511
*This is the first release candidate for the upcoming Singularity 3.11.0

cmd/internal/cli/build_linux.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ func runBuild(cmd *cobra.Command, args []string) {
148148
dest := args[0]
149149
spec := args[1]
150150

151-
if syscall.Getuid() != 0 && !buildArgs.fakeroot && fs.IsFile(spec) && !isImage(spec) {
151+
// Non-remote build with def file as source
152+
rootNeeded := !buildArgs.remote && fs.IsFile(spec) && !isImage(spec)
153+
154+
if rootNeeded && syscall.Getuid() != 0 && !buildArgs.fakeroot {
152155
prootPath, err := bin.FindBin("proot")
153156
if err != nil {
154157
sylog.Fatalf("--remote, --fakeroot, or the proot command are required to build this source as a non-root user")

e2e/env/env.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019-2022, Sylabs Inc. All rights reserved.
1+
// Copyright (c) 2019-2023, Sylabs Inc. All rights reserved.
22
// This software is licensed under a 3-clause BSD license. Please consult the
33
// LICENSE.md file distributed with the sources of this project regarding your
44
// rights to use or distribute this software.
@@ -640,6 +640,7 @@ func E2ETests(env e2e.TestEnv) testhelper.Tests {
640640
"issue 5057": c.issue5057, // https://github.com/sylabs/hpcng/issues/5057
641641
"issue 5426": c.issue5426, // https://github.com/sylabs/hpcng/issues/5426
642642
"issue 43": c.issue43, // https://github.com/sylabs/singularity/issues/43
643+
"issue 1263": c.issue1263, // https://github.com/sylabs/singularity/issues/1263
643644
//
644645
// --oci mode
645646
//

e2e/env/regressions.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020-2022, Sylabs Inc. All rights reserved.
1+
// Copyright (c) 2020-2023, Sylabs Inc. All rights reserved.
22
// This software is licensed under a 3-clause BSD license. Please consult the
33
// LICENSE.md file distributed with the sources of this project regarding your
44
// rights to use or distribute this software.
@@ -122,3 +122,29 @@ func (c ctx) issue43(t *testing.T) {
122122
),
123123
)
124124
}
125+
126+
// https://github.com/sylabs/singularity/issues/1263
127+
// With --env-file we should avoid any override of UID / GID that are set readonly by bash.
128+
func (c ctx) issue1263(t *testing.T) {
129+
e2e.EnsureImage(t, c.env)
130+
131+
// An empty env file is sufficient, as UID/GID come from the mvdan.cc/sh evaluation of it.
132+
envFile, err := e2e.WriteTempFile(c.env.TestDir, "env-file", "")
133+
if err != nil {
134+
t.Fatal(err)
135+
}
136+
t.Cleanup(func() {
137+
os.Remove(envFile)
138+
})
139+
140+
c.env.RunSingularity(
141+
t,
142+
e2e.WithProfile(e2e.UserProfile),
143+
e2e.WithCommand("exec"),
144+
e2e.WithArgs("--env-file", envFile, c.env.ImagePath, "/bin/true"),
145+
e2e.ExpectExit(
146+
0,
147+
e2e.ExpectError(e2e.UnwantedContainMatch, "readonly variable"),
148+
),
149+
)
150+
}

e2e/imgbuild/imgbuild.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,5 +1624,6 @@ func E2ETests(env e2e.TestEnv) testhelper.Tests {
16241624
"issue 5435": c.issue5435, // https://github.com/hpcng/singularity/issues/5435
16251625
"issue 5668": c.issue5668, // https://github.com/hpcng/singularity/issues/5435
16261626
"issue 5690": c.issue5690, // https://github.com/hpcng/singularity/issues/5690
1627+
"issue 1273": c.issue1273, // https://github.com/sylabs/singularity/issues/1273
16271628
}
16281629
}

e2e/imgbuild/regressions.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,3 +445,22 @@ From: {{ .From }}
445445
e2e.ExpectExit(0),
446446
)
447447
}
448+
449+
// Ensure a `--remote` build request fails (not-authorized) and proot flow is not invoked.
450+
func (c *imgBuildTests) issue1273(t *testing.T) {
451+
image := filepath.Join(c.env.TestDir, "issue_1273.sif")
452+
453+
c.env.RunSingularity(
454+
t,
455+
e2e.WithProfile(e2e.UserProfile),
456+
e2e.WithCommand("build"),
457+
e2e.WithArgs("--remote", image, "testdata/proot_alpine.def"),
458+
e2e.PostRun(func(t *testing.T) {
459+
os.Remove(image)
460+
}),
461+
e2e.ExpectExit(
462+
255,
463+
e2e.ExpectError(e2e.UnwantedContainMatch, "proot"),
464+
),
465+
)
466+
}

internal/pkg/runtime/launcher/native/launcher_linux.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019-2022, Sylabs Inc. All rights reserved.
1+
// Copyright (c) 2019-2023, Sylabs Inc. All rights reserved.
22
// This software is licensed under a 3-clause BSD license. Please consult the
33
// LICENSE.md file distributed with the sources of this project regarding your
44
// rights to use or distribute this software.
@@ -859,6 +859,11 @@ func (l *Launcher) setEnv(ctx context.Context, args []string) error {
859859
sylog.Warningf("Ignored environment variable %q: '=' is missing", envar)
860860
continue
861861
}
862+
// Don't attempt to overwrite bash builtin readonly vars
863+
// https://github.com/sylabs/singularity/issues/1263
864+
if e[0] == "UID" || e[0] == "GID" {
865+
continue
866+
}
862867
// Ensure we don't overwrite --env variables with environment file
863868
if _, ok := l.cfg.Env[e[0]]; ok {
864869
sylog.Warningf("Ignored environment variable %s from %s: override from --env", e[0], l.cfg.EnvFile)

0 commit comments

Comments
 (0)