-
Notifications
You must be signed in to change notification settings - Fork 98
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
Add support for certificate_content and private_key_content parameters #385
Merged
chelnak
merged 1 commit into
puppetlabs:main
from
enterprisemodules:add_support_for_certificate_content
Mar 30, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
commit 2875855c77e7c83d32cf7afaed76f715c3b40266
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or... anytime after this method exits leading to a race condition. See #425