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

quadlet .container can no longer use systemd specifier in a volume name #24872

Open
7fffffff opened this issue Dec 19, 2024 · 3 comments
Open
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@7fffffff
Copy link

Issue Description

With podman 4.9.4 and 5.2.2, I can use a systemd specifier like %N to name the volume to use but 5.3.1 rejects this

Steps to reproduce the issue

# valkey-demo.container
[Unit]
Description=valkey demo
Wants=network-online.target
After=network-online.target

[Container]
Image=docker.io/valkey/valkey:8.0.1
Pull=missing
PublishPort=127.0.0.1:6379:6379/tcp
#EnvironmentFile=./%N.env
User=999
Group=999
DropCapability=ALL
NoNewPrivileges=true
Volume=%N.volume:/data
Exec=/usr/local/bin/valkey-server --save 60 1 --loglevel warning

[Service]
Restart=always
# valkey-demo.volume
[Volume]

Describe the results you received

$ podman version
Client:       Podman Engine
Version:      5.3.1
API Version:  5.3.1
Go Version:   go1.23.2 (Red Hat 1.23.2-1.el9)
Built:        Wed Nov 27 03:57:53 2024
OS/Arch:      linux/amd64

$ /usr/libexec/podman/quadlet -dryrun -user
quadlet-generator[40649]: Loading source unit file /home/stream/.config/containers/systemd/valkey-demo.container
quadlet-generator[40649]: Loading source unit file /home/stream/.config/containers/systemd/valkey-demo.volume
---valkey-demo-volume.service---
[X-Volume]

[Unit]
Wants=podman-user-wait-network-online.service
After=podman-user-wait-network-online.service
SourcePath=/home/stream/.config/containers/systemd/valkey-demo.volume
RequiresMountsFor=%t/containers

[Service]
ExecStart=/usr/bin/podman volume create --ignore systemd-valkey-demo
SyslogIdentifier=%N
Type=oneshot
RemainAfterExit=yes

quadlet-generator[40649]: converting "valkey-demo.container": requested Quadlet source %N.volume was not found

Describe the results you expected

$ podman version
Client:       Podman Engine
Version:      5.2.2
API Version:  5.2.2
Go Version:   go1.22.7 (Red Hat 1.22.7-2.el9_5)
Built:        Tue Nov 12 07:49:10 2024
OS/Arch:      linux/amd64

$ /usr/libexec/podman/quadlet -dryrun -user
quadlet-generator[6036]: Error occurred resolving path "/etc/containers/systemd/users": lstat /etc/containers/systemd/users: no such file or directory
quadlet-generator[6036]: Error occurred resolving path "/etc/containers/systemd/users/1000": lstat /etc/containers/systemd/users: no such file or directory
quadlet-generator[6036]: Loading source unit file /home/alma/.config/containers/systemd/valkey-demo.container
quadlet-generator[6036]: Loading source unit file /home/alma/.config/containers/systemd/valkey-demo.volume
---valkey-demo-volume.service---
[X-Volume]

[Unit]
RequiresMountsFor=%t/containers

[Service]
ExecStart=/usr/bin/podman volume create --ignore systemd-valkey-demo
Type=oneshot
RemainAfterExit=yes
SyslogIdentifier=%N

---valkey-demo.service---
[Unit]
Wants=network-online.target
After=network-online.target
Description=valkey demo
Wants=network-online.target
After=network-online.target
SourcePath=/home/alma/.config/containers/systemd/valkey-demo.container
RequiresMountsFor=%t/containers
Requires=%N-volume.service
After=%N-volume.service

[X-Container]
Image=docker.io/valkey/valkey:8.0.1
Pull=missing
PublishPort=127.0.0.1:6379:6379/tcp
#EnvironmentFile=./%N.env
User=999
Group=999
DropCapability=ALL
NoNewPrivileges=true
Volume=%N.volume:/data
Exec=/usr/local/bin/valkey-server --save 60 1 --loglevel warning

[Service]
Restart=always
Environment=PODMAN_SYSTEMD_UNIT=%n
KillMode=mixed
ExecStop=/usr/bin/podman rm -v -f -i --cidfile=%t/%N.cid
ExecStopPost=-/usr/bin/podman rm -v -f -i --cidfile=%t/%N.cid
Delegate=yes
Type=notify
NotifyAccess=all
SyslogIdentifier=%N
ExecStart=/usr/bin/podman run --name=systemd-%N --cidfile=%t/%N.cid --replace --rm --cgroups=split --sdnotify=conmon -d --security-opt=no-new-privileges --cap-drop=all --user=999:999 -v systemd-%N:/data --publish 127.0.0.1:6379:6379/tcp --pull missing docker.io/valkey/valkey:8.0.1 /usr/local/bin/valkey-server --save 60 1 --loglevel warning

podman info output

