iptables cgroup フィルタの不一致

iptables cgroup フィルタの不一致

特定のサービスだけがVPN仮想インターフェイスにアクセスできるようにする必要があります。私が知っている限り、iptablesを使用してプロセスcgroupメンバーシップに基づいてフィルタリングするのが最もクリーンな方法です。

そのため、systemdを使用してsshdサービスをvpn.slicecgroupに入れ、チェーンを作成してINPUTとOUTPUTに追加しました。

iptables -N vpn
iptables -A vpn -m cgroup --path /vpn.slice -j ACCEPT
iptables -A vpn -j DROP

iptables -A INPUT  -i $INTERFACE -j vpn
iptables -A OUTPUT -o $INTERFACE -j vpn

iptables -L出力:

[root@sh ~]# iptables -L -v
Chain INPUT (policy ACCEPT 287K packets, 17M bytes)
 pkts bytes target     prot opt in     out     source               destination         
  106  5160 vpn        all  --  homeforward any     anywhere             anywhere            

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 476K packets, 673M bytes)
 pkts bytes target     prot opt in     out     source               destination         
   78 10062 vpn        all  --  any    homeforward  anywhere             anywhere            

Chain vpn (2 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     all  --  any    any     anywhere             anywhere             cgroup /vpn.slice
  184 15222 DROP       all  --  any    any     anywhere             anywhere            

このルールを適用すると、SSHサーバーに接続できなくなり、他のポートのnetcatにも当てはまります。シェルのcgroupメンバーシップを手動で変更し、VPNの他のノードをpingすることも機能しませんでした。私も--path vpn.slice代わりに試してみましたが、--path /vpn.slice違いはありません。

ここで何か抜けましたか?

ベストアンサー1

おすすめ記事