Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support SSL on AWS-based buttonmen sites #2712

Merged
merged 1 commit into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deploy/vagrant/manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
include "postfix::base"
include "user::buttonmen-devs"
include "sudo::buttonmen-devs"
include "fqdn::base"

# Node configuration needed for the buttonmen server
include "apache::server::vagrant"
Expand Down
25 changes: 25 additions & 0 deletions deploy/vagrant/modules/apache/manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@

# Monitor the error log
include "apache::server::feature::monitor-logs"

# Install and configure letsencrypt (SSL/certbot) for AWS instances
case "${ec2_services_partition}" {
"aws": {
include "apache::server::feature::letsencrypt"
}
}
}

class apache::server::vagrant {
Expand Down Expand Up @@ -70,3 +77,21 @@
minute => 5;
}
}

class apache::server::feature::letsencrypt {

# Install the certbot package
package {
"python-certbot-apache": ensure => installed;
}

exec {
# Run certbot to configure LetsEncrypt
# If the site has the special FQDN indicating it's a non-networked sandbox, don't run certbot
"apache_certbot_setup":
command => "/usr/bin/certbot --apache -d $(/bin/cat /usr/local/etc/bmsite_fqdn) -n --email help@buttonweavers.com --agree-tos",
require => [ Exec["fqdn_populate_etc_file"], Package["python-certbot-apache"] ],
creates => "/etc/letsencrypt/live",
unless => "/bin/grep -q sandbox.buttonweavers.com /usr/local/etc/bmsite_fqdn";
}
}
23 changes: 23 additions & 0 deletions deploy/vagrant/modules/fqdn/manifests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#####
# This provides information about the FQDN used for an EC2 site,
# so that consumers like letsencrypt or cloudwatch can access that
# information if it exists.
#
# This module does not change /etc/hosts or /etc/hostname

class fqdn::base {
file {
# The script that queries EC2 instance tags to get an FQDN
"/usr/local/bin/fqdn_from_ec2_tags":
ensure => file,
content => template("fqdn/from_ec2_tags.erb"),
mode => 555;
}

# Use fqdn_from_ec2_tags to populate or update a site file
exec {
"fqdn_populate_etc_file":
command => "/usr/local/bin/fqdn_from_ec2_tags /usr/local/etc/bmsite_fqdn",
require => [ File["/usr/local/bin/fqdn_from_ec2_tags"] ];
}
}
22 changes: 22 additions & 0 deletions deploy/vagrant/modules/fqdn/templates/from_ec2_tags.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
##### fqdn_from_ec2_tags
# Get the FQDN from EC2 instance tags

# Optionally put the FQDN in a file, otherwise just print it to STDOUT
OUTPUT_FILE=$1

FQDN=""
<% if @ec2_services_partition == "aws" -%>
FQDN=$(aws ec2 describe-tags --region <%= ec2_placement_region %> --filters "Name=resource-id,Values=<%= ec2_instance_id %>" "Name=key,Values=fqdn" | grep Value | awk -F\" '{print $4}')
<% end -%>

# Use a static fake site name for both non-AWS instances and instances that failed the above check
if [ "${FQDN}" = "" ]; then
FQDN="sandbox.buttonweavers.com"
fi

if [ "${OUTPUT_FILE}" = "" ]; then
echo $FQDN
else
echo "${FQDN}" > ${OUTPUT_FILE}
fi