mirror of
https://github.com/weaveworks/scope.git
synced 2026-05-13 04:37:36 +00:00
``` $ gvt delete github.com/opencontainers/runc/libcontainer/cgroups $ gvt delete github.com/opencontainers/runc/libcontainer/configs $ gvt delete github.com/opencontainers/runc/libcontainer/system $ gvt delete github.com/opencontainers/runc/libcontainer/user $ gvt delete github.com/opencontainers/runc/libcontainer/utils $ gvt fetch --tag v1.0.0-rc5 github.com/opencontainers/runc/libcontainer 2018/07/23 17:08:18 Fetching: github.com/opencontainers/runc/libcontainer 2018/07/23 17:08:24 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/vishvananda/netlink 2018/07/23 17:08:24 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/golang.org/x/sys/unix 2018/07/23 17:08:24 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/cyphar/filepath-securejoin 2018/07/23 17:08:24 ·· Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/pkg/errors 2018/07/23 17:08:24 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/opencontainers/selinux/go-selinux/label 2018/07/23 17:08:25 ·· Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/opencontainers/selinux/go-selinux 2018/07/23 17:08:25 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/containerd/console 2018/07/23 17:08:25 ·· Fetching recursive dependency: github.com/opencontainers/runc/vendor/golang.org/x/sys/windows 2018/07/23 17:08:25 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/sirupsen/logrus 2018/07/23 17:08:25 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/godbus/dbus 2018/07/23 17:08:25 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/mrunalp/fileutils 2018/07/23 17:08:25 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/coreos/go-systemd/util 2018/07/23 17:08:25 ·· Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/coreos/pkg/dlopen 2018/07/23 17:08:25 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/golang/protobuf/proto 2018/07/23 17:08:25 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/syndtr/gocapability/capability 2018/07/23 17:08:25 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/coreos/go-systemd/dbus 2018/07/23 17:08:25 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/opencontainers/runtime-spec/specs-go 2018/07/23 17:08:25 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/seccomp/libseccomp-golang 2018/07/23 17:08:25 · Fetching recursive dependency: github.com/opencontainers/runc/vendor/github.com/docker/go-units ```
62 lines
1.9 KiB
Go
62 lines
1.9 KiB
Go
package configs
|
|
|
|
import "fmt"
|
|
|
|
// HostUID gets the translated uid for the process on host which could be
|
|
// different when user namespaces are enabled.
|
|
func (c Config) HostUID(containerId int) (int, error) {
|
|
if c.Namespaces.Contains(NEWUSER) {
|
|
if c.UidMappings == nil {
|
|
return -1, fmt.Errorf("User namespaces enabled, but no uid mappings found.")
|
|
}
|
|
id, found := c.hostIDFromMapping(containerId, c.UidMappings)
|
|
if !found {
|
|
return -1, fmt.Errorf("User namespaces enabled, but no user mapping found.")
|
|
}
|
|
return id, nil
|
|
}
|
|
// Return unchanged id.
|
|
return containerId, nil
|
|
}
|
|
|
|
// HostRootUID gets the root uid for the process on host which could be non-zero
|
|
// when user namespaces are enabled.
|
|
func (c Config) HostRootUID() (int, error) {
|
|
return c.HostUID(0)
|
|
}
|
|
|
|
// HostGID gets the translated gid for the process on host which could be
|
|
// different when user namespaces are enabled.
|
|
func (c Config) HostGID(containerId int) (int, error) {
|
|
if c.Namespaces.Contains(NEWUSER) {
|
|
if c.GidMappings == nil {
|
|
return -1, fmt.Errorf("User namespaces enabled, but no gid mappings found.")
|
|
}
|
|
id, found := c.hostIDFromMapping(containerId, c.GidMappings)
|
|
if !found {
|
|
return -1, fmt.Errorf("User namespaces enabled, but no group mapping found.")
|
|
}
|
|
return id, nil
|
|
}
|
|
// Return unchanged id.
|
|
return containerId, nil
|
|
}
|
|
|
|
// HostRootGID gets the root gid for the process on host which could be non-zero
|
|
// when user namespaces are enabled.
|
|
func (c Config) HostRootGID() (int, error) {
|
|
return c.HostGID(0)
|
|
}
|
|
|
|
// Utility function that gets a host ID for a container ID from user namespace map
|
|
// if that ID is present in the map.
|
|
func (c Config) hostIDFromMapping(containerID int, uMap []IDMap) (int, bool) {
|
|
for _, m := range uMap {
|
|
if (containerID >= m.ContainerID) && (containerID <= (m.ContainerID + m.Size - 1)) {
|
|
hostID := m.HostID + (containerID - m.ContainerID)
|
|
return hostID, true
|
|
}
|
|
}
|
|
return -1, false
|
|
}
|