Skip to content

Commit

Permalink
Add HTTPS for LDAP web UI (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhuguesaws authored Dec 6, 2024
1 parent f81f48f commit c174e1c
Showing 1 changed file with 61 additions and 1 deletion.
62 changes: 61 additions & 1 deletion 1.architectures/6.ldap_server/cf_ldap_server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,66 @@ Resources:
ldapadd -x -D cn=admin,dc=example,dc=com -f /tmp/groups.ldif -w "$PASSWD"
# Setup Apache SSL encryption
mkdir -p /etc/apache2/ssl
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-subj "/C=US/ST=WA/L=Seattle/O=AnyCompany/CN=www.example.com" \
-keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt
a2enmod ssl
cat > /etc/apache2/sites-available/ldap.conf << EOF
<VirtualHost *:80>
ServerName ldapserver@localhost
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^/?(.*) https://%{SERVER_NAME}/\$1 [R,L]
</VirtualHost>
EOF
cat > /etc/apache2/sites-available/ldap_ssl.conf << EOF
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin [email protected]
ServerName ldapserver@localhost
DocumentRoot /var/www/html
ErrorLog \${!APACHE_LOG_DIR}/error.log
CustomLog \${!APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
</IfModule>
EOF
## Disable default
a2dissite 000-default.conf
## Enable site
a2ensite ldap.conf ldap_ssl.conf
## Restart apache
a2enmod ssl rewrite
systemctl restart apache2.service
# Notify CloudFormation once completed
/usr/local/bin/cfn-init -v --stack ${AWS::StackName} \
--resource LdapServer \
--configsets full_install \
Expand Down Expand Up @@ -261,6 +321,6 @@ Outputs:
LdapServerInstanceId:
Value: !GetAtt LdapServer.InstanceId
LdapUIUrl:
Value: !Join ['',[!GetAtt LdapServer.PublicIp,'/phpldapadmin']]
Value: !Join ['',['https://',!GetAtt LdapServer.PublicIp,'/phpldapadmin']]
LdapPassword:
Value: !Ref LdapPassword

0 comments on commit c174e1c

Please sign in to comment.