4

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.

1 Answer 1

5

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
1
  • 2
    For all you google-copy-pasters, the exact command is setsebool -P httpd_can_connect_ldap on. (edited to include Michael's info below)
    – bgStack15
    Mar 18, 2016 at 11:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .