-
Notifications
You must be signed in to change notification settings - Fork 698
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
New rule ensure_chrony_is_configured #10353
New rule ensure_chrony_is_configured #10353
Conversation
Hi @rumch-se. Thanks for your PR. I'm waiting for a ComplianceAsCode member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
<ind:textfilecontent54_object comment="Ensure at least one remote NTP server is set" | ||
id="object_chrony_remote_server_configuartion" version="1"> | ||
<ind:filepath operation="pattern match">^/etc/chrony.conf$</ind:filepath> | ||
<ind:pattern operation="pattern match">^(\bserver[[:space:]]|pool[[:space:]]\b)([0-3]\b(.fedora|.suse|.rhel)\b\b(.pool.ntp.org)\b)|([0-3]\b(.pool.ntp.org)\b)|([0-3]\b(.ntp.cloud.aliyuncs.com)\b)|([0-3]\b(.us.pool.ntp.mil)\b)$</ind:pattern> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't you be checking if the server specified in var_multiple_time_servers
is in /etc/chrony.conf
?
That would allow anyone working with a tailoring file to set var_multiple_time_servers
to the servers according to their site policy, and that might be different from this hard-coded check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also isn't this entire rule the same as chronyd_specify_remote_server
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @dodys
At the moment regerp - covers ALL time servers defined into the variable + servers which are not defined - for example .mil. Do you know a way to generate regexp dynamically from the definition of the variable?
There is another issue - the variable defines time servers for different vendors i.e. OVAL check /audit/ has to check if /etc/chrony.conf includes servers for the selected vendor.
Have a nice day
Rumen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't use any regex, I would check if the /etc/chrony.conf
file has the value set in var_multiple_time_servers
, that way you allow users to define their own servers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also @dodys
According to your second question I will propose you to check conversation in #10278. According to me the OVAL part of the rule chronyd_specify_remote_server is not correct - because it checks for ANY word after the word server. I received a proposal to develop another rule, and because of that this PR was developed. With this PR I am trying to control better the content of /etc/chrony.conf - because the correct configuration of servers is very important for audit/ digital forensic/ how IDS/IPS are working.
Have a nice day
Rumen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @dodys
I have a question about your proposal " I would check if the /etc/chrony.conf file has the value set in var_multiple_time_servers, that way you allow users to define their own servers.". The variable includes 4 servers for each vendor delimited by a comma. In /etc/chrony.conf file we have to have at least one line with the following format
server one_space name_of_the_time_server. How can I check that the line in .conf file is correct. Would be possible to provide me an example from another rule?
Have a nice day
Rumen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can create a local_variable from this external_variable and do a regex with it
or you could have 4 local_variables and do 4 checks, I think it might be easier the previous idea.
for some example, see:
https://github.com/ComplianceAsCode/content/blob/master/linux_os/guide/system/logging/rsyslog_filecreatemode/oval/shared.xml#L24
There are other ways to do it as well, it just requires some thinking and creating variables.
|
||
<ind:textfilecontent54_object comment="Ensure at least one remote NTP server is set" | ||
id="object_chrony_remote_server_configuartion" version="1"> | ||
<ind:filepath operation="pattern match">^/etc/chrony.conf$</ind:filepath> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe here you might want to use: {{{ chrony_conf_path }}}
see other rules that have this variable use
Hello @dodys |
hi @rumch-se |
Hello @dodys 2/ 3/ Have a nice day |
Hi @rumch-se, I think I got a working prototype of the OVAL. Do note that I did on top of
This is the result I got: You can see it correctly matched the four entries in chrony.conf |
@vojtapolasek I wonder if we can have the OVAL change I mentioned above in |
Hello @dodys I have corrected this rule, by following your approach. In addition I have added support for server and pool, because:
Have a nice day |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few minor things to fix, but overall it is looking good now
fi | ||
done | ||
|
||
# Check and configure pools in /etc/chorny.conf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo, perhaps use the chrony_conf_path
|
||
config_file="{{{ chrony_conf_path }}}" | ||
|
||
# Check and configigure servers in /etc/chrony.conf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better use chrony_conf_path
<concat> | ||
<literal_component>^(?:pool)[[:space:]]</literal_component> | ||
<split delimiter=","> | ||
<variable_component var_ref="var_multiple_time_servers" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong variable name
|
||
<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_configuartion" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo in configuration
<ind:object object_ref="object_chrony_remote_server_configuartion" /> | ||
</ind:textfilecontent54_test> | ||
|
||
<ind:textfilecontent54_object comment="Ensure at least one NTP server is set" id="object_chrony_remote_server_configuartion" version="1"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo in configuration
</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"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove the space after "set" in comment
|
||
<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_configuartion" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo in configuration
Hello @dodys |
Related to #10278 |
05b8b42
to
9f31915
Compare
@marcusburghardt @vojtapolasek is there any reason for this new rule to not be integrated with the existing rule? |
/packit test |
@rumch-se I am very sorry for a long delay, I am going to review this PR asap since I know it is important for you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @rumch-se and thank you for this new rule. It looks challenging but I believe the goal you are trying to accomplish can be done.
See my comments please. Please fix the wrong variable name in the pci-dss profile so that the product can be built and tested by the CI.
I have two general comments:
- Could you consider a different rule name? This name sounds very generic - I believe time servers and pools are not the only configuration options which can be set in chrony.conf. How about chrony_configure_exact_servers... or something along the lines.
- I see that the rule remediation (I tried Bash so far) configures both servers and pools in the file. Is this what you want to achieve?
Thank you once again.
<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="local var"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make the variable name clearer and / or extend the comment. I think it is enough if you specify that this variable is a regexp.
<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="local var"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make the variable name clearer and / or extend the comment.
@@ -0,0 +1,25 @@ | |||
# platform = multi_platform_sle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer needed, the prodtype should ensure that the remediation is built only with specified products.
# platform = multi_platform_sle | |
# platform = multi_platform_all |
@@ -0,0 +1,30 @@ | |||
# platform = multi_platform_sle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# platform = multi_platform_sle | |
# platform = multi_platform_all |
@@ -0,0 +1,31 @@ | |||
#!/bin/bash | |||
# packages = chrony | |||
# platform = multi_platform_sle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note. Currently, the rule is applicable only to SLE products so this line is fine. If this rule is going to be used in more products, the test will need to be rewritten because each product will have its own correct XCCDF variable.
An example of such test scenario is here:
https://github.com/ComplianceAsCode/content/blob/9f319151147974e333bdb4e5474997a81bf97f3a/linux_os/guide/system/accounts/accounts-physical/logind_session_timeout/tests/correct.pass.sh
@@ -0,0 +1,7 @@ | |||
#!/bin/bash | |||
# packages = chrony | |||
# platform = multi_platform_sle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line not needed as long as the erroneous line does not appear in any value of the XCCDF variable related to the rule.
@@ -0,0 +1,7 @@ | |||
#!/bin/bash | |||
# packages = chrony | |||
# platform = multi_platform_sle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LIne not needed as long as the incorrect line is incorrect for all applicable products.
@@ -0,0 +1,7 @@ | |||
#!/bin/bash | |||
# packages = chrony | |||
# platform = multi_platform_sle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line not needed, see above cases of test scenarios starting with incorrect_line*.
@@ -0,0 +1,7 @@ | |||
#!/bin/bash | |||
# packages = chrony | |||
# platform = multi_platform_sle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line probably not needed, see similar file
@@ -0,0 +1,9 @@ | |||
#!/bin/bash | |||
# packages = chrony | |||
# platform = multi_platform_sle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment on the same line in the file correct_chrony_configuration.pass.sh.
Hello @vojtapolasek I have implemented the proposed corrections. Have a nice day |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the update. There are just minor fixes to Ansible remaining because in the current state it ofter terminates prenaturely.
- name: {{{ rule_title }}} - Add missing / update wrong records for remote time pools | ||
ansible.builtin.lineinfile: | ||
path: {{{ chrony_conf_path }}} | ||
regexp: '^\s*\pool\b\s*\b{{ item }}\b$' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
regexp: '^\s*\pool\b\s*\b{{ item }}\b$' | |
regexp: '^\s*\bpool\b\s*\b{{ item }}\b$' |
path: {{{ chrony_conf_path }}} | ||
regexp: '^\s*\pool\b\s*\b{{ item }}\b$' | ||
state: present | ||
line: 'pool {{ item }}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add create: true because if the file does not exist the task fails.
path: {{{ chrony_conf_path }}} | ||
regexp: '^\s*\bserver\b\s*\b{{ item }}\b$' | ||
state: present | ||
line: 'server {{ item }}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add create: true because if the file does not exist the task fails.
Hello @vojtapolasek The proposed changes were implemented |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the update. It looks good now.
Automatus tests are failing because the rule is SLE specific and therefore Automats has nothing to test... and returns error.
I did the review and I believe the PR is OK.
@teacup-on-rockingchair could you please review? |
@ComplianceAsCode/suse-maintainers please review the PR. Othervise, github does not allow merging. Thank you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks
@rumch-se one more thing to consider... what do you think about splitting the rule into two rules? One would check for pools, one for servers. The reason why I am asking is for example this STIG item: |
Hello @vojtapolasek |
I understand. I think it would be nice to name the rule chronyd_configure_server_and_pool. We could then have separate rules (out of scope of this PR) chronyd_configure_server and chronyd_configure_pool. @yuumasato @jan-cerny ideas? |
16df8c1
to
2c4a081
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
@rumch-se hello, please could you change the rule name? When you look at other rules in the content, they do not contain werbs in third person singular form. I still think that chronyd_configure_pool_and_server fits the rule purpose the best. |
Hello @vojtapolasek |
Code Climate has analyzed commit 5be9450 and detected 0 issues on this pull request. The test coverage on the diff in this pull request is 100.0% (50% is the threshold). This pull request will bring the total coverage in the repository to 52.5% (0.1% change). View more on Code Climate. |
Thank you @rumch-se, merging. |
Description:
Rationale: