-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libcontainer/system: move userns utilities to separate package
Moving these utilities to a separate package, so that consumers of this package don't have to pull in the whole "system" package. Looking at uses of these utilities (outside of runc itself); `RunningInUserNS()` is used by [various external consumers][1], so adding a "Deprecated" alias for this. [1]: https://grep.app/search?current=2&q=.RunningInUserNS Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
- Loading branch information
Showing
15 changed files
with
70 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package system | ||
|
||
import "github.com/opencontainers/runc/libcontainer/userns" | ||
|
||
var RunningInUserNS = userns.RunningInUserNS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package userns | ||
|
||
// RunningInUserNS detects whether we are currently running in a user namespace. | ||
// Originally copied from github.com/lxc/lxd/shared/util.go | ||
var RunningInUserNS = runningInUserNS |
2 changes: 1 addition & 1 deletion
2
libcontainer/system/system_fuzzer.go → libcontainer/userns/userns_fuzzer.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// +build gofuzz | ||
|
||
package system | ||
package userns | ||
|
||
import ( | ||
"strings" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package userns | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/opencontainers/runc/libcontainer/user" | ||
) | ||
|
||
var ( | ||
inUserNS bool | ||
nsOnce sync.Once | ||
) | ||
|
||
// runningInUserNS detects whether we are currently running in a user namespace. | ||
// Originally copied from github.com/lxc/lxd/shared/util.go | ||
func runningInUserNS() bool { | ||
nsOnce.Do(func() { | ||
uidmap, err := user.CurrentProcessUIDMap() | ||
if err != nil { | ||
// This kernel-provided file only exists if user namespaces are supported | ||
return | ||
} | ||
inUserNS = uidMapInUserNS(uidmap) | ||
}) | ||
return inUserNS | ||
} | ||
|
||
func uidMapInUserNS(uidmap []user.IDMap) bool { | ||
/* | ||
* We assume we are in the initial user namespace if we have a full | ||
* range - 4294967295 uids starting at uid 0. | ||
*/ | ||
if len(uidmap) == 1 && uidmap[0].ID == 0 && uidmap[0].ParentID == 0 && uidmap[0].Count == 4294967295 { | ||
return false | ||
} | ||
return true | ||
} |
2 changes: 1 addition & 1 deletion
2
libcontainer/system/linux_test.go → libcontainer/userns/userns_linux_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// +build linux | ||
|
||
package system | ||
package userns | ||
|
||
import ( | ||
"strings" | ||
|
10 changes: 4 additions & 6 deletions
10
libcontainer/system/unsupported.go → libcontainer/userns/userns_unsupported.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters