Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/AkihiroSuda/nerdctl/pkg/rootlessutil"
gocni "github.com/containerd/go-cni"
"github.com/sirupsen/logrus"
)

const AppArmorProfileName = "nerdctl-default"
Expand Down Expand Up @@ -83,7 +84,8 @@ func BuildKitHost() string {
}
xdr, err := rootlessutil.XDGRuntimeDir()
if err != nil {
panic(err)
logrus.Warn(err)
xdr = fmt.Sprintf("/run/user/%d", rootlessutil.ParentEUID())
}
return fmt.Sprintf("unix://%s/buildkit/buildkitd.sock", xdr)
}
37 changes: 37 additions & 0 deletions pkg/rootlessutil/rootlessutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,43 @@

package rootlessutil

import (
"os"
"strconv"

"github.com/pkg/errors"
)

func IsRootless() bool {
return IsRootlessParent() || IsRootlessChild()
}

func ParentEUID() int {
if !IsRootlessChild() {
return os.Geteuid()
}
env := os.Getenv("ROOTLESSKIT_PARENT_EUID")
if env == "" {
panic("environment variable ROOTLESSKIT_PARENT_EUID is not set")
}
i, err := strconv.Atoi(env)
if err != nil {
panic(errors.Wrapf(err, "failed to parse ROOTLESSKIT_PARENT_EUID=%q", env))
}
return i
}

func ParentEGID() int {
if !IsRootlessChild() {
return os.Getegid()
}
env := os.Getenv("ROOTLESSKIT_PARENT_EGID")
if env == "" {
panic("environment variable ROOTLESSKIT_PARENT_EGID is not set")
}
i, err := strconv.Atoi(env)
if err != nil {
panic(errors.Wrapf(err, "failed to parse ROOTLESSKIT_PARENT_EGID=%q", env))
}
return i
}
2 changes: 1 addition & 1 deletion pkg/rootlessutil/xdg.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func XDGRuntimeDir() (string, error) {
if euid := os.Getenv("ROOTLESSKIT_PARENT_EUID"); euid != "" {
return "/run/user/" + euid, nil
}
return "", errors.New("environment variable XDG_RUNTIME_DIR is not set")
return "", errors.New("environment variable XDG_RUNTIME_DIR is not set, see https://rootlesscontaine.rs/getting-started/common/login/")
}

func XDGConfigHome() (string, error) {
Expand Down