mirror of
https://github.com/docker/cli.git
synced 2026-09-27 17:56:04 -04:00
vendor: github.com/moby/sys/userns v0.2.1
userns: fix user-namespace detection on OpenVZ, where namespace inode numbers are virtualized. full diff: https://github.com/moby/sys/userns/compare/v0.2.0...v0.2.1 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
+1
-1
@@ -90,7 +90,7 @@ require (
|
|||||||
github.com/klauspost/compress v1.19.2 // indirect
|
github.com/klauspost/compress v1.19.2 // indirect
|
||||||
github.com/moby/docker-image-spec v1.3.1 // indirect
|
github.com/moby/docker-image-spec v1.3.1 // indirect
|
||||||
github.com/moby/sys/user v0.4.1 // indirect
|
github.com/moby/sys/user v0.4.1 // indirect
|
||||||
github.com/moby/sys/userns v0.2.0 // indirect
|
github.com/moby/sys/userns v0.2.1 // indirect
|
||||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||||
github.com/prometheus/client_golang v1.22.0 // indirect
|
github.com/prometheus/client_golang v1.22.0 // indirect
|
||||||
github.com/prometheus/client_model v0.6.1 // indirect
|
github.com/prometheus/client_model v0.6.1 // indirect
|
||||||
|
|||||||
+2
-2
@@ -112,8 +112,8 @@ github.com/moby/sys/symlink v0.3.0 h1:GZX89mEZ9u53f97npBy4Rc3vJKj7JBDj/PN2I22GrN
|
|||||||
github.com/moby/sys/symlink v0.3.0/go.mod h1:3eNdhduHmYPcgsJtZXW1W4XUJdZGBIkttZ8xKqPUJq0=
|
github.com/moby/sys/symlink v0.3.0/go.mod h1:3eNdhduHmYPcgsJtZXW1W4XUJdZGBIkttZ8xKqPUJq0=
|
||||||
github.com/moby/sys/user v0.4.1 h1:RgjRlaDKi/Xmyrz4t8lyzXT6v2ooFeO/7xtchmhVWE0=
|
github.com/moby/sys/user v0.4.1 h1:RgjRlaDKi/Xmyrz4t8lyzXT6v2ooFeO/7xtchmhVWE0=
|
||||||
github.com/moby/sys/user v0.4.1/go.mod h1:E9QsW5WRe1kUAf7kW8hXKwu1uhsZEAdPLYHYSDudF4Y=
|
github.com/moby/sys/user v0.4.1/go.mod h1:E9QsW5WRe1kUAf7kW8hXKwu1uhsZEAdPLYHYSDudF4Y=
|
||||||
github.com/moby/sys/userns v0.2.0 h1:nEtDtp7NCV/6dutSklNe8FrENPwFdc4mXnZqC/JWgXM=
|
github.com/moby/sys/userns v0.2.1 h1:4OvdM7BcPkASbuouHsbW3aeMJSFlYDldBRnXVZhaRk8=
|
||||||
github.com/moby/sys/userns v0.2.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
|
github.com/moby/sys/userns v0.2.1/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
|
||||||
github.com/moby/term v0.5.2 h1:6qk3FJAFDs6i/q3W/pQ97SX192qKfZgGjCQqfCJkgzQ=
|
github.com/moby/term v0.5.2 h1:6qk3FJAFDs6i/q3W/pQ97SX192qKfZgGjCQqfCJkgzQ=
|
||||||
github.com/moby/term v0.5.2/go.mod h1:d3djjFCrjnB+fl8NJux+EJzu0msscUP+f8it8hPkFLc=
|
github.com/moby/term v0.5.2/go.mod h1:d3djjFCrjnB+fl8NJux+EJzu0msscUP+f8it8hPkFLc=
|
||||||
github.com/morikuni/aec v1.1.0 h1:vBBl0pUnvi/Je71dsRrhMBtreIqNMYErSAbEeb8jrXQ=
|
github.com/morikuni/aec v1.1.0 h1:vBBl0pUnvi/Je71dsRrhMBtreIqNMYErSAbEeb8jrXQ=
|
||||||
|
|||||||
+31
-1
@@ -2,6 +2,7 @@ package userns
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -23,7 +24,16 @@ var inUserNS = sync.OnceValue(runningInUserNS)
|
|||||||
func runningInUserNS() bool {
|
func runningInUserNS() bool {
|
||||||
var st syscall.Stat_t
|
var st syscall.Stat_t
|
||||||
if err := syscall.Stat("/proc/self/ns/user", &st); err == nil {
|
if err := syscall.Stat("/proc/self/ns/user", &st); err == nil {
|
||||||
return st.Ino != procUserInitIno
|
// The kernel's initial user namespace inode is definitive when it
|
||||||
|
// matches. OpenVZ virtualizes namespace inode numbers, so a mismatch
|
||||||
|
// must fall back to uid_map-based detection there.
|
||||||
|
if st.Ino == procUserInitIno {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if runningInOpenVZ() {
|
||||||
|
return runningInUserNSFromUIDMap()
|
||||||
|
}
|
||||||
|
return true
|
||||||
} else if !os.IsNotExist(err) {
|
} else if !os.IsNotExist(err) {
|
||||||
// As long as /proc/self/ns/user exists, we are on a modern kernel.
|
// As long as /proc/self/ns/user exists, we are on a modern kernel.
|
||||||
// Other errors indicate an unexpected procfs state, where assuming the
|
// Other errors indicate an unexpected procfs state, where assuming the
|
||||||
@@ -35,6 +45,10 @@ func runningInUserNS() bool {
|
|||||||
// through procfs at /proc/self/ns/user.
|
// through procfs at /proc/self/ns/user.
|
||||||
// TODO: Remove this fallback once Linux kernels older than 3.8 are no
|
// TODO: Remove this fallback once Linux kernels older than 3.8 are no
|
||||||
// longer supported.
|
// longer supported.
|
||||||
|
return runningInUserNSFromUIDMap()
|
||||||
|
}
|
||||||
|
|
||||||
|
func runningInUserNSFromUIDMap() bool {
|
||||||
file, err := os.Open("/proc/self/uid_map")
|
file, err := os.Open("/proc/self/uid_map")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// This kernel-provided file only exists if user namespaces are supported.
|
// This kernel-provided file only exists if user namespaces are supported.
|
||||||
@@ -69,3 +83,19 @@ func uidMapInUserNS(uidMap string) bool {
|
|||||||
initNS := a == 0 && b == 0 && c == 4294967295
|
initNS := a == 0 && b == 0 && c == 4294967295
|
||||||
return !initNS
|
return !initNS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// runningInOpenVZ reports whether the process is running inside an OpenVZ
|
||||||
|
// container.
|
||||||
|
//
|
||||||
|
// OpenVZ exposes /proc/vz both on the host and inside containers, while
|
||||||
|
// /proc/bc is only exposed on the host. This follows systemd's OpenVZ
|
||||||
|
// detection:
|
||||||
|
// https://github.com/systemd/systemd/blob/v261.2/src/basic/virt.c#L642-L653
|
||||||
|
func runningInOpenVZ() bool {
|
||||||
|
var st syscall.Stat_t
|
||||||
|
if err := syscall.Stat("/proc/vz", &st); err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
err := syscall.Stat("/proc/bc", &st)
|
||||||
|
return errors.Is(err, syscall.ENOENT)
|
||||||
|
}
|
||||||
|
|||||||
Vendored
+1
-1
@@ -231,7 +231,7 @@ github.com/moby/sys/symlink
|
|||||||
# github.com/moby/sys/user v0.4.1
|
# github.com/moby/sys/user v0.4.1
|
||||||
## explicit; go 1.18
|
## explicit; go 1.18
|
||||||
github.com/moby/sys/user
|
github.com/moby/sys/user
|
||||||
# github.com/moby/sys/userns v0.2.0
|
# github.com/moby/sys/userns v0.2.1
|
||||||
## explicit; go 1.21
|
## explicit; go 1.21
|
||||||
github.com/moby/sys/userns
|
github.com/moby/sys/userns
|
||||||
# github.com/moby/term v0.5.2
|
# github.com/moby/term v0.5.2
|
||||||
|
|||||||
Reference in New Issue
Block a user