Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fedora - Podman with capabilities on Fedora

#1
Podman with capabilities on Fedora

<div><p>Containerization is a booming technology. As many as seventy-five percent of global organizations could be running some type of containerization technology in the near future. Since widely used technologies are more likely to be targeted by hackers, securing containers is especially important. This article will demonstrate how <a rel="noreferrer noopener" href="https://www.linuxjournal.com/magazine/making-root-unprivileged" target="_blank">POSIX capabilities</a> are used to secure Podman containers. Podman is the default container management tool in RHEL8.</p>
<p> <span id="more-32158"></span> </p>
<h2>Determine the Podman container’s privilege mode</h2>
<p>Containers run in either privileged or unprivileged mode. In privileged mode, <a rel="noreferrer noopener" href="https://linuxcontainers.org/lxc/security/#privileged-containers" target="_blank">the container uid 0 is mapped to the host’s uid 0</a>. For some use cases, unprivileged containers <a href="https://github.com/containers/podman/blob/master/rootless.md" target="_blank" rel="noreferrer noopener">lack sufficient access</a> to the resources of the host machine. Technologies and techniques including Mandatory Access Control (apparmor, SELinux), seccomp filters, dropping of capabilities, and namespaces help to secure containers regardless of their mode of operation.</p>
<p><strong>To determine the privilege mode from outside the container:</strong></p>
<pre class="wp-block-preformatted">$ podman inspect --format="{{.HostConfig.Privileged}}" &lt;container id&gt;</pre>
<p>If the above command returns <em>true</em> then the container is running in privileged mode. If it returns <em>false</em> then the container is running in unprivileged mode.</p>
<p><strong>To determine the privilege mode from inside the container:</strong></p>
<pre class="wp-block-preformatted">$ ip link add dummy0 type dummy</pre>
<p>If this command allows you to create an interface then you are running a privileged container. Otherwise you are running an unprivileged container.</p>
<h2>Capabilities</h2>
<p>Namespaces isolate a container’s processes from arbitrary access to the resources of its host and from access to the resources of other containers running on the same host. Processes within <em>privileged</em> containers, however, might still be able to do things like alter the IP routing table, trace arbitrary processes, and load kernel modules. Capabilities allow one to apply finer-grained restrictions on what resources the processes within a container can access or alter; even when the container is running in privileged mode. Capabilities also allow one to assign privileges to an unprivileged container that it would not otherwise have.</p>
<p>For example, to add the <em>NET_ADMIN</em> capability to an unprivileged container so that a network interface can be created inside of the container, you would run <em>podman</em> with parameters similar to the following:</p>
<pre class="wp-block-preformatted">[root@vm1 ~]# podman run -it --cap-add=NET_ADMIN centos
[root@b27fea33ccf1 /]# ip link add dummy0 type dummy
[root@b27fea33ccf1 /]# ip link</pre>
<p>The above commands demonstrate a <em>dummy0</em> interface being created in an unprivileged container. Without the <em>NET_ADMIN</em> capability, an unprivileged container would not be able to create an interface. The above commands demonstrate how to grant a capability to an unprivileged container.</p>
<p>Currently, there are about <a href="https://man7.org/linux/man-pages/man7/capabilities.7.html" target="_blank" rel="noreferrer noopener">39 capabilities</a> that can be granted or denied. Privileged containers are granted many capabilities by default. It is advisable to drop unneeded capabilities from privileged containers to make them more secure.</p>
<p><strong>To drop all capabilities from a container:</strong></p>
<pre class="wp-block-preformatted">$ podman run -it -d --name mycontainer --cap-drop=all centos</pre>
<p><strong>To list a container’s capabilities:</strong></p>
<pre class="wp-block-preformatted">$ podman exec -it 48f11d9fa512 capsh --print</pre>
<p>The above command should show that no capabilities are granted to the container.</p>
<p><strong>Refer to the <em>capabilities</em> man page for a complete list of capabilities:</strong></p>
<pre class="wp-block-preformatted">$ man capabilities</pre>
<p><strong>Use the <em>capsh</em> command to list the capabilities you currently possess:</strong></p>
<pre class="wp-block-preformatted">$ capsh --print</pre>
<p>As another example, the below command demonstrates dropping the <em>NET_RAW</em> capability from a container. Without the <em>NET_RAW</em> capability, servers on the internet cannot be pinged from within the container.</p>
<pre class="wp-block-preformatted">$ podman run -it --name mycontainer1 --cap-drop=net_raw centos
&gt;&gt;&gt; ping google.com (will output error, operation not permitted)</pre>
<p>As a final example, if your container were to only need the <em>SETUID</em> and <em>SETGID</em> capabilities, you could achieve such a permission set by dropping all capabilities and then re-adding only those two.</p>
<pre class="wp-block-preformatted">$ podman run -d --cap-drop=all --cap-add=setuid --cap-add=setgid fedora sleep 5 &gt; /dev/null; pscap | grep sleep</pre>
<p>The <em>pscap</em> command shown above should show the capabilities that have been granted to the container.</p>
<p>I hope you enjoyed this brief exploration of how capabilities are used to secure Podman containers.</p>
<p>Thank You!</p>
</div>


https://www.sickgaming.net/blog/2020/11/...on-fedora/
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  Fedora - Contribute to Fedora 39 Upgrade, Virtualization, and Cloud Test Day xSicKxBot 0 2,126 09-30-2023, 03:56 AM
Last Post: xSicKxBot
  Fedora - Share your game achievements with Gamerzilla xSicKxBot 0 1,073 09-27-2023, 09:59 AM
Last Post: xSicKxBot
  Fedora - Using Cockpit to graphically manage systems, without installing Cockpit on xSicKxBot 0 948 09-26-2023, 06:41 AM
Last Post: xSicKxBot
  Fedora - Announcing Fedora Linux 39 Beta xSicKxBot 0 978 09-20-2023, 09:48 AM
Last Post: xSicKxBot
  Fedora - Contribute at Passkey Auth, Fedora CoreOS and IoT Test Week xSicKxBot 0 961 09-19-2023, 12:23 PM
Last Post: xSicKxBot
  Fedora - Quick Fedora shirt update and sale of last stock with the old logo xSicKxBot 0 1,028 09-16-2023, 12:28 PM
Last Post: xSicKxBot
  Fedora - Contribute at the Fedora Linux Test Week for Kernel 6.5 and Toolbx Test Day xSicKxBot 0 1,021 09-11-2023, 02:47 PM
Last Post: xSicKxBot
  Fedora - Fedora Linux Flatpak cool apps to try for September xSicKxBot 0 993 09-10-2023, 04:59 PM
Last Post: xSicKxBot
  Fedora - Contribute at the Test Week for the Anaconda WebUI Installer for Fedora Wor xSicKxBot 0 994 09-09-2023, 11:54 PM
Last Post: xSicKxBot
  Fedora - Docs workshop: Virtually writing together xSicKxBot 0 1,028 09-09-2023, 05:08 AM
Last Post: xSicKxBot

Forum Jump:


Users browsing this thread:

Forum software by © MyBB Theme © iAndrew 2016