シンプルなファイアウォールはパペットを意味します

パペットのインストールと設定の概要と基本事項は既にパート1パート2で公開されているのでここではやめずに、ファイアウォールの設定に進みます。



問題の声明


このプロジェクトでは、多くのサーバーを使用していますが、そのほとんどはクラウド内にあります。 一部は会社のインフラストラクチャを提供するために使用され、一部は顧客に公共サービスを提供します。 集中アクセス制御を提供する必要があります。



この例のサーバーのリスト:



基本設定


最初に、sshを除くすべての着信ポートが閉じられる基本的なファイアウォール構成を作成します。



 class firewall { exec { 'minimal-firewall': path => ["/bin", "/sbin", "/usr/bin", "/usr/sbin"], command => "iptables -P INPUT DROP \ && iptables -P FORWARD DROP \ && iptables --flush \ && iptables -t nat --flush \ && iptables --delete-chain \ && iptables -P FORWARD DROP \ && iptables -P INPUT DROP \ && iptables -A INPUT -i lo --source 127.0.0.1 --destination 127.0.0.1 -j ACCEPT \ && iptables -A INPUT -m state --state \"ESTABLISHED,RELATED\" -j ACCEPT \ && iptables -A INPUT -p icmp --icmp-type destination-unreachable -j ACCEPT \ && iptables -A INPUT -p icmp --icmp-type time-exceeded -j ACCEPT \ && iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT \ && iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT \ && iptables -A INPUT -p tcp --dport ssh -j ACCEPT \ && iptables -A INPUT -j LOG -m limit --limit 40/minute \ && iptables -A INPUT -j DROP", } }
      
      







ここには魔法はありません。 Iptablesルールは「iptables minimal firewall」でグーグルです。最初のリンクは正しいです。 唯一の違い:エンティティを作成しないため-個別のスクリプトを作成しないために、すべてのコマンドが1つの&&



演算子に結合されます。



この構成をサーバーに適用するには、puppetノードの用語で、サーバー設定でクラスを指定する必要があります。



 node 'www' { include firewall }
      
      





ホスト名は、FQDNまたは短いホスト名のいずれかです。 デフォルトでは、Puppetクライアントは30分ごとに構成を再読み取りするため、少し待つか、SIGHUPシグナルをプロセスに送信するか、サービスを再起動するだけです。 その後、ファイアウォールルールが適用されていることを確認できます: iptables -L







入力ポートを開きます


わずかな微妙さがあります。 iptablesにルールを追加する順序は重要です。ポートへのアクセスを許可する新しいルールを追加するだけでは機能しません。 したがって、新しいルールを適切な場所に挿入します。 定義は非常に簡単です: iptables -L --line-numbers



コマンドを実行し、ssh 7 ACCEPT tcp -- anywhere anywhere tcp dpt:ssh



記載されている行を探します7 ACCEPT tcp -- anywhere anywhere tcp dpt:ssh



iptables -L --line-numbers



7 ACCEPT tcp -- anywhere anywhere tcp dpt:ssh



。 したがって、位置7にルールを挿入します。



 define allowport ($protocol, $port) { exec { "/sbin/iptables -I INPUT 7 -p $protocol --dport $port -j ACCEPT": require => Exec['minimal-firewall'], } }
      
      







その後、wwwノードの構成は次のようになります。



 node 'www' { allowport { http: protocol => tcp, port => 80, } allowport { https: protocol => tcp, port => 443, } include firewall }
      
      







注:人形記述言語は宣言的であり、ルールの実行順序は定義されていません。 したがって、実際には、すべて同じように、最初に「ファイアウォールをインポート」と記述され、次に「allowport」と記述されます。 私たちにとって、最小限のファイアウォールを設定するためのルールが最初に解決され、それが初めて-ポートの開放が重要です。 この要件は、許可ポートの定義に記録されます-require require => Exec['minimal-firewall']







管理サーバーの構成:



 node 'admin' { allowport { dns1: protocol => tcp, port => 53, } allowport { dns2: protocol => udp, port => 53, } allowport { http: protocol => tcp, port => 80, } allowport { webmin: protocol => tcp, port => 10000, } include firewall }
      
      







ルールを複雑にする


Tomcatアプリケーションサーバーは、非特権ユーザーから起動する必要がありますが、標準の443ポートから応答する必要があります。 したがって、ポート443への接続のアドレス変換(DNAT)を8443にリダイレクトし、tomcatがリッスンします。



 define dnat ($protocol, $from, $to) { exec { 'dnat-$protocol-$from-$to': command => "/sbin/iptables -t nat -A PREROUTING -d $hostname -p $protocol --dport $from -j DNAT --to-destination $to \ && /sbin/iptables -t nat -A OUTPUT -d $hostname -p $protocol --dport $from -j DNAT --to-destination $to ", require => Exec['minimal-firewall'], } }
      
      







アプリケーションサーバーの構成について説明します。



 node 'app' { allowport { https: protocol => tcp, port => 443, } allowport { tomcat: protocol => tcp, port => 8443, } dnat { java: protocol => tcp, from => 443, to => ':8443', } include firewall }
      
      







Mysqlサーバーは社外からアクセスできないようにする必要があります。 必要に応じて、開発者は管理サーバーからアクセスします。 適切な定義を使用してアクセスを制限します。



 define dmzport ($protocol, $port) { exec { 'dmz-$protocol-$port': command => "/sbin/iptables -I INPUT 7 -s admin.example.com -p $protocol --dport $port -j ACCEPT \ && /sbin/iptables -I INPUT 7 -s www.example.com -p $protocol --dport $port -j ACCEPT \ && /sbin/iptables -I INPUT 7 -s mysql.example.com -p $protocol --dport $port -j ACCEPT \ && /sbin/iptables -I INPUT 7 -s app.example.com -p $protocol --dport $port -j ACCEPT", require => Exec['minimal-firewall'], } }
      
      





次に、mysqlノードの構成:



 node 'mysql' { dmzport { mysql: protocol => tcp, port => 3306, } include firewall }
      
      







したがって、会社のすべてのサーバー用のシンプルな集中型ファイアウォールを取得しました。



All Articles