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) Hardening manifests and tasks #863

Merged
merged 4 commits into from
Oct 28, 2022
Merged

Conversation

LukasAud
Copy link
Contributor

This PR aims to implement some changes that ensure no malformed commands are passed through to the system. Certain commands were left undivided as the commands did not get correctly interpreted.

Primarily, the commands targeted were the ones related to Open3 and exec.

@LukasAud LukasAud requested a review from a team as a code owner October 12, 2022 17:07
@puppet-community-rangefinder
Copy link

docker::compose is a class

Breaking changes to this file WILL impact these 3 modules (exact match):

docker::install is a class

that may have no external impact to Forge modules.

docker::machine is a class

that may have no external impact to Forge modules.

docker::plugin is a type

that may have no external impact to Forge modules.

docker::registry is a type

Breaking changes to this file WILL impact these 2 modules (exact match):

docker::run is a type

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

docker::secrets is a type

that may have no external impact to Forge modules.

docker::services is a type

that may have no external impact to Forge modules.

docker::stack is a type

that may have no external impact to Forge modules.

docker::swarm is a type

Breaking changes to this file WILL impact these 2 modules (exact match):

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

@LukasAud LukasAud marked this pull request as draft October 12, 2022 17:09
@LukasAud LukasAud force-pushed the maint-codebase-hardening branch 2 times, most recently from ed28eed to dce80eb Compare October 17, 2022 16:13
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.

Great work @LukasAud !

I've left some comments for you to address.

manifests/compose.pp Outdated Show resolved Hide resolved
@@ -89,10 +89,11 @@
ensure_packages(['curl'])
}

$compose_install = "curl -s -S -L ${proxy_opt} ${docker_compose_url} -o ${docker_compose_location_versioned}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this not be broken in to args?

Suggested change
$compose_install = "curl -s -S -L ${proxy_opt} ${docker_compose_url} -o ${docker_compose_location_versioned}"
$compose_install = ['curl', '-s', '-S', '-L', $proxy_opt, docker_compose_url, '-o', $docker_compose_location_versioned]"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anything that is not broken into args will cry, scream and kick at me when I run test cases. Tried to figure out the reason behind those failures but eventually had to give up and just let some commands stay the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok cool - understand the frustration but we should investigate why it's failing. There are multiple options here that don't involve running the tests - one being running the module via puppet apply and using pry.

manifests/install.pp Outdated Show resolved Hide resolved
manifests/machine.pp Outdated Show resolved Hide resolved
plugin_name => $plugin_name,
force_remove => $force_remove,
}
)

$exec_rm = "${docker_command} rm ${docker_plugin_remove_flags}"
$exec_rm = [$docker_command, 'rm', $docker_plugin_remove_flags]
$onlyif_rm = "${docker_command} ls --format='{{.PluginReference}}' | grep -w ${plugin_name}"
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an interesting one. $onlyif_rm should be broken out because both $docker_command and $plugin_name come from parameters.

With exec, both onlyif and unless accept a String or an Array[Array[String]].

For the latter it would look like this

onlyif => [ ['my', 'command', 'and', 'args'] ]

When it is evaluated exec looks to see if all commands are truthy (e.g you may have multiple inner arrays for different commands).

The tricky part here is that when using an array of args, exec will disregard any metacharacters (right word??). In this case it would ignore the pipe and everything to the right of it.

There may be an example of how to handle this in apt or mysql. Alternatively we could just clean the strings with shell_escape or something similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Talked with @david22swan about this cases. I believe we just agreed to not touch anything with pipes because of the reason mentioned. I did try some variations arraying and segmenting like:
$onlyif_rm = ["$docker_command, 'ls', "--format='{{.PluginReference}}' | grep -w ${plugin_name}"]

Just for the sake of testing whether the problem was separating the pipe from the rest of the arguments but it did not work. Currently any command with a grep is untouched in this and every other PR afaik.

Copy link
Contributor

Choose a reason for hiding this comment

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

It shouldn't be left. We need to address these.

Copy link
Member

Choose a reason for hiding this comment

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

It should be fine so long as the command is sanitized in some other way.
In this case the only variable part, docker_command should be given a shell escape as while it has a default value of docker it is able to be manually set.
It's a difficult one as it is explicitly meant to be a variable for overriding what the command does....

Copy link
Member

Choose a reason for hiding this comment

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

..... Could add a regex check to it to make sure that the command always includes docker at the end with no white spaces in front of it, i.e. that it's always a path to the docker command

tasks/service_update.rb Outdated Show resolved Hide resolved
tasks/swarm_init.rb Outdated Show resolved Hide resolved
tasks/swarm_join.rb Outdated Show resolved Hide resolved
tasks/swarm_leave.rb Outdated Show resolved Hide resolved
tasks/swarm_token.rb Outdated Show resolved Hide resolved
This PR aims to implement some changes that ensure no malformed commands
are passed through to the system. Certain commands were left undivided
as the commands did not get correctly interpreted.

Primarily, the commands targeted were the ones related to Open3 and exec.
Prior to this commit lint would not work properly in Github Actions.

This commit aims to fix the problems that cause failure in CI.
Prior to this commit, there was a block of code checking for puppet 5,
which we no longer support.

This commit aims to clean up this unnecesary code in order to keep the
module tidy.
@LukasAud LukasAud force-pushed the maint-codebase-hardening branch from ce64aa5 to 40f1a09 Compare October 26, 2022 10:58
@LukasAud LukasAud marked this pull request as ready for review October 28, 2022 09:30
Copy link
Member

@david22swan david22swan left a comment

Choose a reason for hiding this comment

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

LGTM

@david22swan david22swan merged commit ba2c378 into main Oct 28, 2022
@david22swan david22swan deleted the maint-codebase-hardening branch October 28, 2022 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants