Page MenuHomeVyOS Platform

Podman container errors when environment variable contains an asterisk
Closed, ResolvedPublicBUG

Description

Their were significant changes to the container code in a pull request T9129 as part of these changes it appears that environment variable handling breaks when it contains an asterisk.

For example

set container name my_container environment MY_ENV_VARIABLE value "00 30 03 00 00 00"

works but

set container name my_container environment MY_ENV_VARIABLE value "00 30 03 * * *"

returns

[ container ]
Traceback (most recent call last):
File "/usr/libexec/vyos/services/vyos-configd", line 109, in run_script
  config_manager.apply(script_name, c)
File "/usr/lib/python3/dist-packages/vyos/configmanager.py", line 136, in apply
  mod.apply(config_dict)
File "/usr/libexec/vyos/conf_mode/container.py", line 663, in apply
  cmdl(['systemctl', 'restart', f'vyos-container-{name}'])
File "/usr/lib/python3/dist-packages/vyos/utils/process.py", line 217, in cmdl
  raise OSError(code, feedback)
PermissionError: [Errno 1] failed to run command: systemctl restart vyos-container-my_container
returned: 
exit code: 1

[[container]] failed
Commit failed

Details

Version
-
Is it a breaking change?
Behavior change
Issue type
Bug (incorrect behavior)

Event Timeline

I have setup a very basic container and investigated how the environment variables are actually passed and noticed that they are not being quoted correctly. So
"00 30 03 * * *" end up as just 00

set container name mycontainer environment MY_ENV_VARIABLE value "00 30 03 * * *"
[edit]
vyos@vyos# commit
[edit]
vyos@vyos# cat /run/systemd/generator/vyos-container-
vyos-container-mosquitto.service    vyos-container-mpc-service.service  vyos-container-mycontainer.service  
[edit]
vyos@vyos# cat /run/systemd/generator/vyos-container-mycontainer.service 
# Automatically generated by /usr/lib/systemd/system-generators/podman-system-generator
# 
### Autogenerated by container.py ###
[Unit]
Wants=network-online.target
After=network-online.target
Description=VyOS Container mycontainer
SourcePath=/run/containers/systemd/vyos-container-mycontainer.container
RequiresMountsFor=%t/containers

[X-Container]
ContainerName=mycontainer
Image=alpine
LogDriver=journald
PodmanArgs=--memory=512m
ShmSize=64m
StopTimeout=10
PodmanArgs=--cpus=0
PodmanArgs=--interactive
PodmanArgs=--tty
Network=host
Environment=MY_ENV_VARIABLE=00 30 03 * * *
PodmanArgs=--no-healthcheck

[Service]
Restart=on-failure
Environment=PODMAN_SYSTEMD_UNIT=%n
KillMode=mixed
ExecStop=/usr/bin/podman rm -v -f -i mycontainer
ExecStopPost=-/usr/bin/podman rm -v -f -i mycontainer
Delegate=yes
Type=notify
NotifyAccess=all
SyslogIdentifier=%N
ExecStart=/usr/bin/podman run --name mycontainer --replace --rm --log-driver journald --cgroups=split --stop-timeout 10 --shm-size 64m --network host --sdnotify=conmon -d --env * --env 03 --env 30 --env MY_ENV_VARIABLE=00 --memory=512m --cpus=0 --interactive --tty --no-healthcheck alpine
[edit]

I have looked at how it used to work at it appears it still had the same issue but without the error.

ExecStart=/usr/bin/podman run --name mycontainer --replace --rm --log-driver journald --cgroups=split --stop-timeout 10 --shm-size 64m --network host --sdnotify=conmon -d --env * --env 03 --env 30 --env MY_ENV_VARIABLE=00 --memory=512m --cpus=0 --interactive --tty --no-healthcheck alpine

Is the same with both.

Environment=MY_ENV_VARIABLE=00 30 03 * * *

and

--env MY_ENV_VARIABLE=00

should be

Environment=MY_ENV_VARIABLE="00 30 03 * * *"

and

--env MY_ENV_VARIABLE="00 30 03 * * *"

but none of the environment variables are in quotation marks.

sarthurdev changed the task status from Open to In progress.Fri, Sep 11, 8:40 AM
sarthurdev claimed this task.
Viacheslav triaged this task as Normal priority.Fri, Sep 11, 9:37 AM
Viacheslav moved this task from Need Triage to Completed on the VyOS Rolling board.