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

Feature/inv 41 Firewalld in PF #8055

Open
wants to merge 382 commits into
base: devel
Choose a base branch
from
Open

Feature/inv 41 Firewalld in PF #8055

wants to merge 382 commits into from

Conversation

JeGoi
Copy link
Contributor

@JeGoi JeGoi commented Apr 2, 2024

Description

Move from iptables to firewalld
Make things more dynamic to update the firewall rules.

Impacts

Get out of iptables

Code / PR Dependencies

feature/INV-41 on figerbank-collector

Delete branch after merge

YES

Checklist

  • Document the feature
  • Update venom tests

NEWS file entries

New Features

  • Move from iptables to firewalld

@JeGoi JeGoi added this to the PacketFence-13.2 milestone Apr 2, 2024
@JeGoi JeGoi requested a review from fdurand April 2, 2024 19:36
conf/firewalld/firewalld_services.conf.defaults Outdated Show resolved Hide resolved
conf/firewalld/firewalld_services.conf.defaults Outdated Show resolved Hide resolved
conf/firewalld/firewalld_services.conf.defaults Outdated Show resolved Hide resolved
conf/firewalld/firewalld_services.conf.defaults Outdated Show resolved Hide resolved
conf/firewalld/firewalld_services.conf.defaults Outdated Show resolved Hide resolved
lib/pf/Firewalld/icmptypes.pm Outdated Show resolved Hide resolved
lib/pf/services/manager/firewalld.pm Outdated Show resolved Hide resolved
lib/pfconfig/namespaces/config/Firewalld_Helpers.pm Outdated Show resolved Hide resolved
lib/pfconfig/namespaces/config/Firewalld_Icmptypes.pm Outdated Show resolved Hide resolved
lib/pfconfig/namespaces/resource/all_firewalld.pm Outdated Show resolved Hide resolved
@satkunas satkunas modified the milestones: PacketFence-13.2, PacketFence-14.0 Apr 18, 2024
@JeGoi JeGoi force-pushed the feature/INV-41 branch 2 times, most recently from c7e9808 to 64290f6 Compare June 5, 2024 13:50
conf/documentation.conf Show resolved Hide resolved
conf/firewalld/firewalld.conf.example Outdated Show resolved Hide resolved
conf/firewalld/firewalld_services.conf.defaults Outdated Show resolved Hide resolved
conf/firewalld/firewalld_services.conf.defaults Outdated Show resolved Hide resolved
port=1822
type=tcp
[radius_auth_clu_port3]
port=2093
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's the radsec one

conf/firewalld/firewalld_services.conf.defaults Outdated Show resolved Hide resolved
conf/pf.conf.defaults Show resolved Hide resolved
Before=packetfence-haproxy-admin.service
Before=packetfence-docker-iptables.service
Requires=packetfence-docker-iptables.service
PartOf=packetfence-docker-iptables.service
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why there is no call to generate the firewalld config ?

Copy link
Contributor Author

@JeGoi JeGoi Jun 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it is starting at the installation https://github.com/inverse-inc/packetfence/blob/feature/INV-41/debian/packetfence.postinst#L228, and at this point pfconfig is empty.
There is no config done.
In current Devel, iptables is started at this point at the same point docker-iptables service is a fake one. https://github.com/inverse-inc/packetfence/blob/devel/conf/systemd/packetfence-docker-iptables.service#L9

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact that iptables service dependency at boot is using the fact that the service iptables during pf installation will fail.
Thanks to the failure, at the exiit of iptables, new rules are defined.

