Skip to content

Commit d48d683

Browse files
authored
Merge pull request #8789 from BobosilaVictor/PUP-8094/lookup-ignores-env
(PUP-8094) Puppet lookup ignores trusted fact rule for classifier
2 parents 29ac61d + 3338148 commit d48d683

File tree

3 files changed

+57
-16
lines changed

3 files changed

+57
-16
lines changed

acceptance/tests/parser_functions/puppet_lookup_cmd.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,6 +2075,7 @@ def data()
20752075
environmentpath = #{@coderoot}/environments
20762076
hiera_config = #{@coderoot}/hiera.yaml
20772077
environment = env1
2078+
server = #{master.connection.hostname}
20782079
",
20792080
}
20802081
MANI1
@@ -2094,6 +2095,7 @@ def data()
20942095
environmentpath = #{@coderoot}/environments
20952096
hiera_config = #{@coderoot}/hiera.yaml
20962097
environment = env2
2098+
server = #{master.connection.hostname}
20972099
",
20982100
}
20992101
MANI2
@@ -2113,6 +2115,7 @@ def data()
21132115
environmentpath = #{@coderoot}/environments
21142116
hiera_config = #{@coderoot}/hiera.yaml
21152117
environment = env3
2118+
server = #{master.connection.hostname}
21162119
",
21172120
}
21182121
MANI3
@@ -2132,6 +2135,7 @@ def data()
21322135
environmentpath = #{@coderoot}/environments
21332136
hiera_config = #{@coderoot}/hiera.yaml
21342137
environment = env4
2138+
server = #{master.connection.hostname}
21352139
",
21362140
}
21372141
MANI4
@@ -2167,16 +2171,38 @@ def data()
21672171
[main]
21682172
environmentpath = #{@coderoot}/environments
21692173
hiera_config = #{@coderoot}/hiera.yaml
2174+
server = #{master.connection.hostname}
21702175
",
21712176
}
21722177
MANIENC
21732178

2179+
teardown do
2180+
on(master, "rm -f /etc/puppetlabs/puppet/ssl/certs/#{@node1}.pem")
2181+
on(master, "rm -f /etc/puppetlabs/puppet/ssl/certs/#{@node2}.pem")
2182+
on(master, "rm -f /etc/puppetlabs/puppet/ssl/ca/signed/#{@node1}.pem")
2183+
on(master, "rm -f /etc/puppetlabs/puppet/ssl/ca/signed/#{@node2}.pem")
2184+
on(master, "rm -f /etc/puppetlabs/puppet/ssl/private_keys/#{@node1}.pem")
2185+
on(master, "rm -f /etc/puppetlabs/puppet/ssl/private_keys/#{@node2}.pem")
2186+
on(master, "rm -f /etc/puppetlabs/puppet/ssl/public_keys/#{@node1}.pem")
2187+
on(master, "rm -f /etc/puppetlabs/puppet/ssl/public_keys/#{@node2}.pem")
2188+
end
2189+
21742190
step 'apply main manifest'
21752191
apply_manifest_on(master, @manifest, :catch_failures => true)
21762192

21772193
step 'start puppet server'
21782194
with_puppet_running_on master, @master_opts, @coderoot do
21792195

2196+
step "handle certificate"
2197+
on(master, "puppetserver ca generate --certname #{@node1}")
2198+
on(master, "puppetserver ca generate --certname #{@node2}")
2199+
on(master, "mkdir -p #{@testroot}/puppet/ssl/certs")
2200+
on(master, "mkdir -p #{@testroot}/puppet/ssl/private_keys")
2201+
on(master, "cp -a /etc/puppetlabs/puppet/ssl/certs/ca.pem #{@testroot}/puppet/ssl/certs")
2202+
on(master, "cp -a /etc/puppetlabs/puppet/ssl/crl.pem #{@testroot}/puppet/ssl")
2203+
on(master, "cp -a /etc/puppetlabs/puppet/ssl/private_keys/#{master.connection.hostname}.pem #{@testroot}/puppet/ssl/private_keys")
2204+
on(master, "cp -a /etc/puppetlabs/puppet/ssl/certs/#{master.connection.hostname}.pem #{@testroot}/puppet/ssl/certs")
2205+
21802206
step "global_key"
21812207
rg = on(master, puppet('lookup', 'global_key'))
21822208
result = rg.stdout

lib/puppet/application/lookup.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,21 @@ def generate_scope
367367
ni = Puppet::Node.indirection
368368
tc = ni.terminus_class
369369

370-
if tc == :plain || options[:compile]
371-
node = ni.find(node, facts: facts)
372-
else
373-
ni.terminus_class = :plain
374-
node = ni.find(node, facts: facts)
375-
ni.terminus_class = tc
370+
service = Puppet.runtime[:http]
371+
session = service.create_session
372+
cert = session.route_to(:ca)
373+
374+
cert = cert.get_certificate(node)
375+
trusted = Puppet::Context::TrustedInformation.new(true, node, cert)
376+
377+
Puppet.override(trusted_information: trusted) do
378+
if tc == :plain || options[:compile]
379+
node = ni.find(node, facts: facts)
380+
else
381+
ni.terminus_class = :plain
382+
node = ni.find(node, facts: facts)
383+
ni.terminus_class = tc
384+
end
376385
end
377386
else
378387
node.add_extra_facts(given_facts) if given_facts

spec/integration/application/lookup_spec.rb

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
include PuppetSpec::Files
88

99
context 'with an environment' do
10+
let(:fqdn) { Puppet.runtime[:facter].value(:fqdn) }
1011
let(:env_name) { 'spec' }
1112
let(:env_dir) { tmpdir('environments') }
1213
let(:environment_files) do
@@ -46,15 +47,16 @@
4647
let(:environments) { Puppet::Environments::Directories.new(populated_env_dir, []) }
4748
let(:facts) { Puppet::Node::Facts.new("facts", {'my_fact' => 'my_fact_value'}) }
4849

49-
before do
50-
allow(Puppet::Node::Facts.indirection).to receive(:find).and_return(facts)
51-
end
52-
5350
let(:populated_env_dir) do
5451
dir_contained_in(env_dir, environment_files)
5552
env_dir
5653
end
5754

55+
before do
56+
stub_request(:get, "https://puppet:8140/puppet-ca/v1/certificate/#{fqdn}")
57+
allow(Puppet::Node::Facts.indirection).to receive(:find).and_return(facts)
58+
end
59+
5860
def lookup(key, options = {}, explain = false)
5961
key = [key] unless key.is_a?(Array)
6062
allow(app.command_line).to receive(:args).and_return(key)
@@ -101,13 +103,17 @@ def explain(key, options = {})
101103
lookup('a')
102104
end
103105

104-
it 'skip loading of external facts when run with --node' do
105-
app.options[:node] = "random_node"
106+
describe 'when using --node' do
107+
let(:fqdn) { 'random_node' }
106108

107-
expect(Puppet::Node::Facts.indirection).to receive(:find).and_return(facts)
108-
expect(Facter).to receive(:load_external).once.with(false)
109-
expect(Facter).to receive(:load_external).once.with(true)
110-
lookup('a')
109+
it 'skip loading of external facts' do
110+
app.options[:node] = fqdn
111+
112+
expect(Puppet::Node::Facts.indirection).to receive(:find).and_return(facts)
113+
expect(Facter).to receive(:load_external).once.with(false)
114+
expect(Facter).to receive(:load_external).once.with(true)
115+
lookup('a')
116+
end
111117
end
112118

113119
context 'uses node_terminus' do

0 commit comments

Comments
 (0)