Skip to content

Commit

Permalink
fix: lack of passwd / group should be warning in --oci mode
Browse files Browse the repository at this point in the history
In the --oci launcher, When a minimal container doesn't have an
`/etc/passwd` or `/etc/groups` file then don't fail with a fatal
error. Instead warn like the native runtime does.

Fixes sylabs#1286
  • Loading branch information
dtrudg committed Feb 6, 2023
1 parent 104493f commit 51fdcbe
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions e2e/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,7 @@ func E2ETests(env e2e.TestEnv) testhelper.Tests {
t.Run("user", c.testDockerUSER)
// Regressions
t.Run("issue 4524", c.issue4524)
t.Run("issue 1286", c.issue1286)
},
// Tests that are especially slow, or run against a local docker
// registry, can be run in parallel, with `--disable-cache` used within
Expand Down
17 changes: 17 additions & 0 deletions e2e/docker/regressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,20 @@ From: continuumio/miniconda3:latest
),
)
}

// https://github.com/sylabs/singularity/issues/1286
// Ensure the bare docker://hello-world image runs in all modes
func (c ctx) issue1286(t *testing.T) {
for _, profile := range e2e.AllProfiles() {
c.env.RunSingularity(
t,
e2e.AsSubtest(profile.String()),
e2e.WithProfile(profile),
e2e.WithCommand("run"),
e2e.WithArgs("docker://hello-world"),
e2e.ExpectExit(0,
e2e.ExpectOutput(e2e.ContainMatch, "Hello from Docker!"),
),
)
}
}
12 changes: 12 additions & 0 deletions e2e/internal/e2e/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@ var OCIProfiles = map[string]Profile{
},
}

// AllProfiles is initialized to the union of NativeProfiles and OCIProfiles
func AllProfiles() map[string]Profile {
ap := map[string]Profile{}
for k, p := range NativeProfiles {
ap[k] = p
}
for k, p := range OCIProfiles {
ap[k] = p
}
return ap
}

// Privileged returns whether the test should be executed with
// elevated privileges or not.
func (p Profile) Privileged() bool {
Expand Down
10 changes: 4 additions & 6 deletions internal/pkg/runtime/launcher/oci/launcher_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,18 +327,16 @@ func (l *Launcher) updatePasswdGroup(rootfs string, uid, gid uint32) error {
sylog.Debugf("Updating passwd file: %s", containerPasswd)
content, err := files.Passwd(containerPasswd, pw.Dir, int(uid))
if err != nil {
return fmt.Errorf("while creating passwd file: %w", err)
}
if err := os.WriteFile(containerPasswd, content, 0o755); err != nil {
sylog.Warningf("%s", err)
} else if err := os.WriteFile(containerPasswd, content, 0o755); err != nil {
return fmt.Errorf("while writing passwd file: %w", err)
}

sylog.Debugf("Updating group file: %s", containerGroup)
content, err = files.Group(containerGroup, int(uid), []int{int(gid)})
if err != nil {
return fmt.Errorf("while creating group file: %w", err)
}
if err := os.WriteFile(containerGroup, content, 0o755); err != nil {
sylog.Warningf("%s", err)
} else if err := os.WriteFile(containerGroup, content, 0o755); err != nil {
return fmt.Errorf("while writing passwd file: %w", err)
}

Expand Down

0 comments on commit 51fdcbe

Please sign in to comment.