Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Dockerfiles/test_suite-sle15
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ENV AUTH_KEYS=/root/.ssh/authorized_keys
ARG CLIENT_PUBLIC_KEY
ARG ADDITIONAL_PACKAGES

RUN zypper ar --no-gpgcheck http://download.opensuse.org/distribution/leap/15.5/repo/oss/ oss
RUN zypper ar --no-gpgcheck http://download.opensuse.org/distribution/leap/15.6/repo/oss/ oss
RUN zypper refresh

RUN true \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,28 @@
# disruption = low
{{{ ansible_instantiate_variables("sshd_approved_ciphers") }}}

{{{ ansible_sshd_set(parameter="Ciphers", value="{{ sshd_approved_ciphers }}", rule_title=rule_title) }}}
{{% if product in [ 'sle16', 'slmicro6' ] %}}
{{{ ansible_copy_distro_defaults("/usr/etc/ssh/sshd_config", sshd_main_config_file, rule_title=rule_title) }}}
- name: Check if SSH {{{ sshd_main_config_file }}} configuration file exists
ansible.builtin.stat:
path: {{{ sshd_main_config_file }}}
register: sshd_main_config_file_{{{ rule_id }}}
{{{
ansible_lineinfile(
rule_title + ' - Remove /usr/etc/ssh/sshd_config.d/*.conf include directive from ' + sshd_main_config_file,
path=sshd_main_config_file,
regex='^\s*Include\s+\/usr\/etc\/ssh\/sshd_config\.d/\*\.conf',
state='absent',
when='sshd_main_config_file_' + rule_id + '.stat.exists'
)
}}}
{{% endif %}}

{{{
ansible_sshd_set(
parameter="Ciphers",
value="{{ sshd_approved_ciphers }}",
config_is_distributed=sshd_distributed_config,
rule_title=rule_title
)
}}}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

{{{ bash_instantiate_variables("sshd_approved_ciphers") }}}

{{% if product in ['sle16', 'slmicro6'] %}}
{{{ bash_copy_distro_defaults("/usr/etc/ssh/sshd_config", sshd_main_config_file) }}}
{{{ lineinfile_absent(sshd_main_config_file, "^\s*Include\s*/usr/etc/ssh/sshd_config\.d/\*\.conf", sed_path_separator="#", rule_id=rule_id) }}}
{{% endif %}}

{{{ bash_sshd_remediation(
parameter="Ciphers",
value="$sshd_approved_ciphers",
config_is_distributed=sshd_distributed_config,
rule_id=rule_id) }}}
rule_id=rule_id)
}}}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{%- set sshd_main_config = sshd_main_config_file -%}}
{{%- set sshd_drop_in_dir = sshd_config_dir -%}}
<def-group>
<definition class="compliance" id="sshd_use_approved_ciphers" version="1">
{{{ oval_metadata("Limit the ciphers to those which are FIPS-approved.", rule_title=rule_title) }}}
Expand All @@ -15,14 +16,29 @@
definition_ref="sshd_required_or_unset" />
<extend_definition comment="rpm package openssh-server installed"
definition_ref="package_openssh-server_installed" />
<criterion comment="Check the Ciphers list in /etc/ssh/sshd_config"
{{% if product in [ 'sle16', 'slmicro6' ] %}}
<criterion comment="test if SSH main configuration {{{ sshd_main_config }}} exists for {{{ rule_id }}}"
test_ref="test_{{{ rule_id }}}_config_file_exists"/>
{{% endif %}}
<criterion comment="Check the Ciphers list in {{{ sshd_main_config }}}"
test_ref="test_sshd_use_approved_ciphers" />
{{%- if sshd_distributed_config == "true" %}}
<criterion comment="Check the Ciphers list in {{{ sshd_config_dir }}}"
test_ref="test_sshd_use_approved_ciphers_config_dir" />
{{%- endif %}}
<criterion comment="the configuration exists"
test_ref="test_sshd_ciphers_exists" />
</criteria>
</criteria>
</definition>

