Rootless podman on trixie

Published

This is a guide on how to install cradle-cms as a rootless podman systemd service on a DietPI trixie distribution. DietPI provides a minimal debian installation mainly targeted for SBC:s but it works well on PC:s and laptops too.

This guide is for systems that does not have podman quadlet support.

We are going to use an older version of podman from debian trixie. If you have a more recent version v5.8+ you should follow our rootless podman installation guide.

Install podman and required dependencies

apt install podman dbus-user-session passt polkitd uidmap slirp4netns

Fix so that rootless users can bind to priviledged ports

Rootless users can not normally bind to priviledged ports such as http and https. To circumvent that we lower the unpriviledged port threshold on the whole system to 80. It would’ve been nice if we could add capabilites to a user or service/container instead.

Allow all users to bind to ports starting from 80 http and reboot the system.

echo "net.ipv4.ip_unprivileged_port_start=80" > /etc/sysctl.d/unprivileged.conf
reboot

Create a non root user

We want a rootless podman that runs as a non root cradle user.

adduser --comment "Cradle Podman" cradle
# setup podman user runtime directory
mkdir -p /run/user/$(id -u cradle)
chown -R cradle:cradle /run/user/$(id -u cradle)
echo '[ -z "${XDG_RUNTIME_DIR}" ] && export XDG_RUNTIME_DIR=/run/user/$(id -ru)' >> /home/cradle/.profile
chown -R cradle:cradle /home/cradle/.profile
# allow cradle user to have lingering processes
systemctl unmask systemd-logind.service
systemctl start systemd-logind.service
loginctl enable-linger cradle

Instead of password login you should use ssh authorized_keys and disable password logins.

Login as the cradle user and setup podman environment

Login to your server as the cradle user ssh cradle@your.server.ip

# check that you have a working podman and that the version is `v5.8+`
podman -v
# login to the registry using your licensekey and account password
# we store the authentication in `auth.json` as it's needed for automatic updates 
mkdir -p /home/cradle/.config/containers/systemd
podman login --authfile /home/cradle/.config/containers/auth.json registry.cradlecms.com/cradle-cms
# test that pulling from the registry using the `auth.json` actually works
podman pull --authfile /home/cradle/.config/containers/auth.json registry.cradlecms.com/cradle-cms:latest

Create container configuration

This is a basic configuration which uses a self signed certificate for https. If you need a letsencrypt certificate for your own domain name then change Environment=ACME=false to Environment=DOMAIN_NAME=your.domain.name.

Create the following podman container file ~/.config/containers/systemd/cradle-cms.container

[Unit]
Description=Cradle CMS

[Container]
Image=registry.cradlecms.com/cradle-cms:latest
ContainerName=cradle-cms
Environment=ACME=false
PublishPort=443:4040
PublishPort=80:8080
Volume=storage:/storage
AutoUpdate=registry
Label=io.containers.autoupdate.authfile=/home/cradle/.config/containers/auth.json

[Service]
Restart=always
RestartSec=10

[Install]
WantedBy=default.target

In production we recommend that you pin the version number instead of using :latest so set it to a feature release number like :0.14.

For tests or if you want early access to new features you may use the :test tag.

Verify that podman can generate a service file from the container specification.

/usr/lib/systemd/system-generators/podman-system-generator --user --dryrun 

Start the cradle-cms service

# create the service
systemctl --user daemon-reload
# check that the cradle-cms.service has been generated
systemctl --user cat cradle-cms
# start the container
systemctl --user start cradle-cms
# check the service status
systemctl --user status cradle-cms

Install and start the auto-update service

systemctl --user enable --now podman-auto-update.timer

The auto update timer is by default set to daily updates. If you want to schedule the updates more specifically i.e when you have least traffic, you can override the timer configuration.

# override the auto update OnCalendar timer
systemctl --user edit podman-auto-update.timer
# Insert the following lines so that podman auto update runs daily at 4am.
[Timer]
OnCalendar=
OnCalendar=*-*-* 04:00:00

And finally, reboot the server to ensure the service starts up automatically as expected.

That’s it, test by opening a browser and enter the hostname or ip address of your server. If you configured a domain name using letsencrypt the first request takes a couple of seconds.

Troubleshooting

Since there are many linux distributions and they work a bit differently, you likely need to adjust this setup a bit. The most common problems are missing or conflicting dependencies and various permission errors.

If you get service not found when starting the service it’s most likely caused by errors in the podman quadlet config. You can validate the service file generation using /usr/lib/systemd/system-generators/podman-system-generator --user --dryrun and correct any reported issues. Then run systemctl --user daemon-reload which should produce a cradle-cms service file, verify with systemctl --user cat cradle-cms.

You can inspect the container logs using podman logs cradle-cms.