Skip to content
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

(maint) Codebase Hardening #2313

Merged
merged 3 commits into from
Sep 23, 2022

Conversation

david22swan
Copy link
Member

@david22swan david22swan commented Sep 13, 2022

Changes made to ensure that no malformed commands are passed through to the system.

Includes an update the the $verify_command variable type
The unless variable in an exec manifest, which $verify_command is directly passed too, accepts either an Array or and Array of Arrays as input.
Updating the variables type and default values to match this.
In the case where it is passed a String it proceeds to wrap it in an Array and then treat it as such.

@david22swan david22swan requested a review from a team as a code owner September 13, 2022 16:30
@puppet-community-rangefinder
Copy link

apache::custom_config is a type

Breaking changes to this file WILL impact these 5 modules (exact match):
Breaking changes to this file MAY impact these 5 modules (near match):

apache is a class

Breaking changes to this file WILL impact these 144 modules (exact match):
Breaking changes to this file MAY impact these 56 modules (near match):

apache::mpm::disable_mpm_event is a class

that may have no external impact to Forge modules.

apache::mpm::disable_mpm_prefork is a class

that may have no external impact to Forge modules.

apache::mpm::disable_mpm_worker is a class

that may have no external impact to Forge modules.

This module is declared in 174 of 579 indexed public Puppetfiles.


These results were generated with Rangefinder, a tool that helps predict the downstream impact of breaking changes to elements used in Puppet modules. You can run this on the command line to get a full report.

Exact matches are those that we can positively identify via namespace and the declaring modules' metadata. Non-namespaced items, such as Puppet 3.x functions, will always be reported as near matches only.

Copy link
Collaborator

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments apply multiple times

manifests/custom_config.pp Outdated Show resolved Hide resolved
manifests/init.pp Show resolved Hide resolved
manifests/mpm/disable_mpm_event.pp Outdated Show resolved Hide resolved
manifests/custom_config.pp Outdated Show resolved Hide resolved
manifests/custom_config.pp Outdated Show resolved Hide resolved
manifests/custom_config.pp Outdated Show resolved Hide resolved
Copy link
Contributor

@chelnak chelnak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Just one question regarding $verify_command.

command => "/bin/rm ${confdir}/${_filename}",
unless => $verify_command,
command => $remove_command,
unless => [$verify_command],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless accepts an array of arrays. What do you think about using shellsplit here? That way we can ensure that the command will be handled as expected by the exec provider.
For example:
[shellsplit($verify_command)]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit iffy on doing this.
The verify command can be manually set and we know that splitting the command can cause errors in certain situations, i.e. the use of pipes
Not sure I like the idea of splitting the command when I don't know what it may be.
Probably other thinking it, but still

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that is a good point.. but to me bolsters the fact that we should be guiding people to properly structure their commands.

unless takes an array of arrays. Each inner array is interpreted as a command by the provider. When multiple commands are passed each one needs to evaluate as true for the overall success of `unless.

Though the above would be a breaking change for some which adds to the complication.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could split the default command into an array. Then set verify_command to be: Variant[String, Array[String], Array[Array[String]]
It's a bit messy, but is technically what it should accept

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then maybe remove the string in the next major release

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could split the default command into an array. Then set verify_command to be: Variant[String, Array[String], Array[Array[String]]
It's a bit messy, but is technically what it should accept

I like this, but would it make sense to (also) introduce a Stdlib::Exec::Unless data type? While we couldn't use it immediately, it does signal to the user how it should be used. Just like there's Stdlib::Ensure::*.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also rebased onto main

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and squashed down all my corrective changes into one commit

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ekohl that would be nice yes. I'm a fan of anything we can do to help users on their journey.

@ekohl
Copy link
Collaborator

ekohl commented Sep 20, 2022

Just a thought: can we develop a puppet-lint plugin that detects string interpolation in exec's command/unless attributes? It will probably be easy to fool (doing string interpolation and store that in a variable will be much harder to detect), but simple cases could be caught.

@chelnak
Copy link
Contributor

chelnak commented Sep 20, 2022

Just a thought: can we develop a puppet-lint plugin that detects string interpolation in exec's command/unless attributes? It will probably be easy to fool (doing string interpolation and store that in a variable will be much harder to detect), but simple cases could be caught.

Yes! This is actually something that we were planning when we had our team meet up last week. Should be a nice piece of work for someone on the team to run with.

@david22swan david22swan force-pushed the maint/codebase_hardening branch 3 times, most recently from dbba2ae to a14c834 Compare September 20, 2022 10:52
chelnak
chelnak previously approved these changes Sep 20, 2022
chelnak
chelnak previously approved these changes Sep 23, 2022
Copy link
Contributor

@chelnak chelnak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great @david22swan

Your branch could do with a rebase before merge though please 👍

Changes made to ensure that no malformed commands are passed through to the system.
- Fixes made to spec tests
- onlyif commands corrected
- remove unnecessary shell_escapes
- variable used in place of replicated assignment
- $_file_path neatened
The unless variable in an exec manifest, which $verify_command is directly passed too, accepts either an Array or and Array of Arrays as input.
Updating the variables type and default values to match this.
In the case where it is passed a String it proceeds to wrap it in an Array and then treat it as such.
@chelnak chelnak merged commit 3b4bae8 into puppetlabs:main Sep 23, 2022
@david22swan david22swan deleted the maint/codebase_hardening branch December 20, 2022 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants