Bonjour à tous,
Je suis entrain de réaliser un script Ansible pour deployer une Seedbox (Transmission) sur une Raspberry pi. Le script sera surement mis a disposition Github une fois présentable.
Ma seebox est composé:
- Transmission
- Nginx + Letsencrypt
- openvpn
- fail2ban
- iptables
Je souhaiterais que tout le traffic de Transmission passe par mon VPN mais je ne suis pas très à l'aise avec iptables. Mon idée est de restreindre l'utilisateur debian-transmission a l'interface tun0 créer par openvpn.
Voila ce que j'ai pour l'instant :
#!/bin/sh
SSH_PORT=22
HTTP_PORT=80
HTTPS_PORT=443
INTERNAL_IFACE=eth0
VPN_IFACE=tun0
GROUP=debian-transmission
# empty the table
iptables -t filter -F
iptables -t filter -X
# Forbide all in/out connection
iptables -t filter -P INPUT DROP
iptables -t filter -P FORWARD DROP
iptables -t filter -P OUTPUT DROP
# Authorize loopback
iptables -t filter -A INPUT -i lo -j ACCEPT
iptables -t filter -A OUTPUT -o lo -j ACCEPT
# Authorize ping
iptables -t filter -A INPUT -p icmp -j ACCEPT
iptables -t filter -A OUTPUT -p icmp -j ACCEPT
# Forbide access INTERNAL_IFACE to GROUP
iptables -t filter -A OUTPUT -o $INTERNAL_IFACE -m owner --gid-owner $GROUP -j REJECT
###
# $INTERNAL_IFACE
###
# Not broke open connection
iptables -t filter -A INPUT -i $INTERNAL_IFACE -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t filter -A OUTPUT -o $INTERNAL_IFACE -m state --state RELATED,ESTABLISHED -j ACCEPT
# Accept SSH connection
iptables -t filter -A INPUT -p tcp -i $INTERNAL_IFACE --dport $SSH_PORT -j ACCEPT
iptables -t filter -A OUTPUT -p tcp -o $INTERNAL_IFACE --dport $SSH_PORT -j ACCEPT
# Accept HTTP/HTTPS connection
iptables -t filter -A INPUT -p tcp -i $INTERNAL_IFACE --dport $HTTP_PORT -j ACCEPT
iptables -t filter -A OUTPUT -p tcp -o $INTERNAL_IFACE --dport $HTTP_PORT -j ACCEPT
iptables -t filter -A INPUT -p tcp -i $INTERNAL_IFACE --dport $HTTPS_PORT -j ACCEPT
iptables -t filter -A OUTPUT -p tcp -o $INTERNAL_IFACE --dport $HTTPS_PORT -j ACCEPT
###
# tun0
###
# Accept in and out for VPN
iptables -t filter -A OUTPUT -m owner --gid-owner $GROUP -j REJECT
iptables -t filter -A OUTPUT -o $VPN_IFACE -m owner --gid-owner $GROUP -j ACCEPT
Qu'en pensez vous ?
EDIT: Modification des règles qui ne fonctionnaient pas.