|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Release Container Images" |
| 4 | +section: Blog |
| 5 | +date: 2022-03-25T15:00:00 |
| 6 | +author: Eric Garver |
| 7 | +category: feature |
| 8 | +--- |
| 9 | + |
| 10 | +## Introduction |
| 11 | + |
| 12 | +Firewalld releases are now additionally distributed as an OCI container |
| 13 | +image. This image is usable on any Linux distribution with docker (or |
| 14 | +podman) and Linux kernel >= 5.3. |
| 15 | + |
| 16 | +This image is self contained. The firewalld configuration lives inside |
| 17 | +the container. It does not integrate with host services (e.g. |
| 18 | +NetworkManager). |
| 19 | + |
| 20 | +It provides a very convenient and risk-free way to trial firewalld. |
| 21 | + |
| 22 | +## Starting the container |
| 23 | + |
| 24 | +The container can be started in one command: |
| 25 | + |
| 26 | +``` |
| 27 | +# docker run -d --network host --privileged \ |
| 28 | + --name my-firewalld quay.io/firewalld/firewalld |
| 29 | +``` |
| 30 | + |
| 31 | +This will pull (download) the image from |
| 32 | +[quay.io](https://quay.io/repository/firewalld/firewalld) if the image |
| 33 | +is not already in the local cache. |
| 34 | + |
| 35 | +The `--network host` means the container will run in the default network |
| 36 | +namespace and thus make firewall changes affecting the entire host. |
| 37 | + |
| 38 | +## Making firewall changes |
| 39 | + |
| 40 | +To make changes to firewalld running inside the container `docker exec` |
| 41 | +must be used. |
| 42 | + |
| 43 | +For example, to list all the settings in the default zone: |
| 44 | + |
| 45 | +``` |
| 46 | +# docker exec my-firewalld firewall-cmd --list-all |
| 47 | +public |
| 48 | + target: default |
| 49 | + icmp-block-inversion: no |
| 50 | + interfaces: |
| 51 | + sources: |
| 52 | + services: dhcpv6-client ssh |
| 53 | + ports: |
| 54 | + protocols: |
| 55 | + forward: yes |
| 56 | + masquerade: no |
| 57 | + forward-ports: |
| 58 | + source-ports: |
| 59 | + icmp-blocks: |
| 60 | + rich rules: |
| 61 | +``` |
| 62 | + |
| 63 | +## Shell alias for convenience |
| 64 | + |
| 65 | +The above is a long command. It can be made more convenient with a shell |
| 66 | +alias. |
| 67 | + |
| 68 | +``` |
| 69 | +# alias my-firewall-cmd='docker exec my-firewalld firewall-cmd' |
| 70 | +``` |
| 71 | + |
| 72 | +Then use the alias: |
| 73 | + |
| 74 | +``` |
| 75 | +# my-firewall-cmd --list-all |
| 76 | +public |
| 77 | + target: default |
| 78 | + icmp-block-inversion: no |
| 79 | + interfaces: |
| 80 | + sources: |
| 81 | + services: dhcpv6-client ssh |
| 82 | + ports: |
| 83 | + protocols: |
| 84 | + forward: yes |
| 85 | + masquerade: no |
| 86 | + forward-ports: |
| 87 | + source-ports: |
| 88 | + icmp-blocks: |
| 89 | + rich rules: |
| 90 | +``` |
| 91 | + |
| 92 | +## What it looks like on the host |
| 93 | + |
| 94 | +As started above, the container runs in the default network namespace. |
| 95 | +This means we should see the changes in the host's nftables output. |
| 96 | + |
| 97 | +``` |
| 98 | +# my-firewall-cmd --add-service https |
| 99 | +success |
| 100 | +
|
| 101 | +# nft list ruleset |grep 443 |
| 102 | + tcp dport 443 ct state { new, untracked } accept |
| 103 | +``` |
| 104 | + |
| 105 | +## Saving the container and firewalld's configuration |
| 106 | + |
| 107 | +The modified container can be saved to an image like any other |
| 108 | +container. This is useful if you want to save your precious firewalld |
| 109 | +container and configuration. |
| 110 | + |
| 111 | +``` |
| 112 | +# docker commit my-firewalld my-firewalld |
| 113 | +sha256:2923f03657ee877b55a72f80f6211c7065328a47b247c05fd3a0f09dcea67fc3 |
| 114 | +
|
| 115 | +# docker image list |
| 116 | +REPOSITORY TAG IMAGE ID CREATED SIZE |
| 117 | +my-firewalld latest 2923f03657ee 2 seconds ago 247MB |
| 118 | +quay.io/firewalld/firewalld latest b0d3f2666c4f 4 hours ago 246MB |
| 119 | +``` |
| 120 | + |
| 121 | +## Optional: Store firewalld's configuration on the host |
| 122 | + |
| 123 | +An alternative to storing the configuration inside the container is to |
| 124 | +use a volume mount to store it on the host. This has the major advantage |
| 125 | +that the container can be upgraded to a new release of the container |
| 126 | +image while keeping your firewalld configuration intact. |
| 127 | + |
| 128 | +To accomplish you must start the container with a volume mount. |
| 129 | + |
| 130 | +``` |
| 131 | +# docker run -d -v /etc/firewalld:/etc/firewalld |
| 132 | + --network host --privileged \ |
| 133 | + --name my-firewalld quay.io/firewalld/firewalld |
| 134 | +``` |
| 135 | + |
| 136 | +Otherwise, usage is the same as described above. |
| 137 | + |
| 138 | +## Summary |
| 139 | + |
| 140 | +The container image provides a low effort way to get started with |
| 141 | +firewalld while also being easy to manage. |
0 commit comments