Skip to content

Commit

Permalink
fix: use rootless umoci inside user namespace
Browse files Browse the repository at this point in the history
If we are running from within a user namespace, then use rootless OCI
layer with umoci.

This permits the extraction to complete when singularity is run under
`unshare -r`.

Part of sylabs#2698
  • Loading branch information
dtrudg committed Mar 4, 2024
1 parent 28058f2 commit 430134a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
the original image.
- Fix `target: no such file or directory` error in native mode when extracting
layers from certain OCI images that manipulate hard links across layers.
- Fix extraction of OCI layers when run in a root mapped user namespace
(e.g.. `unshare -r`).

## 4.1.1 \[2024-02-01\]

Expand Down
4 changes: 3 additions & 1 deletion internal/pkg/ociimage/unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/opencontainers/umoci/pkg/idtools"
"github.com/sylabs/singularity/v4/internal/pkg/util/fs"
"github.com/sylabs/singularity/v4/pkg/sylog"
"github.com/sylabs/singularity/v4/pkg/util/namespaces"
)

// isExtractable checks if we have extractable layers in the image. Shouldn't be
Expand Down Expand Up @@ -69,7 +70,8 @@ func UnpackRootfs(_ context.Context, srcImage v1.Image, destDir string) (err err
}

// Allow unpacking as non-root
if os.Geteuid() != 0 {
insideUserNs, _ := namespaces.IsInsideUserNamespace(os.Getpid())
if os.Geteuid() != 0 || insideUserNs {
mapOptions.Rootless = true

uidMap, err := idtools.ParseMapping(fmt.Sprintf("0:%d:1", os.Geteuid()))
Expand Down

0 comments on commit 430134a

Please sign in to comment.