Skip to content

Commit 43c415e

Browse files
committed
fix: Show informative error for non-executable exec target
When the target executable of `singularity exec` lacks `+x` permissions, show a sensible error message rather than `permission denied`. Fixes #607
1 parent 20a0c17 commit 43c415e

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
- Support nvidia-container-cli v1.8.0 and above, via fix to capability set.
4949
- Do not truncate environment variables with commas
50+
- Show an informative error when `exec` target is not executable.
5051

5152
## v3.9.6 \[2022-03-10\]
5253

Diff for: e2e/actions/actions.go

+16-4
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,10 @@ func (c actionTests) actionExec(t *testing.T) {
109109
homePath := filepath.Join("/home", basename)
110110

111111
tests := []struct {
112-
name string
113-
argv []string
114-
exit int
112+
name string
113+
argv []string
114+
exit int
115+
errorContains string
115116
}{
116117
{
117118
name: "NoCommand",
@@ -250,17 +251,28 @@ func (c actionTests) actionExec(t *testing.T) {
250251
argv: []string{"--no-home", c.env.ImagePath, "ls", "-ld", user.Dir},
251252
exit: 1,
252253
},
254+
{
255+
name: "NotExecutable",
256+
argv: []string{c.env.ImagePath, "/etc/hosts"},
257+
exit: 1,
258+
errorContains: "/etc/hosts is not an executable file in the container. Check it exists and has executable permissions.",
259+
},
253260
}
254261

255262
for _, tt := range tests {
263+
resultOps := []e2e.SingularityCmdResultOp{}
264+
if tt.errorContains != "" {
265+
resultOps = append(resultOps, e2e.ExpectError(e2e.ContainMatch, tt.errorContains))
266+
}
267+
256268
c.env.RunSingularity(
257269
t,
258270
e2e.AsSubtest(tt.name),
259271
e2e.WithProfile(e2e.UserProfile),
260272
e2e.WithCommand("exec"),
261273
e2e.WithDir("/tmp"),
262274
e2e.WithArgs(tt.argv...),
263-
e2e.ExpectExit(tt.exit),
275+
e2e.ExpectExit(tt.exit, resultOps...),
264276
)
265277
}
266278
}

Diff for: internal/pkg/util/fs/files/action_scripts.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,14 @@ sylog debug "Running action command ${__singularity_cmd__}"
157157
158158
case "${__singularity_cmd__}" in
159159
exec)
160-
exec "$@" ;;
160+
# This uses the limited type -p behavior of mvdan.cc/sh and is *not* POSIX.
161+
execbin=$(type -p "$1")
162+
if test $? -ne 0 || test -z "${execbin}" ; then
163+
sylog error "$1 is not an executable file in the container. Check it exists and has executable permissions."
164+
exit 1
165+
fi
166+
exec "$@"
167+
;;
161168
shell)
162169
if test -n "${SINGULARITY_SHELL:-}" -a -x "${SINGULARITY_SHELL:-}"; then
163170
exec "${SINGULARITY_SHELL:-}" "$@"

0 commit comments

Comments
 (0)