|
|
54c0d5 |
From e826795667e319a336ccbfe0919c044766801cb8 Mon Sep 17 00:00:00 2001
|
|
|
54c0d5 |
From: =?UTF-8?q?Mat=C4=9Bj=20T=C3=BD=C4=8D?= <matyc@redhat.com>
|
|
|
54c0d5 |
Date: Fri, 17 Jan 2020 10:49:36 +0100
|
|
|
54c0d5 |
Subject: [PATCH 1/7] Added lineinfile shell assignment support to our macros.
|
|
|
54c0d5 |
|
|
|
54c0d5 |
---
|
|
|
54c0d5 |
shared/macros-ansible.jinja | 20 +++++++++++++++++++
|
|
|
54c0d5 |
shared/macros-bash.jinja | 26 +++++++++++++++++++++++++
|
|
|
54c0d5 |
shared/macros-oval.jinja | 39 ++++++++++++++++++++++++++++++++-----
|
|
|
54c0d5 |
3 files changed, 80 insertions(+), 5 deletions(-)
|
|
|
54c0d5 |
|
|
|
54c0d5 |
diff --git a/shared/macros-ansible.jinja b/shared/macros-ansible.jinja
|
|
|
54c0d5 |
index 3e4a441225..c42a5156ce 100644
|
|
|
54c0d5 |
--- a/shared/macros-ansible.jinja
|
|
|
54c0d5 |
+++ b/shared/macros-ansible.jinja
|
|
|
54c0d5 |
@@ -141,6 +141,26 @@
|
|
|
54c0d5 |
{{{ ansible_set_config_file(msg, "/etc/ssh/sshd_config", parameter, value=value, create="yes", prefix_regex='(?i)^\s*', validate="/usr/sbin/sshd -t -f %s", insert_before="^[#\s]*Match") }}}
|
|
|
54c0d5 |
{{%- endmacro %}}
|
|
|
54c0d5 |
|
|
|
54c0d5 |
+{{#
|
|
|
54c0d5 |
+ High level macro to set a value in a shell-related file that contains var assignments. This
|
|
|
54c0d5 |
+ takes these values: msg (the name for the Ansible task), path to the file, a parameter to set
|
|
|
54c0d5 |
+ in the configuration file, and the value to set it to. We specify a case
|
|
|
54c0d5 |
+ sensitive comparison in the prefix since this is used to deduplicate since
|
|
|
54c0d5 |
+ We also specify the validation program here; see 'bash -c "help set" | grep -e -n'
|
|
|
54c0d5 |
+#}}
|
|
|
54c0d5 |
+{{%- macro ansible_shell_set(msg, path, parameter, value='', no_quotes=false) %}}
|
|
|
54c0d5 |
+{{% if no_quotes -%}}
|
|
|
54c0d5 |
+{{%- else -%}}
|
|
|
54c0d5 |
+{{%- set quotes = "\"'" -%}}
|
|
|
54c0d5 |
+ {{% if "$" in value %}}
|
|
|
54c0d5 |
+ {{% set value = '"%s"' % value %}}
|
|
|
54c0d5 |
+ {{% else %}}
|
|
|
54c0d5 |
+ {{% set value = "'%s'" % value %}}
|
|
|
54c0d5 |
+ {{% endif %}}
|
|
|
54c0d5 |
+{{%- endif -%}}
|
|
|
54c0d5 |
+{{{ ansible_set_config_file(msg, path, parameter, value=value, create="yes", prefix_regex='^\s*', validate="/usr/bin/bash -n %s", insert_before="^[#\s]*Match") }}}
|
|
|
54c0d5 |
+{{%- endmacro %}}
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
{{#
|
|
|
54c0d5 |
High level macro to set a command in tmux configuration file /etc/tmux.conf.
|
|
|
54c0d5 |
Parameters:
|
|
|
54c0d5 |
diff --git a/shared/macros-bash.jinja b/shared/macros-bash.jinja
|
|
|
54c0d5 |
index 43200bdd8a..6c0bb2facc 100644
|
|
|
54c0d5 |
--- a/shared/macros-bash.jinja
|
|
|
54c0d5 |
+++ b/shared/macros-bash.jinja
|
|
|
54c0d5 |
@@ -1,5 +1,31 @@
|
|
|
54c0d5 |
{{# ##### High level macros ##### #}}
|
|
|
54c0d5 |
|
|
|
54c0d5 |
+{{%- macro bash_shell_file_set(path, parameter, value, no_quotes=false) -%}}
|
|
|
54c0d5 |
+{{% if no_quotes -%}}
|
|
|
54c0d5 |
+ {{% if "$" in value %}}
|
|
|
54c0d5 |
+ {{% set value = '%s' % value.replace("$", "\\$") %}}
|
|
|
54c0d5 |
+ {{% endif %}}
|
|
|
54c0d5 |
+{{%- else -%}}
|
|
|
54c0d5 |
+ {{% if "$" in value %}}
|
|
|
54c0d5 |
+ {{% set value = '\\"%s\\"' % value.replace("$", "\\$") %}}
|
|
|
54c0d5 |
+ {{% else %}}
|
|
|
54c0d5 |
+ {{% set value = "'%s'" % value %}}
|
|
|
54c0d5 |
+ {{% endif %}}
|
|
|
54c0d5 |
+{{%- endif -%}}
|
|
|
54c0d5 |
+{{{ set_config_file(
|
|
|
54c0d5 |
+ path=path,
|
|
|
54c0d5 |
+ parameter=parameter,
|
|
|
54c0d5 |
+ value=value,
|
|
|
54c0d5 |
+ create=true,
|
|
|
54c0d5 |
+ insert_after="",
|
|
|
54c0d5 |
+ insert_before="^Match",
|
|
|
54c0d5 |
+ insensitive=false,
|
|
|
54c0d5 |
+ separator="=",
|
|
|
54c0d5 |
+ separator_regex="=",
|
|
|
54c0d5 |
+ prefix_regex="^\s*")
|
|
|
54c0d5 |
+ }}}
|
|
|
54c0d5 |
+{{%- endmacro -%}}
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
{{%- macro bash_sshd_config_set(parameter, value) -%}}
|
|
|
54c0d5 |
{{{ set_config_file(
|
|
|
54c0d5 |
path="/etc/ssh/sshd_config",
|
|
|
54c0d5 |
diff --git a/shared/macros-oval.jinja b/shared/macros-oval.jinja
|
|
|
54c0d5 |
index 2049a24d6e..696cf36db0 100644
|
|
|
54c0d5 |
--- a/shared/macros-oval.jinja
|
|
|
54c0d5 |
+++ b/shared/macros-oval.jinja
|
|
|
54c0d5 |
@@ -17,8 +17,9 @@
|
|
|
54c0d5 |
- multi_value (boolean): If set, it means that the parameter can accept multiple values and the expected value must be present in the current list of values.
|
|
|
54c0d5 |
- missing_config_file_fail (boolean): If set, the check will fail if the configuration is not existent in the system.
|
|
|
54c0d5 |
- section (String): If set, the parameter will be checked only within the given section defined by [section].
|
|
|
54c0d5 |
+ - quotes (String): If non-empty, one level of matching quotes is considered when checking the value. See comment of oval_line_in_file_state for more info.
|
|
|
54c0d5 |
#}}
|
|
|
54c0d5 |
-{{%- macro oval_check_config_file(path='', prefix_regex='^[ \\t]*', parameter='', separator_regex='[ \\t]+', value='', missing_parameter_pass=false, application='', multi_value=false, missing_config_file_fail=false, section='') -%}}
|
|
|
54c0d5 |
+{{%- macro oval_check_config_file(path='', prefix_regex='^[ \\t]*', parameter='', separator_regex='[ \\t]+', value='', missing_parameter_pass=false, application='', multi_value=false, missing_config_file_fail=false, section='', quotes='') -%}}
|
|
|
54c0d5 |
<def-group>
|
|
|
54c0d5 |
<definition class="compliance" id="{{{ rule_id }}}" version="1">
|
|
|
54c0d5 |
<metadata>
|
|
|
54c0d5 |
@@ -60,7 +61,7 @@
|
|
|
54c0d5 |
</definition>
|
|
|
54c0d5 |
{{{ oval_line_in_file_test(path, parameter) }}}
|
|
|
54c0d5 |
{{{ oval_line_in_file_object(path, section, prefix_regex, parameter, separator_regex, false, multi_value) }}}
|
|
|
54c0d5 |
- {{{ oval_line_in_file_state(value, multi_value) }}}
|
|
|
54c0d5 |
+ {{{ oval_line_in_file_state(value, multi_value, quotes) }}}
|
|
|
54c0d5 |
{{%- if missing_parameter_pass %}}
|
|
|
54c0d5 |
{{{ oval_line_in_file_test(path, parameter, missing_parameter_pass) }}}
|
|
|
54c0d5 |
{{{ oval_line_in_file_object(path, section, prefix_regex, parameter, separator_regex, missing_parameter_pass, multi_value) }}}
|
|
|
54c0d5 |
@@ -173,12 +174,21 @@
|
|
|
54c0d5 |
This macro can take two parameters:
|
|
|
54c0d5 |
- value (String): The value to be checked. This can also be a regular expression (e.g: value1|value2 can match both values).
|
|
|
54c0d5 |
- multi_value (boolean): If set, it means that the parameter can accept multiple values and the expected value must be present in the current list of values.
|
|
|
54c0d5 |
+ - quotes (String): If non-empty, one level of matching quotes is considered when checking the value. Specify one or more quote types as a string.
|
|
|
54c0d5 |
+ For example, for shell quoting, specify quotes="'\""), which will make sure that value, 'value' and "value" are matched, but 'value" or '"value"' won't be.
|
|
|
54c0d5 |
#}}
|
|
|
54c0d5 |
-{{%- macro oval_line_in_file_state(value='', multi_value='') -%}}
|
|
|
54c0d5 |
+{{%- macro oval_line_in_file_state(value='', multi_value='', quotes='') -%}}
|
|
|
54c0d5 |
+{{%- set regex = value -%}}
|
|
|
54c0d5 |
+{{%- if quotes != "" %}}
|
|
|
54c0d5 |
+{{%- if "\\1" in value > 0 %}}
|
|
|
54c0d5 |
+{{{ raise("The regex for matching '%s' already references capturing groups, which doesn't go well with quoting that adds a capturing group to the beginning." % value) }}}
|
|
|
54c0d5 |
+{{%- endif %}}
|
|
|
54c0d5 |
+{{%- set regex = "((?:%s)?)%s\\1" % ("|".join(quotes), regex) -%}}
|
|
|
54c0d5 |
+{{%- endif %}}
|
|
|
54c0d5 |
{{%- if multi_value %}}
|
|
|
54c0d5 |
-{{%- set regex = "^.*\\b"+value+"\\b.*$" -%}}
|
|
|
54c0d5 |
+{{%- set regex = "^.*\\b"+regex+"\\b.*$" -%}}
|
|
|
54c0d5 |
{{%- else %}}
|
|
|
54c0d5 |
-{{%- set regex = "^"+value+"$" -%}}
|
|
|
54c0d5 |
+{{%- set regex = "^"+regex+"$" -%}}
|
|
|
54c0d5 |
{{%- endif %}}
|
|
|
54c0d5 |
<ind:textfilecontent54_state id="state_{{{ rule_id }}}" version="1">
|
|
|
54c0d5 |
<ind:subexpression datatype="string" operation="pattern match">{{{ regex }}}</ind:subexpression>
|
|
|
54c0d5 |
@@ -232,6 +242,25 @@
|
|
|
54c0d5 |
{{{ oval_check_config_file("/etc/ssh/sshd_config", prefix_regex="^[ \\t]*(?i)", parameter=parameter, separator_regex='(?-i)[ \\t]+', value=value, missing_parameter_pass=missing_parameter_pass, application="sshd", multi_value=multi_value, missing_config_file_fail=missing_config_file_fail) }}}
|
|
|
54c0d5 |
{{%- endmacro %}}
|
|
|
54c0d5 |
|
|
|
54c0d5 |
+{{#
|
|
|
54c0d5 |
+ High level macro to check if a particular shell variable is set.
|
|
|
54c0d5 |
+ This macro can take five parameters:
|
|
|
54c0d5 |
+ - path (String): Path to the file.
|
|
|
54c0d5 |
+ - parameter (String): The shell variable name.
|
|
|
54c0d5 |
+ - value (String): The variable value WITHOUT QUOTES.
|
|
|
54c0d5 |
+ - missing_parameter_pass (boolean): If set, the check will also pass if the parameter is not present in the configuration file (default is applied).
|
|
|
54c0d5 |
+ - multi_value (boolean): If set, it means that the parameter can accept multiple values and the expected value must be present in the current list of values.
|
|
|
54c0d5 |
+ - missing_config_file_fail (boolean): If set, the check will fail if the configuration is not existent in the system.
|
|
|
54c0d5 |
+#}}
|
|
|
54c0d5 |
+{{%- macro oval_check_shell_file(path, parameter='', value='', application='', no_quotes=false, missing_parameter_pass=false, multi_value=false, missing_config_file_fail=false) %}}
|
|
|
54c0d5 |
+{{% if no_quotes -%}}
|
|
|
54c0d5 |
+{{%- set quotes = "" -%}}
|
|
|
54c0d5 |
+{{%- else -%}}
|
|
|
54c0d5 |
+{{%- set quotes = "\"'" -%}}
|
|
|
54c0d5 |
+{{%- endif -%}}
|
|
|
54c0d5 |
+{{{ oval_check_config_file(path, prefix_regex="^[ \\t]*", parameter=parameter, separator_regex='=', value=value, missing_parameter_pass=missing_parameter_pass, application=application, multi_value=multi_value, missing_config_file_fail=missing_config_file_fail, quotes=quotes) }}}
|
|
|
54c0d5 |
+{{%- endmacro %}}
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
{{#
|
|
|
54c0d5 |
High level macro to check if a particular combination of parameter and value in the Audit daemon configuration file is set.
|
|
|
54c0d5 |
This function can take five parameters:
|
|
|
54c0d5 |
|
|
|
54c0d5 |
From a7281779e424a0b481e1b08ca01d2ebd1af2e834 Mon Sep 17 00:00:00 2001
|
|
|
54c0d5 |
From: =?UTF-8?q?Mat=C4=9Bj=20T=C3=BD=C4=8D?= <matyc@redhat.com>
|
|
|
54c0d5 |
Date: Fri, 17 Jan 2020 10:50:16 +0100
|
|
|
54c0d5 |
Subject: [PATCH 2/7] Added tests for shell lineinfile.
|
|
|
54c0d5 |
|
|
|
54c0d5 |
---
|
|
|
54c0d5 |
tests/test_macros_oval.py | 142 ++++++++++++++++++
|
|
|
54c0d5 |
.../unit/bash/test_set_config_file.bats.jinja | 56 +++++++
|
|
|
54c0d5 |
2 files changed, 198 insertions(+)
|
|
|
54c0d5 |
|
|
|
54c0d5 |
diff --git a/tests/test_macros_oval.py b/tests/test_macros_oval.py
|
|
|
54c0d5 |
index 65a88ba7b4..8acae8548b 100755
|
|
|
54c0d5 |
--- a/tests/test_macros_oval.py
|
|
|
54c0d5 |
+++ b/tests/test_macros_oval.py
|
|
|
54c0d5 |
@@ -896,6 +896,148 @@ def main():
|
|
|
54c0d5 |
"[vehicle]\nspeed =\n100",
|
|
|
54c0d5 |
"false"
|
|
|
54c0d5 |
)
|
|
|
54c0d5 |
+ tester.test(
|
|
|
54c0d5 |
+ "SHELL commented out",
|
|
|
54c0d5 |
+ r"""{{{ oval_check_shell_file(
|
|
|
54c0d5 |
+ path='CONFIG_FILE',
|
|
|
54c0d5 |
+ parameter='SHELL',
|
|
|
54c0d5 |
+ value='/bin/bash',
|
|
|
54c0d5 |
+ missing_parameter_pass=false,
|
|
|
54c0d5 |
+ application='',
|
|
|
54c0d5 |
+ multi_value=false,
|
|
|
54c0d5 |
+ missing_config_file_fail=false,
|
|
|
54c0d5 |
+ ) }}}""",
|
|
|
54c0d5 |
+ "# SHELL=/bin/bash\n",
|
|
|
54c0d5 |
+ "false"
|
|
|
54c0d5 |
+ )
|
|
|
54c0d5 |
+ tester.test(
|
|
|
54c0d5 |
+ "SHELL correct",
|
|
|
54c0d5 |
+ r"""{{{ oval_check_shell_file(
|
|
|
54c0d5 |
+ path='CONFIG_FILE',
|
|
|
54c0d5 |
+ parameter='SHELL',
|
|
|
54c0d5 |
+ value='/bin/bash',
|
|
|
54c0d5 |
+ missing_parameter_pass=false,
|
|
|
54c0d5 |
+ application='',
|
|
|
54c0d5 |
+ multi_value=false,
|
|
|
54c0d5 |
+ missing_config_file_fail=false,
|
|
|
54c0d5 |
+ ) }}}""",
|
|
|
54c0d5 |
+ " SHELL=/bin/bash\n",
|
|
|
54c0d5 |
+ "true"
|
|
|
54c0d5 |
+ )
|
|
|
54c0d5 |
+ tester.test(
|
|
|
54c0d5 |
+ "SHELL single-quoted",
|
|
|
54c0d5 |
+ r"""{{{ oval_check_shell_file(
|
|
|
54c0d5 |
+ path='CONFIG_FILE',
|
|
|
54c0d5 |
+ parameter='SHELL',
|
|
|
54c0d5 |
+ value='/bin"/bash',
|
|
|
54c0d5 |
+ missing_parameter_pass=false,
|
|
|
54c0d5 |
+ application='',
|
|
|
54c0d5 |
+ multi_value=false,
|
|
|
54c0d5 |
+ missing_config_file_fail=false,
|
|
|
54c0d5 |
+ ) }}}""",
|
|
|
54c0d5 |
+ " SHELL='/bin\"/bash'\n",
|
|
|
54c0d5 |
+ "true"
|
|
|
54c0d5 |
+ )
|
|
|
54c0d5 |
+ tester.test(
|
|
|
54c0d5 |
+ "SHELL double-quoted",
|
|
|
54c0d5 |
+ r"""{{{ oval_check_shell_file(
|
|
|
54c0d5 |
+ path='CONFIG_FILE',
|
|
|
54c0d5 |
+ parameter='SHELL',
|
|
|
54c0d5 |
+ value=' /bin/bash',
|
|
|
54c0d5 |
+ missing_parameter_pass=false,
|
|
|
54c0d5 |
+ application='',
|
|
|
54c0d5 |
+ multi_value=false,
|
|
|
54c0d5 |
+ missing_config_file_fail=false,
|
|
|
54c0d5 |
+ ) }}}""",
|
|
|
54c0d5 |
+ """ SHELL=" /bin/bash"\n""",
|
|
|
54c0d5 |
+ "true"
|
|
|
54c0d5 |
+ )
|
|
|
54c0d5 |
+ tester.test(
|
|
|
54c0d5 |
+ "SHELL unwanted double-quoted",
|
|
|
54c0d5 |
+ r"""{{{ oval_check_shell_file(
|
|
|
54c0d5 |
+ path='CONFIG_FILE',
|
|
|
54c0d5 |
+ parameter='SHELL',
|
|
|
54c0d5 |
+ value=' /bin/bash',
|
|
|
54c0d5 |
+ no_quotes=true,
|
|
|
54c0d5 |
+ missing_parameter_pass=false,
|
|
|
54c0d5 |
+ application='',
|
|
|
54c0d5 |
+ multi_value=false,
|
|
|
54c0d5 |
+ missing_config_file_fail=false,
|
|
|
54c0d5 |
+ ) }}}""",
|
|
|
54c0d5 |
+ """ SHELL=" /bin/bash"\n""",
|
|
|
54c0d5 |
+ "false"
|
|
|
54c0d5 |
+ )
|
|
|
54c0d5 |
+ tester.test(
|
|
|
54c0d5 |
+ "SHELL unwanted single-quoted",
|
|
|
54c0d5 |
+ r"""{{{ oval_check_shell_file(
|
|
|
54c0d5 |
+ path='CONFIG_FILE',
|
|
|
54c0d5 |
+ parameter='SHELL',
|
|
|
54c0d5 |
+ value='/bin"/bash',
|
|
|
54c0d5 |
+ no_quotes=true,
|
|
|
54c0d5 |
+ missing_parameter_pass=false,
|
|
|
54c0d5 |
+ application='',
|
|
|
54c0d5 |
+ multi_value=false,
|
|
|
54c0d5 |
+ missing_config_file_fail=false,
|
|
|
54c0d5 |
+ ) }}}""",
|
|
|
54c0d5 |
+ " SHELL='/bin\"/bash'\n",
|
|
|
54c0d5 |
+ "false"
|
|
|
54c0d5 |
+ )
|
|
|
54c0d5 |
+ tester.test(
|
|
|
54c0d5 |
+ "SHELL double-quoted spaced",
|
|
|
54c0d5 |
+ r"""{{{ oval_check_shell_file(
|
|
|
54c0d5 |
+ path='CONFIG_FILE',
|
|
|
54c0d5 |
+ parameter='SHELL',
|
|
|
54c0d5 |
+ value='/bin/bash',
|
|
|
54c0d5 |
+ missing_parameter_pass=false,
|
|
|
54c0d5 |
+ application='',
|
|
|
54c0d5 |
+ multi_value=false,
|
|
|
54c0d5 |
+ missing_config_file_fail=false,
|
|
|
54c0d5 |
+ ) }}}""",
|
|
|
54c0d5 |
+ """ SHELL= "/bin/bash"\n""",
|
|
|
54c0d5 |
+ "false"
|
|
|
54c0d5 |
+ )
|
|
|
54c0d5 |
+ tester.test(
|
|
|
54c0d5 |
+ "SHELL bad_var_case",
|
|
|
54c0d5 |
+ r"""{{{ oval_check_shell_file(
|
|
|
54c0d5 |
+ path='CONFIG_FILE',
|
|
|
54c0d5 |
+ parameter='SHELL',
|
|
|
54c0d5 |
+ value='/bin/bash',
|
|
|
54c0d5 |
+ missing_parameter_pass=false,
|
|
|
54c0d5 |
+ application='',
|
|
|
54c0d5 |
+ multi_value=false,
|
|
|
54c0d5 |
+ missing_config_file_fail=false,
|
|
|
54c0d5 |
+ ) }}}""",
|
|
|
54c0d5 |
+ """ Shell="/bin/bash"\n""",
|
|
|
54c0d5 |
+ "false"
|
|
|
54c0d5 |
+ )
|
|
|
54c0d5 |
+ tester.test(
|
|
|
54c0d5 |
+ "SHELL bad_value_case",
|
|
|
54c0d5 |
+ r"""{{{ oval_check_shell_file(
|
|
|
54c0d5 |
+ path='CONFIG_FILE',
|
|
|
54c0d5 |
+ parameter='SHELL',
|
|
|
54c0d5 |
+ value='/bin/bash',
|
|
|
54c0d5 |
+ missing_parameter_pass=false,
|
|
|
54c0d5 |
+ application='',
|
|
|
54c0d5 |
+ multi_value=false,
|
|
|
54c0d5 |
+ missing_config_file_fail=false,
|
|
|
54c0d5 |
+ ) }}}""",
|
|
|
54c0d5 |
+ """ SHELL="/bin/Bash"\n""",
|
|
|
54c0d5 |
+ "false"
|
|
|
54c0d5 |
+ )
|
|
|
54c0d5 |
+ tester.test(
|
|
|
54c0d5 |
+ "SHELL badly quoted",
|
|
|
54c0d5 |
+ r"""{{{ oval_check_shell_file(
|
|
|
54c0d5 |
+ path='CONFIG_FILE',
|
|
|
54c0d5 |
+ parameter='SHELL',
|
|
|
54c0d5 |
+ value='/bin/bash',
|
|
|
54c0d5 |
+ missing_parameter_pass=false,
|
|
|
54c0d5 |
+ application='',
|
|
|
54c0d5 |
+ multi_value=false,
|
|
|
54c0d5 |
+ missing_config_file_fail=false,
|
|
|
54c0d5 |
+ ) }}}""",
|
|
|
54c0d5 |
+ """ SHELL="/bin/bash'\n""",
|
|
|
54c0d5 |
+ "false"
|
|
|
54c0d5 |
+ )
|
|
|
54c0d5 |
|
|
|
54c0d5 |
tester.finish()
|
|
|
54c0d5 |
|
|
|
54c0d5 |
diff --git a/tests/unit/bash/test_set_config_file.bats.jinja b/tests/unit/bash/test_set_config_file.bats.jinja
|
|
|
54c0d5 |
index 3dc2c721d4..4126d0440e 100644
|
|
|
54c0d5 |
--- a/tests/unit/bash/test_set_config_file.bats.jinja
|
|
|
54c0d5 |
+++ b/tests/unit/bash/test_set_config_file.bats.jinja
|
|
|
54c0d5 |
@@ -126,3 +126,59 @@ function call_set_config_file {
|
|
|
54c0d5 |
|
|
|
54c0d5 |
rm "$tmp_file"
|
|
|
54c0d5 |
}
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+@test "Basic Bash remediation" {
|
|
|
54c0d5 |
+ tmp_file="$(mktemp)"
|
|
|
54c0d5 |
+ printf "%s\n" "something=foo" > "$tmp_file"
|
|
|
54c0d5 |
+ expected_output="something='va lue'\n"
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+ {{{ bash_shell_file_set("$tmp_file", "something", "va lue") | indent(4) }}}
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+ run diff -U2 "$tmp_file" <(printf "$expected_output")
|
|
|
54c0d5 |
+ echo "$output"
|
|
|
54c0d5 |
+ [ "$status" -eq 0 ]
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+ rm "$tmp_file"
|
|
|
54c0d5 |
+}
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+@test "Variable remediation - preserve dollar and use double quotes" {
|
|
|
54c0d5 |
+ tmp_file="$(mktemp)"
|
|
|
54c0d5 |
+ printf "%s\n" "something=bar" > "$tmp_file"
|
|
|
54c0d5 |
+ expected_output='something="$value"'"\n"
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+ {{{ bash_shell_file_set("$tmp_file", "something", '$value') | indent(4) }}}
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+ run diff -U2 "$tmp_file" <(printf "$expected_output")
|
|
|
54c0d5 |
+ echo "$output"
|
|
|
54c0d5 |
+ [ "$status" -eq 0 ]
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+ rm "$tmp_file"
|
|
|
54c0d5 |
+}
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+@test "Basic Bash remediation - don't quote" {
|
|
|
54c0d5 |
+ tmp_file="$(mktemp)"
|
|
|
54c0d5 |
+ printf "%s\n" "something=foo" > "$tmp_file"
|
|
|
54c0d5 |
+ expected_output="something=va lue\n"
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+ {{{ bash_shell_file_set("$tmp_file", "something", "va lue", no_quotes=true) | indent(4) }}}
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+ run diff -U2 "$tmp_file" <(printf "$expected_output")
|
|
|
54c0d5 |
+ echo "$output"
|
|
|
54c0d5 |
+ [ "$status" -eq 0 ]
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+ rm "$tmp_file"
|
|
|
54c0d5 |
+}
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+@test "Variable remediation - don't quote" {
|
|
|
54c0d5 |
+ tmp_file="$(mktemp)"
|
|
|
54c0d5 |
+ printf "%s\n" "something=bar" > "$tmp_file"
|
|
|
54c0d5 |
+ expected_output='something=$value'"\n"
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+ {{{ bash_shell_file_set("$tmp_file", "something", '$value', no_quotes=true) | indent(4) }}}
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+ run diff -U2 "$tmp_file" <(printf "$expected_output")
|
|
|
54c0d5 |
+ echo "$output"
|
|
|
54c0d5 |
+ [ "$status" -eq 0 ]
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+ rm "$tmp_file"
|
|
|
54c0d5 |
+}
|
|
|
54c0d5 |
|
|
|
54c0d5 |
From 347e7ab345a35fc3045a886d883d8efe7d9820b2 Mon Sep 17 00:00:00 2001
|
|
|
54c0d5 |
From: =?UTF-8?q?Mat=C4=9Bj=20T=C3=BD=C4=8D?= <matyc@redhat.com>
|
|
|
54c0d5 |
Date: Fri, 17 Jan 2020 10:51:02 +0100
|
|
|
54c0d5 |
Subject: [PATCH 3/7] Added the shell lineinfile template.
|
|
|
54c0d5 |
|
|
|
54c0d5 |
---
|
|
|
54c0d5 |
docs/manual/developer_guide.adoc | 21 +++++++++++++++++
|
|
|
54c0d5 |
.../template_ANSIBLE_shell_lineinfile | 21 +++++++++++++++++
|
|
|
54c0d5 |
.../templates/template_BASH_shell_lineinfile | 6 +++++
|
|
|
54c0d5 |
.../templates/template_OVAL_shell_lineinfile | 10 ++++++++
|
|
|
54c0d5 |
ssg/templates.py | 23 +++++++++++++++++++
|
|
|
54c0d5 |
5 files changed, 81 insertions(+)
|
|
|
54c0d5 |
create mode 100644 shared/templates/template_ANSIBLE_shell_lineinfile
|
|
|
54c0d5 |
create mode 100644 shared/templates/template_BASH_shell_lineinfile
|
|
|
54c0d5 |
create mode 100644 shared/templates/template_OVAL_shell_lineinfile
|
|
|
54c0d5 |
|
|
|
54c0d5 |
diff --git a/docs/manual/developer_guide.adoc b/docs/manual/developer_guide.adoc
|
|
|
54c0d5 |
index aa0a7491c3..b5d22213b7 100644
|
|
|
54c0d5 |
--- a/docs/manual/developer_guide.adoc
|
|
|
54c0d5 |
+++ b/docs/manual/developer_guide.adoc
|
|
|
54c0d5 |
@@ -1591,6 +1591,27 @@ service_enabled::
|
|
|
54c0d5 |
** *daemonname* - name of the daemon. This argument is optional. If *daemonname* is not specified it means the name of the daemon is the same as the name of service.
|
|
|
54c0d5 |
* Languages: Ansible, Bash, OVAL, Puppet
|
|
|
54c0d5 |
|
|
|
54c0d5 |
+shell_lineinfile::
|
|
|
54c0d5 |
+* Checks shell variable assignments in files.
|
|
|
54c0d5 |
+Remediations will paste assignments with single shell quotes unless there is the dollar sign in the value string, in which case double quotes are administered.
|
|
|
54c0d5 |
+The OVAL checks for a match with either of no quotes, single quoted string, or double quoted string.
|
|
|
54c0d5 |
+* Parameters:
|
|
|
54c0d5 |
+** *path* - What file to check.
|
|
|
54c0d5 |
+** *parameter* - name of the shell variable, eg. `SHELL`.
|
|
|
54c0d5 |
+** *value* - value of the SSH configuration option specified by *parameter*, eg. `"/bin/bash"`. Don't pass extra shell quoting - that will be handled on the lower level.
|
|
|
54c0d5 |
+** *no_quotes* - If set to `"true"`, the assigned value has to be without quotes during the check and remediation doesn't quote assignments either.
|
|
|
54c0d5 |
+** *missing_parameter_pass* - If set to `"true"` the OVAL check will pass if the parameter is not present in the target file.
|
|
|
54c0d5 |
+* Languages: Ansible, Bash, OVAL
|
|
|
54c0d5 |
+* Example:
|
|
|
54c0d5 |
+A template invocation specifying that parameter `HISTSIZE` should be set to value `500` in `/etc/profile` will produce a check that passes if any of the following lines are present in `/etc/profile`:
|
|
|
54c0d5 |
+** `HISTSIZE=500`
|
|
|
54c0d5 |
+** `HISTSIZE="500"`
|
|
|
54c0d5 |
+** `HISTSIZE='500'`
|
|
|
54c0d5 |
++
|
|
|
54c0d5 |
+The remediation would insert one of the quoted forms if the line was not present.
|
|
|
54c0d5 |
++
|
|
|
54c0d5 |
+If the `no_quotes` would be set in the template, only the first form would be checked for, and the unquoted assignment would be inserted to the file by the remediation if not present.
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
sshd_lineinfile::
|
|
|
54c0d5 |
* Checks SSH server configuration items in `/etc/ssh/sshd_config`.
|
|
|
54c0d5 |
* Parameters:
|
|
|
54c0d5 |
diff --git a/shared/templates/template_ANSIBLE_shell_lineinfile b/shared/templates/template_ANSIBLE_shell_lineinfile
|
|
|
54c0d5 |
new file mode 100644
|
|
|
54c0d5 |
index 0000000000..7d0a3ebcbd
|
|
|
54c0d5 |
--- /dev/null
|
|
|
54c0d5 |
+++ b/shared/templates/template_ANSIBLE_shell_lineinfile
|
|
|
54c0d5 |
@@ -0,0 +1,21 @@
|
|
|
54c0d5 |
+# platform = multi_platform_all
|
|
|
54c0d5 |
+# reboot = false
|
|
|
54c0d5 |
+# strategy = restrict
|
|
|
54c0d5 |
+# complexity = low
|
|
|
54c0d5 |
+# disruption = low
|
|
|
54c0d5 |
+{{% set msg = "shell-style assignment of '" ~ PARAMETER ~ "' to '" ~ VALUE ~ "' in '" ~ PATH ~ "'." -%}}
|
|
|
54c0d5 |
+{{%- if NO_QUOTES -%}}
|
|
|
54c0d5 |
+ {{% set msg = "Setting unquoted " ~ msg %}}
|
|
|
54c0d5 |
+{{%- else -%}}
|
|
|
54c0d5 |
+ {{% set msg = "Setting shell-quoted " ~ msg %}}
|
|
|
54c0d5 |
+{{%- endif -%}}
|
|
|
54c0d5 |
+{{{
|
|
|
54c0d5 |
+ ansible_shell_set(
|
|
|
54c0d5 |
+ msg=msg,
|
|
|
54c0d5 |
+ path=PATH,
|
|
|
54c0d5 |
+ parameter=PARAMETER,
|
|
|
54c0d5 |
+ value=VALUE,
|
|
|
54c0d5 |
+ no_quotes=NO_QUOTES
|
|
|
54c0d5 |
+ )
|
|
|
54c0d5 |
+}}}
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
diff --git a/shared/templates/template_BASH_shell_lineinfile b/shared/templates/template_BASH_shell_lineinfile
|
|
|
54c0d5 |
new file mode 100644
|
|
|
54c0d5 |
index 0000000000..6bf869d62b
|
|
|
54c0d5 |
--- /dev/null
|
|
|
54c0d5 |
+++ b/shared/templates/template_BASH_shell_lineinfile
|
|
|
54c0d5 |
@@ -0,0 +1,6 @@
|
|
|
54c0d5 |
+# platform = multi_platform_all
|
|
|
54c0d5 |
+# reboot = false
|
|
|
54c0d5 |
+# strategy = restrict
|
|
|
54c0d5 |
+# complexity = low
|
|
|
54c0d5 |
+# disruption = low
|
|
|
54c0d5 |
+{{{ bash_shell_file_set(path=PATH, parameter=PARAMETER, value=VALUE, no_quotes=NO_QUOTES) }}}
|
|
|
54c0d5 |
diff --git a/shared/templates/template_OVAL_shell_lineinfile b/shared/templates/template_OVAL_shell_lineinfile
|
|
|
54c0d5 |
new file mode 100644
|
|
|
54c0d5 |
index 0000000000..fd05b6b568
|
|
|
54c0d5 |
--- /dev/null
|
|
|
54c0d5 |
+++ b/shared/templates/template_OVAL_shell_lineinfile
|
|
|
54c0d5 |
@@ -0,0 +1,10 @@
|
|
|
54c0d5 |
+{{{
|
|
|
54c0d5 |
+oval_check_shell_file(
|
|
|
54c0d5 |
+ path=PATH,
|
|
|
54c0d5 |
+ parameter=PARAMETER,
|
|
|
54c0d5 |
+ value=VALUE,
|
|
|
54c0d5 |
+ no_quotes=NO_QUOTES,
|
|
|
54c0d5 |
+ missing_parameter_pass=MISSING_PARAMETER_PASS
|
|
|
54c0d5 |
+)
|
|
|
54c0d5 |
+}}}
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
diff --git a/ssg/templates.py b/ssg/templates.py
|
|
|
54c0d5 |
index f4f56c94e6..c2c82e6c29 100644
|
|
|
54c0d5 |
--- a/ssg/templates.py
|
|
|
54c0d5 |
+++ b/ssg/templates.py
|
|
|
54c0d5 |
@@ -290,6 +290,29 @@ def sshd_lineinfile(data, lang):
|
|
|
54c0d5 |
return data
|
|
|
54c0d5 |
|
|
|
54c0d5 |
|
|
|
54c0d5 |
+@template(["ansible", "bash", "oval"])
|
|
|
54c0d5 |
+def shell_lineinfile(data, lang):
|
|
|
54c0d5 |
+ value = data["value"]
|
|
|
54c0d5 |
+ if value[0] in ("'", '"') and value[0] == value[1]:
|
|
|
54c0d5 |
+ msg = (
|
|
|
54c0d5 |
+ "Value >>{value}<< of shell variable '{varname}' "
|
|
|
54c0d5 |
+ "has been supplied with quotes, please fix the content - "
|
|
|
54c0d5 |
+ "shell quoting is handled by the check/remediation code."
|
|
|
54c0d5 |
+ .format(value=value, varname=data["parameter"]))
|
|
|
54c0d5 |
+ raise Exception(msg)
|
|
|
54c0d5 |
+ missing_parameter_pass = data.get("missing_parameter_pass", "false")
|
|
|
54c0d5 |
+ if missing_parameter_pass == "true":
|
|
|
54c0d5 |
+ missing_parameter_pass = True
|
|
|
54c0d5 |
+ elif missing_parameter_pass == "false":
|
|
|
54c0d5 |
+ missing_parameter_pass = False
|
|
|
54c0d5 |
+ data["missing_parameter_pass"] = missing_parameter_pass
|
|
|
54c0d5 |
+ no_quotes = False
|
|
|
54c0d5 |
+ if data["no_quotes"] == "true":
|
|
|
54c0d5 |
+ no_quotes = True
|
|
|
54c0d5 |
+ data["no_quotes"] = no_quotes
|
|
|
54c0d5 |
+ return data
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
@template(["ansible", "bash", "oval"])
|
|
|
54c0d5 |
def timer_enabled(data, lang):
|
|
|
54c0d5 |
if "packagename" not in data:
|
|
|
54c0d5 |
|
|
|
54c0d5 |
From ac5d1a8ad511e828e652ce1ca58b06c18f8c083b Mon Sep 17 00:00:00 2001
|
|
|
54c0d5 |
From: =?UTF-8?q?Mat=C4=9Bj=20T=C3=BD=C4=8D?= <matyc@redhat.com>
|
|
|
54c0d5 |
Date: Tue, 21 Jan 2020 14:13:01 +0100
|
|
|
54c0d5 |
Subject: [PATCH 4/7] Fixed the templated string evaluation.
|
|
|
54c0d5 |
|
|
|
54c0d5 |
---
|
|
|
54c0d5 |
ssg/templates.py | 2 +-
|
|
|
54c0d5 |
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
54c0d5 |
|
|
|
54c0d5 |
diff --git a/ssg/templates.py b/ssg/templates.py
|
|
|
54c0d5 |
index c2c82e6c29..873f543f41 100644
|
|
|
54c0d5 |
--- a/ssg/templates.py
|
|
|
54c0d5 |
+++ b/ssg/templates.py
|
|
|
54c0d5 |
@@ -293,7 +293,7 @@ def sshd_lineinfile(data, lang):
|
|
|
54c0d5 |
@template(["ansible", "bash", "oval"])
|
|
|
54c0d5 |
def shell_lineinfile(data, lang):
|
|
|
54c0d5 |
value = data["value"]
|
|
|
54c0d5 |
- if value[0] in ("'", '"') and value[0] == value[1]:
|
|
|
54c0d5 |
+ if value[0] in ("'", '"') and value[0] == value[-1]:
|
|
|
54c0d5 |
msg = (
|
|
|
54c0d5 |
"Value >>{value}<< of shell variable '{varname}' "
|
|
|
54c0d5 |
"has been supplied with quotes, please fix the content - "
|
|
|
54c0d5 |
|
|
|
54c0d5 |
From 8589574707c63eb3ac4c56674326b70dacfd2ee4 Mon Sep 17 00:00:00 2001
|
|
|
54c0d5 |
From: =?UTF-8?q?Mat=C4=9Bj=20T=C3=BD=C4=8D?= <matyc@redhat.com>
|
|
|
54c0d5 |
Date: Tue, 21 Jan 2020 14:46:39 +0100
|
|
|
54c0d5 |
Subject: [PATCH 5/7] Fixed jinja macros
|
|
|
54c0d5 |
|
|
|
54c0d5 |
- Fixed macro descriptions.
|
|
|
54c0d5 |
- Fixed Ansible insert_after.
|
|
|
54c0d5 |
---
|
|
|
54c0d5 |
shared/macros-ansible.jinja | 18 ++++++++----------
|
|
|
54c0d5 |
shared/macros-bash.jinja | 2 +-
|
|
|
54c0d5 |
shared/macros-oval.jinja | 7 +++----
|
|
|
54c0d5 |
3 files changed, 12 insertions(+), 15 deletions(-)
|
|
|
54c0d5 |
|
|
|
54c0d5 |
diff --git a/shared/macros-ansible.jinja b/shared/macros-ansible.jinja
|
|
|
54c0d5 |
index c42a5156ce..81e18e2d5c 100644
|
|
|
54c0d5 |
--- a/shared/macros-ansible.jinja
|
|
|
54c0d5 |
+++ b/shared/macros-ansible.jinja
|
|
|
54c0d5 |
@@ -143,22 +143,20 @@
|
|
|
54c0d5 |
|
|
|
54c0d5 |
{{#
|
|
|
54c0d5 |
High level macro to set a value in a shell-related file that contains var assignments. This
|
|
|
54c0d5 |
- takes these values: msg (the name for the Ansible task), path to the file, a parameter to set
|
|
|
54c0d5 |
- in the configuration file, and the value to set it to. We specify a case
|
|
|
54c0d5 |
- sensitive comparison in the prefix since this is used to deduplicate since
|
|
|
54c0d5 |
+ takes these values:
|
|
|
54c0d5 |
+ - msg (the name for the Ansible task),
|
|
|
54c0d5 |
+ - path to the file,
|
|
|
54c0d5 |
+ - parameter to set in the configuration file, and
|
|
|
54c0d5 |
+ - value to set it to.
|
|
|
54c0d5 |
We also specify the validation program here; see 'bash -c "help set" | grep -e -n'
|
|
|
54c0d5 |
#}}
|
|
|
54c0d5 |
{{%- macro ansible_shell_set(msg, path, parameter, value='', no_quotes=false) %}}
|
|
|
54c0d5 |
{{% if no_quotes -%}}
|
|
|
54c0d5 |
{{%- else -%}}
|
|
|
54c0d5 |
-{{%- set quotes = "\"'" -%}}
|
|
|
54c0d5 |
- {{% if "$" in value %}}
|
|
|
54c0d5 |
- {{% set value = '"%s"' % value %}}
|
|
|
54c0d5 |
- {{% else %}}
|
|
|
54c0d5 |
- {{% set value = "'%s'" % value %}}
|
|
|
54c0d5 |
- {{% endif %}}
|
|
|
54c0d5 |
+{{# Use the double quotes in all cases, as the underlying macro single-quotes the assignment line. #}}
|
|
|
54c0d5 |
+{{% set value = '"%s"' % value %}}
|
|
|
54c0d5 |
{{%- endif -%}}
|
|
|
54c0d5 |
-{{{ ansible_set_config_file(msg, path, parameter, value=value, create="yes", prefix_regex='^\s*', validate="/usr/bin/bash -n %s", insert_before="^[#\s]*Match") }}}
|
|
|
54c0d5 |
+{{{ ansible_set_config_file(msg, path, parameter, separator="=", separator_regex="=", value=value, create="yes", prefix_regex='^\s*', validate="/usr/bin/bash -n %s", insert_before="^# " ~ parameter) }}}
|
|
|
54c0d5 |
{{%- endmacro %}}
|
|
|
54c0d5 |
|
|
|
54c0d5 |
{{#
|
|
|
54c0d5 |
diff --git a/shared/macros-bash.jinja b/shared/macros-bash.jinja
|
|
|
54c0d5 |
index 6c0bb2facc..dc7fd25588 100644
|
|
|
54c0d5 |
--- a/shared/macros-bash.jinja
|
|
|
54c0d5 |
+++ b/shared/macros-bash.jinja
|
|
|
54c0d5 |
@@ -18,7 +18,7 @@
|
|
|
54c0d5 |
value=value,
|
|
|
54c0d5 |
create=true,
|
|
|
54c0d5 |
insert_after="",
|
|
|
54c0d5 |
- insert_before="^Match",
|
|
|
54c0d5 |
+ insert_before="^#\s*" ~ parameter,
|
|
|
54c0d5 |
insensitive=false,
|
|
|
54c0d5 |
separator="=",
|
|
|
54c0d5 |
separator_regex="=",
|
|
|
54c0d5 |
diff --git a/shared/macros-oval.jinja b/shared/macros-oval.jinja
|
|
|
54c0d5 |
index 696cf36db0..cfa9de9d2d 100644
|
|
|
54c0d5 |
--- a/shared/macros-oval.jinja
|
|
|
54c0d5 |
+++ b/shared/macros-oval.jinja
|
|
|
54c0d5 |
@@ -233,7 +233,7 @@
|
|
|
54c0d5 |
- value (String): The value to be checked. This can also be a regular expression (e.g: value1|value2 can match both values).
|
|
|
54c0d5 |
- missing_parameter_pass (boolean): If set, the check will also pass if the parameter is not present in the configuration file (default is applied).
|
|
|
54c0d5 |
- multi_value (boolean): If set, it means that the parameter can accept multiple values and the expected value must be present in the current list of values.
|
|
|
54c0d5 |
- - missing_config_file_fail (boolean): If set, the check will fail if the configuration is not existent in the system.
|
|
|
54c0d5 |
+ - missing_config_file_fail (boolean): If set, the check will fail if the configuration file doesn't exist in the system.
|
|
|
54c0d5 |
|
|
|
54c0d5 |
We specify a case insensitive comparison in the prefix because
|
|
|
54c0d5 |
sshd_config has case-insensitive parameters (but case-sensitive values).
|
|
|
54c0d5 |
@@ -250,7 +250,7 @@
|
|
|
54c0d5 |
- value (String): The variable value WITHOUT QUOTES.
|
|
|
54c0d5 |
- missing_parameter_pass (boolean): If set, the check will also pass if the parameter is not present in the configuration file (default is applied).
|
|
|
54c0d5 |
- multi_value (boolean): If set, it means that the parameter can accept multiple values and the expected value must be present in the current list of values.
|
|
|
54c0d5 |
- - missing_config_file_fail (boolean): If set, the check will fail if the configuration is not existent in the system.
|
|
|
54c0d5 |
+ - missing_config_file_fail (boolean): If set, the check will fail if the configuration file doesn't exist in the system.
|
|
|
54c0d5 |
#}}
|
|
|
54c0d5 |
{{%- macro oval_check_shell_file(path, parameter='', value='', application='', no_quotes=false, missing_parameter_pass=false, multi_value=false, missing_config_file_fail=false) %}}
|
|
|
54c0d5 |
{{% if no_quotes -%}}
|
|
|
54c0d5 |
@@ -268,8 +268,7 @@
|
|
|
54c0d5 |
- value (String): The value to be checked. This can also be a regular expression (e.g: value1|value2 can match both values).
|
|
|
54c0d5 |
- missing_parameter_pass (boolean): If set, the check will also pass if the parameter is not present in the configuration file (default is applied).
|
|
|
54c0d5 |
- multi_value (boolean): If set, it means that the parameter can accept multiple values and the expected value must be present in the current list of values.
|
|
|
54c0d5 |
- - missing_config_file_fail (boolean): If set, the check will fail if the configuration is not existent in the system.
|
|
|
54c0d5 |
-
|
|
|
54c0d5 |
+ - missing_config_file_fail (boolean): If set, the check will fail if the configuration file doesn't exist in the system.
|
|
|
54c0d5 |
#}}
|
|
|
54c0d5 |
{{%- macro oval_auditd_config(parameter='', value='', missing_parameter_pass=false, multi_value=false, missing_config_file_fail=false) %}}
|
|
|
54c0d5 |
{{{ oval_check_config_file("/etc/audit/auditd.conf", prefix_regex="^[ \\t]*(?i)", parameter=parameter, separator_regex='(?-i)[ \\t]*=[ \\t]*', value="(?i)"+value+"(?-i)", missing_parameter_pass=missing_parameter_pass, application="auditd", multi_value=multi_value, missing_config_file_fail=missing_config_file_fail) }}}
|
|
|
54c0d5 |
|
|
|
54c0d5 |
From af0e3ba8ef2d5b53dcffed4432ec0415a81ab2bc Mon Sep 17 00:00:00 2001
|
|
|
54c0d5 |
From: =?UTF-8?q?Mat=C4=9Bj=20T=C3=BD=C4=8D?= <matyc@redhat.com>
|
|
|
54c0d5 |
Date: Wed, 22 Jan 2020 11:37:39 +0100
|
|
|
54c0d5 |
Subject: [PATCH 6/7] Shell lineinfile macros and templates style fixes.
|
|
|
54c0d5 |
|
|
|
54c0d5 |
---
|
|
|
54c0d5 |
shared/macros-ansible.jinja | 2 +-
|
|
|
54c0d5 |
shared/macros-oval.jinja | 10 ++++++++--
|
|
|
54c0d5 |
shared/templates/template_ANSIBLE_shell_lineinfile | 4 ++--
|
|
|
54c0d5 |
3 files changed, 11 insertions(+), 5 deletions(-)
|
|
|
54c0d5 |
|
|
|
54c0d5 |
diff --git a/shared/macros-ansible.jinja b/shared/macros-ansible.jinja
|
|
|
54c0d5 |
index 81e18e2d5c..f752e7a2be 100644
|
|
|
54c0d5 |
--- a/shared/macros-ansible.jinja
|
|
|
54c0d5 |
+++ b/shared/macros-ansible.jinja
|
|
|
54c0d5 |
@@ -25,7 +25,7 @@
|
|
|
54c0d5 |
{{%- elif insert_before %}}
|
|
|
54c0d5 |
insertbefore: '{{{ insert_before }}}'
|
|
|
54c0d5 |
{{%- endif %}}
|
|
|
54c0d5 |
- {{% else %}}
|
|
|
54c0d5 |
+ {{%- else %}}
|
|
|
54c0d5 |
state: '{{{ state }}}'
|
|
|
54c0d5 |
{{%- endif %}}
|
|
|
54c0d5 |
{{%- if validate %}}
|
|
|
54c0d5 |
diff --git a/shared/macros-oval.jinja b/shared/macros-oval.jinja
|
|
|
54c0d5 |
index cfa9de9d2d..5f391efdcb 100644
|
|
|
54c0d5 |
--- a/shared/macros-oval.jinja
|
|
|
54c0d5 |
+++ b/shared/macros-oval.jinja
|
|
|
54c0d5 |
@@ -13,13 +13,16 @@
|
|
|
54c0d5 |
- value (String): The value to be checked. This can also be a regular expression (e.g: value1|value2 can match both values).
|
|
|
54c0d5 |
- separator_regex (String): Regular expression to be used as the separator of parameter and value in a configuration file. If spaces are allowed, this should be included in the regular expression.
|
|
|
54c0d5 |
- missing_parameter_pass (boolean): If set, the check will also pass if the parameter is not present in the configuration file (default is applied).
|
|
|
54c0d5 |
- - application (String): The application which the configuration file is being checked. Can be any value and does not affect the OVAL check.
|
|
|
54c0d5 |
+ - application (String): The application which the configuration file is being checked. Can be any value and does not affect the actual OVAL check.
|
|
|
54c0d5 |
- multi_value (boolean): If set, it means that the parameter can accept multiple values and the expected value must be present in the current list of values.
|
|
|
54c0d5 |
- missing_config_file_fail (boolean): If set, the check will fail if the configuration is not existent in the system.
|
|
|
54c0d5 |
- section (String): If set, the parameter will be checked only within the given section defined by [section].
|
|
|
54c0d5 |
- quotes (String): If non-empty, one level of matching quotes is considered when checking the value. See comment of oval_line_in_file_state for more info.
|
|
|
54c0d5 |
#}}
|
|
|
54c0d5 |
{{%- macro oval_check_config_file(path='', prefix_regex='^[ \\t]*', parameter='', separator_regex='[ \\t]+', value='', missing_parameter_pass=false, application='', multi_value=false, missing_config_file_fail=false, section='', quotes='') -%}}
|
|
|
54c0d5 |
+{{%- if application == '' -%}}
|
|
|
54c0d5 |
+ {{%- set application = "The respective application or service" -%}}
|
|
|
54c0d5 |
+{{%- endif -%}}
|
|
|
54c0d5 |
<def-group>
|
|
|
54c0d5 |
<definition class="compliance" id="{{{ rule_id }}}" version="1">
|
|
|
54c0d5 |
<metadata>
|
|
|
54c0d5 |
@@ -248,6 +251,9 @@
|
|
|
54c0d5 |
- path (String): Path to the file.
|
|
|
54c0d5 |
- parameter (String): The shell variable name.
|
|
|
54c0d5 |
- value (String): The variable value WITHOUT QUOTES.
|
|
|
54c0d5 |
+ - application (String): The application which the configuration file is being checked. Can be any value and does not affect the actual OVAL check.
|
|
|
54c0d5 |
+ - no_quotes (boolean): If set, the check will require that the RHS of the assignment is the literal value, without quotes.
|
|
|
54c0d5 |
+ If no_quotes is false, then one level of single or double quotes won't be regarded as part of the value by the check.
|
|
|
54c0d5 |
- missing_parameter_pass (boolean): If set, the check will also pass if the parameter is not present in the configuration file (default is applied).
|
|
|
54c0d5 |
- multi_value (boolean): If set, it means that the parameter can accept multiple values and the expected value must be present in the current list of values.
|
|
|
54c0d5 |
- missing_config_file_fail (boolean): If set, the check will fail if the configuration file doesn't exist in the system.
|
|
|
54c0d5 |
@@ -342,7 +348,7 @@
|
|
|
54c0d5 |
- parameter (String): The parameter to be checked in the configuration file.
|
|
|
54c0d5 |
- value (String): The value to be checked. This can also be a regular expression (e.g: value1|value2 can match both values).
|
|
|
54c0d5 |
- missing_parameter_pass (boolean): If set, the check will also pass if the parameter is not present in the configuration file (default is applied).
|
|
|
54c0d5 |
- - application (String): The application which the configuration file is being checked. Can be any value and does not affect the OVAL check.
|
|
|
54c0d5 |
+ - application (String): The application which the configuration file is being checked. Can be any value and does not affect the actual OVAL check.
|
|
|
54c0d5 |
- multi_value (boolean): If set, it means that the parameter can accept multiple values and the expected value must be present in the current list of values.
|
|
|
54c0d5 |
- missing_config_file_fail (boolean): If set, the check will fail if the configuration is not existent in the system.
|
|
|
54c0d5 |
#}}
|
|
|
54c0d5 |
diff --git a/shared/templates/template_ANSIBLE_shell_lineinfile b/shared/templates/template_ANSIBLE_shell_lineinfile
|
|
|
54c0d5 |
index 7d0a3ebcbd..3e6c5619ea 100644
|
|
|
54c0d5 |
--- a/shared/templates/template_ANSIBLE_shell_lineinfile
|
|
|
54c0d5 |
+++ b/shared/templates/template_ANSIBLE_shell_lineinfile
|
|
|
54c0d5 |
@@ -3,7 +3,7 @@
|
|
|
54c0d5 |
# strategy = restrict
|
|
|
54c0d5 |
# complexity = low
|
|
|
54c0d5 |
# disruption = low
|
|
|
54c0d5 |
-{{% set msg = "shell-style assignment of '" ~ PARAMETER ~ "' to '" ~ VALUE ~ "' in '" ~ PATH ~ "'." -%}}
|
|
|
54c0d5 |
+{{% set msg = "shell-style assignment of '" ~ PARAMETER ~ "' to '" ~ VALUE ~ "' in '" ~ PATH ~ "'" -%}}
|
|
|
54c0d5 |
{{%- if NO_QUOTES -%}}
|
|
|
54c0d5 |
{{% set msg = "Setting unquoted " ~ msg %}}
|
|
|
54c0d5 |
{{%- else -%}}
|
|
|
54c0d5 |
@@ -15,7 +15,7 @@
|
|
|
54c0d5 |
path=PATH,
|
|
|
54c0d5 |
parameter=PARAMETER,
|
|
|
54c0d5 |
value=VALUE,
|
|
|
54c0d5 |
- no_quotes=NO_QUOTES
|
|
|
54c0d5 |
+ no_quotes=NO_QUOTES
|
|
|
54c0d5 |
)
|
|
|
54c0d5 |
}}}
|
|
|
54c0d5 |
|
|
|
54c0d5 |
|
|
|
54c0d5 |
From a7779d2fae1086838daa1ded483decd499e8749f Mon Sep 17 00:00:00 2001
|
|
|
54c0d5 |
From: =?UTF-8?q?Mat=C4=9Bj=20T=C3=BD=C4=8D?= <matyc@redhat.com>
|
|
|
54c0d5 |
Date: Tue, 21 Jan 2020 16:43:23 +0100
|
|
|
54c0d5 |
Subject: [PATCH 7/7] Add a shell_lineinfile template exemplary rule.
|
|
|
54c0d5 |
|
|
|
54c0d5 |
---
|
|
|
54c0d5 |
.../ssh_server/sshd_use_strong_rng/rule.yml | 47 +++++++++++++++++++
|
|
|
54c0d5 |
.../tests/bad_config.fail.sh | 3 ++
|
|
|
54c0d5 |
.../tests/good_config.pass.sh | 3 ++
|
|
|
54c0d5 |
.../tests/no_config.fail.sh | 3 ++
|
|
|
54c0d5 |
.../sshd_use_strong_rng/tests/quoted.fail.sh | 3 ++
|
|
|
54c0d5 |
rhel8/profiles/ospp.profile | 1 +
|
|
|
54c0d5 |
shared/references/cce-redhat-avail.txt | 1 -
|
|
|
54c0d5 |
7 files changed, 60 insertions(+), 1 deletion(-)
|
|
|
54c0d5 |
create mode 100644 linux_os/guide/services/ssh/ssh_server/sshd_use_strong_rng/rule.yml
|
|
|
54c0d5 |
create mode 100644 linux_os/guide/services/ssh/ssh_server/sshd_use_strong_rng/tests/bad_config.fail.sh
|
|
|
54c0d5 |
create mode 100644 linux_os/guide/services/ssh/ssh_server/sshd_use_strong_rng/tests/good_config.pass.sh
|
|
|
54c0d5 |
create mode 100644 linux_os/guide/services/ssh/ssh_server/sshd_use_strong_rng/tests/no_config.fail.sh
|
|
|
54c0d5 |
create mode 100644 linux_os/guide/services/ssh/ssh_server/sshd_use_strong_rng/tests/quoted.fail.sh
|
|
|
54c0d5 |
|
|
|
54c0d5 |
diff --git a/linux_os/guide/services/ssh/ssh_server/sshd_use_strong_rng/rule.yml b/linux_os/guide/services/ssh/ssh_server/sshd_use_strong_rng/rule.yml
|
|
|
54c0d5 |
new file mode 100644
|
|
|
54c0d5 |
index 0000000000..4bfb72702b
|
|
|
54c0d5 |
--- /dev/null
|
|
|
54c0d5 |
+++ b/linux_os/guide/services/ssh/ssh_server/sshd_use_strong_rng/rule.yml
|
|
|
54c0d5 |
@@ -0,0 +1,47 @@
|
|
|
54c0d5 |
+documentation_complete: true
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+# TODO: The plan is not to need this for RHEL>=8.4
|
|
|
54c0d5 |
+# TODO: Compliant setting is SSH_USE_STRONG_RNG set to 32 or more
|
|
|
54c0d5 |
+prodtype: rhel8
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+title: 'SSH server uses strong entropy to seed'
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+description: |-
|
|
|
54c0d5 |
+ To set up SSH server to use entropy from a high-quality source, edit the <tt>/etc/sysconfig/sshd</tt> file.
|
|
|
54c0d5 |
+ The <tt>SSH_USE_STRONG_RNG</tt> configuration value determines how many bytes of entropy to use, so
|
|
|
54c0d5 |
+ make sure that the file contains line
|
|
|
54c0d5 |
+ SSH_USE_STRONG_RNG=32
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+rationale: |-
|
|
|
54c0d5 |
+ SSH implementation in RHEL8 uses the openssl library, which doesn't use high-entropy sources by default.
|
|
|
54c0d5 |
+ Randomness is needed to generate data-encryption keys, and as plaintext padding and initialization vectors
|
|
|
54c0d5 |
+ in encryption algorithms, and high-quality entropy elliminates the possibility that the output of
|
|
|
54c0d5 |
+ the random number generator used by SSH would be known to potential attackers.
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+severity: medium
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+identifiers:
|
|
|
54c0d5 |
+ cce@rhel8: 82462-3
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+references:
|
|
|
54c0d5 |
+ ospp: FIA_AFL.1
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+ocil: |-
|
|
|
54c0d5 |
+ To determine whether the SSH service is configured to use strong entropy seed,
|
|
|
54c0d5 |
+ run $ sudo grep SSH_USE_STRONG_RNG /etc/sysconfig/sshd
|
|
|
54c0d5 |
+ If a line indicating that SSH_USE_STRONG_RNG is set to 32 is returned,
|
|
|
54c0d5 |
+ then the option is set correctly.
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+ocil_clause: |-
|
|
|
54c0d5 |
+ The SSH_USE_STRONG_RNG is not set to 32 in /etc/sysconfig/sshd
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+warnings:
|
|
|
54c0d5 |
+ - general: "This setting can cause problems on computers without the hardware random generator, because insufficient entropy causes the connection to be blocked until enough entropy is available."
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+template:
|
|
|
54c0d5 |
+ name: shell_lineinfile
|
|
|
54c0d5 |
+ vars:
|
|
|
54c0d5 |
+ path: '/etc/sysconfig/sshd'
|
|
|
54c0d5 |
+ parameter: 'SSH_USE_STRONG_RNG'
|
|
|
54c0d5 |
+ value: '32'
|
|
|
54c0d5 |
+ no_quotes: 'true'
|
|
|
54c0d5 |
diff --git a/linux_os/guide/services/ssh/ssh_server/sshd_use_strong_rng/tests/bad_config.fail.sh b/linux_os/guide/services/ssh/ssh_server/sshd_use_strong_rng/tests/bad_config.fail.sh
|
|
|
54c0d5 |
new file mode 100644
|
|
|
54c0d5 |
index 0000000000..f4f8c22f64
|
|
|
54c0d5 |
--- /dev/null
|
|
|
54c0d5 |
+++ b/linux_os/guide/services/ssh/ssh_server/sshd_use_strong_rng/tests/bad_config.fail.sh
|
|
|
54c0d5 |
@@ -0,0 +1,3 @@
|
|
|
54c0d5 |
+# platform = multi_platform_rhel
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+echo 'SSH_USE_STRONG_RNG=1' > /etc/sysconfig/sshd
|
|
|
54c0d5 |
diff --git a/linux_os/guide/services/ssh/ssh_server/sshd_use_strong_rng/tests/good_config.pass.sh b/linux_os/guide/services/ssh/ssh_server/sshd_use_strong_rng/tests/good_config.pass.sh
|
|
|
54c0d5 |
new file mode 100644
|
|
|
54c0d5 |
index 0000000000..70f53ac22b
|
|
|
54c0d5 |
--- /dev/null
|
|
|
54c0d5 |
+++ b/linux_os/guide/services/ssh/ssh_server/sshd_use_strong_rng/tests/good_config.pass.sh
|
|
|
54c0d5 |
@@ -0,0 +1,3 @@
|
|
|
54c0d5 |
+# platform = multi_platform_rhel
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+echo 'SSH_USE_STRONG_RNG=32' > /etc/sysconfig/sshd
|
|
|
54c0d5 |
diff --git a/linux_os/guide/services/ssh/ssh_server/sshd_use_strong_rng/tests/no_config.fail.sh b/linux_os/guide/services/ssh/ssh_server/sshd_use_strong_rng/tests/no_config.fail.sh
|
|
|
54c0d5 |
new file mode 100644
|
|
|
54c0d5 |
index 0000000000..1e5f0b2998
|
|
|
54c0d5 |
--- /dev/null
|
|
|
54c0d5 |
+++ b/linux_os/guide/services/ssh/ssh_server/sshd_use_strong_rng/tests/no_config.fail.sh
|
|
|
54c0d5 |
@@ -0,0 +1,3 @@
|
|
|
54c0d5 |
+# platform = multi_platform_rhel
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+rm -f /etc/sysconfig/sshd
|
|
|
54c0d5 |
diff --git a/linux_os/guide/services/ssh/ssh_server/sshd_use_strong_rng/tests/quoted.fail.sh b/linux_os/guide/services/ssh/ssh_server/sshd_use_strong_rng/tests/quoted.fail.sh
|
|
|
54c0d5 |
new file mode 100644
|
|
|
54c0d5 |
index 0000000000..a10d24a73b
|
|
|
54c0d5 |
--- /dev/null
|
|
|
54c0d5 |
+++ b/linux_os/guide/services/ssh/ssh_server/sshd_use_strong_rng/tests/quoted.fail.sh
|
|
|
54c0d5 |
@@ -0,0 +1,3 @@
|
|
|
54c0d5 |
+# platform = multi_platform_rhel
|
|
|
54c0d5 |
+
|
|
|
54c0d5 |
+echo 'SSH_USE_STRONG_RNG="32"' > /etc/sysconfig/sshd
|
|
|
54c0d5 |
diff --git a/rhel8/profiles/ospp.profile b/rhel8/profiles/ospp.profile
|
|
|
54c0d5 |
index f97527a914..63aea526b7 100644
|
|
|
54c0d5 |
--- a/rhel8/profiles/ospp.profile
|
|
|
54c0d5 |
+++ b/rhel8/profiles/ospp.profile
|
|
|
54c0d5 |
@@ -58,6 +58,7 @@ selections:
|
|
|
54c0d5 |
- sshd_set_keepalive
|
|
|
54c0d5 |
- sshd_enable_warning_banner
|
|
|
54c0d5 |
- sshd_rekey_limit
|
|
|
54c0d5 |
+ - sshd_use_strong_rng
|
|
|
54c0d5 |
|
|
|
54c0d5 |
# Time Server
|
|
|
54c0d5 |
- chronyd_client_only
|
|
|
54c0d5 |
diff --git a/shared/references/cce-redhat-avail.txt b/shared/references/cce-redhat-avail.txt
|
|
|
54c0d5 |
index b665fa1cea..1ff291c7df 100644
|
|
|
54c0d5 |
--- a/shared/references/cce-redhat-avail.txt
|
|
|
54c0d5 |
+++ b/shared/references/cce-redhat-avail.txt
|
|
|
54c0d5 |
@@ -1,4 +1,3 @@
|
|
|
54c0d5 |
-CCE-82462-3
|
|
|
54c0d5 |
CCE-82463-1
|
|
|
54c0d5 |
CCE-82464-9
|
|
|
54c0d5 |
CCE-82465-6
|