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

Fix crony.d config directory in Ansible in rule chronyd_or_ntpd_set_maxpoll #11958

Merged
merged 9 commits into from
May 28, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
path: /etc/ntp.conf
register: ntp_conf_exist_result

- name: "{{{ rule_title }}} - Update the Maxpoll Values in /etc/ntp.conf"
- name: "{{{ rule_title }}} - Update the maxpoll Values in /etc/ntp.conf"
ansible.builtin.replace:
path: /etc/ntp.conf
regexp: '^(server.*maxpoll)[ ]+[0-9]+(.*)$'
replace: '\1 {{ var_time_service_set_maxpoll }}\2'
when: ntp_conf_exist_result.stat.exists

- name: "{{{ rule_title }}} - Set the Maxpoll Values in /etc/ntp.conf"
- name: "{{{ rule_title }}} - Set the maxpoll Values in /etc/ntp.conf"
ansible.builtin.replace:
path: /etc/ntp.conf
regexp: '(^server\s+((?!maxpoll).)*)$'
Expand All @@ -34,29 +34,39 @@
path: {{{ chrony_conf_path }}}
register: chrony_conf_exist_result

- name: "{{{ rule_title }}} - Set Chrony Path Facts"
ansible.builtin.set_fact:
chrony_path: {{{ chrony_conf_path }}}
- name: "{{{ rule_title }}} - Update the maxpoll Values in {{{ chrony_conf_path }}}"
ansible.builtin.replace:
path: "{{{ chrony_conf_path }}}"
regexp: '^((?:server|pool|peer).*maxpoll)[ ]+[0-9]+(.*)$'
replace: '\1 {{ var_time_service_set_maxpoll }}\2'
when: chrony_conf_exist_result.stat.exists

- name: "{{{ rule_title }}} - Set the maxpoll Values in {{{ chrony_conf_path }}}"
ansible.builtin.replace:
path: "{{{ chrony_conf_path }}}"
regexp: '(^(?:server|pool|peer)\s+((?!maxpoll).)*)$'
replace: '\1 maxpoll {{ var_time_service_set_maxpoll }}\n'
when: chrony_conf_exist_result.stat.exists

- name: "{{{ rule_title }}} - Get Conf Files from {{ chrony_path | dirname }}"
- name: "{{{ rule_title }}} - Get Conf Files from {{{ chrony_d_path }}}"
ansible.builtin.find:
path: "{{ chrony_path | dirname }}"
path: "{{{ chrony_d_path }}}"
patterns: '*.conf'
file_type: file
register: chrony_conf_files
register: chrony_d_conf_files

- name: "{{{ rule_title }}} - Update the Maxpoll Values in {{{ chrony_conf_path }}}"
- name: "{{{ rule_title }}} - Update the maxpoll Values in {{{ chrony_d_path }}}"
ansible.builtin.replace:
path: "{{ item.path }}"
regexp: '^((?:server|pool|peer).*maxpoll)[ ]+[0-9]+(.*)$'
replace: '\1 {{ var_time_service_set_maxpoll }}\2'
loop: '{{ chrony_conf_files.files }}'
when: chrony_conf_files.matched
loop: '{{ chrony_d_conf_files.files }}'
when: chrony_d_conf_files.matched

- name: "{{{ rule_title }}} - Set the Maxpoll Values in {{{ chrony_conf_path }}}"
- name: "{{{ rule_title }}} - Set the maxpoll Values in {{{ chrony_d_path }}}"
ansible.builtin.replace:
path: "{{ item.path }}"
regexp: '(^(?:server|pool|peer)\s+((?!maxpoll).)*)$'
replace: '\1 maxpoll {{ var_time_service_set_maxpoll }}\n'
loop: '{{ chrony_conf_files.files }}'
when: chrony_conf_files.matched
loop: '{{ chrony_d_conf_files.files }}'
when: chrony_d_conf_files.matched
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ description: |-
{{{ xccdf_value("var_time_service_set_maxpoll") }}} in <tt>/etc/ntp.conf</tt> or
<tt>{{{ chrony_conf_path }}}</tt> to continuously poll time servers. To configure
<tt>maxpoll</tt> in <tt>/etc/ntp.conf</tt> or <tt>{{{ chrony_conf_path }}}</tt>
add the following after each `server`, `pool` or `peer` entry:
add the following after each <tt>server</tt>, <tt>pool</tt> or <tt>peer</tt> entry:
<pre>maxpoll {{{ xccdf_value("var_time_service_set_maxpoll") }}}</pre>
to <pre>server</pre> directives. If using chrony any <pre>pool</pre> directives
to <tt>server</tt> directives. If using chrony, any <tt>pool</tt> directives
should be configured too.
If no <tt>server</tt> or <tt>pool</tt> directives are configured, the rule evaluates
to pass.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# packages = chrony

{{{ bash_package_remove("ntp") }}}

