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 1, 2024
1 parent 4dd319e commit 2014dbd
Show file tree
Hide file tree
Showing 2 changed files with 6 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
5 changes: 4 additions & 1 deletion internal/pkg/ociimage/unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import (
umocilayer "github.com/opencontainers/umoci/oci/layer"
"github.com/opencontainers/umoci/pkg/idtools"
"github.com/sylabs/singularity/v4/internal/pkg/util/fs"
"github.com/sylabs/singularity/v4/pkg/util/namespaces"
"github.com/sylabs/singularity/v4/pkg/sylog"

)

// isExtractable checks if we have extractable layers in the image. Shouldn't be
Expand Down Expand Up @@ -69,7 +71,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 2014dbd

Please sign in to comment.