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

Harden apt-mark defined type #1051

Merged
merged 2 commits into from
Aug 17, 2022
Merged

Harden apt-mark defined type #1051

merged 2 commits into from
Aug 17, 2022

Conversation

chelnak
Copy link

@chelnak chelnak commented Aug 10, 2022

Prior to this PR the title parameter of this defined type was not properly validated.
This means that it could have been possible to use a resource title outside of the normal bounds of a package name.

Additionally the onlyif and command parameter values were interpolated strings meaning that it may have been possible to execute unsafe code on the remote system.

This PR fixes the above issues by adding a regex to check that the resource title is a valid apt package name and also breaks out the onlyif and command parameter values in to arrays of args.

By doing this we are ensuring that the commands executed in a safe manor on the remote system.

The exception to this is the unless_cmd.

This has not been broken out in to an array of args due to the requirement of the command (explained in more detail in mark.pp:20).

Using an interpolated string here is a reasonable trade off however, due to the fact that action is created from known enum values and title would be pre-validated by the regular expression.

@chelnak chelnak requested a review from a team as a code owner August 10, 2022 21:40
@puppet-community-rangefinder
Copy link

apt_mark is a type

that may have no external impact to Forge modules.

This module is declared in 234 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.

@chelnak chelnak marked this pull request as draft August 10, 2022 21:40
@chelnak chelnak force-pushed the maint-move_apt_mark_to_provider branch 5 times, most recently from 75cef27 to a6a9562 Compare August 12, 2022 10:01
Prior to this commit the title parameter of this defined
type was not properly validated. This means that it could have been
possible to use a resource title outside of the normal bounds of
a package name.

Additionally the `onlyif` and `command` parameter values were
interpolated strings meaning that it may have been possible to
execute unsafe code on the remote system.

This commit fixes the above issues by adding a regex to check that the
resource title is a valid apt package name and also breaks out the
`onlyif` and `command` parameter values in to arrays of args ensuring
that the commands executed in a safe manor on the remote system.

The exception in this commit is the `unless_cmd`. This has not been
broken out in to an array of args due to the requirement of the command.
This is a reasonable trade of however due to the fact that action is
created from known enum values and title would be pre-validated.
This is also explained in mark.pp:20.
@chelnak chelnak force-pushed the maint-move_apt_mark_to_provider branch from a6a9562 to 35b491b Compare August 12, 2022 11:03
@chelnak chelnak changed the title Move apt-mark to provider Harden apt-mark defined type Aug 12, 2022
This commit adds additional spec tests for mark.pp.

The tests validate the new resource name requirements
introduced in the previous commit.
@chelnak chelnak force-pushed the maint-move_apt_mark_to_provider branch from 35b491b to 79bec3d Compare August 12, 2022 11:07
@chelnak chelnak marked this pull request as ready for review August 12, 2022 11:09
@chelnak chelnak added the bugfix label Aug 12, 2022
@chelnak chelnak merged commit 06207c3 into main Aug 17, 2022
@chelnak chelnak deleted the maint-move_apt_mark_to_provider branch August 17, 2022 10:36
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