AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 432650
Accepted
David Tonhofer
David Tonhofer
Asked: 2018-03-22 10:34:27 +0800 CST2018-03-22 10:34:27 +0800 CST 2018-03-22 10:34:27 +0800 CST

MariaDB 从服务器应连接到 127.0.0.1:3307 以到达主服务器。SELinux 说不。做什么?

  • 772

我在 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.

显然,人们立即想到 SELinux 将 kibosh 放在从 MariaDB 服务器传出的非标准连接上。

在将 SELinux 置于许可模式(编辑/etc/selinux/config并重新启动)后,良好的 phociform 进程设法连接。

让我们检查/var/log/audit/audit.log使用哪些日志 SELinux 拒绝事件(以及其他)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

(系统调用 42是sys_connect)

很酷。

现在,我仍然需要通读手册(也许它甚至没有帮助),所以问题是:

我要执行什么命令让 MariaDB 连接到 127.0.0.1:3307?因为我想重新启用 SELinux。

selinux
  • 2 2 个回答
  • 438 Views

2 个回答

  • Voted
  1. Best Answer
    Christopher
    2018-03-23T05:45:37+08:002018-03-23T05:45:37+08:00

    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
  2. David Tonhofer
    2018-03-23T07:53:13+08:002018-03-23T07:53:13+08:00

    如果软件包setroubleshoot-server已经安装(推荐),那么程序setroubleshootd将通过dbus从审计守护进程调用auditd(虽然是间接的)并给定 SELinux AVC 记录来处理:

    SELinux 通知和日志记录级联

    请注意,这setroubleshootd实际上不是一个“守护进程”(它曾经是),而是一个在活动中调用的程序,如果一切都安静,它会再次退出。

    setroubleshootd将记录到 syslog,您将看到 AVC 拒绝信息。默认情况下,/var/log/messages除非rsyslog进行了不同的配置,否则这将结束。

    setroubleshootd还将通知对 SELinux 事件(如GUI 小部件)感兴趣的dbus客户端。sealert

    用于sealert检查 AVC 记录。手册页说:“两个最有用的命令行选项是 -l 来“查找”警报 ID 和 -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!

    • 1

相关问题

  • 如何查看 SELinux 配置文件

  • 如何安装 SELinux 策略手册页?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    ssh 无法协商:“找不到匹配的密码”,正在拒绝 cbc

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    如何卸载内核模块“nvidia-drm”?

    • 13 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Wong Jia Hau ssh-add 返回:“连接代理时出错:没有这样的文件或目录” 2018-08-24 23:28:13 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST
  • Martin Hope
    Bagas Sanjaya 为什么 Linux 使用 LF 作为换行符? 2017-12-20 05:48:21 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve