entrypoint.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/sh
  2. # Log everything to this log file
  3. exec &> $ENTRYLOG
  4. # Inspired by https://github.com/acobaugh/openldap-alpine
  5. # When not limiting the open file descriptors, the memory consumption
  6. # of slapd is absurdly high. See https://github.com/docker/docker/issues/8231
  7. ulimit -n 8192
  8. # If there's no cn=config database, initialize one.
  9. # Take the original slapd.conf file as template.
  10. if [ ! -d '/etc/openldap/slapd.d/cn=config' ]; then
  11. # Limit the access to the database
  12. SLAPD_CONFIG_ROOTPW=`< /dev/urandom tr -dc A-Za-z0-9 | head -c14; echo`
  13. # Generate a password hash
  14. config_rootpw_hash=`slappasswd -s "${SLAPD_CONFIG_ROOTPW}"`
  15. printf "$SLAPD_CONFIG_ROOTPW" > /etc/openldap/slapd.d/slapd_config_rootpw
  16. chmod 400 /etc/openldap/slapd.d/slapd_config_rootpw
  17. # Check if all certificates and keys are present
  18. if [ ! -f ${SSL_PATH}/slurm.ch-rootCA.crt ] || \
  19. [ ! -f ${SSL_PATH}/ldap.slurm.ch.crt ] || \
  20. [ ! -f ${SSL_PATH}/ldap.slurm.ch.key ]; then
  21. echo "Not all certificates and keys found for TLS."
  22. exit 1
  23. fi
  24. # Use the original slapd.conf file
  25. cp /etc/openldap/slapd.conf /tmp/slapd.conf
  26. # Set the correct suffix
  27. sed -i -e "s/dc=my-domain,dc=com/${SUFFIX}/g" /tmp/slapd.conf
  28. sed -i -e "/core.schema/a include\t\t/etc/openldap/schema/cosine.schema" /tmp/slapd.conf
  29. sed -i -e "/cosine.schema/a include\t\t/etc/openldap/schema/inetorgperson.schema" /tmp/slapd.conf
  30. # Add configuration for TLS and set root password for config database.
  31. cat <<-EOF >> /tmp/slapd.conf
  32. TLSCACertificateFile ${SSL_PATH}/slurm.ch-rootCA.crt
  33. TLSCertificateFile ${SSL_PATH}/ldap.slurm.ch.crt
  34. TLSCertificateKeyFile ${SSL_PATH}/ldap.slurm.ch.key
  35. TLSCipherSuite HIGH:-SSLv2:-SSLv3
  36. database config
  37. rootDN "cn=admin,cn=config"
  38. rootPW $config_rootpw_hash
  39. EOF
  40. # Generate config database from slapd.conf file.
  41. echo Generating configuration
  42. slaptest -f /tmp/slapd.conf -F /etc/openldap/slapd.d
  43. fi
  44. # Set all ownerships straight.
  45. chown -R ldap:ldap /etc/openldap/slapd.d /etc/openldap/ssl /run/openldap
  46. echo Starting slapd with $@
  47. exec "$@"