mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 18:00:08 +00:00
This updates vendored runc/libcontainer to 1.1.0, and google/cadvisor to a version updated to runc 1.1.0 (google/cadvisor#3048). Changes in vendor are generated by (roughly): ./hack/pin-dependency.sh github.com/google/cadvisor v0.44.0 ./hack/pin-dependency.sh github.com/opencontainers/runc v1.1.0 ./hack/update-vendor.sh ./hack/lint-dependencies.sh # And follow all its recommendations. ./hack/update-vendor.sh ./hack/update-internal-modules.sh ./hack/lint-dependencies.sh # Re-check everything again. Co-Authored-By: Kir Kolyshkin <kolyshkin@gmail.com>
69 lines
2.0 KiB
Go
69 lines
2.0 KiB
Go
package configs
|
|
|
|
import "errors"
|
|
|
|
var (
|
|
errNoUIDMap = errors.New("User namespaces enabled, but no uid mappings found.")
|
|
errNoUserMap = errors.New("User namespaces enabled, but no user mapping found.")
|
|
errNoGIDMap = errors.New("User namespaces enabled, but no gid mappings found.")
|
|
errNoGroupMap = errors.New("User namespaces enabled, but no group mapping found.")
|
|
)
|
|
|
|
// 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, errNoUIDMap
|
|
}
|
|
id, found := c.hostIDFromMapping(containerId, c.UidMappings)
|
|
if !found {
|
|
return -1, errNoUserMap
|
|
}
|
|
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, errNoGIDMap
|
|
}
|
|
id, found := c.hostIDFromMapping(containerId, c.GidMappings)
|
|
if !found {
|
|
return -1, errNoGroupMap
|
|
}
|
|
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
|
|
}
|