SELinux-システムの操作の説明と機能。 パート2





同僚、SElinuxに関する記事の最初の部分で 、SELinuxシステムを操作する主な機能を調べました。 約束どおり、ポリシーの設定に焦点を当てた第2部を公開しています。 さあ、始めましょう。



SELinuxポリシーのカスタマイズ





ポリシー自体を完全に変更することなく、SELinuxポリシーに若干の変更を加えることができます。 これを行うには、ポリシーで定義されている追加機能に関連付けられた論理値を変更するだけで十分です。 これらの機能により、たとえば、Sambaを使用してユーザーのホームディレクトリへのアクセスを提供したり、Apacheがホームディレクトリにあるファイルを使用したりできます。



デフォルトでは、これらの機能は無効になっています。 これらの機能のリストは事前定義されており、システム管理者が直面する最も頻繁に使用されるタスクで構成されています。



システムで使用可能なすべての機能を表示するには、次のコマンドを実行します。



# getsebool -a
      
      







パラメーターを変更するには、setseboolコマンドを使用する必要があります。 たとえば、HTTPDサービスモジュールとスクリプトがネットワークに接続できるようにするには、コンソールに次のように入力します。



 # setsebool -P httpd_can_network_connect on
      
      







audit2allowを使用してカスタムポリシーを作成する





事前定義された機能が十分にない場合、既存のポリシーに新しいモジュールを追加し、何かへのアクセスを提供する特定の条件を手動で書き留める必要がある場合に、状況が発生することがあります。 たとえば、SMTPメールサーバーにPostgreyアドオンをインストールします。 私たちのサーバーはUnixソケットを介してPostgreyと対話する必要がありますが、メールサーバーの標準SELinuxポリシーはこれを許可せず、ソケットを介した通信の試行をブロックします。



そのような状況では、ファイルのコンテキストを変更しても役に立たず、追加の機能はありません。これにより、状況を修正できます。 もちろん、「問題のある」サービスに対してはいつでもSELinuxを無効にすることができますが、メールサーバーがいつかハッキングされる可能性はゼロではないため、このソリューションはもちろん理想とはほど遠いものです。



そのため、SELinuxをPermissiveモードにして、メールサーバーを起動します。 しばらくすると、AVCメッセージがSELinuxログに表示され、サーバーのすべての無効なアクションが記録されます。



 type=AVC msg=audit(1218128130.653:334): avc: denied { connectto } for pid=9111 comm="smtpd" path="/var/spool/postfix/postgrey/socket" scontext=system_u:system_r:postfix_smtpd_t:s0 tcontext=system_u:system_r:initrc_t:s0 tclass=unix_stream_socket type=AVC msg=audit(1218128130.653:334): avc: denied { write } for pid=9111 comm="smtpd" name="socket" dev=sda6 ino=39977017 scontext=system_u:system_r:postfix_smtpd_t:s0 tcontext=system_u:object_r:postfix_spool_t:s0 tclass=sock_file
      
      







これで、audit2allowユーティリティを使用して、必要なすべてのPostgreyアクションを許可するローカルポリシーの一連のルールを生成できます。



 # grep smtpd_t /var/log/audit/audit.log | audit2allow -m postgreylocal > postgreylocal.te # cat postgreylocal.te module postgreylocal 1.0; require { type postfix_smtpd_t; type postfix_spool_t; type initrc_t; class sock_file write; class unix_stream_socket connectto; } #============= postfix_smtpd_t ============== allow postfix_smtpd_t initrc_t:unix_stream_socket connectto; allow postfix_smtpd_t postfix_spool_t:sock_file write;
      
      







そのため、audit.logファイルがフィルタリングされ、現在のSELinuxポリシーの観点から、Postgreyによって実行されたすべての無効なアクションが抽出されていることがわかります。 これらの手順を確認した後、SMTPサーバーがUnixソケットを使用して接続を作成しようとしており、Postgreyがこのソケットをリッスンしようとしていることがわかります。 この情報を取得し、これらのアクションを許可するSELinuxポリシー用のユーザーモジュールをベースに作成することは非常に論理的なようです。



 # grep smtpd_t /var/log/audit/audit.log | audit2allow -M postgreylocal
      
      







次に、このモジュールをロードし、semoduleコマンドを使用して、既に含まれているポリシーでそれらを補完する必要があります。



 # semodule -i postgreylocal.pp
      
      







その後、モジュールは/etc/selinux/targeted/modules/active/modules/postgreylocal.ppに移動されます。

モジュールが正しくロードされているかどうかを確認するには、「semodule -l」コマンドを使用して、ロードされているすべてのモジュールのリストを表示できます。



その後、SELinuxを引き続き監視して、新しく作成されたポリシーがPostgreyを制限しないことを確認できます。 ポリシーの正しい操作に満足し、自信が持てたらすぐに、強制モードを再度アクティブにできます。これにより、メールサーバーが確実に保護され、同時に完全に機能するようになります。