-- Journal begins at Wed 2024-07-10 11:19:44 UTC, ends at Wed 2024-07-10 11:44:36 UTC. --                                                                                                          [13/1674]
Jul 10 11:29:53 172-234-151-109 systemd[1]: Started PacketFence Iptables configuration.
Jul 10 11:29:55 172-234-151-109 packetfence[30662]: -e(30662) ERROR: unable to connect to database: Access denied for user 'pf'@'localhost' (pf::db::db_connect)
Jul 10 11:29:56 172-234-151-109 packetfence[30662]: -e(30662) ERROR: unable to connect to database: Access denied for user 'pf'@'localhost' (pf::db::db_connect)
Jul 10 11:29:57 172-234-151-109 packetfence[30662]: -e(30662) ERROR: unable to connect to database: Access denied for user 'pf'@'localhost' (pf::db::db_connect)
Jul 10 11:29:58 172-234-151-109 packetfence[30662]: -e(30662) ERROR: unable to connect to database: Access denied for user 'pf'@'localhost' (pf::db::db_connect)
Jul 10 11:29:59 172-234-151-109 packetfence[30662]: -e(30662) ERROR: unable to connect to database: Access denied for user 'pf'@'localhost' (pf::db::db_connect)
Jul 10 11:30:00 172-234-151-109 packetfence[30662]: -e(30662) ERROR: unable to connect to database: Access denied for user 'pf'@'localhost' (pf::db::db_connect)
Jul 10 11:30:01 172-234-151-109 packetfence[30662]: -e(30662) ERROR: unable to connect to database: Access denied for user 'pf'@'localhost' (pf::db::db_connect)
Jul 10 11:30:02 172-234-151-109 systemd[1]: Stopping PacketFence Iptables configuration...
Jul 10 11:30:02 172-234-151-109 packetfence[30662]: -e(30662) ERROR: unable to connect to database: Access denied for user 'pf'@'localhost' (pf::db::db_connect)
Jul 10 11:30:03 172-234-151-109 packetfence[30662]: -e(30662) ERROR: unable to connect to database: Access denied for user 'pf'@'localhost' (pf::db::db_connect)
Jul 10 11:30:04 172-234-151-109 packetfence[30662]: -e(30662) ERROR: unable to connect to database: Access denied for user 'pf'@'localhost' (pf::db::db_connect)
Jul 10 11:30:05 172-234-151-109 sudo[31331]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -F
Jul 10 11:30:05 172-234-151-109 sudo[31331]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31331]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31334]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -X
Jul 10 11:30:05 172-234-151-109 sudo[31334]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31334]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31337]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -t nat -F
Jul 10 11:30:05 172-234-151-109 sudo[31337]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31337]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31340]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -t nat -X
Jul 10 11:30:05 172-234-151-109 sudo[31340]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31340]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31343]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -t mangle -F
Jul 10 11:30:05 172-234-151-109 sudo[31343]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31343]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31346]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -t mangle -X
Jul 10 11:30:05 172-234-151-109 sudo[31346]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31346]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31349]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -P INPUT ACCEPT
Jul 10 11:30:05 172-234-151-109 sudo[31349]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31349]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31352]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -P FORWARD ACCEPT
Jul 10 11:30:05 172-234-151-109 sudo[31352]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31352]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31355]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -P OUTPUT ACCEPT
Jul 10 11:30:05 172-234-151-109 sudo[31355]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31355]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31358]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -t nat -N DOCKER
Jul 10 11:30:05 172-234-151-109 sudo[31358]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31358]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31361]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -t nat -A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
Jul 10 11:30:05 172-234-151-109 sudo[31361]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31361]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31364]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -t nat -A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER
Jul 10 11:30:05 172-234-151-109 sudo[31364]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31364]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31367]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -t nat -A POSTROUTING -s 100.64.0.0/10 ! -o docker0 -j MASQUERADE
Jul 10 11:30:05 172-234-151-109 sudo[31367]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31367]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31370]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -t nat -A DOCKER -i docker0 -j RETURN
Jul 10 11:30:05 172-234-151-109 sudo[31370]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31370]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 systemd[1]: packetfence-iptables.service: Succeeded.
Jul 10 11:30:05 172-234-151-109 systemd[1]: Stopped PacketFence Iptables configuration.
Jul 10 11:30:05 172-234-151-109 systemd[1]: packetfence-iptables.service: Consumed 5.222s CPU time.

So it is tricky, because we are using iptables in order to have the rules defined when it is failing.

Copy link
Contributor Author

@JeGoi JeGoi Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact that iptables service dependency at instlation is using the fact that the service iptables during pf installation will fail. The db is not yet defined and there is no connexion.
Thanks to the failure, at the exiit of iptables, new rules are defined.

-- Journal begins at Wed 2024-07-10 11:19:44 UTC, ends at Wed 2024-07-10 11:44:36 UTC. --                                                                                                          [13/1674]
Jul 10 11:29:53 172-234-151-109 systemd[1]: Started PacketFence Iptables configuration.
Jul 10 11:29:55 172-234-151-109 packetfence[30662]: -e(30662) ERROR: unable to connect to database: Access denied for user 'pf'@'localhost' (pf::db::db_connect)
Jul 10 11:29:56 172-234-151-109 packetfence[30662]: -e(30662) ERROR: unable to connect to database: Access denied for user 'pf'@'localhost' (pf::db::db_connect)
Jul 10 11:29:57 172-234-151-109 packetfence[30662]: -e(30662) ERROR: unable to connect to database: Access denied for user 'pf'@'localhost' (pf::db::db_connect)
Jul 10 11:29:58 172-234-151-109 packetfence[30662]: -e(30662) ERROR: unable to connect to database: Access denied for user 'pf'@'localhost' (pf::db::db_connect)
Jul 10 11:29:59 172-234-151-109 packetfence[30662]: -e(30662) ERROR: unable to connect to database: Access denied for user 'pf'@'localhost' (pf::db::db_connect)
Jul 10 11:30:00 172-234-151-109 packetfence[30662]: -e(30662) ERROR: unable to connect to database: Access denied for user 'pf'@'localhost' (pf::db::db_connect)
Jul 10 11:30:01 172-234-151-109 packetfence[30662]: -e(30662) ERROR: unable to connect to database: Access denied for user 'pf'@'localhost' (pf::db::db_connect)
Jul 10 11:30:02 172-234-151-109 systemd[1]: Stopping PacketFence Iptables configuration...
Jul 10 11:30:02 172-234-151-109 packetfence[30662]: -e(30662) ERROR: unable to connect to database: Access denied for user 'pf'@'localhost' (pf::db::db_connect)
Jul 10 11:30:03 172-234-151-109 packetfence[30662]: -e(30662) ERROR: unable to connect to database: Access denied for user 'pf'@'localhost' (pf::db::db_connect)
Jul 10 11:30:04 172-234-151-109 packetfence[30662]: -e(30662) ERROR: unable to connect to database: Access denied for user 'pf'@'localhost' (pf::db::db_connect)
Jul 10 11:30:05 172-234-151-109 sudo[31331]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -F
Jul 10 11:30:05 172-234-151-109 sudo[31331]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31331]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31334]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -X
Jul 10 11:30:05 172-234-151-109 sudo[31334]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31334]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31337]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -t nat -F
Jul 10 11:30:05 172-234-151-109 sudo[31337]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31337]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31340]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -t nat -X
Jul 10 11:30:05 172-234-151-109 sudo[31340]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31340]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31343]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -t mangle -F
Jul 10 11:30:05 172-234-151-109 sudo[31343]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31343]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31346]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -t mangle -X
Jul 10 11:30:05 172-234-151-109 sudo[31346]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31346]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31349]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -P INPUT ACCEPT
Jul 10 11:30:05 172-234-151-109 sudo[31349]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31349]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31352]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -P FORWARD ACCEPT
Jul 10 11:30:05 172-234-151-109 sudo[31352]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31352]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31355]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -P OUTPUT ACCEPT
Jul 10 11:30:05 172-234-151-109 sudo[31355]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31355]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31358]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -t nat -N DOCKER
Jul 10 11:30:05 172-234-151-109 sudo[31358]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31358]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31361]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -t nat -A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
Jul 10 11:30:05 172-234-151-109 sudo[31361]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31361]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31364]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -t nat -A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER
Jul 10 11:30:05 172-234-151-109 sudo[31364]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31364]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31367]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -t nat -A POSTROUTING -s 100.64.0.0/10 ! -o docker0 -j MASQUERADE
Jul 10 11:30:05 172-234-151-109 sudo[31367]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31367]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 sudo[31370]:     root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/iptables -t nat -A DOCKER -i docker0 -j RETURN
Jul 10 11:30:05 172-234-151-109 sudo[31370]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jul 10 11:30:05 172-234-151-109 sudo[31370]: pam_unix(sudo:session): session closed for user root
Jul 10 11:30:05 172-234-151-109 systemd[1]: packetfence-iptables.service: Succeeded.
Jul 10 11:30:05 172-234-151-109 systemd[1]: Stopped PacketFence Iptables configuration.
Jul 10 11:30:05 172-234-151-109 systemd[1]: packetfence-iptables.service: Consumed 5.222s CPU time.

So it is tricky, because we are using iptables in order to have the rules defined when it is failing.

conf/systemd/packetfence-snmptrapd.service Show resolved Hide resolved
lib/pf/firewalld.pm Outdated Show resolved Hide resolved
@JeGoi
Copy link
Contributor Author

JeGoi commented Jun 26, 2024

Needs dedicated log file

@JeGoi JeGoi force-pushed the feature/INV-41 branch 2 times, most recently from 9e76f84 to aeb44f5 Compare June 27, 2024 16:17
@JeGoi
Copy link
Contributor Author

JeGoi commented Jul 8, 2024

These services have a systemd service related to firewalld but no rules related:

# conf/systemd/packetfence-httpd.dispatcher.service # DONE

conf/systemd/[email protected]
conf/systemd/packetfence-ntlm-auth-api.service
conf/systemd/packetfence-pfconnector-client.service
conf/systemd/packetfence-pfdetect.service
conf/systemd/packetfence-pfdhcplistener.service
conf/systemd/packetfence-pffilter.service
conf/systemd/packetfence-pfldapexplorer.service
conf/systemd/packetfence-pfpki.service
conf/systemd/packetfence-pfqueue-perl.service
conf/systemd/packetfence-pfsetacls.service
conf/systemd/packetfence-pfsso.service
conf/systemd/packetfence-pfstats.service
conf/systemd/packetfence-radsniff.service
conf/systemd/packetfence-redis_ntlm_cache.service

JeGoi added 22 commits July 8, 2024 17:14
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

Successfully merging this pull request may close these issues.

None yet

4 participants