running on Rocky Linux 9.2 with podman 4.4.1.
I got a podman Pod with keycloak + postgresql inside, running rootless. The pod itself with --network 'slirp4netns:port_handler=slirp4netns'
. The keycloak container is running with --log-driver json-file --log-opt path=/var/log/keycloak.log
so I have the log file on the host system itself. There is also a traefik proxy making keycloak accessible, ssl termination on traefik + ssl termination on keycloak itself.
Everything works so far, I see the real IP address of a user trying to login in the logs. Fail2ban is running on the host system, the regex is also working, and it's banning the correct IP address BUT even though the IP is banned (I see it in fail2ban-client status keycloak
), the user is still able to continue submitting logins.
/etc/fail2ban/jail.d/keycloak.local
[keycloak]
backend = auto
enabled = true
filter = keycloak
maxretry = 3
bantime = 86400
findtime = 86400
logpath = /var/log/keycloak.log
action = iptables-allports[name=keycloak]
So before the ban, iptables is empty:
iptables -n -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
After the ban:
iptables -n -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
f2b-keycloak tcp -- 0.0.0.0/0 0.0.0.0/0
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain f2b-keycloak (1 references)
target prot opt source destination
REJECT all -- xx.xx.xx.xx 0.0.0.0/0 reject-with icmp-port-unreachable
RETURN all -- 0.0.0.0/0 0.0.0.0/0
I also read something about that Docker is using the FORWARD chain, so I set action = iptables-allports[name=keycloak, protocol=all, chain=FORWARD]
in the keycloak jail file, iptables had then the rule in the FORWARD chain but it was still not working. Same behaviour like when using the default setting (in the INPUT chain).
How can I make the rootless podman container obey the ip ban from iptables? Any ideas?
podman
withslirp4netns
doesn't useiptables
for routing so that's not the issue.nftables
underneath which supports more chains than whatiptables
can display, although theiptables
chain should still be capable of rejecting packets.tcpdump
sees when filtering on the IP you expect to be blocked, it might also be that your handling of upstream IPs is flawed and what you log isn't really the remote IP.