# Remove all server or pool options
sed -i "/^\(server\|pool\).*/d" {{{ chrony_d_path }}}/20-pools.conf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These configs seem platform specific. Maybe the tests should be made platform specific?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to agree with the above comment, instead of making it platform specific we can replace 20-pools.conf with wildcard


echo "pool pool.ntp.org iburst maxpoll 18" >> {{{ chrony_d_path }}}/20-pools.conf

systemctl enable chronyd.service

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
# packages = chrony

{{{ bash_package_remove("ntp") }}}

# Remove all pool options
sed -i "/^pool.*/d" {{{ chrony_d_path }}}/10-servers.conf

if ! grep "^server.*maxpoll 10" {{{ chrony_d_path }}}/10-servers.conf ; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These configs seem platform specific. Maybe the tests should be made platform specific?

sed -i "s/^server.*/& maxpoll 10/" {{{ chrony_d_path }}}/10-servers.conf
fi

echo "server test.ntp.org" >> {{{ chrony_d_path }}}/10-servers.conf

systemctl enable chronyd.service
1 change: 1 addition & 0 deletions products/debian10/product.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ init_system: "systemd"


chrony_conf_path: "/etc/chrony/chrony.conf"
chrony_d_path: "/etc/chrony/conf.d/"

cpes_root: "../../shared/applicability"
cpes:
Expand Down
1 change: 1 addition & 0 deletions products/ubuntu1604/product.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ oval_feed_url: "https://people.canonical.com/~ubuntu-security/oval/com.ubuntu.xe


chrony_conf_path: "/etc/chrony/chrony.conf"
chrony_d_path: "/etc/chrony/conf.d/"

aide_bin_path: "/usr/bin/aide.wrapper"
aide_conf_path: "/etc/aide/aide.conf"
Expand Down
1 change: 1 addition & 0 deletions products/ubuntu1804/product.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ init_system: "systemd"


chrony_conf_path: "/etc/chrony/chrony.conf"
chrony_d_path: "/etc/chrony/conf.d/"

aide_bin_path: "/usr/bin/aide.wrapper"
aide_conf_path: "/etc/aide/aide.conf"
Expand Down
1 change: 1 addition & 0 deletions products/ubuntu2004/product.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ aide_conf_path: "/etc/aide/aide.conf"
aide_default_path: "/etc/default/aide"
audisp_conf_path: "/etc/audisp"
chrony_conf_path: "/etc/chrony/chrony.conf"
chrony_d_path: "/etc/chrony/conf.d/"

cpes_root: "../../shared/applicability"
cpes:
Expand Down
1 change: 1 addition & 0 deletions products/ubuntu2204/product.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ aide_bin_path: "/usr/bin/aide"
aide_conf_path: "/etc/aide/aide.conf"
audisp_conf_path: "/etc/audit"
chrony_conf_path: "/etc/chrony/chrony.conf"
chrony_d_path: "/etc/chrony/conf.d/"

cpes_root: "../../shared/applicability"
cpes:
Expand Down
1 change: 1 addition & 0 deletions ssg/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@
DEFAULT_SSH_DISTRIBUTED_CONFIG = 'false'
DEFAULT_PRODUCT = 'example'
DEFAULT_CHRONY_CONF_PATH = '/etc/chrony.conf'
DEFAULT_CHRONY_D_PATH = '/etc/chrony.d/'
DEFAULT_AUDISP_CONF_PATH = '/etc/audit'
DEFAULT_SYSCTL_REMEDIATE_DROP_IN_FILE = 'false'

Expand Down
4 changes: 4 additions & 0 deletions ssg/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
DEFAULT_AIDE_BIN_PATH,
DEFAULT_SSH_DISTRIBUTED_CONFIG,
DEFAULT_CHRONY_CONF_PATH,
DEFAULT_CHRONY_D_PATH,
DEFAULT_AUDISP_CONF_PATH,
DEFAULT_FAILLOCK_PATH,
DEFAULT_SYSCTL_REMEDIATE_DROP_IN_FILE,
Expand Down Expand Up @@ -66,6 +67,9 @@ def _get_implied_properties(existing_properties):
if "chrony_conf_path" not in existing_properties:
result["chrony_conf_path"] = DEFAULT_CHRONY_CONF_PATH

if "chrony_d_path" not in existing_properties:
result["chrony_d_path"] = DEFAULT_CHRONY_D_PATH

if "audisp_conf_path" not in existing_properties:
result["audisp_conf_path"] = DEFAULT_AUDISP_CONF_PATH

Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/alinux2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: ALINUX-2
benchmark_root: ../../linux_os/guide
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
cpes:
- alinux2:
check_id: installed_OS_is_alinux2
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/alinux3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: ALINUX-3
benchmark_root: ../../linux_os/guide
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
cpes:
- alinux3:
check_id: installed_OS_is_alinux3
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/anolis23.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: ANOLIS-23
benchmark_root: ../../linux_os/guide
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
cpes:
- anolis23:
check_id: installed_OS_is_anolis23
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/anolis8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: ANOLIS-8
benchmark_root: ../../linux_os/guide
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
cpes:
- anolis8:
check_id: installed_OS_is_anolis8
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/chromium.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: CHROMIUM
benchmark_root: ./guide
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
cpes:
- chromium:
check_id: installed_app_is_chromium
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/debian10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: DEBIAN-10
benchmark_root: ../../linux_os/guide
chrony_conf_path: /etc/chrony/chrony.conf
chrony_d_path: /etc/chrony/conf.d/
cpes:
- debian10:
check_id: installed_OS_is_debian10
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/debian11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: DEBIAN-11
benchmark_root: ../../linux_os/guide
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
cpes:
- debian11:
check_id: installed_OS_is_debian11
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/debian12.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: DEBIAN-12
benchmark_root: ../../linux_os/guide
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
cpes:
- debian12:
check_id: installed_OS_is_debian12
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/eks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: EKS
benchmark_root: ../../applications
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
cpes:
- eks:
check_id: installed_app_is_eks
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: EXAMPLE
benchmark_root: ../../linux_os/guide
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
components_root: ../../components
cpes:
- example:
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/fedora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: FEDORA
benchmark_root: ../../linux_os/guide
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
components_root: ../../components
cpes:
- fedora_40:
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/firefox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: FIREFOX
benchmark_root: ./guide
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
cpes:
- firefox:
check_id: installed_app_is_firefox
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/macos1015.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: macOS-1015
benchmark_root: ../../apple_os/
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
cpes:
- macos15:
check_id: installed_OS_is_macos1015
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/ocp4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: OCP-4
benchmark_root: ../../applications
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
cpes:
- ocp4:
check_id: installed_app_is_ocp4
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/ol7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: OL-7
benchmark_root: ../../linux_os/guide
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
cpes:
- ol7:
check_id: installed_OS_is_ol7
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/ol8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: OL-8
benchmark_root: ../../linux_os/guide
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
cpes:
- ol8:
check_id: installed_OS_is_ol8
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/ol9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ basic_properties_derived: true
benchmark_id: OL-9
benchmark_root: ../../linux_os/guide
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
cpes:
- ol9:
check_id: installed_OS_is_ol9
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/openembedded.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: OPENEMBEDDED
benchmark_root: ../../linux_os/guide
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
cpes:
- openembedded:
check_id: installed_OS_is_openembedded
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/opensuse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: OPENSUSE
benchmark_root: ../../linux_os/guide
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
cpes:
- opensuse-42.1:
check_id: installed_OS_is_opensuse_leap42
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/rhcos4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: RHCOS-4
benchmark_root: ../../linux_os/guide
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
cpes:
- rhcos4:
check_id: installed_OS_is_rhcos4
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/rhel7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ centos_major_version: '7'
centos_pkg_release: 53a7ff4b
centos_pkg_version: f4a80eb5
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
components_root: ../../components
cpes:
- rhel7:
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/rhel8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ centos_major_version: '8'
centos_pkg_release: 5ccc5b19
centos_pkg_version: 8483c65d
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
components_root: ../../components
cpes:
- rhel8:
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/rhel9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ centos_major_version: '9'
centos_pkg_release: 5ccc5b19
centos_pkg_version: 8483c65d
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
components_root: ../../components
cpes:
- rhel9:
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/rhv4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ basic_properties_derived: true
benchmark_id: RHV-4
benchmark_root: ../../linux_os/guide
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
cpes:
- rhel8-host:
check_id: installed_OS_is_rhv4
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/sle12.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: SLE-12
benchmark_root: ../../linux_os/guide
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
cpes:
- sle12-server:
check_id: installed_OS_is_sle12
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/sle15.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: SLE-15
benchmark_root: ../../linux_os/guide
chrony_conf_path: /etc/chrony.conf
chrony_d_path: /etc/chrony.d/
cpes:
- sle15-server:
check_id: installed_OS_is_sle15
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/ubuntu1604.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: UBUNTU-XENIAL
benchmark_root: ../../linux_os/guide
chrony_conf_path: /etc/chrony/chrony.conf
chrony_d_path: /etc/chrony/conf.d/
cpes:
- ubuntu1604:
check_id: installed_OS_is_ubuntu1604
Expand Down
1 change: 1 addition & 0 deletions tests/data/product_stability/ubuntu1804.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ basic_properties_derived: true
benchmark_id: UBUNTU-BIONIC
benchmark_root: ../../linux_os/guide
chrony_conf_path: /etc/chrony/chrony.conf
chrony_d_path: /etc/chrony/conf.d/
cpes:
- ubuntu1804:
check_id: installed_OS_is_ubuntu1804
Expand Down
Loading
Loading