|
| 1 | +{{% macro test_sshd_lineinfile(filepath, param, id) %}} |
| 2 | +{{%- set object_id = filepath | replace("/", "_") | replace("-", "_") | replace(".", "_") -%}} |
| 3 | + <ind:textfilecontent54_test id="{{{ id }}}" version="1" check="all" |
| 4 | + check_existence="only_one_exists" comment="Check if there is an {{{ param }}} entry in {{{ filepath }}}"> |
| 5 | + <ind:object object_ref="object_{{{ param }}}{{{ object_id }}}" /> |
| 6 | + </ind:textfilecontent54_test> |
| 7 | + <ind:textfilecontent54_object id="object_{{{ param }}}{{{ object_id }}}" version="1"> |
| 8 | + <ind:filepath operation="pattern match">^{{{ filepath }}}</ind:filepath> |
| 9 | + <ind:pattern operation="pattern match" datatype="string">(?i)^[ ]*{{{ param }}}[ ]+((?:[^ \n]+[ ]*)+)$</ind:pattern> |
| 10 | + <ind:instance operation="greater than or equal" datatype="int">1</ind:instance> |
| 11 | + </ind:textfilecontent54_object> |
| 12 | +{{% endmacro %}} |
| 13 | + |
| 14 | +{{% macro test_sshd_lineindir(filepath, param, id) %}} |
| 15 | +{{%- set object_id = filepath | replace("/", "_") | replace("-", "_") | replace(".", "_") -%}} |
| 16 | + <ind:textfilecontent54_test id="{{{ id }}}" version="1" check="all" |
| 17 | + check_existence="only_one_exists" comment="Check if there is an {{{ param }}} entry in {{{ filepath }}}"> |
| 18 | + <ind:object object_ref="object_{{{ param }}}{{{ object_id }}}" /> |
| 19 | + </ind:textfilecontent54_test> |
| 20 | + <ind:textfilecontent54_object id="object_{{{ param }}}{{{ object_id }}}" version="1"> |
| 21 | + <ind:path>{{{ filepath }}}</ind:path> |
| 22 | + <ind:filename operation="pattern match">.*\.conf$</ind:filename> |
| 23 | + <ind:pattern operation="pattern match" datatype="string">(?i)^[ ]*{{{ param }}}[ ]+((?:[^ \n]+[ ]*)+)$</ind:pattern> |
| 24 | + <ind:instance operation="greater than or equal" datatype="int">1</ind:instance> |
| 25 | + </ind:textfilecontent54_object> |
| 26 | +{{% endmacro %}} |
| 27 | + |
| 28 | +<def-group> |
| 29 | + <definition class="compliance" id="{{{ rule_id }}}" version="1"> |
| 30 | + {{{ oval_metadata("One of the following parameters of the sshd configuration file is set: AllowUsers, DenyUsers, AllowGroups, DenyGroups.", rule_title=rule_title) }}} |
| 31 | + <criteria operator="OR" comment="sshd limits the users who can log in"> |
| 32 | + <criteria comment="AllowUsers, DenyUsers, AllowGroups, DenyGroups when using /etc/ssh/sshd_config" operator="AND"> |
| 33 | + <criterion comment="SSH configuration /etc/ssh/sshd_config exists" test_ref="test_etc_ssh_sshd_config_exist"/> |
| 34 | + <criteria operator="OR"> |
| 35 | + <criterion test_ref="test_allow_user_is_configured_etc_ssh_sshdconfig" /> |
| 36 | + <criterion test_ref="test_allow_groups_is_configured_etc_ssh_sshdconfig" /> |
| 37 | + <criterion test_ref="test_deny_users_is_configured_etc_ssh_sshdconfig" /> |
| 38 | + <criterion test_ref="test_deny_groups_is_configured_etc_ssh_sshdconfig" /> |
| 39 | + <criterion test_ref="test_allow_user_is_configured_etc_ssh_sshdconfig_dir" /> |
| 40 | + <criterion test_ref="test_allow_groups_is_configured_etc_ssh_sshdconfig_dir" /> |
| 41 | + <criterion test_ref="test_deny_users_is_configured_etc_ssh_sshdconfig_dir" /> |
| 42 | + <criterion test_ref="test_deny_groups_is_configured_etc_ssh_sshdconfig_dir" /> |
| 43 | + <criterion test_ref="test_allow_user_is_configured_usr_etc_ssh_sshdconfig_dir" /> |
| 44 | + <criterion test_ref="test_allow_groups_is_configured_usr_etc_ssh_sshdconfig_dir" /> |
| 45 | + <criterion test_ref="test_deny_users_is_configured_usr_etc_ssh_sshdconfig_dir" /> |
| 46 | + <criterion test_ref="test_deny_groups_is_configured_usr_etc_ssh_sshdconfig_dir" /> |
| 47 | + </criteria> |
| 48 | + </criteria> |
| 49 | + <criteria comment="AllowUsers, DenyUsers, AllowGroups, DenyGroups when using /usr/etc/ssh/sshd_config" operator="AND"> |
| 50 | + <criterion comment="SSH configuration /etc/ssh/sshd_config does not exists" test_ref="test_etc_ssh_sshd_config_exist" negate="true"/> |
| 51 | + <criteria operator="OR"> |
| 52 | + <criterion test_ref="test_allow_user_is_configured_usr_etc_ssh_sshdconfig" /> |
| 53 | + <criterion test_ref="test_allow_groups_is_configured_usr_etc_ssh_sshdconfig" /> |
| 54 | + <criterion test_ref="test_deny_users_is_configured_usr_etc_ssh_sshdconfig" /> |
| 55 | + <criterion test_ref="test_deny_groups_is_configured_usr_etc_ssh_sshdconfig" /> |
| 56 | + <criterion test_ref="test_allow_user_is_configured_etc_ssh_sshdconfig_dir" /> |
| 57 | + <criterion test_ref="test_allow_groups_is_configured_etc_ssh_sshdconfig_dir" /> |
| 58 | + <criterion test_ref="test_deny_users_is_configured_etc_ssh_sshdconfig_dir" /> |
| 59 | + <criterion test_ref="test_deny_groups_is_configured_etc_ssh_sshdconfig_dir" /> |
| 60 | + <criterion test_ref="test_allow_user_is_configured_usr_etc_ssh_sshdconfig_dir" /> |
| 61 | + <criterion test_ref="test_allow_groups_is_configured_usr_etc_ssh_sshdconfig_dir" /> |
| 62 | + <criterion test_ref="test_deny_users_is_configured_usr_etc_ssh_sshdconfig_dir" /> |
| 63 | + <criterion test_ref="test_deny_groups_is_configured_usr_etc_ssh_sshdconfig_dir" /> |
| 64 | + </criteria> |
| 65 | + </criteria> |
| 66 | + </criteria> |
| 67 | + </definition> |
| 68 | + |
| 69 | + <unix:file_test check="all" check_existence="all_exist" |
| 70 | + comment="SSH configuration /etc/ssh/sshd_config exists" |
| 71 | + id="test_etc_ssh_sshd_config_exist" |
| 72 | + state_operator="AND" version="1"> |
| 73 | + <unix:object object_ref="obj_etc_ssh_sshd_config_exist"/> |
| 74 | + </unix:file_test> |
| 75 | + <unix:file_object |
| 76 | + comment="SSH configuration /etc/ssh/sshd_config exists" |
| 77 | + id="obj_etc_ssh_sshd_config_exist" version="1"> |
| 78 | + <unix:filepath operation="pattern match">^/etc/ssh/sshd_config</unix:filepath> |
| 79 | + </unix:file_object> |
| 80 | + |
| 81 | + {{{ test_sshd_lineinfile("/etc/ssh/sshd_config", "AllowUsers", "test_allow_user_is_configured_etc_ssh_sshdconfig") }}} |
| 82 | + {{{ test_sshd_lineinfile("/etc/ssh/sshd_config", "AllowGroups", "test_allow_groups_is_configured_etc_ssh_sshdconfig") }}} |
| 83 | + {{{ test_sshd_lineinfile("/etc/ssh/sshd_config", "DenyUsers", "test_deny_users_is_configured_etc_ssh_sshdconfig") }}} |
| 84 | + {{{ test_sshd_lineinfile("/etc/ssh/sshd_config", "DenyGroups", "test_deny_groups_is_configured_etc_ssh_sshdconfig") }}} |
| 85 | + |
| 86 | + {{{ test_sshd_lineinfile("/usr/etc/ssh/sshd_config", "AllowUsers", "test_allow_user_is_configured_usr_etc_ssh_sshdconfig") }}} |
| 87 | + {{{ test_sshd_lineinfile("/usr/etc/ssh/sshd_config", "AllowGroups", "test_allow_groups_is_configured_usr_etc_ssh_sshdconfig") }}} |
| 88 | + {{{ test_sshd_lineinfile("/usr/etc/ssh/sshd_config", "DenyUsers", "test_deny_users_is_configured_usr_etc_ssh_sshdconfig") }}} |
| 89 | + {{{ test_sshd_lineinfile("/usr/etc/ssh/sshd_config", "DenyGroups", "test_deny_groups_is_configured_usr_etc_ssh_sshdconfig") }}} |
| 90 | + |
| 91 | + {{{ test_sshd_lineindir("/etc/ssh/sshd_config.d", "AllowUsers", "test_allow_user_is_configured_etc_ssh_sshdconfig_dir") }}} |
| 92 | + {{{ test_sshd_lineindir("/etc/ssh/sshd_config.d", "AllowGroups", "test_allow_groups_is_configured_etc_ssh_sshdconfig_dir") }}} |
| 93 | + {{{ test_sshd_lineindir("/etc/ssh/sshd_config.d", "DenyUsers", "test_deny_users_is_configured_etc_ssh_sshdconfig_dir") }}} |
| 94 | + {{{ test_sshd_lineindir("/etc/ssh/sshd_config.d", "DenyGroups", "test_deny_groups_is_configured_etc_ssh_sshdconfig_dir") }}} |
| 95 | + |
| 96 | + {{{ test_sshd_lineindir("/usr/etc/ssh/sshd_config.d", "AllowUsers", "test_allow_user_is_configured_usr_etc_ssh_sshdconfig_dir") }}} |
| 97 | + {{{ test_sshd_lineindir("/usr/etc/ssh/sshd_config.d", "AllowGroups", "test_allow_groups_is_configured_usr_etc_ssh_sshdconfig_dir") }}} |
| 98 | + {{{ test_sshd_lineindir("/usr/etc/ssh/sshd_config.d", "DenyUsers", "test_deny_users_is_configured_usr_etc_ssh_sshdconfig_dir") }}} |
| 99 | + {{{ test_sshd_lineindir("/usr/etc/ssh/sshd_config.d", "DenyGroups", "test_deny_groups_is_configured_usr_etc_ssh_sshdconfig_dir") }}} |
| 100 | +</def-group> |
0 commit comments