summaryrefslogtreecommitdiff
path: root/src/conf_mode/container.py
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-02-02 10:05:05 +0100
committerGitHub <noreply@github.com>2024-02-02 10:05:05 +0100
commit4b0a78b0d2e4e0ea813e93b0842ae3aed15d1a43 (patch)
tree04aa9fc0f5571f1b96b006211bbda02fac89ce96 /src/conf_mode/container.py
parentf2de4378b5048fb4fc3a493aa2a214a320dd8d48 (diff)
parentfaa4c87d93c7808c6a4edd8eddd29049ec8ec3fa (diff)
downloadvyos-1x-4b0a78b0d2e4e0ea813e93b0842ae3aed15d1a43.tar.gz
vyos-1x-4b0a78b0d2e4e0ea813e93b0842ae3aed15d1a43.zip
Merge pull request #2927 from ishioni/T5955
container: T5955: add uid/gid settings
Diffstat (limited to 'src/conf_mode/container.py')
-rwxr-xr-xsrc/conf_mode/container.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/conf_mode/container.py b/src/conf_mode/container.py
index 59d11c5a3..321d00abf 100755
--- a/src/conf_mode/container.py
+++ b/src/conf_mode/container.py
@@ -214,6 +214,10 @@ def verify(container):
if {'allow_host_networks', 'network'} <= set(container_config):
raise ConfigError(f'"allow-host-networks" and "network" for "{name}" cannot be both configured at the same time!')
+ # gid cannot be set without uid
+ if 'gid' in container_config and 'uid' not in container_config:
+ raise ConfigError(f'Cannot set "gid" without "uid" for container')
+
# Add new network
if 'network' in container:
for network, network_config in container['network'].items():
@@ -308,6 +312,14 @@ def generate_run_arguments(name, container_config):
# If listen_addresses is empty, just include the standard publish command
port += f' --publish {sport}:{dport}/{protocol}'
+ # Set uid and gid
+ uid = ''
+ if 'uid' in container_config:
+ uid = container_config['uid']
+ if 'gid' in container_config:
+ uid += ':' + container_config['gid']
+ uid = f'--user {uid}'
+
# Bind volume
volume = ''
if 'volume' in container_config:
@@ -320,7 +332,7 @@ def generate_run_arguments(name, container_config):
container_base_cmd = f'--detach --interactive --tty --replace {cap_add} ' \
f'--memory {memory}m --shm-size {shared_memory}m --memory-swap 0 --restart {restart} ' \
- f'--name {name} {hostname} {device} {port} {volume} {env_opt} {label}'
+ f'--name {name} {hostname} {device} {port} {volume} {env_opt} {label} {uid}'
entrypoint = ''
if 'entrypoint' in container_config: