Jira (PUP-11265) puppet-agent : Concat not respecting environments

26 views
Skip to first unread message

Josh Cooper (Jira)

unread,
Sep 27, 2021, 3:32:01 PM9/27/21
to puppe...@googlegroups.com
Josh Cooper updated an issue
 
Puppet / Bug PUP-11265
puppet-agent : Concat not respecting environments
Change By: Josh Cooper
Fix Version/s: PUP 7.11.0
Fix Version/s: PUP 7.10.0
Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.13.2#813002-sha1:c495a97)
Atlassian logo

Josh Cooper (Jira)

unread,
Sep 27, 2021, 3:32:01 PM9/27/21
to puppe...@googlegroups.com
Josh Cooper moved an issue
Change By: Josh Cooper
Fix Version/s: puppet-agent 7.9.0
Fix Version/s: PUP 7.12.0
Fix Version/s: PUP 7.11.0
Fix Version/s: PUP 7.10.0
Key: PA PUP - 3977 11265
Affects Version/s: puppet-agent 7.10.0
Affects Version/s: PUP 7.10.0
Project: Puppet Agent

Josh Cooper (Jira)

unread,
Sep 27, 2021, 3:56:03 PM9/27/21
to puppe...@googlegroups.com
Josh Cooper commented on Bug PUP-11265
 
Re: puppet-agent : Concat not respecting environments

To repro delete everything from the production environment:

# rm -rf /etc/puppetlabs/code/environments/production/

Create a new environment and install puppetlabs-concat into it:

# mkdir -p /etc/puppetlabs/code/environments/customer1/{manifests,files}
# puppet module install puppetlabs-concat -v 7.1.1 --environment customer1
# cat <<END > /etc/puppetlabs/code/environments/customer1/manifests/site.pp 
include df_modsec
END
# cat <<END > /etc/puppetlabs/code/environments/customer1/modules/df_modsec/manifests/init.pp 
class df_modsec {
  $file = '/tmp/file'
 
  concat { $file:
    ensure => 'present',
  } -> concat::fragment { 'main':
    target => $file,
    source => 'puppet:///modules/df_modsec/modsecurity_main.conf',
  }
}
END
# cat <<END > /etc/puppetlabs/code/environments/customer1/modules/df_modsec/files/modsecurity_main.conf 
# this is a comment
END
# chown -R puppet:puppet /etc/puppetlabs/code/environments

Configure the server to assign the environment:

# puppet config set node_terminus exec --section server
# puppet config set external_nodes /etc/puppetlabs/puppet/enc.sh --section server
# cat <<EOF > /etc/puppetlabs/puppet/enc.sh
#!/bin/sh
 
cat <<END
---
environment: customer1
END
EOF
# chmod a+x /etc/puppetlabs/puppet/enc.sh
# chown puppet:puppet /etc/puppetlabs/puppet/enc.sh
# systemctl restart puppetserver

Delete the last run summary and run the agent once:

# rm -f /opt/puppetlabs/puppet/public/last_run_summary.yaml
# puppet agent -t
Info: Using environment 'production'
...
Notice: Local environment: 'production' doesn't match server specified environment 'customer1', restarting agent run with environment 'customer1'
...
# cat /tmp/file 
# this is a comment

Note the mismatched last environments:

# cat  /opt/puppetlabs/puppet/public/last_run_summary.yaml
---
version:
  config: 1632772088
  puppet: 7.10.0
application:
  run_mode: agent
  initial_environment: production
  converged_environment: customer1

Run the agent a second time and it will fail:

# puppet agent -t
...
Error: /Stage[main]/Df_modsec/Concat[/tmp/file]/Concat_file[/tmp/file]: Failed to generate additional resources using 'eval_generate': Could not retrieve source(s) puppet:///modules/df_modsec/modsecurity_main.conf

This is because the concat module doesn't specify an environment when making the metadata request: https://github.com/puppetlabs/puppetlabs-concat/blob/7c356efc62b092b71eb40f63d9a7c362b825210f/lib/puppet/type/concat_file.rb#L305 so the indirector will fallback to the environment stored in the context https://github.com/puppetlabs/puppet/blob/3828aabe8d32368faa5cdc1a428189d0cb117e52/lib/puppet/indirector/request.rb#L33

But the agent doesn't push a new environment when it detects the mismatch: https://github.com/puppetlabs/puppet/blob/3828aabe8d32368faa5cdc1a428189d0cb117e52/lib/puppet/configurer.rb#L394

It needs to push a new environment and loaders like we do in https://github.com/puppetlabs/puppet/blob/3828aabe8d32368faa5cdc1a428189d0cb117e52/lib/puppet/configurer.rb#L449-L456

Ciprian Badescu (Jira)

unread,
Sep 28, 2021, 3:40:03 AM9/28/21
to puppe...@googlegroups.com

Ciprian Badescu (Jira)

unread,
Sep 28, 2021, 3:41:03 AM9/28/21
to puppe...@googlegroups.com

Gabriel Nagy (Jira)

unread,
Sep 28, 2021, 3:56:02 AM9/28/21
to puppe...@googlegroups.com

Gabriel Nagy (Jira)

unread,
Sep 28, 2021, 6:11:01 AM9/28/21
to puppe...@googlegroups.com
Gabriel Nagy updated an issue
Change By: Gabriel Nagy
Fix Version/s: PUP 6.25.0

Josh Cooper (Jira)

unread,
Sep 28, 2021, 12:31:02 PM9/28/21
to puppe...@googlegroups.com

Ciprian Badescu (Jira)

unread,
Sep 29, 2021, 3:26:03 AM9/29/21
to puppe...@googlegroups.com

Claire Cadman (Jira)

unread,
Oct 5, 2021, 8:17:02 AM10/5/21
to puppe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages