mirror of
https://github.com/containers/podman.git
synced 2025-08-06 03:19:52 +08:00
libpod: allow userns=keep-id for root
copy the current mapping into a new user namespace, and run into a separate user namespace. Closes: https://github.com/containers/podman/issues/17337 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -113,13 +113,34 @@ func ParseSignal(rawSignal string) (syscall.Signal, error) {
|
||||
|
||||
// GetKeepIDMapping returns the mappings and the user to use when keep-id is used
|
||||
func GetKeepIDMapping(opts *namespaces.KeepIDUserNsOptions) (*stypes.IDMappingOptions, int, int, error) {
|
||||
if !rootless.IsRootless() {
|
||||
return nil, -1, -1, errors.New("keep-id is only supported in rootless mode")
|
||||
}
|
||||
options := stypes.IDMappingOptions{
|
||||
HostUIDMapping: false,
|
||||
HostGIDMapping: false,
|
||||
}
|
||||
|
||||
if !rootless.IsRootless() {
|
||||
uids, err := rootless.ReadMappingsProc("/proc/self/uid_map")
|
||||
if err != nil {
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
gids, err := rootless.ReadMappingsProc("/proc/self/uid_map")
|
||||
if err != nil {
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
options.UIDMap = uids
|
||||
options.GIDMap = gids
|
||||
|
||||
uid, gid := 0, 0
|
||||
if opts.UID != nil {
|
||||
uid = int(*opts.UID)
|
||||
}
|
||||
if opts.GID != nil {
|
||||
gid = int(*opts.GID)
|
||||
}
|
||||
|
||||
return &options, uid, gid, nil
|
||||
}
|
||||
|
||||
min := func(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
|
Reference in New Issue
Block a user