<ind:variable_test check="all" check_existence="all_exist"
comment="tests the value of Ciphers setting in the /etc/ssh/sshd_config file"
{{% if product in [ 'sle16', 'slmicro6' ] %}}
{{{ oval_config_file_exists_test(sshd_main_config, rule_id=rule_id) }}}
{{{ oval_config_file_exists_object(sshd_main_config, rule_id=rule_id) }}}
{{% endif %}}

<ind:variable_test check="all" check_existence="any_exist"
comment="tests the value of Ciphers setting in the {{{ sshd_main_config }}} file"
id="test_sshd_use_approved_ciphers" version="1">
<ind:object object_ref="obj_sshd_use_approved_ciphers" />
<ind:state state_ref="ste_sshd_use_approved_ciphers" />
Expand All @@ -32,8 +48,8 @@
<ind:var_ref>var_sshd_config_ciphers</ind:var_ref>
</ind:variable_object>

<ind:variable_state comment="approved ciphers" id="ste_sshd_use_approved_ciphers" version="1">
<ind:value operation="equals" datatype="string" var_ref="var_sshd_approved_ciphers" var_check="at least one" />
<ind:variable_state comment="approved ciphers list" id="ste_sshd_use_approved_ciphers" version="1">
<ind:value operation="equals" datatype="string" var_ref="var_sshd_approved_ciphers" var_check="at least one"/>
</ind:variable_state>

<ind:textfilecontent54_object id="obj_sshd_config_ciphers" version="1">
Expand All @@ -48,6 +64,50 @@
</split>
</local_variable>

{{%- if sshd_distributed_config == "true" %}}
<ind:variable_test check="all" check_existence="any_exist"
comment="tests the value of Ciphers setting in {{{ sshd_drop_in_dir }}}"
id="test_sshd_use_approved_ciphers_config_dir" version="1">
<ind:object object_ref="obj_sshd_use_approved_ciphers_config_dir" />
<ind:state state_ref="ste_sshd_use_approved_ciphers_config_dir" />
</ind:variable_test>

<ind:variable_object id="obj_sshd_use_approved_ciphers_config_dir" version="1">
<ind:var_ref>var_sshd_config_ciphers_config_dir</ind:var_ref>
</ind:variable_object>

<ind:variable_state comment="approved ciphers list" id="ste_sshd_use_approved_ciphers_config_dir" version="1">
<ind:value operation="equals" datatype="string" var_ref="var_sshd_approved_ciphers" var_check="at least one" />
</ind:variable_state>

