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

SLE platforms use drop in file for sysctl variables for SLE platforms #10367

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/templates/template_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,10 @@ The selected value can be changed in the profile (consult the actual variable fo
- **sysctlval_regex** - if **operation** is `pattern match`, this
parameter is used instead of **sysctlval**.

In case the **sysctl_remediate_drop_in_file** property is set to true in the product file,
the remediation scripts will set the variable with correct value to a drop-in file in
`/etc/sysctl.d/var_name.conf` file.

- Languages: Ansible, Bash, OVAL

#### timer_enabled
Expand Down
2 changes: 2 additions & 0 deletions products/sle12/product.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ reference_uris:
cis: 'https://www.cisecurity.org/benchmark/suse_linux/'

dconf_gdm_dir: "gdm.d"

sysctl_remediate_drop_in_file: "true"
2 changes: 2 additions & 0 deletions products/sle15/product.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ reference_uris:
cis: 'https://www.cisecurity.org/benchmark/suse_linux/'

dconf_gdm_dir: "gdm.d"

sysctl_remediate_drop_in_file: "true"
13 changes: 13 additions & 0 deletions shared/templates/sysctl/ansible.template
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
replace: '#{{{ SYSCTLVAR }}}'
loop: "{{ find_sysctl_d.files }}"

{{% if sysctl_remediate_drop_in_file == "true" %}}
- name: Comment out any occurrences of {{{ SYSCTLVAR }}} from /etc/sysctl.conf
replace:
path: "/etc/sysctl.conf"
regexp: '^[\s]*{{{ SYSCTLVAR }}}'
replace: '#{{{ SYSCTLVAR }}}'
{{% endif %}}

{{%- if SYSCTLVAL == "" or SYSCTLVAL is not string %}}
- (xccdf-var sysctl_{{{ SYSCTLID }}}_value)

Expand All @@ -45,6 +53,11 @@
name: "{{{ SYSCTLVAR }}}"
value: "{{{ SYSCTLVAL }}}"
{{%- endif %}}
{{% if sysctl_remediate_drop_in_file == "true" %}}
sysctl_file: "/etc/sysctl.d/{{{ SYSCTLVAR | replace('.','_') }}}.conf"
{{% else %}}
sysctl_file: "/etc/sysctl.conf"
{{% endif %}}
state: present
reload: yes

20 changes: 18 additions & 2 deletions shared/templates/sysctl/bash.template
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.con
fi
done

#
# Set sysctl config file which to save the desired value
#
{{% if sysctl_remediate_drop_in_file == "true" %}}
SYSCONFIG_FILE='/etc/sysctl.d/{{{ SYSCTLVAR | replace(".","_") }}}.conf'
{{% else %}}
SYSCONFIG_FILE="/etc/sysctl.conf"
{{% endif %}}

{{%- if SYSCTLVAL == "" or SYSCTLVAL is not string %}}
{{{ bash_instantiate_variables("sysctl_" ~ SYSCTLID ~ "_value") }}}

Expand All @@ -34,7 +43,11 @@ done
# If {{{ SYSCTLVAR }}} present in /etc/sysctl.conf, change value to appropriate value
# else, add "{{{ SYSCTLVAR }}} = value" to /etc/sysctl.conf
#
{{{ bash_replace_or_append('/etc/sysctl.conf', '^' ~ SYSCTLVAR , '$sysctl_' ~ SYSCTLID ~ '_value') }}}
{{% if sysctl_remediate_drop_in_file == "true" %}}
sed -i "/^$SYSCONFIG_VAR/d" /etc/sysctl.conf
{{% endif %}}
{{{ bash_replace_or_append('${SYSCONFIG_FILE}', '^' ~ SYSCTLVAR , '$sysctl_' ~ SYSCTLID ~ '_value') }}}

{{%- else %}}

#
Expand All @@ -46,5 +59,8 @@ done
# If {{{ SYSCTLVAR }}} present in /etc/sysctl.conf, change value to "{{{ SYSCTLVAL }}}"
# else, add "{{{ SYSCTLVAR }}} = {{{ SYSCTLVAL }}}" to /etc/sysctl.conf
#
{{{ bash_replace_or_append('/etc/sysctl.conf', '^' ~ SYSCTLVAR , SYSCTLVAL ) }}}
{{% if sysctl_remediate_drop_in_file == "true" %}}
sed -i "/^$SYSCONFIG_VAR/d" /etc/sysctl.conf
{{% endif %}}
{{{ bash_replace_or_append('${SYSCONFIG_FILE}', '^' ~ SYSCTLVAR , SYSCTLVAL ) }}}
{{%- endif %}}
1 change: 1 addition & 0 deletions ssg/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,4 @@
DEFAULT_PRODUCT = 'example'
DEFAULT_CHRONY_CONF_PATH = '/etc/chrony.conf'
DEFAULT_AUDISP_CONF_PATH = '/etc/audit'
DEFAULT_SYSCTL_REMEDIATE_DROP_IN_FILE = 'false'
3 changes: 3 additions & 0 deletions ssg/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ def _get_implied_properties(existing_properties):
if "faillock_path" not in existing_properties:
result["faillock_path"] = DEFAULT_FAILLOCK_PATH

if "sysctl_remediate_drop_in_file" not in existing_properties:
result["sysctl_remediate_drop_in_file"] = DEFAULT_SYSCTL_REMEDIATE_DROP_IN_FILE
yuumasato marked this conversation as resolved.
Show resolved Hide resolved

return result


Expand Down