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

Firewall example with nftables #74

Open
p5 opened this issue May 15, 2024 · 1 comment
Open

Firewall example with nftables #74

p5 opened this issue May 15, 2024 · 1 comment

Comments

@p5
Copy link

p5 commented May 15, 2024

Hey FCOS team!

Currently the only example you have for configuring a firewall is with Ansible, which brings in a bunch of unwanted dependencies.

It would be great if you could provide some examples of layering firewall rules (ideally in a .d directory) to demonstrate some of the common configurations someone may want to do on a FCOS system.

For example, the OpenVPN setup scripts include the following, but it's not obvious how we can create an image with this configuration in a declarative manor at build time.

# Configure NAT
sudo firewall-cmd --permanent --add-masquerade
sudo firewall-cmd --permanent --direct --add-rule ipv4 nat POSTROUTING 0 -j MASQUERADE
sudo firewall-cmd --permanent --direct --add-rule ipv4 filter FORWARD 0 -j ACCEPT
sudo firewall-cmd --permanent --direct --add-rule ipv6 nat POSTROUTING 0 -j MASQUERADE
sudo firewall-cmd --permanent --direct --add-rule ipv6 filter FORWARD 0 -j ACCEPT
sudo systemctl restart firewalld

The title mentions nftables, but any file-based declarative approach would be appreciated.

Thank you
Robert

@miabbott
Copy link
Member

miabbott commented May 16, 2024

One option using the ansible-firewalld example is to adapt it to a multi-stage build, where the firewall rules are configured and then copied to the destination image.

FROM registry.fedoraproject.org/fedora:40 AS builder
ADD configure-firewall-playbook.yml .
RUN dnf -y install firewalld ansible && \
    ansible-playbook configure-firewall-playbook.yml

FROM quay.io/fedora/fedora-coreos:stable
RUN rpm-ostree install firewalld
COPY --from=builder /etc/firewalld /etc/firewalld
RUN ostree container commit

It's not as elegant as a truly declarative approach, but could work.

If you are interested in using nftables, they have scripting support which would probably be a better way forward - https://wiki.nftables.org/wiki-nftables/index.php/Scripting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants