-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for certificate_content and private_key_content parameters
The current implementation only allows you to pass a file name to the certificate and private_key parameters. When you are fetching certificates from vault or another secure store, you'll first have to save them to a file. This is very innconveniant. This PR add's the parameters certificate_content and private_key_content. These parameters are mutually exclusive from their file counterparts. With this change, you can now fetch a certificate and/or a password from vault (through a hiera lookup for example) and use it directly on the type. Because these values can be sensitive, both of the new parameters support passing the value as a sensitive data type.
- Loading branch information
Showing
6 changed files
with
210 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper_acceptance' | ||
|
||
RSpec.shared_examples 'a private key creator' do |sensitive| | ||
it 'creates a private key' do | ||
pp = if sensitive | ||
<<-MANIFEST | ||
java_ks { 'broker.example.com:#{temp_dir}private_key.ts': | ||
ensure => #{@ensure_ks}, | ||
certificate_content => "#{ca_content}", | ||
private_key_content => "#{priv_key_content}", | ||
password => 'puppet', | ||
path => #{@resource_path}, | ||
} | ||
MANIFEST | ||
else | ||
<<-MANIFEST | ||
java_ks { 'broker.example.com:#{temp_dir}private_key.ts': | ||
ensure => #{@ensure_ks}, | ||
certificate_content => Sensitive("#{ca_content}"), | ||
private_key_content => Sensitive("#{priv_key_content}"), | ||
password => 'puppet', | ||
path => #{@resource_path}, | ||
} | ||
MANIFEST | ||
end | ||
idempotent_apply(pp) | ||
end | ||
|
||
expectations = [ | ||
%r{Alias name: broker\.example\.com}, | ||
%r{Entry type: (keyEntry|PrivateKeyEntry)}, | ||
%r{CN=Test CA}, | ||
] | ||
it 'verifies the private key' do | ||
run_shell(keytool_command("-list -v -keystore #{temp_dir}private_key.ts -storepass puppet"), expect_failures: true) do |r| | ||
expectations.each do |expect| | ||
expect(r.stdout).to match(expect) | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe 'using certificate_content and private_key_content' do | ||
include_context 'common variables' | ||
let(:ca_content) { File.read('spec/acceptance/certs/ca.pem') } | ||
let(:priv_key_content) { File.read('spec/acceptance/certs/privkey.pem') } | ||
|
||
context 'Using data type String' do | ||
it_behaves_like 'a private key creator', false | ||
end | ||
|
||
context 'Using data type Sensitive' do | ||
it_behaves_like 'a private key creator', true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters