Skip to content

Commit

Permalink
Fixes #29892 - Use server certs for websockets
Browse files Browse the repository at this point in the history
Prior to this the user needed to specify the certs both for the server
and websockets. In practice these are pretty much always the same files.
By using undef + pick() the option to specify these is maintained, but
the defaults are better.
  • Loading branch information
ekohl authored and mmoll committed May 24, 2020
1 parent 58c797b commit 2dc5e7d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
4 changes: 4 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
}
}

# Used in the settings template
$websockets_ssl_cert = pick($foreman::websockets_ssl_cert, $foreman::server_ssl_cert)
$websockets_ssl_key = pick($foreman::websockets_ssl_key, $foreman::server_ssl_key)

concat::fragment {'foreman_settings+01-header.yaml':
target => '/etc/foreman/settings.yaml',
content => template('foreman/settings.yaml.erb'),
Expand Down
4 changes: 2 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@
String $pam_service = $foreman::params::pam_service,
Boolean $ipa_manage_sssd = $foreman::params::ipa_manage_sssd,
Boolean $websockets_encrypt = $foreman::params::websockets_encrypt,
Stdlib::Absolutepath $websockets_ssl_key = $foreman::params::websockets_ssl_key,
Stdlib::Absolutepath $websockets_ssl_cert = $foreman::params::websockets_ssl_cert,
Optional[Stdlib::Absolutepath] $websockets_ssl_key = $foreman::params::websockets_ssl_key,
Optional[Stdlib::Absolutepath] $websockets_ssl_cert = $foreman::params::websockets_ssl_cert,
Enum['debug', 'info', 'warn', 'error', 'fatal'] $logging_level = $foreman::params::logging_level,
Enum['file', 'syslog', 'journald'] $logging_type = $foreman::params::logging_type,
Enum['pattern', 'multiline_pattern', 'json'] $logging_layout = $foreman::params::logging_layout,
Expand Down
4 changes: 2 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@

# Websockets
$websockets_encrypt = true
$websockets_ssl_key = $server_ssl_key
$websockets_ssl_cert = $server_ssl_cert
$websockets_ssl_key = undef
$websockets_ssl_cert = undef

# Application logging
$logging_level = 'info'
Expand Down
12 changes: 10 additions & 2 deletions spec/classes/foreman_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
.with_content(/^:oauth_consumer_key:\s*\w+$/)
.with_content(/^:oauth_consumer_secret:\s*\w+$/)
.with_content(/^:websockets_encrypt:\s*true$/)
.with_content(%r{^:websockets_ssl_key:\s*/etc/puppetlabs/puppet/ssl/private_keys/foo\.example\.com\.pem$})
.with_content(%r{^:websockets_ssl_cert:\s*/etc/puppetlabs/puppet/ssl/certs/foo\.example\.com\.pem$})
.with_content(%r{^:ssl_certificate:\s*/etc/puppetlabs/puppet/ssl/certs/foo\.example\.com\.pem$})
.with_content(%r{^:ssl_ca_file:\s*/etc/puppetlabs/puppet/ssl/certs/ca.pem$})
.with_content(%r{^:ssl_priv_key:\s*/etc/puppetlabs/puppet/ssl/private_keys/foo\.example\.com\.pem$})
Expand Down Expand Up @@ -236,8 +238,8 @@
pam_service: 'foreman',
ipa_manage_sssd: true,
websockets_encrypt: true,
websockets_ssl_key: '/etc/ssl/private/snakeoil.pem',
websockets_ssl_cert: '/etc/ssl/certs/snakeoil.pem',
websockets_ssl_key: '/etc/ssl/private/snakeoil-ws.pem',
websockets_ssl_cert: '/etc/ssl/certs/snakeoil-ws.pem',
logging_level: 'info',
loggers: {},
email_delivery_method: 'sendmail',
Expand All @@ -260,6 +262,12 @@
.with_keycloak_app_name('cloak-app')
.with_keycloak_realm('myrealm')
end

it 'should configure certificates in settings.yaml' do
is_expected.to contain_concat__fragment('foreman_settings+01-header.yaml')
.with_content(%r{^:websockets_ssl_key: /etc/ssl/private/snakeoil-ws\.pem$})
.with_content(%r{^:websockets_ssl_cert: /etc/ssl/certs/snakeoil-ws\.pem$})
end
end

context 'with journald logging' do
Expand Down
4 changes: 2 additions & 2 deletions templates/settings.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

# Websockets
:websockets_encrypt: <%= scope.lookupvar("foreman::websockets_encrypt") %>
:websockets_ssl_key: <%= scope.lookupvar("foreman::websockets_ssl_key") %>
:websockets_ssl_cert: <%= scope.lookupvar("foreman::websockets_ssl_cert") %>
:websockets_ssl_key: <%= @websockets_ssl_key %>
:websockets_ssl_cert: <%= @websockets_ssl_cert %>

# SSL-settings
:ssl_certificate: <%= scope.lookupvar("foreman::client_ssl_cert") %>
Expand Down

0 comments on commit 2dc5e7d

Please sign in to comment.