-
Notifications
You must be signed in to change notification settings - Fork 710
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10353 from rumch-se/rule_ensure_chrony_is_configured
New rule ensure_chrony_is_configured
- Loading branch information
Showing
32 changed files
with
290 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
linux_os/guide/services/ntp/chronyd_configure_pool_and_server/ansible/shared.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# platform = multi_platform_all | ||
# reboot = false | ||
# strategy = configure | ||
# complexity = low | ||
# disruption = low | ||
{{{ ansible_instantiate_variables("var_multiple_time_servers") }}} | ||
{{{ ansible_instantiate_variables("var_multiple_time_pools") }}} | ||
|
||
- name: {{{ rule_title }}} - Add missing / update wrong records for remote time servers | ||
ansible.builtin.lineinfile: | ||
path: {{{ chrony_conf_path }}} | ||
regexp: '^\s*\bserver\b\s*\b{{ item }}\b$' | ||
state: present | ||
line: 'server {{ item }}' | ||
create: true | ||
with_items: | ||
- '{{ var_multiple_time_servers.split(",") }}' | ||
|
||
- name: {{{ rule_title }}} - Add missing / update wrong records for remote time pools | ||
ansible.builtin.lineinfile: | ||
path: {{{ chrony_conf_path }}} | ||
regexp: '^\s*\bpool\b\s*\b{{ item }}\b$' | ||
state: present | ||
line: 'pool {{ item }}' | ||
create: true | ||
with_items: | ||
- '{{ var_multiple_time_pools.split(",") }}' |
30 changes: 30 additions & 0 deletions
30
linux_os/guide/services/ntp/chronyd_configure_pool_and_server/bash/shared.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# platform = multi_platform_all | ||
|
||
{{{ bash_instantiate_variables("var_multiple_time_servers") }}} | ||
{{{ bash_instantiate_variables("var_multiple_time_pools") }}} | ||
|
||
config_file="{{{ chrony_conf_path }}}" | ||
|
||
# Check and configigure servers in {{{ chrony_conf_path }}} | ||
IFS="," read -a SERVERS <<< $var_multiple_time_servers | ||
for srv in "${SERVERS[@]}" | ||
do | ||
NTP_SRV=$(grep -w $srv $config_file) | ||
if [[ ! "$NTP_SRV" == "server "* ]] | ||
then | ||
time_server="server $srv" | ||
echo $time_server >> "$config_file" | ||
fi | ||
done | ||
|
||
# Check and configure pools in {{{ chrony_conf_path }}} | ||
IFS="," read -a POOLS <<< $var_multiple_time_pools | ||
for srv in "${POOLS[@]}" | ||
do | ||
NTP_POOL=$(grep -w $srv $config_file) | ||
if [[ ! "$NTP_POOL" == "pool "* ]] | ||
then | ||
time_server="pool $srv" | ||
echo $time_server >> "$config_file" | ||
fi | ||
done |
58 changes: 58 additions & 0 deletions
58
linux_os/guide/services/ntp/chronyd_configure_pool_and_server/oval/shared.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<def-group> | ||
<definition class="compliance" id="{{{ rule_id }}}" version="1"> | ||
{{{ oval_metadata("A remote NTP Server for time synchronization should be specified (and dependencies are met)") }}} | ||
<criteria comment="chrony.conf conditions are met" operator="OR"> | ||
<criterion test_ref="test_chrony_remote_server_configuration" /> | ||
<criterion test_ref="test_chrony_remote_pool_configuration" /> | ||
</criteria> | ||
</definition> | ||
|
||
<external_variable comment="remote vendor-approved time servers" datatype="string" | ||
id="var_multiple_time_servers" version="1" /> | ||
|
||
<local_variable id="temp_variable_test_servers" datatype="string" version="1" comment="a local variable which includes all vendor-approved time servers"> | ||
<concat> | ||
<literal_component>^(?:server)[[:space:]]</literal_component> | ||
<split delimiter=","> | ||
<variable_component var_ref="var_multiple_time_servers" /> | ||
</split> | ||
<literal_component>$</literal_component> | ||
</concat> | ||
</local_variable> | ||
|
||
<external_variable comment="remote vendor-approved pool servers" datatype="string" | ||
id="var_multiple_time_pools" version="1" /> | ||
|
||
<local_variable id="temp_variable_test_pools" datatype="string" version="1" comment="a local variable which includes all vendor-approved pool servers"> | ||
<concat> | ||
<literal_component>^(?:pool)[[:space:]]</literal_component> | ||
<split delimiter=","> | ||
<variable_component var_ref="var_multiple_time_pools" /> | ||
</split> | ||
<literal_component>$</literal_component> | ||
</concat> | ||
</local_variable> | ||
|
||
<ind:textfilecontent54_test check="all" check_existence="at_least_one_exists" | ||
comment="Ensure remote NTP server is set" id="test_chrony_remote_server_configuration" version="1"> | ||
<ind:object object_ref="object_chrony_remote_server_configuration" /> | ||
</ind:textfilecontent54_test> | ||
|
||
<ind:textfilecontent54_object comment="Ensure at least one NTP server is set" id="object_chrony_remote_server_configuration" version="1"> | ||
<ind:filepath>{{{ chrony_conf_path }}}</ind:filepath> | ||
<ind:pattern operation="pattern match" var_ref="temp_variable_test_servers"/> | ||
<ind:instance datatype="int" operation="greater than or equal">1</ind:instance> | ||
</ind:textfilecontent54_object> | ||
|
||
<ind:textfilecontent54_test check="all" check_existence="at_least_one_exists" | ||
comment="Ensure remote NTP pool is set" id="test_chrony_remote_pool_configuration" version="1"> | ||
<ind:object object_ref="object_chrony_remote_pool_configuration" /> | ||
</ind:textfilecontent54_test> | ||
|
||
<ind:textfilecontent54_object comment="Ensure at least one NTP pool is set" id="object_chrony_remote_pool_configuration" version="1"> | ||
<ind:filepath>{{{ chrony_conf_path }}}</ind:filepath> | ||
<ind:pattern operation="pattern match" var_ref="temp_variable_test_pools"/> | ||
<ind:instance datatype="int" operation="greater than or equal">1</ind:instance> | ||
</ind:textfilecontent54_object> | ||
|
||
</def-group> |
42 changes: 42 additions & 0 deletions
42
linux_os/guide/services/ntp/chronyd_configure_pool_and_server/rule.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
documentation_complete: true | ||
|
||
prodtype: sle12,sle15 | ||
|
||
title: 'Chrony Configure Pool and Server' | ||
|
||
description: |- | ||
<tt>Chrony</tt> is a daemon which implements the Network Time Protocol (NTP). It is designed to | ||
synchronize system clocks across a variety of systems and use a source that is highly | ||
accurate. More information on <tt>chrony</tt> can be found at | ||
{{{ weblink(link="http://chrony.tuxfamily.org/") }}}. | ||
<tt>Chrony</tt> can be configured to be a client and/or a server. | ||
Add or edit server or pool lines to <tt>{{{ chrony_conf_path }}}</tt> as appropriate: | ||
<pre>server <remote-server></pre> | ||
Multiple servers may be configured. | ||
rationale: |- | ||
If <tt>chrony</tt> is in use on the system proper configuration is vital to ensuring time | ||
synchronization is working properly. | ||
severity: medium | ||
|
||
platform: package[chrony] | ||
|
||
identifiers: | ||
cce@sle12: CCE-92394-6 | ||
cce@sle15: CCE-92526-3 | ||
|
||
references: | ||
anssi: BP28(R43) | ||
cis@sle12: 2.2.1.3 | ||
cis@sle15: 2.2.1.3 | ||
disa: CCI-000160,CCI-001891 | ||
ism: 0988,1405 | ||
nist: CM-6(a),AU-8(1)(a) | ||
pcidss: Req-10.4.3 | ||
|
||
ocil_clause: 'a remote time server is not configured' | ||
|
||
ocil: |- | ||
Run the following command and verify remote servers are configured properly: | ||
<pre># grep -E "^(server|pool)" {{{ chrony_conf_path }}}</pre> |
31 changes: 31 additions & 0 deletions
31
...services/ntp/chronyd_configure_pool_and_server/tests/correct_chrony_configuration.pass.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
# packages = chrony | ||
|
||
|
||
{{{ bash_instantiate_variables("var_multiple_time_servers") }}} | ||
{{{ bash_instantiate_variables("var_multiple_time_pools") }}} | ||
|
||
config_file="{{{ chrony_conf_path }}}" | ||
|
||
IFS="," read -a SERVERS <<< $var_multiple_time_servers | ||
for srv in "${SERVERS[@]}" | ||
do | ||
NTP_SRV=$(grep -w $srv $config_file) | ||
if [[ ! "$NTP_SRV" == "server "* ]] | ||
then | ||
time_server="server $srv" | ||
echo $time_server >> "$config_file" | ||
fi | ||
done | ||
|
||
# Check and configure pools in /etc/chorny.conf | ||
IFS="," read -a POOLS <<< $var_multiple_time_pools | ||
for srv in "${POOLS[@]}" | ||
do | ||
NTP_POOL=$(grep -w $srv $config_file) | ||
if [[ ! "$NTP_POOL" == "pool "* ]] | ||
then | ||
time_server="pool $srv" | ||
echo $time_server >> "$config_file" | ||
fi | ||
done |
5 changes: 5 additions & 0 deletions
5
linux_os/guide/services/ntp/chronyd_configure_pool_and_server/tests/file_empty.fail.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
# packages = chrony | ||
|
||
|
||
echo "" > {{{ chrony_conf_path }}} |
5 changes: 5 additions & 0 deletions
5
linux_os/guide/services/ntp/chronyd_configure_pool_and_server/tests/file_missing.fail.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
# packages = chrony | ||
|
||
|
||
rm -f {{{ chrony_conf_path }}} |
7 changes: 7 additions & 0 deletions
7
linux_os/guide/services/ntp/chronyd_configure_pool_and_server/tests/incorrect_line1.fail.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
# packages = chrony | ||
|
||
|
||
echo "" > {{{ chrony_conf_path }}} | ||
echo "server0.suse.pool.ntp.org" >> {{{ chrony_conf_path }}} | ||
echo "pool1.suse.pool.ntp.org" >> {{{ chrony_conf_path }}} |
7 changes: 7 additions & 0 deletions
7
linux_os/guide/services/ntp/chronyd_configure_pool_and_server/tests/incorrect_line2.fail.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
# packages = chrony | ||
|
||
|
||
echo "" > {{{ chrony_conf_path }}} | ||
echo "server 0.suse.pool.ntp.org" >> {{{ chrony_conf_path }}} | ||
echo "pool 1.suse.pool.ntp.org" >> {{{ chrony_conf_path }}} |
7 changes: 7 additions & 0 deletions
7
linux_os/guide/services/ntp/chronyd_configure_pool_and_server/tests/incorrect_line3.fail.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
# packages = chrony | ||
|
||
|
||
echo "" > {{{ chrony_conf_path }}} | ||
echo " server 0.suse.pool.ntp.org" >> {{{ chrony_conf_path }}} | ||
echo " pool 1.suse.pool.ntp.org" >> {{{ chrony_conf_path }}} |
7 changes: 7 additions & 0 deletions
7
linux_os/guide/services/ntp/chronyd_configure_pool_and_server/tests/incorrect_line4.fail.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
# packages = chrony | ||
|
||
|
||
echo "" > {{{ chrony_conf_path }}} | ||
echo " server 0.suse.pool.ntp.org" >> {{{ chrony_conf_path }}} | ||
echo " pool 1.suse.pool.ntp.org" >> {{{ chrony_conf_path }}} |
9 changes: 9 additions & 0 deletions
9
linux_os/guide/services/ntp/chronyd_configure_pool_and_server/tests/multiple_servers.pass.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
# packages = chrony | ||
|
||
|
||
echo "" > {{{ chrony_conf_path }}} | ||
echo "server 0.suse.pool.ntp.org" >> {{{ chrony_conf_path }}} | ||
echo "server 1.suse.pool.ntp.org" >> {{{ chrony_conf_path }}} | ||
echo "pool 2.suse.pool.ntp.org" >> {{{ chrony_conf_path }}} | ||
echo "pool 3.suse.pool.ntp.org" >> {{{ chrony_conf_path }}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
documentation_complete: true | ||
|
||
title: 'Vendor Approved Time pools' | ||
|
||
description: 'The list of vendor-approved pool servers' | ||
|
||
type: string | ||
|
||
interactive: true | ||
|
||
options: | ||
default: "0.pool.ntp.org,1.pool.ntp.org,2.pool.ntp.org,3.pool.ntp.org" | ||
fedora: "0.fedora.pool.ntp.org,1.fedora.pool.ntp.org,2.fedora.pool.ntp.org,3.fedora.pool.ntp.org" | ||
rhel: "0.rhel.pool.ntp.org,1.rhel.pool.ntp.org,2.rhel.pool.ntp.org,3.rhel.pool.ntp.org" | ||
ol: "0.pool.ntp.org,1.pool.ntp.org,2.pool.ntp.org,3.pool.ntp.org" | ||
suse: "0.suse.pool.ntp.org,1.suse.pool.ntp.org,2.suse.pool.ntp.org,3.suse.pool.ntp.org" | ||
alinux: "0.ntp.cloud.aliyuncs.com,1.ntp.aliyun.com,2.ntp1.aliyun.com,3.ntp1.cloud.aliyuncs.com" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,5 @@ description: |- | |
|
||
selections: | ||
- anssi:all:high | ||
- var_multiple_time_servers=suse | ||
- var_multiple_time_pools=suse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,5 @@ description: |- | |
|
||
selections: | ||
- anssi:all:high | ||
- var_multiple_time_servers=suse | ||
- var_multiple_time_pools=suse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.