<ind:textfilecontent54_object id="obj_sshd_config_ciphers_config_dir" version="1">
<ind:path>{{{ sshd_drop_in_dir }}}</ind:path>
<ind:filename operation="pattern match">.*\.conf$</ind:filename>
<ind:pattern operation="pattern match">^[\s]*(?i)Ciphers(?-i)[\s]+([\w,-@]+)+[\s]*(?:#.*)?$</ind:pattern>
<ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
</ind:textfilecontent54_object>

<local_variable id="var_sshd_config_ciphers_config_dir" datatype="string" version="1" comment="Ciphers values split on comma">
<split delimiter=",">
<object_component item_field="subexpression" object_ref="obj_sshd_config_ciphers_config_dir" />
</split>
</local_variable>
{{%- endif %}}

<ind:textfilecontent54_test id="test_sshd_ciphers_exists" version="1" check="all" check_existence="at_least_one_exists"
comment="Verify that the value of Ciphers is present">
<ind:object object_ref="obj_sshd_ciphers_all_configs" />
</ind:textfilecontent54_test>

<ind:textfilecontent54_object comment="All confs collection" id="obj_sshd_ciphers_all_configs" version="1">
<set>
<object_reference>obj_sshd_config_ciphers</object_reference>
{{% if sshd_distributed_config == "true" %}}
<object_reference>obj_sshd_config_ciphers_config_dir</object_reference>
{{% endif %}}
</set>
</ind:textfilecontent54_object>

<local_variable id="var_sshd_approved_ciphers" datatype="string" version="1" comment="approved ciphers values split on comma">
<split delimiter=",">
<variable_component var_ref="sshd_approved_ciphers" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
{{% if sshd_distributed_config == "false" %}}
# platform = Not Applicable
{{% else %}}
# platform = multi_platform_sle
{{% endif %}}

source include.sh
{{% if product in [ 'sle16', 'slmicro6' ] %}}
touch "{{{ sshd_main_config_file }}}"
{{% endif %}}

echo 'Ciphers aes128-ctr,aes192-ctr' >> "{{{ sshd_config_dir }}}/00-test.conf"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
{{% if sshd_distributed_config == "false" %}}
# platform = Not Applicable
{{% else %}}
# platform = multi_platform_sle
{{% endif %}}

source include.sh
{{% if product in [ 'sle16', 'slmicro6' ] %}}
touch "{{{ sshd_main_config_file }}}"
{{% endif %}}
echo 'Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,aes192-cbc,aes256-cbc,3des-cbc,rijndael-cbc@lysator.liu.se' >> "{{{ sshd_config_dir }}}/00-test.conf"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
{{% if sshd_distributed_config == "false" %}}
# platform = Not Applicable
{{% else %}}
# platform = multi_platform_sle
{{% endif %}}
# variables = sshd_approved_ciphers=ijkl158,sits,wwq-98,kl24

source include.sh
{{% if product in [ 'sle16', 'slmicro6' ] %}}
touch "{{{ sshd_main_config_file }}}"
{{% endif %}}

echo 'Ciphers ijkl158,sits,wwq-98,kl24' >> "{{{ sshd_config_dir }}}/00-test.conf"
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

declare -a SSHD_PATHS=({{{ sshd_main_config_file }}})
{{% if product in [ 'sle16', 'slmicro6' ] %}}
SSHD_PATHS+=({{{ sshd_config_dir }}}/*)
{{% endif %}}
# clean up configurations
sed -i '/^Ciphers.*/d' "${SSHD_PATHS[@]}"

# restore to defaults for sle16 and slmicro6
{{% if product in [ 'sle16', 'slmicro6' ] %}}
if [ -e "{{{ sshd_main_config_file }}}" ] ; then
rm "{{{ sshd_main_config_file }}}"
fi
{{% endif %}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
{{% if sshd_distributed_config == "false" %}}
# platform = Not Applicable
{{% else %}}
# platform = multi_platform_sle
{{% endif %}}

source include.sh
{{% if product in [ 'sle16', 'slmicro6' ] %}}
touch "{{{ sshd_main_config_file }}}"
{{% endif %}}
echo 'Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,aes192-cbc,aes256-cbc,3des-cbc,rijndael-cbc@lysator.liu.se' >> {{{ sshd_main_config_file }}}
echo 'Ciphers weak-cipher' >> "{{{ sshd_config_dir }}}/00-test.conf"
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,21 @@
{{{ ansible_instantiate_variables('sshd_approved_ciphers') }}}
{{{ ansible_sshd_set(parameter="Ciphers", value="{{ sshd_approved_ciphers }}", config_is_distributed=sshd_distributed_config, rule_title=rule_title) }}}
{{%- else %}}
{{% if product in [ 'sle16', 'slmicro6' ] %}}
{{{ ansible_copy_distro_defaults("/usr/etc/ssh/sshd_config", sshd_main_config_file, rule_title=rule_title) }}}
- name: Check if SSH {{{ sshd_main_config_file }}} configuration file exists
ansible.builtin.stat:
path: {{{ sshd_main_config_file }}}
register: sshd_main_config_file_{{{ rule_id }}}
{{{
ansible_lineinfile(
rule_title + ' - Remove /usr/etc/ssh/sshd_config.d/*.conf include directive from ' + sshd_main_config_file,
path=sshd_main_config_file,
regex='^\s*Include\s+\/usr\/etc\/ssh\/sshd_config\.d/\*\.conf',
state='absent',
when='sshd_main_config_file_' + rule_id + '.stat.exists'
)
}}}
{{% endif %}}
{{{ ansible_sshd_set(parameter="Ciphers", value="aes256-ctr,aes192-ctr,aes128-ctr", config_is_distributed=sshd_distributed_config, rule_title=rule_title) }}}
{{%- endif %}}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# platform = Oracle Linux 7,multi_platform_sle,multi_platform_slmicro

{{% if product in ['sle16', 'slmicro6'] %}}
{{{ bash_copy_distro_defaults("/usr/etc/ssh/sshd_config", sshd_main_config_file) }}}
{{{ lineinfile_absent(sshd_main_config_file, "^\s*Include\s*/usr/etc/ssh/sshd_config\.d/\*\.conf", sed_path_separator="#", rule_id=rule_id) }}}
{{% endif %}}

{{{ bash_sshd_remediation(
parameter="Ciphers",
value="aes256-ctr,aes192-ctr,aes128-ctr",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,95 @@
{{%- set sshd_main_config = sshd_main_config_file -%}}
{{%- set sshd_drop_in_dir = sshd_config_dir -%}}
{{% set sufix_conf="(\s.*)?" %}}
{{% set prefix_conf="^\s*Ciphers\s*" %}}
{{% set ciphers=["aes256-ctr","aes192-ctr","aes128-ctr"] %}}
{{% set ciphers_regex=prefix_conf ~ "(?=[\w-])" "(\\b" ~ ciphers|join("\\b,?)?(\\b") ~ ")?" ~ sufix_conf ~ "[\\s]*(?:#.*)?$" %}}
<def-group>
<definition class="compliance" id="sshd_use_approved_ciphers_ordered_stig" version="1">
<definition class="compliance" id="{{{ rule_id }}}" version="1">
{{{ oval_metadata("Limit the ciphers to those which are FIPS-approved.", rule_title=rule_title) }}}
<criteria comment="SSH is configured correctly or is not installed"
operator="OR">
<criteria comment="sshd is configured correctly or is not installed" operator="OR">
<criteria comment="sshd is not installed" operator="AND">
<extend_definition comment="sshd is not required or requirement is unset"
definition_ref="sshd_not_required_or_unset" />
<extend_definition comment="rpm package openssh-server removed"
definition_ref="package_openssh-server_removed" />
definition_ref="sshd_not_required_or_unset" />
<extend_definition comment="package openssh-server removed"
definition_ref="package_openssh-server_removed" />
</criteria>

<criteria comment="sshd is installed and configured" operator="AND">
<extend_definition comment="sshd is required or requirement is unset"
definition_ref="sshd_required_or_unset" />
<extend_definition comment="rpm package openssh-server installed"
definition_ref="package_openssh-server_installed" />
<criterion comment="Check the Ciphers list in /etc/ssh/sshd_config"
test_ref="test_sshd_use_approved_ciphers_ordered_stig" />
definition_ref="sshd_required_or_unset" />
<extend_definition comment="package openssh-server installed"
definition_ref="package_openssh-server_installed" />
<criteria comment="sshd is configured correctly" operator="AND">
<criteria comment="the configuration is correct if it exists" operator="AND">
{{% if product in [ 'sle16', 'slmicro6' ] %}}
<criterion comment="test if SSH main configuration {{{ sshd_main_config }}} exists for {{{ rule_id }}}"
test_ref="test_{{{ rule_id }}}_config_file_exists"/>
{{% endif %}}
<criterion comment="Check the ciphers in {{{ sshd_main_config }}} if any"
test_ref="test_{{{ rule_id }}}" />
{{%- if sshd_distributed_config == "true" %}}
<criterion comment="Check the ciphers in {{{ sshd_drop_in_dir }}} if any"
test_ref="test_{{{ rule_id }}}_config_dir" />
{{%- endif %}}
</criteria>
<criterion comment="the configuration exists" test_ref="test_ciphers_present_{{{ rule_id }}}" />
</criteria>
</criteria>

</criteria>
</definition>

<ind:textfilecontent54_test check="all" check_existence="all_exist"
comment="tests the value of Ciphers setting in the /etc/ssh/sshd_config file"
id="test_sshd_use_approved_ciphers_ordered_stig" version="1">
<ind:object object_ref="obj_sshd_use_approved_ciphers_ordered_stig" />
{{% if product in [ 'sle16', 'slmicro6' ] %}}
{{{ oval_config_file_exists_test(sshd_main_config, rule_id=rule_id) }}}
{{{ oval_config_file_exists_object(sshd_main_config, rule_id=rule_id) }}}
{{% endif %}}
<ind:textfilecontent54_test check="all" check_existence="any_exist"
comment="tests the value of ciphers setting in the {{{ sshd_main_config }}} file"
id="test_{{{ rule_id }}}" version="1">
<ind:object object_ref="obj_{{{ rule_id }}}" />
<ind:state state_ref="state_{{{ rule_id }}}" />
</ind:textfilecontent54_test>

<ind:textfilecontent54_object id="obj_sshd_use_approved_ciphers_ordered_stig" version="1">
<ind:textfilecontent54_state id="state_{{{ rule_id }}}" version="1">
<ind:text operation="pattern match">{{{ ciphers_regex }}}</ind:text>
</ind:textfilecontent54_state>

<ind:textfilecontent54_object id="obj_{{{ rule_id }}}" version="1">
<ind:filepath>{{{ sshd_main_config }}}</ind:filepath>
<ind:pattern operation="pattern match">^[\s]*(?i)Ciphers(?-i)[\s]+(?=[\w]+)(aes256-ctr(?=[\w,]+|$),?)?(aes192-ctr(?=[\w,]+|$),?)?(aes128-ctr)?[\s]*(?:#.*)?$</ind:pattern>
<ind:instance datatype="int">1</ind:instance>
<ind:pattern operation="pattern match">{{{ prefix_conf }}}.*</ind:pattern>
<ind:instance datatype="int" operation="greater than or equal" >1</ind:instance>
</ind:textfilecontent54_object>
Comment thread
teacup-on-rockingchair marked this conversation as resolved.

{{%- if sshd_distributed_config == "true" %}}
<ind:textfilecontent54_test check="all" check_existence="any_exist"
comment="tests the value of ciphers setting in the {{{ sshd_drop_in_dir }}} file"
id="test_{{{ rule_id }}}_config_dir" version="1">
<ind:object object_ref="obj_{{{ rule_id }}}_config_dir" />
<ind:state state_ref="state_{{{ rule_id }}}" />
</ind:textfilecontent54_test>

<ind:textfilecontent54_object id="obj_{{{ rule_id }}}_config_dir" version="1">
<ind:path>{{{ sshd_drop_in_dir }}}</ind:path>
<ind:filename operation="pattern match">.*\.conf$</ind:filename>
<ind:pattern operation="pattern match">{{{ prefix_conf }}}.*</ind:pattern>
<ind:instance datatype="int" operation="greater than or equal" >1</ind:instance>
</ind:textfilecontent54_object>
{{%- endif %}}

<ind:textfilecontent54_object comment="All confs collection" id="obj_collection_obj_{{{ rule_id }}}" version="1">
<set>
<object_reference>obj_{{{ rule_id }}}</object_reference>
{{% if sshd_distributed_config == "true" %}}
<object_reference>obj_{{{ rule_id }}}_config_dir</object_reference>
{{% endif %}}
</set>
</ind:textfilecontent54_object>

<ind:textfilecontent54_test id="test_ciphers_present_{{{ rule_id }}}" version="1"
check="all" check_existence="at_least_one_exists"
comment="Verify that the value of ciphers is present">
<ind:object object_ref="obj_collection_obj_{{{ rule_id }}}" />
</ind:textfilecontent54_test>

</def-group>
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

source common.sh

echo "ciphers $sshd_approved_ciphers" >> /etc/ssh/sshd_config
echo "Ciphers $sshd_approved_ciphers" >> /etc/ssh/sshd_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

source common.sh

echo "Ciphers $sshd_approved_ciphers" >> "{{{ sshd_config_dir }}}/00-test.conf"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

source common.sh

echo "Ciphers $sshd_approved_ciphers,weak-cipher" >> "{{{ sshd_config_dir }}}/00-test.conf"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# platform = multi_platform_sle
source common.sh

echo "Ciphers $sshd_approved_ciphers" >> "{{{ sshd_config_dir }}}/00-test.conf"
echo "Ciphers weak-cipher" >> "{{{ sshd_config_dir }}}/01-test.conf"
Loading
Loading