This commit is contained in:
github-actions[bot] 2025-08-01 00:25:19 +00:00
parent ecd6da2442
commit 65a62d9c1d
2 changed files with 325 additions and 73 deletions

View File

@ -1790,27 +1790,12 @@
</li>
<li class="md-nav__item">
<a href="#installation-in-rootfull-mode" class="md-nav__link">
<a href="#installation-in-rootful-mode" class="md-nav__link">
<span class="md-ellipsis">
Installation in Rootfull Mode
Installation in Rootful Mode
</span>
</a>
<nav class="md-nav" aria-label="Installation in Rootfull Mode">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#self-start-in-rootfull-mode" class="md-nav__link">
<span class="md-ellipsis">
Self-start in Rootfull Mode
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
@ -1824,6 +1809,54 @@
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#rootless-quadlet" class="md-nav__link">
<span class="md-ellipsis">
Rootless Quadlet
</span>
</a>
<nav class="md-nav" aria-label="Rootless Quadlet">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#example-quadlet-file" class="md-nav__link">
<span class="md-ellipsis">
Example Quadlet file
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#mapping-ownership-between-container-and-host-users" class="md-nav__link">
<span class="md-ellipsis">
Mapping ownership between container and host users
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#start-dms-container-at-boot" class="md-nav__link">
<span class="md-ellipsis">
Start DMS container at boot
</span>
</a>
<nav class="md-nav" aria-label="Start DMS container at boot">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#security-in-rootless-mode" class="md-nav__link">
<span class="md-ellipsis">
Security in Rootless Mode
@ -1840,6 +1873,15 @@
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#use-the-pasta-network-driver" class="md-nav__link">
<span class="md-ellipsis">
Use the pasta network driver
</span>
</a>
</li>
<li class="md-nav__item">
@ -1854,15 +1896,6 @@
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#self-start-in-rootless-mode" class="md-nav__link">
<span class="md-ellipsis">
Self-start in Rootless Mode
</span>
</a>
</li>
<li class="md-nav__item">
@ -2550,27 +2583,12 @@
</li>
<li class="md-nav__item">
<a href="#installation-in-rootfull-mode" class="md-nav__link">
<a href="#installation-in-rootful-mode" class="md-nav__link">
<span class="md-ellipsis">
Installation in Rootfull Mode
Installation in Rootful Mode
</span>
</a>
<nav class="md-nav" aria-label="Installation in Rootfull Mode">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#self-start-in-rootfull-mode" class="md-nav__link">
<span class="md-ellipsis">
Self-start in Rootfull Mode
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
@ -2584,6 +2602,54 @@
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#rootless-quadlet" class="md-nav__link">
<span class="md-ellipsis">
Rootless Quadlet
</span>
</a>
<nav class="md-nav" aria-label="Rootless Quadlet">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#example-quadlet-file" class="md-nav__link">
<span class="md-ellipsis">
Example Quadlet file
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#mapping-ownership-between-container-and-host-users" class="md-nav__link">
<span class="md-ellipsis">
Mapping ownership between container and host users
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#start-dms-container-at-boot" class="md-nav__link">
<span class="md-ellipsis">
Start DMS container at boot
</span>
</a>
<nav class="md-nav" aria-label="Start DMS container at boot">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#security-in-rootless-mode" class="md-nav__link">
<span class="md-ellipsis">
Security in Rootless Mode
@ -2600,6 +2666,15 @@
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#use-the-pasta-network-driver" class="md-nav__link">
<span class="md-ellipsis">
Use the pasta network driver
</span>
</a>
</li>
<li class="md-nav__item">
@ -2614,15 +2689,6 @@
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#self-start-in-rootless-mode" class="md-nav__link">
<span class="md-ellipsis">
Self-start in Rootless Mode
</span>
</a>
</li>
<li class="md-nav__item">
@ -2688,7 +2754,7 @@
<p>Running podman in rootless mode requires additional modifications in order to keep your mailserver secure.
Make sure to read the related documentation.</p>
</div>
<h2 id="installation-in-rootfull-mode"><a class="toclink" href="#installation-in-rootfull-mode">Installation in Rootfull Mode</a></h2>
<h2 id="installation-in-rootful-mode"><a class="toclink" href="#installation-in-rootful-mode">Installation in Rootful Mode</a></h2>
<p>While using Podman, you can just manage docker-mailserver as what you did with Docker. Your best friend <code>setup.sh</code> includes the minimum code in order to support Podman since it's 100% compatible with the Docker CLI.</p>
<p>The installation is basically the same. Podman v3.2 introduced a RESTful API that is 100% compatible with the Docker API, so you can use Docker Compose with Podman easily. Install Podman and Docker Compose with your package manager first.</p>
<div class="highlight"><pre><span></span><code>sudo<span class="w"> </span>dnf<span class="w"> </span>install<span class="w"> </span>podman<span class="w"> </span>docker-compose
@ -2702,14 +2768,8 @@ docker<span class="w"> </span>compose<span class="w"> </span>up<span class="w">
docker<span class="w"> </span>compose<span class="w"> </span>ps
</code></pre></div>
<p>You should see that docker-mailserver is running now.</p>
<h3 id="self-start-in-rootfull-mode"><a class="toclink" href="#self-start-in-rootfull-mode">Self-start in Rootfull Mode</a></h3>
<p>Podman is daemonless, that means if you want docker-mailserver self-start while boot up the system, you have to generate a systemd file with Podman CLI.</p>
<div class="highlight"><pre><span></span><code>podman<span class="w"> </span>generate<span class="w"> </span>systemd<span class="w"> </span>mailserver<span class="w"> </span>&gt;<span class="w"> </span>/etc/systemd/system/mailserver.service
systemctl<span class="w"> </span>daemon-reload
systemctl<span class="w"> </span><span class="nb">enable</span><span class="w"> </span>--now<span class="w"> </span>mailserver.service
</code></pre></div>
<h2 id="installation-in-rootless-mode"><a class="toclink" href="#installation-in-rootless-mode">Installation in Rootless Mode</a></h2>
<p>Running rootless containers is one of Podman's major features. But due to some restrictions, deploying docker-mailserver in rootless mode is not as easy compared to rootfull mode.</p>
<p>Running <a href="https://docs.podman.io/en/stable/markdown/podman.1.html#rootless-mode">rootless containers</a> is one of Podman's major features. But due to some restrictions, deploying docker-mailserver in rootless mode is not as easy compared to rootful mode.</p>
<ul>
<li>a rootless container is running in a user namespace so you cannot bind ports lower than 1024</li>
<li>a rootless container's systemd file can only be placed in folder under <code>~/.config</code></li>
@ -2718,7 +2778,7 @@ systemctl<span class="w"> </span><span class="nb">enable</span><span class="w">
<p>Also notice that Podman's rootless mode is not about running as a non-root user inside the container, but about the mapping of (normal, non-root) host users to root inside the container.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>In order to make rootless DMS work we must modify some settings in the Linux system, it requires some basic linux server knowledge so don't follow this guide if you not sure what this guide is talking about. Podman rootfull mode and Docker are still good and security enough for normal daily usage.</p>
<p>In order to make rootless DMS work we must modify some settings in the Linux system, it requires some basic linux server knowledge so don't follow this guide if you not sure what this guide is talking about. Podman rootful mode and Docker are still good and security enough for normal daily usage.</p>
</div>
<p>First, enable <code>podman.socket</code> in systemd's userspace with a non-root user.</p>
<div class="highlight"><pre><span></span><code>systemctl<span class="w"> </span><span class="nb">enable</span><span class="w"> </span>--now<span class="w"> </span>--user<span class="w"> </span>podman.socket
@ -2738,11 +2798,213 @@ systemctl<span class="w"> </span><span class="nb">enable</span><span class="w">
docker<span class="w"> </span>compose<span class="w"> </span>up<span class="w"> </span>-d<span class="w"> </span>mailserver
docker<span class="w"> </span>compose<span class="w"> </span>ps
</code></pre></div>
<h3 id="rootless-quadlet"><a class="toclink" href="#rootless-quadlet">Rootless Quadlet</a></h3>
<div class="admonition info">
<p class="admonition-title">What is a Quadlet?</p>
<p>A <a href="https://mo8it.com/blog/quadlet/">Quadlet</a> file uses the <a href="https://www.freedesktop.org/software/systemd/man/latest/systemd.syntax.html">systemd config format</a> which is similar to the INI format.</p>
<p><a href="https://docs.podman.io/en/latest/markdown/podman-systemd.unit.5.html#examples">Quadlets define your podman configuration</a> (<em>pods, volumes, networks, images, etc</em>) which are <a href="https://blog.while-true-do.io/podman-quadlets/#writing-quadlets">adapted into the equivalent systemd service config files</a> at <a href="https://docs.podman.io/en/latest/markdown/podman-systemd.unit.5.html#description">boot or when reloading the systemd daemon</a> (<code>systemctl daemon-reload</code> / <code>systemctl --user daemon-reload</code>).</p>
</div>
<div class="admonition tip">
<p class="admonition-title">Rootless compatibility</p>
<p>Quadlets can <a href="https://matduggan.com/replace-compose-with-quadlet/#rootless">support rootless with a few differences</a>:</p>
<ul>
<li><code>Network=pasta</code> configures <a href="https://passt.top/passt/about/#pasta"><code>pasta</code></a> as a rootless compatible network driver (<em>a popular alternative to <code>slirp4netns</code>. <code>pasta</code> is the default for rootless since Podman v5</em>).</li>
<li>
<p><code>Restart=always</code> will auto-start your Quadlet at login. Rootless support requires to enable <a href="https://www.freedesktop.org/software/systemd/man/latest/loginctl.html#enable-linger%20USER%E2%80%A6">lingering</a> for your user:</p>
<div class="highlight"><pre><span></span><code>loginctl<span class="w"> </span>enable-linger<span class="w"> </span>user
</code></pre></div>
</li>
<li>
<p><a href="https://docs.podman.io/en/latest/markdown/podman-systemd.unit.5.html#podman-rootful-unit-search-path">Config locations between rootful vs rootless</a>.</p>
</li>
</ul>
</div>
<h4 id="example-quadlet-file"><a class="toclink" href="#example-quadlet-file">Example Quadlet file</a></h4>
<details class="example" open="open">
<summary>Example</summary>
<ol>
<li>Create your DMS Quadlet at <code>~/.config/containers/systemd/dms.container</code> with the example content shown below.<ul>
<li>Adjust settings like <code>HostName</code> as needed. You may prefer a different convention for your <code>Volume</code> host paths.</li>
<li>Some syntax like systemd specifiers and Podman's <code>UIDMap</code> value are explained in detail after this example.</li>
</ul>
</li>
<li>Run <a href="https://www.freedesktop.org/software/systemd/man/latest/systemctl.html#daemon-reload"><code>systemctl --user daemon-reload</code></a>, which will trigger the Quadlet service generator. This command is required whenever you adjust config in <code>dms.container</code>.</li>
<li>You should now be able to start the service with <code>systemctl --user start dms</code>.</li>
</ol>
<div class="highlight"><span class="filename">dms.container</span><pre><span></span><code><span class="k">[Unit]</span>
<span class="na">Description</span><span class="o">=</span><span class="s">&quot;Docker Mail Server&quot;</span>
<span class="na">Documentation</span><span class="o">=</span><span class="s">https://docker-mailserver.github.io/docker-mailserver/latest</span>
<span class="k">[Service]</span>
<span class="na">Restart</span><span class="o">=</span><span class="s">always</span>
<span class="c1"># Optional - This will run before the container starts:</span>
<span class="c1"># - It ensures all the DMS volumes have the host directories created for you.</span>
<span class="c1"># - For `mkdir` command to leverage the shell brace expansion syntax, you need to run it via bash.</span>
<span class="na">ExecStartPre</span><span class="o">=</span><span class="s">/usr/bin/bash -c &#39;mkdir -p %h/volumes/%N/{mail-data,mail-state,mail-logs,config}&#39;</span>
<span class="c1"># This section enables the service at generation, avoids requiring `systemctl --user enable dms`:</span>
<span class="c1"># - `multi-user.target` =&gt; root</span>
<span class="c1"># - `default.target` =&gt; rootless</span>
<span class="k">[Install]</span>
<span class="na">WantedBy</span><span class="o">=</span><span class="s">default.target</span>
<span class="k">[Container]</span>
<span class="na">ContainerName</span><span class="o">=</span><span class="s">%N</span>
<span class="na">HostName</span><span class="o">=</span><span class="s">mail.example.com</span>
<span class="na">Image</span><span class="o">=</span><span class="s">docker.io/mailserver/docker-mailserver:latest</span>
<span class="na">PublishPort</span><span class="o">=</span><span class="s">25:25</span>
<span class="na">PublishPort</span><span class="o">=</span><span class="s">143:143</span>
<span class="na">PublishPort</span><span class="o">=</span><span class="s">587:587</span>
<span class="na">PublishPort</span><span class="o">=</span><span class="s">993:993</span>
<span class="c1"># The container UID for root will be mapped to the host UID running this Quadlet service.</span>
<span class="c1"># All other UIDs in the container are mapped via the sub-id range for that user from host configs `/etc/subuid` + `/etc/subgid`.</span>
<span class="na">UIDMap</span><span class="o">=</span><span class="s">+0:@%U</span>
<span class="c1"># Volumes (Base location example: `%h/volumes/%N` =&gt; `~/volumes/dms`)</span>
<span class="c1"># NOTE: If your host has SELinux enabled, avoid permission errors by appending the mount option `:Z`.</span>
<span class="na">Volume</span><span class="o">=</span><span class="s">%h/volumes/%N/mail-data:/var/mail</span>
<span class="na">Volume</span><span class="o">=</span><span class="s">%h/volumes/%N/mail-state:/var/mail-state</span>
<span class="na">Volume</span><span class="o">=</span><span class="s">%h/volumes/%N/mail-logs:/var/log/mail</span>
<span class="na">Volume</span><span class="o">=</span><span class="s">%h/volumes/%N/config:/tmp/docker-mailserver</span>
<span class="c1"># Optional - Additional mounts:</span>
<span class="c1"># NOTE: For SELinux, when using the `z` or `Z` mount options:</span>
<span class="c1"># Take caution if choosing a host location not belonging to your user. Consider using `SecurityLabelDisable=true` instead.</span>
<span class="c1"># https://docs.podman.io/en/latest/markdown/podman-run.1.html#volume-v-source-volume-host-dir-container-dir-options</span>
<span class="na">Volume</span><span class="o">=</span><span class="s">%h/volumes/certbot/certs:/etc/letsencrypt:ro</span>
<span class="c1"># Podman can create a timer (defaults to daily at midnight) to check the `registry` or `local` storage for detecting if the</span>
<span class="c1"># image tag points to a new digest, if so it updates the image and restarts the service (similar to `containrrr/watchtower`):</span>
<span class="c1"># https://docs.podman.io/en/latest/markdown/podman-auto-update.1.html</span>
<span class="na">AutoUpdate</span><span class="o">=</span><span class="s">registry</span>
<span class="c1"># Podman Quadlet has a better alternative instead of a volume directly bind mounting `/etc/localtime` to match the host TZ:</span>
<span class="c1"># https://docs.podman.io/en/latest/markdown/podman-run.1.html#tz-timezone</span>
<span class="c1"># NOTE: Should the host modify the system TZ, neither approach will sync the change to the `/etc/localtime` inside the running container.</span>
<span class="na">Timezone</span><span class="o">=</span><span class="s">local</span>
<span class="na">Environment</span><span class="o">=</span><span class="s">SSL_TYPE=letsencrypt</span>
<span class="c1"># NOTE: You may need to adjust the default `NETWORK_INTERFACE`:</span>
<span class="c1"># https://docker-mailserver.github.io/docker-mailserver/latest/config/environment/#network_interface</span>
<span class="c1">#Environment=NETWORK_INTERFACE=enp1s0</span>
<span class="c1">#Environment=NETWORK_INTERFACE=tap0</span>
</code></pre></div>
</details>
<details class="info">
<summary>Systemd specifiers</summary>
<p>Systemd has a <a href="https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html#Specifiers">variety of specifiers</a> (<em>prefixed with <code>%</code></em>) that help manage configs.</p>
<p>Here are the ones used in the Quadlet config example:</p>
<ul>
<li><strong><code>%h</code>:</strong> Location of the users home directory. Use this instead of <code>~</code> (<em>which would only work in a shell, not this config</em>).</li>
<li><strong><code>%N</code>:</strong> Represents the unit service name, which is taken from the filename excluding the extension (<em>thus <code>dms.container</code> =&gt; <code>dms</code></em>).</li>
<li><strong><code>%U</code>:</strong> The UID of the user running this service. The next section details the relevance with <code>UIDMap</code>.</li>
</ul>
<hr />
<p>If you prefer the conventional XDG locations, you may prefer <code>%D</code> + <code>%E</code> + <code>%S</code> as part of your <code>Volume</code> host paths.</p>
</details>
<p>Stopping the service with systemd will result in the container being removed. Restarting will use the existing container, which is however not recommended. You do not need to enable services with Quadlet.</p>
<p>Start container:</p>
<p><code>systemctl --user start dockermailserver</code></p>
<p>Stop container:</p>
<p><code>systemctl --user stop dockermailserver</code></p>
<p>Using root with machinectl (used for some Ansible versions):</p>
<p><code>machinectl -q shell yourrootlessuser@ /bin/systemctl --user start dockermailserver</code></p>
<h4 id="mapping-ownership-between-container-and-host-users"><a class="toclink" href="#mapping-ownership-between-container-and-host-users">Mapping ownership between container and host users</a></h4>
<p>Podman supports a few different approaches for this functionality. For rootless Quadlets you will likely want to use <code>UIDMap</code> (<em><code>GIDMap</code> will use this same mapping by default</em>).</p>
<ul>
<li><code>UIDMap</code> + <code>GIDMap</code> works by mapping user and group IDs from a container, to IDs associated for a user on the host <a href="https://docs.podman.io/en/stable/markdown/podman.1.html#rootless-mode">configured in <code>/etc/subuid</code> + <code>/etc/subgid</code></a> (<em>this isn't necessary for rootful Podman</em>).</li>
<li>Each mapping must be unique, thus only a single container UID can map to your rootless UID on the host. Every other container UID mapped must be within the configured range from <code>/etc/subuid</code>.</li>
<li>Rootless containers have one additional level of mapping involved. This is an offset from their <code>/etc/subuid</code> entry starting from <code>0</code>, but can be inferred when the intended UID on the host is prefixed with <code>@</code></li>
</ul>
<details class="tip">
<summary>Why should I prefer <code>UIDMap=+0:@%U</code>? How does the <code>@</code> syntax work?</summary>
<p>The most common case is to map the containers root user (UID <code>0</code>) to your host user ID.</p>
<p>For a rootless user with the UID <code>1000</code> on the host, any of the following <code>UIDMap</code> values are equivalent:</p>
<ul>
<li><strong><code>UIDMap=+0:0</code>:</strong> The 1st <code>0</code> is the container root ID and the 2nd <code>0</code> refers to host mapping ID. For rootless the mapping ID is an indirect offset to their user entry in <code>/etc/subuid</code> where <code>0</code> maps to their host user ID, while <code>1</code> or higher maps to the users subuid range.</li>
<li><strong><code>UIDMap=+0:@1000</code>:</strong> A rootless Quadlet can also use <code>@</code> as a prefix which Podman will then instead lookup as the host ID in <code>/etc/subuid</code> to get the offset value. If the host user ID was <code>1000</code>, then <code>@1000</code> would resolve that to <code>0</code>.</li>
<li><strong><code>UIDMap=+0:@%U</code>:</strong> Instead of providing the explicit rootless UID, a better approach is to leverage <code>%U</code> (<em>a <a href="https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html#Specifiers">systemd specifier</a></em>) which will resolve to the UID of your rootless user that starts the Quadlet service.</li>
</ul>
</details>
<details class="tip">
<summary>What is the <code>+</code> syntax used with <code>UIDMap</code>?</summary>
<p>Prefixing the container ID with <code>+</code> is a a podman feature similar to <code>@</code>, which ensures <code>/etc/subuid</code> is mapped fully.</p>
<p>For example <code>UIDMap=+5000:@%U</code> is the short-hand equivalent to:</p>
<div class="highlight"><pre><span></span><code><span class="na">UIDMap</span><span class="o">=</span><span class="s">5000:0:1</span>
<span class="na">UIDMap</span><span class="o">=</span><span class="s">0:1:5000</span>
<span class="na">UIDMap</span><span class="o">=</span><span class="s">5001:5001:60536</span>
</code></pre></div>
<p>The third value is the amount of IDs to map from the <code>container:host</code> pair as an offset/range. It defaults to <code>1</code>.</p>
<p>In addition to our explicit <code>5000:0</code> mapping, the <code>+</code> ensures:</p>
<ul>
<li>That we have a mapping of all container ID prior to <code>5000</code> to IDs from our rootless user entry in <code>/etc/subuid</code> on the host.</li>
<li>It also adds a mapping after this value for the remainder of the range configured in <code>/etc/subuid</code> which covers the <code>nobody</code> user in the container.</li>
</ul>
<p>Within the container you can view these mappings via <code>cat /proc/self/uid_map</code>.</p>
</details>
<details class="warning">
<summary>Impact on disk usage of images with Rootless</summary>
<p><strong>NOTE:</strong> This should not usually be a concern, but is documented here to explain the impact of creating new user namespaces (<em>such as by running a container with settings like <code>UIDMap</code> that differ between runs</em>).</p>
<hr />
<p>Rootless containers <a href="https://github.com/containers/podman/issues/16541#issuecomment-1352790422">perform a copy of the image with <code>chown</code></a> during the first pull/run of the image.</p>
<ul>
<li>The larger the image to copy, the longer the initial delay on first use.</li>
<li>This process will be repeated if the <code>UIDMap</code> / <code>GIDMap</code> settings are changed to a value that has not been used previously (<em>accumulating more disk usage with additional image layer copies</em>).</li>
<li>Only when the original image is removed will any of these associated <code>chown</code> image copies be purged from storage.</li>
</ul>
<p>When you specify a <code>UIDMap</code> like demonstrated in the earlier tip for the <code>+</code> syntax with <code>UIDMap=+0:5000</code>, if the <code>/proc/self/uid_map</code> shows a row with the first two columns as equivalent then no excess <code>chown</code> should be applied.</p>
<ul>
<li><code>UIDMap=+0:@%U</code> is equivalent from ID 2 onwards.</li>
<li><code>UIDMap=+5000:@%U</code> is equivalent from ID 5001 onwards. This is relevant with DMS as the container UID 200 is assigned to ClamAV, the offset introduced will now incur a <code>chown</code> copy of 230MB.</li>
</ul>
</details>
<h2 id="start-dms-container-at-boot"><a class="toclink" href="#start-dms-container-at-boot">Start DMS container at boot</a></h2>
<p>Unlike Docker, Podman is daemonless thus containers do not start at boot. You can create your own systemd service to schedule this or use the Podman CLI.</p>
<div class="admonition warning">
<p class="admonition-title"><code>podman generate systemd</code> is deprecated</p>
<p>The <a href="https://docs.podman.io/en/latest/markdown/podman-generate-systemd.1.html"><code>podman generate systemd</code></a> command has been deprecated <a href="https://github.com/containers/podman/releases/tag/v4.7.0">since Podman v4.7</a> (Sep 2023) in favor of Quadlets (<em>available <a href="https://github.com/containers/podman/releases/tag/v4.4.0">since Podman v4.4</a></em>).</p>
</div>
<div class="admonition example">
<p class="admonition-title">Create a systemd service</p>
<p>Use the Podman CLI to generate a systemd service at the rootful or rootless location.</p>
<div class="tabbed-set tabbed-alternate" data-tabs="1:2"><input checked="checked" id="rootful" name="__tabbed_1" type="radio" /><input id="rootless" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="rootful">Rootful</label><label for="rootless">Rootless</label></div>
<div class="tabbed-content">
<div class="tabbed-block">
<div class="highlight"><pre><span></span><code>podman<span class="w"> </span>generate<span class="w"> </span>systemd<span class="w"> </span>mailserver<span class="w"> </span>&gt;<span class="w"> </span>/etc/systemd/system/mailserver.service
systemctl<span class="w"> </span>daemon-reload
systemctl<span class="w"> </span><span class="nb">enable</span><span class="w"> </span>--now<span class="w"> </span>mailserver.service
</code></pre></div>
</div>
<div class="tabbed-block">
<div class="highlight"><pre><span></span><code>podman<span class="w"> </span>generate<span class="w"> </span>systemd<span class="w"> </span>mailserver<span class="w"> </span>&gt;<span class="w"> </span>~/.config/systemd/user/mailserver.service
systemctl<span class="w"> </span>--user<span class="w"> </span>daemon-reload
systemctl<span class="w"> </span><span class="nb">enable</span><span class="w"> </span>--user<span class="w"> </span>--now<span class="w"> </span>mailserver.service
</code></pre></div>
</div>
</div>
</div>
</div>
<p>A systemd user service will only start when that specific user logs in and stops when after log out. To instead allow user services to run when that user has no active session running run:</p>
<div class="highlight"><pre><span></span><code>loginctl<span class="w"> </span>enable-linger<span class="w"> </span>&lt;username&gt;
</code></pre></div>
<h3 id="security-in-rootless-mode"><a class="toclink" href="#security-in-rootless-mode">Security in Rootless Mode</a></h3>
<p>In rootless mode, podman resolves all incoming IPs as localhost, which results in an open gateway in the default configuration. There are two workarounds to fix this problem, both of which have their own drawbacks.</p>
<h4 id="enforce-authentication-from-localhost"><a class="toclink" href="#enforce-authentication-from-localhost">Enforce authentication from localhost</a></h4>
<p>The <code>PERMIT_DOCKER</code> variable in the <code>mailserver.env</code> file allows to specify trusted networks that do not need to authenticate. If the variable is left empty, only requests from localhost and the container IP are allowed, but in the case of rootless podman any IP will be resolved as localhost. Setting <code>PERMIT_DOCKER=none</code> enforces authentication also from localhost, which prevents sending unauthenticated emails.</p>
<h4 id="use-the-slip4netns-network-driver"><a class="toclink" href="#use-the-slip4netns-network-driver">Use the slip4netns network driver</a></h4>
<h4 id="use-the-pasta-network-driver"><a class="toclink" href="#use-the-pasta-network-driver">Use the <code>pasta</code> network driver</a></h4>
<p>Since <a href="https://github.com/containers/podman/releases/tag/v5.0.0">Podman 5.0</a> the default rootless network driver is now <code>pasta</code> instead of <code>slirp4netns</code>. These two drivers <a href="https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/building_running_and_managing_containers/assembly_communicating-among-containers_building-running-and-managing-containers#differences-between-slirp4netns-and-pasta_assembly_communicating-among-containers">have some differences</a>:</p>
<blockquote>
<p>Notable differences of <code>pasta</code> network mode compared to <code>slirp4netns</code> include:</p>
<ul>
<li><code>pasta</code> supports IPv6 port forwarding.</li>
<li><code>pasta</code> is more efficient than <code>slirp4netns</code>.</li>
<li><code>pasta</code> copies IP addresses from the host, while <code>slirp4netns</code> uses a predefined IPv4 address.</li>
<li><code>pasta</code> uses an interface name from the host, while <code>slirp4netns</code> uses <code>tap0</code> as an interface name.</li>
<li><code>pasta</code> uses the gateway address from the host, while <code>slirp4netns</code> defines its own gateway address and uses NAT.</li>
</ul>
</blockquote>
<h4 id="use-the-slip4netns-network-driver"><a class="toclink" href="#use-the-slip4netns-network-driver">Use the <code>slip4netns</code> network driver</a></h4>
<p>The second workaround is slightly more complicated because the <code>compose.yaml</code> has to be modified.
As shown in the <a href="../../security/fail2ban/#rootless-container">fail2ban section</a> the <code>slirp4netns</code> network driver has to be enabled.
This network driver enables podman to correctly resolve IP addresses but it is not compatible with
@ -2763,16 +3025,6 @@ user defined networks which might be a problem depending on your setup.</p>
<p class="admonition-title">Note</p>
<p><code>podman-compose</code> is not compatible with this configuration.</p>
</div>
<h3 id="self-start-in-rootless-mode"><a class="toclink" href="#self-start-in-rootless-mode">Self-start in Rootless Mode</a></h3>
<p>Generate a systemd file with the Podman CLI.</p>
<div class="highlight"><pre><span></span><code>podman<span class="w"> </span>generate<span class="w"> </span>systemd<span class="w"> </span>mailserver<span class="w"> </span>&gt;<span class="w"> </span>~/.config/systemd/user/mailserver.service
systemctl<span class="w"> </span>--user<span class="w"> </span>daemon-reload
systemctl<span class="w"> </span><span class="nb">enable</span><span class="w"> </span>--user<span class="w"> </span>--now<span class="w"> </span>mailserver.service
</code></pre></div>
<p>Systemd's user space service is only started when a specific user logs in and stops when you log out. In order to make it to start with the system, we need to enable linger with <code>loginctl</code></p>
<div class="highlight"><pre><span></span><code>loginctl<span class="w"> </span>enable-linger<span class="w"> </span>&lt;username&gt;
</code></pre></div>
<p>Remember to run this command as root user.</p>
<h3 id="port-forwarding"><a class="toclink" href="#port-forwarding">Port Forwarding</a></h3>
<p>When it comes to forwarding ports using <code>firewalld</code>, see <a href="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/securing_networks/using-and-configuring-firewalld_securing-networks#port-forwarding_using-and-configuring-firewalld">these port forwarding docs</a> for more information.</p>
<div class="highlight"><pre><span></span><code>firewall-cmd<span class="w"> </span>--permanent<span class="w"> </span>--add-forward-port<span class="o">=</span><span class="nv">port</span><span class="o">=</span>&lt;<span class="m">25</span><span class="p">|</span><span class="m">143</span><span class="p">|</span><span class="m">465</span><span class="p">|</span><span class="m">587</span><span class="p">|</span><span class="m">993</span>&gt;:proto<span class="o">=</span>&lt;tcp&gt;:toport<span class="o">=</span>&lt;<span class="m">10025</span><span class="p">|</span><span class="m">10143</span><span class="p">|</span><span class="m">10465</span><span class="p">|</span><span class="m">10587</span><span class="p">|</span><span class="m">10993</span>&gt;

File diff suppressed because one or more lines are too long