SELinuxポリシーのモジュールの手動構成。




Adit2allowは、間違いなく、特定の問題を解決するポリシーのモデルの作成に対応しています。 ただし、このユーティリティが正しく機能しない場合があるため、モジュールを手動で構成する必要があります。 たとえば、SELinux AVCログエントリを考えます。



 Summary: SELinux is preventing postdrop (postfix_postdrop_t) "getattr" to /var/log/httpd/error_log (httpd_log_t). Detailed Description: SELinux denied access requested by postdrop. It is not expected that this access is required by postdrop and this access may signal an intrusion attempt. It is also possible that the specific version or configuration of the application is causing it to require additional access. Allowing Access: Sometimes labeling problems can cause SELinux denials. You could try to restore the default system file context for /var/log/httpd/error_log, restorecon -v '/var/log/httpd/error_log' If this does not work, there is currently no automatic way to allow this access. Instead, you can generate a local policy module to allow this access - see FAQ (http://fedora.redhat.com/docs/selinux-faq-fc5/#id2961385) Or you can disable SELinux protection altogether. Disabling SELinux protection is not recommended. Please file a bug report (http://bugzilla.redhat.com/bugzilla/enter_bug.cgi) against this package. Additional Information: Source Context system_u:system_r:postfix_postdrop_t Target Context root:object_r:httpd_log_t Target Objects /var/log/httpd/error_log [ file ] Source postdrop Source Path /usr/sbin/postdrop Port <Unknown> Host sanitized Source RPM Packages postfix-2.3.3-2 Target RPM Packages Policy RPM selinux-policy-2.4.6-137.1.el5 Selinux Enabled True Policy Type targeted MLS Enabled True Enforcing Mode Enforcing Plugin Name catchall_file Host Name sanitized Platform Linux sanitized 2.6.18-53.1.21.el5 #1 SMP Tue May 20 09:35:07 EDT 2008 x86_64 x86_64 Alert Count 599 First Seen Wed Jul 2 08:27:15 2008 Last Seen Sun Aug 10 22:47:52 2008 Local ID c303a4ea-8e7a-4acc-9118-9cc61c6a2ec8 Line Numbers Raw Audit Messages host=sanitized type=AVC msg=audit(1218397672.372:352): avc: denied { getattr } for pid=4262 comm="postdrop" path="/var/log/httpd/error_log" dev=md2 ino=117005 scontext=system_u:system_r:postfix_postdrop_t:s0 tcontext=root:object_r:httpd_log_t:s0 tclass=file host=sanitized type=SYSCALL msg=audit(1218397672.372:352): arch=c000003e syscall=5 success=no exit=-13 a0=2 a1=7fffd6febca0 a2=7fffd6febca0 a3=0 items=0 ppid=4261 pid=4262 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=90 sgid=90 fsgid=90 tty=(none) comm="postdrop" exe="/usr/sbin/postdrop" subj=system_u:system_r:postfix_postdrop_t:s0 key=(null)
      
      







audit2allowを実行し、結果のpostfixlocal.teポリシーを確認すると、次のように表示されます。



 # grep postdrop /var/log/audit/audit.log | audit2allow -M postfixlocal # cat postfixlocal.te module postfixlocal 1.0; require { type httpd_log_t; type postfix_postdrop_t; class dir getattr; class file { read getattr }; } #============= postfix_postdrop_t ============== allow postfix_postdrop_t httpd_log_t:file getattr;
      
      







質問がすぐに発生します。PostDropが/ var / log / httpd / error_logにアクセスしようとするのはなぜですか? これはこのプログラムに期待できるアクションではないため、このアクションを許可するかどうかを判断するのは私たち次第です。



この問題を解決する方法はいくつかあります。



-このエラーを無視して、SELinuxがファイルへのアクセスをブロックできるようにすることができます。



-audit2allowを使用して適切なポリシーモジュールを作成することにより、このアクションを有効にできます。

-このモジュールのファイルを手動で編集して、ファイルへのアクセス試行に対する望ましいSELinux応答を決定できます。 たとえば、アクセスをブロックしている間、このイベントの監査を禁止できます。 これを行うには、対応する行の「allow」値を「dontaudit」に変更する必要があります。



 #============= postfix_postdrop_t ============== dontaudit postfix_postdrop_t httpd_log_t:file getattr;
      
      







編集したポリシーモジュールを手動でコンパイルしてロードする必要があります。



 # checkmodule -M -m -o postfixlocal.mod postfixlocal.te # semodule_package -o postfixlocal.pp -m postfixlocal.mod # semodule -i postfixlocal.pp
      
      







したがって、ファイル/ var / log / httpd / error_logへのアクセスはブロックされますが、SELinuxからこれに関する一定の警告を受け取りません。



実際、SELinuxについてはこれですべてです。以降の記事では、rpmディストリビューションのLinuxでのディスククォータなど、興味深い(そして、できれば便利な)トピックを検討します。 新しい記事は月曜日に公開されます。



All Articles