host:
  arch: amd64
  buildahVersion: 1.38.0
  cgroupControllers:
  - memory
  - pids
  cgroupManager: systemd
  cgroupVersion: v2
  conmon:
    package: conmon-2.1.12-1.el9.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.1.12, commit: 7ba5bd6c81ff2c10e07aee8c4281d12a2878fa12'
  cpuUtilization:
    idlePercent: 89.92
    systemPercent: 2.84
    userPercent: 7.24
  cpus: 2
  databaseBackend: sqlite
  distribution:
    distribution: centos
    version: "9"
  eventLogger: journald
  freeLocks: 2048
  hostname: localhost.localdomain
  idMappings:
    gidmap:
    - container_id: 0
      host_id: 1000
      size: 1
    - container_id: 1
      host_id: 100000
      size: 65536
    uidmap:
    - container_id: 0
      host_id: 1000
      size: 1
    - container_id: 1
      host_id: 100000
      size: 65536
  kernel: 5.14.0-542.el9.x86_64
  linkmode: dynamic
  logDriver: journald
  memFree: 5166260224
  memTotal: 8057311232
  networkBackend: netavark
  networkBackendInfo:
    backend: netavark
    dns:
      package: aardvark-dns-1.13.1-1.el9.x86_64
      path: /usr/libexec/podman/aardvark-dns
      version: aardvark-dns 1.13.1
    package: netavark-1.13.1-1.el9.x86_64
    path: /usr/libexec/podman/netavark
    version: netavark 1.13.1
  ociRuntime:
    name: crun
    package: crun-1.19-2.el9.x86_64
    path: /usr/bin/crun
    version: |-
      crun version 1.19
      commit: db31c42ac46e20b5527f5339dcbf6f023fcd539c
      rundir: /run/user/1000/crun
      spec: 1.0.0
      +SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +CRIU +YAJL
  os: linux
  pasta:
    executable: /usr/bin/pasta
    package: passt-0^20241121.g238c69f-1.el9.x86_64
    version: |
      pasta 0^20241121.g238c69f-1.el9.x86_64
      Copyright Red Hat
      GNU General Public License, version 2 or later
        <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
      This is free software: you are free to change and redistribute it.
      There is NO WARRANTY, to the extent permitted by law.
  remoteSocket:
    exists: true
    path: /run/user/1000/podman/podman.sock
  rootlessNetworkCmd: pasta
  security:
    apparmorEnabled: false
    capabilities: CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_FOWNER,CAP_FSETID,CAP_KILL,CAP_NET_BIND_SERVICE,CAP_SETFCAP,CAP_SETGID,CAP_SETPCAP,CAP_SETUID,CAP_SYS_CHROOT
    rootless: true
    seccompEnabled: true
    seccompProfilePath: /usr/share/containers/seccomp.json
    selinuxEnabled: true
  serviceIsRemote: false
  slirp4netns:
    executable: /usr/bin/slirp4netns
    package: slirp4netns-1.3.1-1.el9.x86_64
    version: |-
      slirp4netns version 1.3.1
      commit: e5e368c4f5db6ae75c2fce786e31eef9da6bf236
      libslirp: 4.4.0
      SLIRP_CONFIG_VERSION_MAX: 3
      libseccomp: 2.5.2
  swapFree: 3439325184
  swapTotal: 3439325184
  uptime: 0h 9m 53.00s
  variant: ""
plugins:
  authorization: null
  log:
  - k8s-file
  - none
  - passthrough
  - journald
  network:
  - bridge
  - macvlan
  - ipvlan
  volume:
  - local
registries:
  search:
  - registry.access.redhat.com
  - registry.redhat.io
  - docker.io
store:
  configFile: /home/stream/.config/containers/storage.conf
  containerStore:
    number: 0
    paused: 0
    running: 0
    stopped: 0
  graphDriverName: overlay
  graphOptions: {}
  graphRoot: /home/stream/.local/share/containers/storage
  graphRootAllocated: 29775364096
  graphRootUsed: 5518712832
  graphStatus:
    Backing Filesystem: xfs
    Native Overlay Diff: "true"
    Supports d_type: "true"
    Supports shifting: "false"
    Supports volatile: "true"
    Using metacopy: "false"
  imageCopyTmpDir: /var/tmp
  imageStore:
    number: 0
  runRoot: /run/user/1000/containers
  transientStore: false
  volumePath: /home/stream/.local/share/containers/storage/volumes
version:
  APIVersion: 5.3.1
  Built: 1732708673
  BuiltTime: Wed Nov 27 03:57:53 2024
  GitCommit: ""
  GoVersion: go1.23.2 (Red Hat 1.23.2-1.el9)
  Os: linux
  OsArch: linux/amd64
  Version: 5.3.1

Podman in a container

No

Privileged Or Rootless

Rootless

Upstream Latest Release

Yes

Additional environment details

No response

Additional information

No response

@7fffffff 7fffffff added the kind/bug Categorizes issue or PR as related to a bug. label Dec 19, 2024
@giuseppe
Copy link
Member

795851e introduced the issue.

@ygalblum should we handle %N or should it be passed down to systemd?

@rhatdan
Copy link
Member

rhatdan commented Dec 19, 2024

I think we should special case %N

@ygalblum
Copy link
Contributor

Not sure what should be done here.

In previous versions, if the .volume file was not found when converting the .container file, the code assumed that the volume name is systemd-<Name of the Volume Unit> and the service name was <Name of the Volume Unit>-volume.service.
As a result, the generated service file has -v systemd-%N:/data in the ExecStart and Requires=%N-volume.service in its [Unit] section.

Setting aside the service name (for which we added support in 5.3.x), the configuration in the issue description worked in previous versions only because the volume name was not set in the .volume file.

If it were something like:

[Volume]
VolumeName=foo

Then, the default resolution of the volume would cause the service to fail because the volume's name would have been foo and not systemd-valkey-demo.

As for the current version, since Quadlet also support setting the name of the generated service, if the key ServiceName is set in the .volume file, the dependency would fail.

To summarize, this configuration worked in previous versions in the sense that it created the service units. But, it might have generated faulty service units.

So, I see three options here:

  1. Break the previous behaviour and not support specifiers - generates correct service files, but breaks previously supported configuration.
  2. Restore the previous behaviour and just assume the names whenever the file is not found - same as just passing it down the systemd but without caring why the files were not found.
  3. Really support specifiers (I don't think %N is the only one we may encounter here). That means resolve the specifier in order to find the real dependencies - best in terms of outcome, but it will require work

BTW the same applies for other dependencies, e.g. Network

WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

4 participants