Skip to content

Commit ee2f81b

Browse files
committed
Add support for copying any 'ldap*' cert to a folder slapd can read and restarting slapd
1 parent 2fc05b2 commit ee2f81b

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

centos6/hook.sh

+39-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
# - Will automatically identify the correct Route 53 zone for each domain name
66
# - Supports certificates with alternative names in different Route 53 zones
77
#
8-
# This version includes a deploy_cert function for CentOS 6 / RHEL 6 for webmin and apache
8+
# This version includes a deploy_cert function for CentOS 6 / RHEL 6 / Amazon Linux
9+
# for webmin, apache, and slapd (Sys V init 'service' command)
910
#
1011
# Aaron Roydhouse <[email protected]>, 2016
1112
# https://github.com/whereisaaron/dehydrated-route53-hook-script
@@ -100,10 +101,10 @@ deploy_cert() {
100101
#
101102
# Restart apache to read the new certificate files
102103
# Requires that user running dehydrated has sudoer rights to execute the commands, e.g
103-
# dehydrated ALL = NOPASSWD: /sbin/service httpd configtest, /sbin/service httpd graceful
104+
# dehydrated ALL = NOPASSWD: /sbin/service httpd status, /sbin/service httpd configtest, /sbin/service httpd graceful
104105
#
105106

106-
# Only consider restarting if apache if it is installed and running
107+
# Only consider restarting apache if it is installed and running
107108
if [[ "$(sudo service httpd status)" =~ "running" ]]; then
108109

109110
# Restart apache if the configuration is valid
@@ -117,6 +118,41 @@ deploy_cert() {
117118
fi
118119

119120
fi
121+
122+
#
123+
# Restart slapd (openldap) to read the new certificate files bash on heuristic that domain starts with 'ldap'
124+
# Requires that user running dehydrated has sudoer rights to execute the commands, e.g
125+
# dehydrated ALL = NOPASSWD: /sbin/service slapd status, /sbin/service slapd configtest, /sbin/service slapd restart
126+
#
127+
128+
# Only consider restarting slapd if cert starts with ldap
129+
if [[ "${DOMAIN}" =~ ^ldap ]]; then
130+
131+
# Copy the cert if the target folder exists and it writable
132+
# Target folder should be set-gid 'ldap' to ensure slapd can read the files
133+
local LDAP_DEPLOY=/etc/openldap/dehydrated
134+
if [[ -d "${LDAP_DEPLOY}" && -w "${LDAP_DEPLOY}" ]]; then
135+
echo "Copying slapd cert/key/chain (${KEYFILE} ${CERTFILE} ${CHAINFILE}) to ${LDAP_DEPLOY}"
136+
cp "${KEYFILE}" "${CERTFILE}" "${CHAINFILE}" "${LDAP_DEPLOY}"
137+
chmod g+r "${KEYFILE}" "${CERTFILE}" "${CHAINFILE}"
138+
fi
139+
140+
# Only consider restarting slapd if it is installed and running
141+
if [[ "$(sudo service slapd status)" =~ "running" ]]; then
142+
143+
# Restart slapd if the configuration is valid
144+
echo -n "Checking slapd config: "
145+
sudo service slapd configtest
146+
if [[ $? -eq 0 ]]; then
147+
echo "Config OK"
148+
echo "Restarting slapd to read the new certificate files for ${DOMAIN}"
149+
sudo service slapd restart
150+
else
151+
echo "Config is invalid"
152+
(>&2 echo "Skipping restarting slapd because slapd config is invalid")
153+
fi
154+
fi
155+
fi
120156
}
121157

122158
#

centos6/sudoers-dehydrated

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
dehydrated ALL = NOPASSWD: /sbin/service httpd status, /sbin/service httpd configtest, /sbin/service httpd graceful
22
dehydrated ALL = NOPASSWD: /sbin/service webmin status, /sbin/service webmin restart
3+
dehydrated ALL = NOPASSWD: /sbin/service slapd status, /sbin/service slapd configtest, /sbin/service slapd restart

0 commit comments

Comments
 (0)