(MODULES-11074) Fix facts_diff
task argument parsing on Windows
#561
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.
Previously, running the
facts_diff
task with itsexclude
argument set to a regular expression with characters considered special incmd
/powershell
/bash
could end up discarded or injected as part of the underlyingpuppet facts diff
CLI command.This commit ensures that all
cmd
/powershell
/bash
special characters are escaped by wrapping theexclude
regular expression argument content between double quotes and validates it before passing it to thePuppet::Util::Execution.execute
method. Invalid regular expressions will raiseRegexpError
.Used
^!@%\$&(a)d+\w*\.\/|facter|\|d?[a-z]-=<>;:|a{3}|0`~|\(\[\<$|custom
as a base for testing the exclude argument against special characters. Manual tests passed using CLI, PE console and bolt on both Linux and Windows machines.Tests included adding custom facts that contained such special characters to ensure excluding mechanism still works as expected. Some examples:
Known issues
Ideally, we should be able to give the same input to all 3 methods mentioned (PE console, bolt and CLI), as seen below:
But there are some limitations:
All regular expressions need to be accordingly escaped when running
puppet facts diff
orbolt task run puppet_agent::facts_diff
depending on the shell limitations.Regular expressions starting with double quote (
"
) need to be escaped using backslash (\
) in PE console due to puppetserver nature of dealing with strings.With above limitations in mind, the initial regular expression was also combined with user query given in ticket, resulting in
^!@%\$&(a)d+\w*\.\/|facter|\|d?[a-z]-=<>;:|a{3}|0`~|\(\[\<$|custom|puppet_agent_pid|puppet_inventory_metadata|processors\.|disks.*type|os\.distro|lsb.*release|dhcp_servers\.system|hypervisors\.|ec2_userdata|networking.*\.scope6|pe_postgresql_info|docker\.SystemTime|docker\.Swarm\.RemoteManagers|docker\.NGoroutines
and everything worked as expected.