Skip to content

Commit b9ae517

Browse files
committed
Enable nova server to be run in SSL mode
This commit allows one to specify ca, cert and key file to run nova server in SSL mode. Note: The flag use_ssl per se is not used in nova yet, its purpose here it to verify collateral parameters. Change-Id: I5aed08afc2b6ac94bf9e1929f6b1f41a88882f02 (cherry picked from commit 31048d2)
1 parent 1da5943 commit b9ae517

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

manifests/init.pp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,27 @@
175175
# (optional) Syslog facility to receive log lines.
176176
# Defaults to 'LOG_USER'
177177
#
178+
# [*use_ssl*]
179+
# (optional) Enable SSL on the API server
180+
# Defaults to false, not set
181+
#
182+
# [*enabled_ssl_apis*]
183+
# (optional) List of APIs to SSL enable
184+
# Defaults to []
185+
# Possible values : 'ec2', 'osapi_compute', 'metadata'
186+
#
187+
# [*cert_file*]
188+
# (optinal) Certificate file to use when starting API server securely
189+
# Defaults to false, not set
190+
#
191+
# [*key_file*]
192+
# (optional) Private key file to use when starting API server securely
193+
# Defaults to false, not set
194+
#
195+
# [*ca_file*]
196+
# (optional) CA certificate file to use to verify connecting clients
197+
# Defaults to false, not set_
198+
#
178199
# [*nova_user_id*]
179200
# (optional) Create the nova user with the specified gid.
180201
# Changing to a new uid after specifying a different uid previously,
@@ -271,6 +292,11 @@
271292
$periodic_interval = '60',
272293
$report_interval = '10',
273294
$rootwrap_config = '/etc/nova/rootwrap.conf',
295+
$use_ssl = false,
296+
$enabled_ssl_apis = ['ec2', 'metadata', 'osapi_compute'],
297+
$ca_file = false,
298+
$cert_file = false,
299+
$key_file = false,
274300
$nova_user_id = undef,
275301
$nova_group_id = undef,
276302
$nova_public_key = undef,
@@ -299,6 +325,20 @@
299325
warning('The nova_cluster_id parameter is deprecated and has no effect.')
300326
}
301327

328+
validate_array($enabled_ssl_apis)
329+
if empty($enabled_ssl_apis) and $use_ssl {
330+
warning('enabled_ssl_apis is empty but use_ssl is set to true')
331+
}
332+
333+
if $use_ssl {
334+
if !$cert_file {
335+
fail('The cert_file parameter is required when use_ssl is set to true')
336+
}
337+
if !$key_file {
338+
fail('The key_file parameter is required when use_ssl is set to true')
339+
}
340+
}
341+
302342
group { 'nova':
303343
ensure => present,
304344
system => true,
@@ -553,6 +593,31 @@
553593
}
554594
}
555595

596+
# SSL Options
597+
if $use_ssl {
598+
nova_config {
599+
'DEFAULT/enabled_ssl_apis' : value => $enabled_ssl_apis;
600+
'DEFAULT/ssl_cert_file' : value => $cert_file;
601+
'DEFAULT/ssl_key_file' : value => $key_file;
602+
}
603+
if $ca_file {
604+
nova_config { 'DEFAULT/ssl_ca_file' :
605+
value => $ca_file,
606+
}
607+
} else {
608+
nova_config { 'DEFAULT/ssl_ca_file' :
609+
ensure => absent,
610+
}
611+
}
612+
} else {
613+
nova_config {
614+
'DEFAULT/enabled_ssl_apis' : ensure => absent;
615+
'DEFAULT/ssl_cert_file' : ensure => absent;
616+
'DEFAULT/ssl_key_file' : ensure => absent;
617+
'DEFAULT/ssl_ca_file' : ensure => absent;
618+
}
619+
}
620+
556621
if $logdir {
557622
warning('The logdir parameter is deprecated, use log_dir instead.')
558623
$log_dir_real = $logdir

spec/classes/nova_init_spec.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,53 @@
535535
end
536536
end
537537

538+
context 'with SSL socket options set' do
539+
let :params do
540+
{
541+
:use_ssl => true,
542+
:enabled_ssl_apis => ['ec2'],
543+
:cert_file => '/path/to/cert',
544+
:ca_file => '/path/to/ca',
545+
:key_file => '/path/to/key',
546+
}
547+
end
548+
549+
it { should contain_nova_config('DEFAULT/enabled_ssl_apis').with_value(['ec2']) }
550+
it { should contain_nova_config('DEFAULT/ssl_ca_file').with_value('/path/to/ca') }
551+
it { should contain_nova_config('DEFAULT/ssl_cert_file').with_value('/path/to/cert') }
552+
it { should contain_nova_config('DEFAULT/ssl_key_file').with_value('/path/to/key') }
553+
end
554+
555+
context 'with SSL socket options set with wrong parameters' do
556+
let :params do
557+
{
558+
:use_ssl => true,
559+
:enabled_ssl_apis => ['ec2'],
560+
:ca_file => '/path/to/ca',
561+
:key_file => '/path/to/key',
562+
}
563+
end
564+
565+
it_raises 'a Puppet::Error', /The cert_file parameter is required when use_ssl is set to true/
566+
end
567+
568+
context 'with SSL socket options set to false' do
569+
let :params do
570+
{
571+
:use_ssl => false,
572+
:enabled_ssl_apis => [],
573+
:cert_file => false,
574+
:ca_file => false,
575+
:key_file => false,
576+
}
577+
end
578+
579+
it { should contain_nova_config('DEFAULT/enabled_ssl_apis').with_ensure('absent') }
580+
it { should contain_nova_config('DEFAULT/ssl_ca_file').with_ensure('absent') }
581+
it { should contain_nova_config('DEFAULT/ssl_cert_file').with_ensure('absent') }
582+
it { should contain_nova_config('DEFAULT/ssl_key_file').with_ensure('absent') }
583+
end
584+
538585
end
539586

540587
context 'on Debian platforms' do

0 commit comments

Comments
 (0)