Skip to content
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
62 changes: 62 additions & 0 deletions manifests/iop.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Contains certs specific configurations for IOP
class certs::iop (
Stdlib::Fqdn $hostname = 'localhost',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

So we're keeping the localhostness.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Otherwise we have to expose the Gateway on the public interface which I believe we wanted to avoid.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I was thinking of an alternative, to create a custom name in /etc/hosts for it that would point to local interface.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

What's the value you are thinking?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No value, just cosmetics. As it would look like a link to something external (that it technically can be). Having a specific name could distinguish other local services, if needed.

Just a suggestion for future. No need to change this.

Boolean $generate = $certs::generate,
Boolean $regenerate = $certs::regenerate,
Boolean $deploy = $certs::deploy,
String[2,2] $country = $certs::country,
String $state = $certs::state,
String $city = $certs::city,
String $org = $certs::org,
String $org_unit = $certs::org_unit,
String $expiration = $certs::expiration,
Stdlib::Absolutepath $ca_key_password_file = $certs::ca_key_password_file,
String $owner = 'root',
String $group = 'root',
Stdlib::Filemode $private_key_mode = '0440',
Stdlib::Filemode $public_key_mode = '0444',
) inherits certs {
$server_cert_name = "${hostname}-iop-core-gateway-server"
$client_cert_name = "${hostname}-iop-core-gateway-client"

cert { $server_cert_name:
ensure => present,
hostname => $hostname,
country => $country,
state => $state,
city => $city,
org => $org,
org_unit => $org_unit,
expiration => $expiration,
ca => $certs::default_ca,
generate => $generate,
regenerate => $regenerate,
password_file => $ca_key_password_file,
build_dir => $certs::ssl_build_dir,
}

cert { $client_cert_name:
ensure => present,
purpose => 'client',
hostname => $hostname,
country => $country,
state => $state,
city => $city,
org => $org,
org_unit => $org_unit,
expiration => $expiration,
ca => $certs::default_ca,
generate => $generate,
regenerate => $regenerate,
password_file => $ca_key_password_file,
build_dir => $certs::ssl_build_dir,
}

$server_cert = "${certs::ssl_build_dir}/${hostname}/${server_cert_name}.crt"
$server_key = "${certs::ssl_build_dir}/${hostname}/${server_cert_name}.key"
$server_ca_cert = $certs::katello_default_ca_cert

$client_cert = "${certs::ssl_build_dir}/${hostname}/${client_cert_name}.crt"
$client_key = "${certs::ssl_build_dir}/${hostname}/${client_cert_name}.key"
$client_ca_cert = $certs::katello_server_ca_cert
}
98 changes: 98 additions & 0 deletions spec/acceptance/iop_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
require 'spec_helper_acceptance'

describe 'certs::iop' do
fqdn = fact('fqdn')
hostname = 'localhost'

before(:all) do
on default, 'rm -rf /root/ssl-build'

manifest = <<~MANIFEST
file { '/etc/foreman-proxy':
ensure => directory,
}

group { 'foreman-proxy':
ensure => present,
system => true,
}
MANIFEST
apply_manifest(manifest, catch_failures: true)
end

context 'with default parameters' do
it_behaves_like 'an idempotent resource' do
let(:manifest) { 'include certs::iop' }
end

