大网数据广告活动
服务器运维问答

SELinux context for apache ldap ssl

· 52CE 我爱测

Question What SELinux context do I need, for what file to get apache ldap (over ssl) auth to work? Or is it a network protocol or system call or something else entirely? Environment Apache 2.4 on Centos 7 using basic ldap authent…

问题原文

原帖链接 · bgStack15 · CC BY-SA 3.0

Question

What SELinux context do I need, for what file to get apache ldap (over ssl) auth to work? Or is it a network protocol or system call or something else entirely?

Environment

Apache 2.4 on Centos 7 using basic ldap authentication over ssl.

With SELinux permissive (setenforce 0), everything runs well and fine. I can log in to the protected directory with ldap perfectly.

When SELinux is enabled (setenforce 1), apache cannot perform the ldap search and allow the user through. It has something to do with ssl or certificates and I can't figure it out.

/var/log/httpd/ssl_error_log

[Thu Mar 17 15:33:32.529755 2016] [authnz_ldap:debug] [pid 6412] mod_authnz_ldap.c(501): [client 158.158.193.232:17386] AH01691: auth_ldap authenticate: using URL ldaps://ldap-ad.example.org:636/ou=Auto-Accounts,dc=example,dc=org?sAMAccountname?sub
[Thu Mar 17 15:33:32.530792 2016] [ldap:debug] [pid 6412] util_ldap.c(372): AH01278: LDAP: Setting referrals to On.
[Thu Mar 17 15:33:32.531845 2016] [ldap:debug] [pid 6412] util_ldap.c(372): AH01278: LDAP: Setting referrals to On.
[Thu Mar 17 15:33:32.532936 2016] [ldap:debug] [pid 6412] util_ldap.c(372): AH01278: LDAP: Setting referrals to On.
[Thu Mar 17 15:33:32.533568 2016] [authnz_ldap:info] [pid 6412] [client 158.158.193.232:17386] AH01695: auth_ldap authenticate: user bgstack15 authentication failed; URI /auth1/ [LDAP: ldap_simple_bind() failed][Can't contact LDAP server]
[Thu Mar 17 15:33:32.533784 2016] [ssl:debug] [pid 6412] ssl_engine_io.c(992): [client 158.158.193.232:17386] AH02001: Connection closed to child 1 with standard shutdown (server sample.example.org:443)

/var/log/audit/audit.log

type=AVC msg=audit(1458243341.951:1234): avc:  denied  { name_connect } for  pid=6428 comm="httpd" dest=636 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:ldap_port_t:s0 tclass=tcp_socket
type=SYSCALL msg=audit(1458243341.951:1234): arch=c000003e syscall=42 success=no exit=-13 a0=12 a1=7f2c0498eab0 a2=10 a3=0 items=0 ppid=6409 pid=6428 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)
type=AVC msg=audit(1458243341.952:1235): avc:  denied  { name_connect } for  pid=6428 comm="httpd" dest=636 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:ldap_port_t:s0 tclass=tcp_socket
type=SYSCALL msg=audit(1458243341.952:1235): arch=c000003e syscall=42 success=no exit=-13 a0=12 a1=7f2c0498eab0 a2=10 a3=0 items=0 ppid=6409 pid=6428 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)
type=AVC msg=audit(1458243341.952:1236): avc:  denied  { name_connect } for  pid=6428 comm="httpd" dest=636 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:ldap_port_t:s0 tclass=tcp_socket
type=SYSCALL msg=audit(1458243341.952:1236): arch=c000003e syscall=42 success=no exit=-13 a0=12 a1=7f2c0498d580 a2=10 a3=0 items=0 ppid=6409 pid=6428 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)
type=AVC msg=audit(1458243341.953:1237): avc:  denied  { name_connect } for  pid=6428 comm="httpd" dest=636 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:ldap_port_t:s0 tclass=tcp_socket
type=SYSCALL msg=audit(1458243341.953:1237): arch=c000003e syscall=42 success=no exit=-13 a0=12 a1=7f2c0498d580 a2=10 a3=0 items=0 ppid=6409 pid=6428 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)

What I've tried already

I have started reading up on SELinux and have tried copying the context from other certificates. I tried doing that on the certificates in /etc/openldap/certs and also /etc/pki/tls/certs. Perhaps I need to try something for the tcp port 636?

Updates

SElinux: allow httpd to connect to a specific port provides a working solution, but it is not refined for maximum security yet. The command

setsebool httpd_can_network_connect on

allows httpd to perform the ldaps bind. However, this opens up httpd too much so I am still looking for a way to allow just port 636.

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 3.0

There's always the boolean httpd_can_connect_ldap.

This allows:

# sesearch -b httpd_can_connect_ldap -AC
Found 1 semantic av rules:
DT allow httpd_t ldap_port_t : tcp_socket name_connect ; [ httpd_can_connect_ldap ]

And ldap_port_t provides access to the relevant ports:

# semanage port -l
ldap_port_t                    tcp      389, 636, 3268, 7389
ldap_port_t                    udp      389, 636

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-03-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。