Skip to content

Commit 104493f

Browse files
authored
Merge pull request #1278 from dtrudg/issue1263
fix: avoid readonly warnings with --env-file
2 parents fba06ee + f6a2396 commit 104493f

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
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

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+
}

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)