mirror of https://github.com/containers/podman.git
Merge pull request #16895 from giuseppe/always-create-userns-with-euid-not-0
rootless: always create userns with euid != 0
This commit is contained in:
commit
db648dc005
|
@ -420,13 +420,14 @@ func makeRuntime(runtime *Runtime) (retErr error) {
|
|||
}
|
||||
logrus.Debugf("Set libpod namespace to %q", runtime.config.Engine.Namespace)
|
||||
|
||||
hasCapSysAdmin, err := unshare.HasCapSysAdmin()
|
||||
if err != nil {
|
||||
return err
|
||||
needsUserns := os.Geteuid() != 0
|
||||
if !needsUserns {
|
||||
hasCapSysAdmin, err := unshare.HasCapSysAdmin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
needsUserns = !hasCapSysAdmin
|
||||
}
|
||||
|
||||
needsUserns := !hasCapSysAdmin
|
||||
|
||||
// Set up containers/storage
|
||||
var store storage.Store
|
||||
if needsUserns {
|
||||
|
|
|
@ -172,7 +172,7 @@ func joinUserAndMountNS(pid uint, pausePid string) (bool, int, error) {
|
|||
if err != nil {
|
||||
return false, 0, err
|
||||
}
|
||||
if hasCapSysAdmin || os.Getenv("_CONTAINERS_USERNS_CONFIGURED") != "" {
|
||||
if (os.Geteuid() == 0 && hasCapSysAdmin) || os.Getenv("_CONTAINERS_USERNS_CONFIGURED") != "" {
|
||||
return false, 0, nil
|
||||
}
|
||||
|
||||
|
@ -223,6 +223,11 @@ func GetConfiguredMappings(quiet bool) ([]idtools.IDMap, []idtools.IDMap, error)
|
|||
}
|
||||
|
||||
func copyMappings(from, to string) error {
|
||||
// when running as non-root always go through the newuidmap/newgidmap
|
||||
// configuration since this is the expectation when running on Kubernetes
|
||||
if os.Geteuid() != 0 {
|
||||
return errors.New("copying mappings is allowed only for root")
|
||||
}
|
||||
content, err := os.ReadFile(from)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -243,7 +248,7 @@ func becomeRootInUserNS(pausePid, fileToRead string, fileOutput *os.File) (_ boo
|
|||
return false, 0, err
|
||||
}
|
||||
|
||||
if hasCapSysAdmin || os.Getenv("_CONTAINERS_USERNS_CONFIGURED") != "" {
|
||||
if (os.Geteuid() == 0 && hasCapSysAdmin) || os.Getenv("_CONTAINERS_USERNS_CONFIGURED") != "" {
|
||||
if os.Getenv("_CONTAINERS_USERNS_CONFIGURED") == "init" {
|
||||
return false, 0, runInUser()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue