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

create ssl cert per vhost, not one monster #2129

Merged
merged 1 commit into from
Oct 29, 2024
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
4 changes: 0 additions & 4 deletions puppet/modules/profiles/manifests/jenkins/controller.pp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@
require => Package[$packages],
}

class { 'web::base':
letsencrypt => $https,
}

class { 'web::jenkins':
hostname => $hostname,
https => $https,
Expand Down
2 changes: 2 additions & 0 deletions puppet/modules/redmine/manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@
}

if $https {
include web::letsencrypt

letsencrypt::certonly { $servername:
plugin => 'webroot',
domains => [$servername],
Expand Down
11 changes: 1 addition & 10 deletions puppet/modules/web/manifests/base.pp
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
# Basic webserver config
#
# @param letsencrypt
# Whether to include letsencrypt
class web::base(
Boolean $letsencrypt = true,
) {
if $letsencrypt {
include web::letsencrypt
}

class web::base {
include apache

file { '/var/www/vhosts':
Expand Down
35 changes: 1 addition & 34 deletions puppet/modules/web/manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,7 @@
class web(
Boolean $https = false,
) {
class { 'web::base':
letsencrypt => $https,
}

if $https {
$letsencypt_domain = 'theforeman.org'
ekohl marked this conversation as resolved.
Show resolved Hide resolved

letsencrypt::certonly { $letsencypt_domain:
plugin => 'webroot',
# domain / webroot_paths must match exactly
domains => [
'theforeman.org',
'archivedeb.theforeman.org',
'deb.theforeman.org',
'debugs.theforeman.org',
'downloads.theforeman.org',
'stagingdeb.theforeman.org',
'www.theforeman.org',
'yum.theforeman.org',
'stagingyum.theforeman.org',
],
webroot_paths => [
'/var/www/vhosts/web/htdocs',
'/var/www/vhosts/archivedeb/htdocs',
'/var/www/vhosts/deb/htdocs',
'/var/www/vhosts/debugs/htdocs',
'/var/www/vhosts/downloads/htdocs',
'/var/www/vhosts/stagingdeb/htdocs',
'/var/www/vhosts/web/htdocs',
'/var/www/vhosts/yum/htdocs',
'/var/www/vhosts/stagingyum/htdocs',
],
}
}
include web::base

if $facts['os']['selinux']['enabled'] {
include selinux
Expand Down
6 changes: 4 additions & 2 deletions puppet/modules/web/manifests/jenkins.pp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we could migrate this to using web::vhost as well after this change.

https://webmasters.stackexchange.com/questions/97005/setting-x-forwarded-proto-under-apache-2-4 suggests you can also use RequestHeader set X-Forwarded-Proto expr=%{REQUEST_SCHEME} to make it dynamic, meaning it's going to be the same directive for HTTP and HTTPS.

I can submit a follow up PR to do so.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
'no_proxy_uris' => ['/.well-known'],
}

if $web::base::letsencrypt {
if $https {
include web::letsencrypt

letsencrypt::certonly { $hostname:
plugin => 'webroot',
domains => [$hostname],
Expand All @@ -34,7 +36,7 @@
mode => '0755',
}

if $web::base::letsencrypt and $https {
if $https {
$url = "https://${hostname}"

apache::vhost { 'jenkins':
Expand Down
16 changes: 12 additions & 4 deletions puppet/modules/web/manifests/vhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
}

if $web::https {
evgeni marked this conversation as resolved.
Show resolved Hide resolved
include web::letsencrypt

letsencrypt::certonly { $servername:
plugin => 'webroot',
domains => [$servername] + $serveraliases,
webroot_paths => [$docroot],
}

apache::vhost { "${title}-https":
servername => $servername,
serveraliases => $serveraliases,
Expand All @@ -62,10 +70,10 @@
docroot_mode => $docroot_mode,
port => 443,
ssl => true,
ssl_cert => "${letsencrypt::config_dir}/live/${web::letsencypt_domain}/cert.pem",
ssl_chain => "${letsencrypt::config_dir}/live/${web::letsencypt_domain}/chain.pem",
ssl_key => "${letsencrypt::config_dir}/live/${web::letsencypt_domain}/privkey.pem",
require => Letsencrypt::Certonly[$web::letsencypt_domain],
ssl_cert => "${letsencrypt::config_dir}/live/${servername}/cert.pem",
ssl_chain => "${letsencrypt::config_dir}/live/${servername}/chain.pem",
ssl_key => "${letsencrypt::config_dir}/live/${servername}/privkey.pem",
require => Letsencrypt::Certonly[$servername],
* => $attrs,
}
}
Expand Down