describe x509_certificate("/root/ssl-build/#{hostname}/#{hostname}-iop-core-gateway-server.crt") do
it { should be_certificate }
it { should be_valid }
it { should have_purpose 'SSL server' }
its(:issuer) { should match_without_whitespace(/C = US, ST = North Carolina, L = Raleigh, O = Katello, OU = SomeOrgUnit, CN = #{fqdn}/) }
its(:subject) { should match_without_whitespace(/C = US, ST = North Carolina, O = Katello, OU = SomeOrgUnit, CN = #{hostname}/) }
its(:keylength) { should be >= 4096 }
end

describe x509_private_key("/root/ssl-build/#{hostname}/#{hostname}-iop-core-gateway-server.key") do
it { should_not be_encrypted }
it { should be_valid }
it { should have_matching_certificate("/root/ssl-build/#{hostname}/#{hostname}-iop-core-gateway-server.crt") }
end

describe x509_certificate("/root/ssl-build/#{hostname}/#{hostname}-iop-core-gateway-client.crt") do
it { should be_certificate }
it { should be_valid }
it { should have_purpose 'SSL client' }
its(:issuer) { should match_without_whitespace(/C = US, ST = North Carolina, L = Raleigh, O = Katello, OU = SomeOrgUnit, CN = #{fqdn}/) }
its(:subject) { should match_without_whitespace(/C = US, ST = North Carolina, O = Katello, OU = SomeOrgUnit, CN = #{hostname}/) }
its(:keylength) { should be >= 4096 }
end

describe x509_private_key("/root/ssl-build/#{hostname}/#{hostname}-iop-core-gateway-client.key") do
it { should_not be_encrypted }
it { should be_valid }
it { should have_matching_certificate("/root/ssl-build/#{hostname}/#{hostname}-iop-core-gateway-client.crt") }
end

describe file('/etc/iop') do
it { should_not exist }
end
end

context 'with generate false' do
before(:context) do
on default, 'rm -rf /root/ssl-build'
end

it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
class { 'certs::iop':
generate => false
}
PUPPET
end
end

describe file("/root/ssl-build/#{hostname}/#{hostname}-iop-core-gateway-server.crt") do
it { should_not exist }
end

describe file("/root/ssl-build/#{hostname}/#{hostname}-iop-core-gateway-server.key") do
it { should_not exist }
end

describe file("/root/ssl-build/#{hostname}/#{hostname}-iop-core-gateway-client.crt") do
it { should_not exist }
end

describe file("/root/ssl-build/#{hostname}/#{hostname}-iop-core-gateway-client.key") do
it { should_not exist }
end

describe file('/etc/iop') do
it { should_not exist }
end
end
end
135 changes: 135 additions & 0 deletions spec/classes/certs_iop_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
require 'spec_helper'

describe 'certs::iop' do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let :facts do
os_facts
end

let(:pre_condition) { 'include certs' }

describe 'with default parameters' do
it { should compile.with_all_deps }

it 'should create server certificate' do
should contain_cert('localhost-iop-core-gateway-server').with(
:ensure => 'present',
:hostname => 'localhost',
:purpose => nil,
:country => 'US',
:state => 'North Carolina',
:city => 'Raleigh',
:org => 'Katello',
:org_unit => 'SomeOrgUnit',
:expiration => '7300',
:generate => true,
:regenerate => false,
:password_file => '/root/ssl-build/katello-default-ca.pwd',
:build_dir => '/root/ssl-build'
)
end

it 'should create client certificate' do
should contain_cert('localhost-iop-core-gateway-client').with(
:ensure => 'present',
:hostname => 'localhost',
:purpose => 'client',
:country => 'US',
:state => 'North Carolina',
:city => 'Raleigh',
:org => 'Katello',
:org_unit => 'SomeOrgUnit',
:expiration => '7300',
:generate => true,
:regenerate => false,
:password_file => '/root/ssl-build/katello-default-ca.pwd',
:build_dir => '/root/ssl-build'
)
end
end

describe 'with custom hostname' do
let(:params) { { :hostname => 'example.com' } }

it { should compile.with_all_deps }

it 'should create server certificate with custom hostname' do
should contain_cert('example.com-iop-core-gateway-server').with(
:hostname => 'example.com'
)
end

it 'should create client certificate with custom hostname' do
should contain_cert('example.com-iop-core-gateway-client').with(
:hostname => 'example.com'
)
end
end

describe 'with generate false' do
let(:params) { { :generate => false } }

it { should compile.with_all_deps }

it 'should create certificates with generate false' do
should contain_cert('localhost-iop-core-gateway-server').with(
:generate => false
)
should contain_cert('localhost-iop-core-gateway-client').with(
:generate => false
)
end
end

describe 'with regenerate true' do
let(:params) { { :regenerate => true } }

it { should compile.with_all_deps }

it 'should create certificates with regenerate true' do
should contain_cert('localhost-iop-core-gateway-server').with(
:regenerate => true
)
should contain_cert('localhost-iop-core-gateway-client').with(
:regenerate => true
)
end
end

describe 'with custom certificate attributes' do
let(:params) do
{
:country => 'CA',
:state => 'Ontario',
:city => 'Toronto',
:org => 'TestOrg',
:org_unit => 'TestUnit',
:expiration => '3650'
}
end

it { should compile.with_all_deps }

it 'should create certificates with custom attributes' do
should contain_cert('localhost-iop-core-gateway-server').with(
:country => 'CA',
:state => 'Ontario',
:city => 'Toronto',
:org => 'TestOrg',
:org_unit => 'TestUnit',
:expiration => '3650'
)
should contain_cert('localhost-iop-core-gateway-client').with(
:country => 'CA',
:state => 'Ontario',
:city => 'Toronto',
:org => 'TestOrg',
:org_unit => 'TestUnit',
:expiration => '3650'
)
end
end
end
end
end