Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof-of-concept: set up necessary idmappings for userns_mode=auto in Container.create() #499

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions podman/domain/containers_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,33 @@ def parse_host_port(_container_port, _protocol, _host):
if "userns_mode" in args:
params["userns"] = {"nsmode": args.pop("userns_mode")}

# proof-of-concept
def merge_dicts(d1, d2):
for dk in d2:
if dk in d1:
if not isinstance(d1[dk], dict) or not isinstance(d2[dk], dict):
d1[dk] = d2[dk]
else:
d1[dk] = merge_dicts(d1[dk], d2[dk])
else:
d1[dk] = d2[dk]
return d1

default_idmappings = {
"AutoUserNs": False if params["userns"]["nsmode"] != "auto" else True,
"AutoUserNsOpts": None if params["userns"]["nsmode"] != "auto" else {
"AdditionalUIDMappings": None,
"AdditionalGIDMappings": None,
"PasswdFile": "",
"GroupFile": "",
"InitialSize": 0,
"Size": 0,
},
}

old_idmappings = params.get("idmappings") or {}
params.update(idmappings=merge_dicts(default_idmappings, old_idmappings))

if "uts_mode" in args:
params["utsns"] = {"nsmode": args.pop("uts_mode")}

Expand Down
Loading