MariaDBスレーブサーバーは、マスターサーバーに接続するために127.0.0.1:3307に接続する必要があります。 SELinuxはそうではないと言います。何をしますか?

MariaDBスレーブサーバーは、マスターサーバーに接続するために127.0.0.1:3307に接続する必要があります。 SELinuxはそうではないと言います。何をしますか?

CentOS 7にMariaDBサーバーがあります。このサーバーはスレーブとして機能し、リモートマスターを複製する必要があります。リモートマスターサーバーはSSHトンネルを介して接続できます。 SSHトンネル「入り口」は127.0.0.1:3307にあります。

MariaDBクライアントプログラムを使用してこのエンドポイントに接続できます。

ただし、MariaDBサーバーは接続できません。 MySQLエラーログには次のものがあります。Slave I/O: error connecting to master '[email protected]:3307' - retry-time: 60 maximum-retries: 86400 message: Can't connect to MySQL server on '127.0.0.1' (13 "Permission denied"), Internal MariaDB error code: 2003

明らかに、人々はすぐにMariaDBサーバーからの非標準接続を拒否するSELinuxを考えています。

SELinuxを許可モード(編集/etc/selinux/configと再起動)に切り替えた後、良いphociformプロセスをリンクできました。

/var/log/audit/audit.logSELinux拒否イベント(およびその他のイベント)を使用するログを確認しましょうausearch(auditdの詳細については、auditdの簡単な紹介")

ausearch --comm mysqld

これにより、次の項目が提供されます。

time->Wed Mar 21 18:52:53 2018
type=PROCTITLE msg=audit(1521654773.504:120): proctitle="/usr/sbin/mysqld"
type=SYSCALL msg=audit(1521654773.504:120): arch=c000003e syscall=42 success=no exit=-115 a0=41 a1=7fd1f4028ad0 a2=10 a3=72 items=0 ppid=1 pid=1342 auid=4294967295 uid=27 gid=27 euid=27 suid=27 fsuid=27 egid=27 sgid=27 fsgid=27 tty=(none) ses=4294967295 comm="mysqld" exe="/usr/sbin/mysqld" subj=system_u:system_r:mysqld_t:s0 key=(null)
type=AVC msg=audit(1521654773.504:120): avc:  denied  { name_connect } for  pid=1342 comm="mysqld" dest=3307 scontext=system_u:system_r:mysqld_t:s0 tcontext=system_u:object_r:unreserved_port_t:s0 tclass=tcp_socket

システムコール 42sys_connect

とても素敵です。

今読んでください。手動(おそらく役に立たないかもしれません。)したがって、質問は次のようになります。

MariaDBを127.0.0.1:3307に接続するには、どのコマンドを実行する必要がありますか?私が欲しいからSELinuxを再度有効にします。

答え1

SELinuxポリシーは、プロセスがファイル、デバイス、ソケットなどの特定のオブジェクトで実行できるすべての操作を制御します。非標準ポートを使用して受信または通信するようにデーモンが設定されている場合、ターゲットポリシーはそのアクションを拒否します。ラベルはポートを制御するために使用されます。 MariaDBタグを見つけるには、を使用し、semanageよく知られているポート番号を使用して結果をフィルタリングします。grep

semanage port -l | grep 3306

これにより、次のような出力が生成されます。

mysqld_port_t tcp 1186, 3306, 63132-63164

このラベルのルールを変更するには、semanage次のようにポート 3307 を再度使用します。

semanage port -a -t mysqld_port_t -p tcp 3307

上記のコマンドを実行した後、ルールを再確認して3307が許可されていることを確認します。

semanage port -l | grep 3307

ポートリストに3307が表示されます。

mysqld_port_t tcp 3307, 1186, 3306, 63132-63164

答え2

パッケージがインストールさsetroubleshoot-serverれている場合(推奨)、プログラムはsetroubleshootd次のように呼び出されます。バス監査デーモンauditd(間接的にも) および指定された SELinux AVC レコードで以下を処理します.

SELinux通知とロギングカスケード

実際にはsetroubleshootd(かつてそうだった)「デーモン」ではなくすべてが静かになると、活動呼び出し側が再び終了します。

setroubleshootdこれはsyslogに記録され、AVC拒否メッセージが表示されます。デフォルトで他に設定しない/var/log/messages限り、これは終了しますrsyslog

setroubleshootdまたお知らせしますバスsealertGUIウィジェットなどSELinuxイベントに興味があるお客様です。

sealertAVCレコードを確認するために使用します。マニュアルページには次のように記載されています。「最も便利な2つのコマンドラインオプションは、警告IDを「検索する」-lとログファイルを「分析」する-aです。

見て/var/log/messages、人々は次のようなものを見るでしょう:

setroubleshoot: SELinux is preventing mysqld from
name_connect access on the tcp_socket port 3307. For complete SELinux
messages run: sealert -l 90cd70e9-0bb2-4668-b165-d5be37e26b22

..そして非常に読みやすい情報で構成された数行の追加情報はsealert -l 90cd70e9-0bb2-4668-b165-d5be37e26b22

それではこれを実行してみましょうsealert -l 90cd70e9-0bb2-4668-b165-d5be37e26b22。これは私たちに良いアドバイスを提供します(このレコードはSELinuxを有効にしたものではありません)。

SELinux is preventing mysqld from name_connect access on the tcp_socket port 3307.

*****  Plugin connect_ports (85.9 confidence) suggests   *********************

If you want to allow mysqld to connect to network port 3307
Then you need to modify the port type.
Do
# semanage port -a -t PORT_TYPE -p tcp 3307
    where PORT_TYPE is one of the following: dns_port_t, dnssec_port_t,
    kerberos_port_t, mysqld_port_t, ocsp_port_t, tram_port_t.

*****  Plugin catchall_boolean (7.33 confidence) suggests   ******************

If you want to allow nis to enabled
Then you must tell SELinux about this by enabling the 'nis_enabled' boolean.
You can read 'None' man page for more details.
Do
setsebool -P nis_enabled 1

*****  Plugin catchall_boolean (7.33 confidence) suggests   ******************

If you want to allow mysql to connect any
Then you must tell SELinux about this by enabling the 'mysql_connect_any' boolean.
You can read 'None' man page for more details.
Do
setsebool -P mysql_connect_any 1

*****  Plugin catchall (1.35 confidence) suggests   **************************

If you believe that mysqld should be allowed name_connect access on the
port 3307 tcp_socket by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# ausearch -c 'mysqld' --raw | audit2allow -M my-mysqld
# semodule -i my-mysqld.pp


Additional Information:
Source Context                system_u:system_r:mysqld_t:s0
Target Context                system_u:object_r:unreserved_port_t:s0
Target Objects                port 3307 [ tcp_socket ]
Source                        mysqld
Source Path                   mysqld
Port                          3307
Host                          foobar.example.com
Source RPM Packages
Target RPM Packages
Policy RPM                    selinux-policy-3.13.1-166.el7_4.9.noarch
Selinux Enabled               True
Policy Type                   targeted
Enforcing Mode                Enforcing
Host Name                     foobar.example.com
Platform                      Linux foobar.example.com
                              3.10.0-693.21.1.el7.x86_64 #1 SMP Wed Mar 7
                              19:03:37 UTC 2018 x86_64 x86_64
Alert Count                   36
First Seen                    2018-03-22 16:04:59 CET
Last Seen                     2018-03-22 16:39:59 CET
Local ID                      90cd70e9-0bb2-4668-b165-d5be37e26b22

Raw Audit Messages
type=AVC msg=audit(1521733199.870:201): avc:  denied  { name_connect }
for  pid=1352 comm="mysqld" dest=3307
scontext=system_u:system_r:mysqld_t:s0
tcontext=system_u:object_r:unreserved_port_t:s0 tclass=tcp_socket


Hash: mysqld,mysqld_t,unreserved_port_t,tcp_socket,name_connect

だから、85.9自信(「私は戻ってきます!」)

「mysqldがネットワークポート3307に接続できるようにするには、ポートタイプを変更する必要があります。実行semanage port -a -t PORT_TYPE -p tcp 3307」ここでPORT_TYPEはmysqld_port_t

関連情報