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

fix: use quote with command, shell and validate with variable #298

Merged
merged 7 commits into from
Sep 12, 2024

Conversation

Jakuje
Copy link
Collaborator

@Jakuje Jakuje commented Sep 6, 2024

This is the replacement for the stale PR #245, where the reporter never came back to fix the CI issues, but we still consider that useful change.

Enhancement: Use quote command when calling shell/command modules.

Reason: The user suplied variables could split if they contain whitespace and cause unexpected behavior.

Result: User input is validated.

Issue Tracker Tickets (Jira or BZ if any): -

tasks/install.yml Outdated Show resolved Hide resolved
tests/tests_hostkeys_unsafe_path.yml Show resolved Hide resolved
tasks/install.yml Outdated Show resolved Hide resolved
maage and others added 6 commits September 6, 2024 15:11
This avoids issues if file names are not safepaths.
Skip quotation only if variable is checked.

Add test suit to excercise some quote use cases.
Ensure systemd.unit contents is robust. This disables possibility to
have something that needs to be quoted there. But as ansible lacks
proper way to quote systemd unit files (see man systemd.syntax, rules
are not shell rules), it is better to fail such configs. If you are
trying to do that, you are doing it wrong anyway or have malicious
intent.

Also ensure similar issue with sysctl.conf.

Issue can be seen with `tests_hostkeys_unsafe_path.yml`, when adding
following to role params:

       sshd_install_service: true
       sshd_config_file: "{{ ansible_facts.env.TMPDIR }}/sshd.d/foo.conf"
       sshd_binary: "{{ ansible_facts.env.TMPDIR }}/sshd"
       __sshd_runtime_directory: "{{ ansible_facts.env.TMPDIR }}/run"
@Jakuje Jakuje force-pushed the command-quote branch 2 times, most recently from 3187481 to 1debbff Compare September 6, 2024 13:25
... and explain better why this is problematic

Drops also the check for internal variables as the user should not
bother with these.

Signed-off-by: Jakub Jelen <[email protected]>
Copy link
Member

@mattwillsher mattwillsher left a comment

Choose a reason for hiding this comment

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

Thanks @Jakuje !

@mattwillsher
Copy link
Member

Is this ready for merge?

@Jakuje
Copy link
Collaborator Author

Jakuje commented Sep 11, 2024

Yes, I do not have anything else to add here. Feel free to merge when needed.

@mattwillsher mattwillsher merged commit d10f2ad into willshersystems:main Sep 12, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants