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
46 changes: 46 additions & 0 deletions spec/classes/puppet_server_puppetserver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@
.with_content(/^\s+name: "puppetlabs cert status"/)
.with_content(%r{^\s+path: "/puppet-ca/v1/certificate_statuses"})
.with_content(/^\s+name: "puppetlabs cert statuses"/)
.with_content(%r{^\s+path: "/puppet-ca/v1/sign"})
.with_content(/^\s+name: "puppetlabs cert sign"/)
.with_content(%r{^\s+path: "/puppet-ca/v1/sign/all"})
.with_content(/^\s+name: "puppetlabs cert sign all"/)
.with_content(%r{^\s+path: "/puppet-admin-api/v1/environment-cache"})
.with_content(/^\s+name: "environment-cache"/)
.with_content(%r{^\s+path: "/puppet-admin-api/v1/jruby-pool"})
Expand Down Expand Up @@ -577,6 +581,48 @@
it { expect(rule['allow']).to eq(['localhost', 'host.example.com']) }
end
end

describe 'cert sign endpoint' do
let(:content) { catalogue.resource('file', auth_conf).send(:parameters)[:content] }
let(:rules) { Hocon.parse(content)['authorization']['rules'] }
let(:rule) { rules.find {|rule| rule['name'] == 'puppetlabs cert sign' } }

context 'by default' do
it { expect(rule).not_to be_nil }
it { expect(rule['match-request']['path']).to eq('/puppet-ca/v1/sign') }
it { expect(rule['match-request']['type']).to eq('path') }
it { expect(rule['match-request']['method']).to eq('post') }
it { expect(rule['sort-order']).to eq(500) }
it { expect(rule['allow']).to eq(['localhost', 'foo.example.com', {'extensions' => {'pp_cli_auth' => 'true'}}]) }
end

context 'with server_ca_client_allowlist set' do
let(:params) { super().merge(server_ca_client_allowlist: ['puppetserver.example.com', 'admin.example.com']) }

it { expect(rule['allow']).to eq(['puppetserver.example.com', 'admin.example.com', {'extensions' => {'pp_cli_auth' => 'true'}}]) }
end
end

describe 'cert sign all endpoint' do
let(:content) { catalogue.resource('file', auth_conf).send(:parameters)[:content] }
let(:rules) { Hocon.parse(content)['authorization']['rules'] }
let(:rule) { rules.find {|rule| rule['name'] == 'puppetlabs cert sign all' } }

context 'by default' do
it { expect(rule).not_to be_nil }
it { expect(rule['match-request']['path']).to eq('/puppet-ca/v1/sign/all') }
it { expect(rule['match-request']['type']).to eq('path') }
it { expect(rule['match-request']['method']).to eq('post') }
it { expect(rule['sort-order']).to eq(500) }
it { expect(rule['allow']).to eq(['localhost', 'foo.example.com', {'extensions' => {'pp_cli_auth' => 'true'}}]) }
end

context 'with server_ca_client_allowlist set' do
let(:params) { super().merge(server_ca_client_allowlist: ['puppetserver.example.com', 'admin.example.com']) }

it { expect(rule['allow']).to eq(['puppetserver.example.com', 'admin.example.com', {'extensions' => {'pp_cli_auth' => 'true'}}]) }
end
end
end
end
end
5 changes: 5 additions & 0 deletions spec/classes/puppet_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@
)
end

it 'should not sync the crl' do

Check warning on line 481 in spec/classes/puppet_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

puppet on debian-12-x86_64 with server_ca_crl_sync => true with server_ca => false and running "puppet apply" should not sync the crl Failure/Error: should_not contain_file('/etc/custom/puppetlabs/puppet/ssl/crl.pem') expected that the catalogue would not contain File[/etc/custom/puppetlabs/puppet/ssl/crl.pem]

Check warning on line 481 in spec/classes/puppet_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

puppet on debian-11-x86_64 with server_ca_crl_sync => true with server_ca => false and running "puppet apply" should not sync the crl Failure/Error: should_not contain_file('/etc/custom/puppetlabs/puppet/ssl/crl.pem') expected that the catalogue would not contain File[/etc/custom/puppetlabs/puppet/ssl/crl.pem]

Check warning on line 481 in spec/classes/puppet_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

puppet on fedora-36-x86_64 with server_ca_crl_sync => true with server_ca => false and running "puppet apply" should not sync the crl Failure/Error: should_not contain_file('/etc/custom/puppetlabs/puppet/ssl/crl.pem') expected that the catalogue would not contain File[/etc/custom/puppetlabs/puppet/ssl/crl.pem]

Check warning on line 481 in spec/classes/puppet_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

puppet on rocky-9-x86_64 with server_ca_crl_sync => true with server_ca => false and running "puppet apply" should not sync the crl Failure/Error: should_not contain_file('/etc/custom/puppetlabs/puppet/ssl/crl.pem') expected that the catalogue would not contain File[/etc/custom/puppetlabs/puppet/ssl/crl.pem]

Check warning on line 481 in spec/classes/puppet_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

puppet on almalinux-9-x86_64 with server_ca_crl_sync => true with server_ca => false and running "puppet apply" should not sync the crl Failure/Error: should_not contain_file('/etc/custom/puppetlabs/puppet/ssl/crl.pem') expected that the catalogue would not contain File[/etc/custom/puppetlabs/puppet/ssl/crl.pem]

Check warning on line 481 in spec/classes/puppet_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

puppet on almalinux-8-x86_64 with server_ca_crl_sync => true with server_ca => false and running "puppet apply" should not sync the crl Failure/Error: should_not contain_file('/etc/custom/puppetlabs/puppet/ssl/crl.pem') expected that the catalogue would not contain File[/etc/custom/puppetlabs/puppet/ssl/crl.pem]

Check warning on line 481 in spec/classes/puppet_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

puppet on oraclelinux-9-x86_64 with server_ca_crl_sync => true with server_ca => false and running "puppet apply" should not sync the crl Failure/Error: should_not contain_file('/etc/custom/puppetlabs/puppet/ssl/crl.pem') expected that the catalogue would not contain File[/etc/custom/puppetlabs/puppet/ssl/crl.pem]

Check warning on line 481 in spec/classes/puppet_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

puppet on centos-9-x86_64 with server_ca_crl_sync => true with server_ca => false and running "puppet apply" should not sync the crl Failure/Error: should_not contain_file('/etc/custom/puppetlabs/puppet/ssl/crl.pem') expected that the catalogue would not contain File[/etc/custom/puppetlabs/puppet/ssl/crl.pem]

Check warning on line 481 in spec/classes/puppet_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

puppet on redhat-9-x86_64 with server_ca_crl_sync => true with server_ca => false and running "puppet apply" should not sync the crl Failure/Error: should_not contain_file('/etc/custom/puppetlabs/puppet/ssl/crl.pem') expected that the catalogue would not contain File[/etc/custom/puppetlabs/puppet/ssl/crl.pem]

Check warning on line 481 in spec/classes/puppet_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

puppet on redhat-8-x86_64 with server_ca_crl_sync => true with server_ca => false and running "puppet apply" should not sync the crl Failure/Error: should_not contain_file('/etc/custom/puppetlabs/puppet/ssl/crl.pem') expected that the catalogue would not contain File[/etc/custom/puppetlabs/puppet/ssl/crl.pem]
# https://github.com/puppetlabs/rspec-puppet/issues/37
pending("rspec-puppet always sets $server_facts['servername']")
should_not contain_file('/etc/custom/puppetlabs/puppet/ssl/crl.pem')
Expand Down Expand Up @@ -524,6 +524,11 @@
it 'should not sync the crl' do
should_not contain_file('/etc/custom/puppetlabs/puppet/ssl/crl.pem')
end
it { should contain_file("#{conf_d_dir}/auth.conf").with_content(%r{path:\s*"/puppet-ca/v1/certificate_renewal"}) }
it { should contain_file("#{conf_d_dir}/auth.conf").with_content(%r{path:\s*"/puppet-ca/v1/certificate_status"}) }
it { should contain_file("#{conf_d_dir}/auth.conf").with_content(%r{path:\s*"/puppet-ca/v1/certificate_statuses"}) }
it { should contain_file("#{conf_d_dir}/auth.conf").with_content(%r{path:\s*"/puppet-ca/v1/sign"}) }
it { should contain_file("#{conf_d_dir}/auth.conf").with_content(%r{path:\s*"/puppet-ca/v1/sign/all"}) }
end
end

Expand Down
40 changes: 40 additions & 0 deletions templates/server/puppetserver/conf.d/auth.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,46 @@ authorization: {
sort-order: 500
name: "puppetlabs cert clean"
},
{
# Allow the CA CLI to access the certificate sign endpoint
match-request: {
path: "/puppet-ca/v1/sign"
type: path
method: post
}
allow: [
<%- @server_ca_client_allowlist.each do |client| -%>
"<%= client %>",
<%- end -%>
{
extensions: {
pp_cli_auth: "true"
}
}
]
sort-order: 500
name: "puppetlabs cert sign"
},
{
# Allow the CA CLI to access the certificate sign all endpoint
match-request: {
path: "/puppet-ca/v1/sign/all"
type: path
method: post
}
allow: [
<%- @server_ca_client_allowlist.each do |client| -%>
"<%= client %>",
<%- end -%>
{
extensions: {
pp_cli_auth: "true"
}
}
]
sort-order: 500
name: "puppetlabs cert sign all"
},
{
# Allow unauthenticated access to the status service endpoint
match-request: {
Expand Down
Loading