Skip to content

Commit 8da9b53

Browse files
committed
feat: implement Rocky Linux 9 CIS
1 parent b5b82f7 commit 8da9b53

File tree

309 files changed

+6219
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

309 files changed

+6219
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ playbooks/test.yml
88
roles/test
99
context/
1010
particle/.vagrant
11+
<<<<<<< HEAD
1112

1213
# mkdocs documentation
1314
/docs/CHANGELOG.md
@@ -20,3 +21,6 @@ particle/.vagrant
2021
/docs/stigs.md
2122
/mkdocs.yml
2223
/site
24+
=======
25+
stig/stig.db
26+
>>>>>>> 0a78d88e (feat: implement Rocky Linux 9 CIS)

stig/README.rst

Lines changed: 335 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,335 @@
1+
Secure Technical Implementation Guide - Audit and Remediations
2+
===============================================================
3+
4+
Overview
5+
--------
6+
7+
Round about 300 unofficial audit and remediation tasks for different Secure Technical Implementation Guides (STIG).
8+
9+
Compiled STIGs:
10+
11+
.. csv-table::
12+
:header-rows: 1
13+
14+
Type, Name, Version, ``stig_profile_name:``, ``stig_profile_version:``, Tested Platforms
15+
CIS, Rocky Linux 9 Benchmark, v2.0.0, ``CIS Rocky Linux 9``, ``v2.0.0``, Rocky Linux 9
16+
17+
`Drop us a line <https://www.linuxfabrik.ch/ueber-uns/kontakt>`_ if you have successfully used any of the STIG profiles on other platforms.
18+
19+
To audit before and after applying the remediations, you might use tools like `OpenVAS <https://www.openvas.org/>`_, `Lynis <https://cisofy.com/lynis/>`_, `Nessus <https://www.tenable.com>`_ or our Python script `files/audit.py <https://git.linuxfabrik.ch/linuxfabrik-ansible/roles/stig/-/blob/master/files/audit.py>`_. Remediations are done using the `tasks/main.yml <https://git.linuxfabrik.ch/linuxfabrik-ansible/roles/stig/-/blob/master/tasks/main.yml>`_.
20+
21+
.. attention::
22+
23+
Do not attempt to use any of the Ansible tasks without first testing them in a non-operational environment. Linuxfabrik assume no responsibility whatsoever for its use by other parties, and makes no guarantees, expressed or implied, about its quality, reliability, or any other characteristic.
24+
25+
.. note::
26+
27+
* This role cannot be run with the ``--check`` parameter.
28+
* Password-less SSH access is required for the audits and remediations.
29+
* The Rocky Linux 9 profile is intended for Rocky Linux 9 systems.
30+
31+
32+
Before you begin
33+
----------------
34+
35+
While remediating, this role breaks things on productive machines when applied completely.
36+
This role **will make changes to the system that could or will break things**. Please take the time to familarise yourself with the STIG profile of your choice before applying this role to a system.
37+
38+
Compile a list of non-applicable remediations for each server.
39+
For example: If you are running an outbound proxy with Squid and would like to apply the "CIS CentOS Linux 7 v3.1.2" profile, you should exclude "2.2.12 Ensure HTTP Proxy Server is not installed".
40+
41+
This role does not create or change host firewalls.
42+
Because there are far more firewall tools on earth than just firewalld, nftables and iptables, and maybe you create your firewall rules using other techniques or roles. This topic is too complex to be configured automatically.
43+
44+
45+
Installation
46+
------------
47+
48+
Place this Ansible role in an appropriate directory:
49+
50+
.. code-block:: text
51+
52+
stig
53+
├── audit.csv: Audit script definitions
54+
├── audit.py: Python audit script
55+
├── audits: Contains all Audit Snippets (Bash)
56+
├── create-db: Script to create stig.db from CSV files
57+
├── dump-db: Script to dump stig.db to CSV files
58+
├── lib: Home of Linuxfabrik libraries
59+
├── profile.csv: STIG profile definitions
60+
├── remediation.csv: Remediation variable definitions
61+
└── stig.db: SQLite database file
62+
63+
If you want to use ``audit.py``:
64+
65+
* Install Python modules:
66+
67+
.. code-block::
68+
69+
dnf -y install python3-termcolor
70+
71+
* Copy all Python files from https://git.linuxfabrik.ch/linuxfabrik/lib into ``stig/lib``.
72+
73+
74+
Auditing a Machine (audit.py)
75+
-----------------------------
76+
77+
If using our Python script `files/audit.py <https://git.linuxfabrik.ch/linuxfabrik-ansible/roles/stig/-/blob/master/files/audit.py>`_, ensure that you are able to access the machine using SSH with root privileges and password-less authentication. The script checks SSH connectivity and password-less ``sudo`` before running audits.
78+
79+
For example, start an audit only with controls whose name starts with "1", but at the same time exclude all controls whose name starts with "1.3" and "1.4":
80+
81+
.. code-block:: bash
82+
83+
./audit.py --profile-name="CIS Rocky Linux 9" --profile-version="v2.0.0" --hostname=192.0.2.249 --username=root --lengthy --control-name-include='^1' --control-name-exclude='^1\.3|^1\.4'
84+
85+
Example output (parts ommitted)::
86+
87+
Audit Result
88+
============
89+
90+
...
91+
92+
Summary Table
93+
-------------
94+
95+
Control ! Script ! Scoring ! Lvl ! Result
96+
------------------------------------------------------------------------+-------------------+---------+-----+-------
97+
1.1.1.1 Ensure mounting of cramfs filesystems is disabled (Automated) ! cramfs_off.sh ! Scored ! 1 ! Failed
98+
1.1.1.2 Ensure mounting of squashfs filesystems is disabled (Automated) ! squashfs_off.sh ! Scored ! 2 ! Failed
99+
1.1.1.3 Ensure mounting of udf filesystems is disabled (Automated) ! udf_off.sh ! Scored ! 1 ! Failed
100+
1.1.2 Ensure /tmp is configured (Automated) ! tmp_separate_partition.sh ! Scored ! 1 ! Passed
101+
1.1.3 Ensure noexec option set on /tmp partition (Automated) ! tmp_noexec.sh ! Scored ! 1 ! Passed
102+
1.1.4 Ensure nodev option set on /tmp partition (Automated) ! tmp_nodev.sh ! Scored ! 1 ! Passed
103+
1.1.5 Ensure nosuid option set on /tmp partition (Automated) ! tmp_nosuid.sh ! Scored ! 1 ! Passed
104+
...
105+
106+
Profile
107+
-------
108+
109+
* Benchmark: CIS Rocky Linux 9 (v2.0.0)
110+
* Host: ``192.0.2.194``
111+
* Datetime: 2021-09-28 14:22:45
112+
* Score: 128/236 points (54.2%)
113+
* Grade: F
114+
115+
For each control:
116+
117+
* If you get "Passed", the configuration is CIS-compliant for that control.
118+
* If you get "Failed", the CIS requirements are not met.
119+
* If you get "Skipped", the control is not applicable on that system.
120+
* If you get "TODO", no audit script is implemented for that control yet.
121+
* If you get "Review", we cannot detect compliance automatically; check the configuration manually.
122+
123+
The overall grade is calculated as follows:
124+
125+
.. code-block:: python
126+
127+
def get_grade(percentage):
128+
if percentage >= 97:
129+
return 'A+'
130+
if percentage >= 93:
131+
return 'A'
132+
if percentage >= 90:
133+
return 'A-'
134+
if percentage >= 87:
135+
return 'B+'
136+
if percentage >= 83:
137+
return 'B'
138+
if percentage >= 80:
139+
return 'B-'
140+
if percentage >= 77:
141+
return 'C+'
142+
if percentage >= 73:
143+
return 'C'
144+
if percentage >= 70:
145+
return 'C-'
146+
if percentage >= 67:
147+
return 'D+'
148+
if percentage >= 63:
149+
return 'D'
150+
if percentage >= 60:
151+
return 'D-'
152+
return 'F'
153+
154+
155+
Remediating a Machine
156+
---------------------
157+
158+
We have implemented more audits than remediation measures, especially in the area of application servers (for example Apache). The reason: Audits are not only easier to implement, but the configuration of an existing application server is far too specialized and complex to be done by a small, general role. Better, specialized or custom Ansible roles must be used here to deploy and maintain the server.
159+
160+
After applying remediations:
161+
162+
* Reboot. Always reboot a remediated machine to be sure for all settings to take effect.
163+
* Keep an eye on your monitoring software.
164+
* Run a second audit.
165+
* Fix further findings using other roles.
166+
167+
Variables (have a look at `defaults/main.yml <https://git.linuxfabrik.ch/linuxfabrik-ansible/roles/stig/-/blob/master/defaults/main.yml>`_ for a complete list of available variables):
168+
169+
.. code-block:: yml
170+
171+
stig:
172+
- profile_name: 'CIS Rocky Linux 9' # mandatory
173+
profile_version: 'v2.0.0' # default: "latest"
174+
also_use_controls_disabled_by_default: True # default: false
175+
control_name_include: # use regular expressions here
176+
- '^1'
177+
- '^2'
178+
control_name_exclude: # use regular expressions here
179+
- '^2\.1'
180+
- '^2\.3'
181+
182+
183+
Ansible Role Variables
184+
----------------------
185+
186+
Have a look at `defaults/main.yml <https://git.linuxfabrik.ch/linuxfabrik-ansible/roles/stig/-/blob/master/defaults/main.yml>`_ for a complete list of available variables.
187+
188+
189+
STIG "CIS Rocky Linux 9 Benchmark" - Details
190+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
191+
192+
Mandatory:
193+
194+
* You have to set the ``stig__grub2_password`` variable.
195+
196+
Some remediations are disabled by default for various reasons - enable them only if needed:
197+
198+
* | Audit system file permissions (or similar)
199+
| Reason: File permissions can be reset by the package manager or even a reboot at any time, which means that auditing tends to fail. For this reason, our audit task ignores some of the known files in ``var/log``.
200+
* | Ensure audit logs are not automatically deleted (or similar)
201+
| Reason: No customer likes to have his machine stopped simply because the audit partition runs out of space, and the mass of cryptic audit logs cannot be checked anyway.
202+
* | Ensure password expiration is 365 days or less (or similar)
203+
| Reason: May lock you and Ansible out.
204+
* | Ensure rsyslog is configured to send logs to a remote log host (or similar)
205+
| Reason: This is more complex in reality than the CIS mediation suggests.
206+
* | Ensure SSH root login is disabled (or similar)
207+
| Reason: May lock you and Ansible out.
208+
* | Ensure updates, patches, and additional security software are installed (or similar)
209+
| Reason: Skipping this saves quite some time during the run. Also, there are other possible update strategies.
210+
211+
212+
stig.db
213+
-------
214+
215+
This is a SQLite file and can be viewed and edited with *DB Browser for SQLite*, for example.
216+
217+
The ``profile`` table contains STIG control definitions (currently some CIS benchmarks). The meaning of some of the columns:
218+
219+
* ``enabled``: Specifies whether a *remediation* should be applied automatically or not. Set to "0" if this causes problems or is unnecessary.
220+
221+
The ``audit`` table maps controls to audit scripts (Bash). The meaning of some of the columns:
222+
223+
* ``exec_order``: Execution order within the specific STIG profile.
224+
* ``audit_name``: Filename of the audit script in the ``audits/`` directory.
225+
226+
The ``remediation`` table maps controls to Ansible remediation variables.
227+
228+
Use NULL to unset any value.
229+
230+
To get a complete list of disabled remediations, execute this SQL statement on ``stig.db``:
231+
232+
.. code-block:: text
233+
234+
SELECT *
235+
FROM profile
236+
WHERE
237+
enabled = 0
238+
239+
Some audits and remediations in some STIG profiles might not be implemented for various reasons. As an example, to get a list, execute this SQL statement on ``stig.db``:
240+
241+
.. code-block:: text
242+
243+
SELECT p.*
244+
FROM profile p
245+
LEFT JOIN audit a ON p.id = a.id
246+
WHERE
247+
p.profile_name = "CIS Rocky Linux 9"
248+
AND a.id IS NULL
249+
250+
251+
Naming Scheme for Controls
252+
--------------------------
253+
254+
From a remediation action point of view: ``<package or device>[-<section or detail>][-<section or detail>]-<action>``
255+
256+
* package or device: for example "httpd" or "tmp"
257+
* section: for example "vhosts"
258+
* action: a remediation action that should be done. One of
259+
260+
* get: fetch some information - for audit tasks that will never have a remediation counterpart
261+
* compare: compare two or more items - for audit tasks that will never have a remediation counterpart
262+
263+
* off: disabling or configuring something to "off"
264+
* on: enabling or configuring something to "on"
265+
* disable: disabling a service
266+
* enable: enabling a service
267+
268+
* install: install a package
269+
* update: update a package or packages
270+
* remove: uninstalling a package, deleting files and directories
271+
272+
* chmod: changing permissions using chmod
273+
* chown: changing owner using chown
274+
275+
* cron: configuring cronjobs
276+
* timer: configuring systemd timer
277+
* select: set something from a list of choices
278+
* configure: more or less complex configuration tasks
279+
* setup: both installation and configuration
280+
281+
282+
Examples
283+
--------
284+
285+
Auditing a Rocky Linux 9 VM, excluding some controls:
286+
287+
.. code-block:: bash
288+
289+
./audit.py --lengthy --profile-name='CIS Rocky Linux 9' --profile-version='v2.0.0' --hostname=192.0.2.194 --control-name-exclude='^1\.9|^3\.4\.|^4\.1\.2\.2|^4\.2\.1\.5|^5\.2\.10|^5\.3\.1|^5\.3\.2|^5\.3\.3|^5\.4\.2|^5\.5\.1\.1'
290+
291+
Apply the remedies of "CIS Rocky Linux 9" (use this as a starting point):
292+
293+
.. code-block:: text
294+
295+
# hosts.yml
296+
cis_hosts:
297+
vars:
298+
ansible_become: True
299+
hosts:
300+
192.0.2.194:
301+
302+
.. code-block:: text
303+
304+
# host_vars/192.0.2.194.yml
305+
stig__crypto_policy: 'FIPS'
306+
stig__grub2_password: 'BlueLake23'
307+
308+
.. code-block:: text
309+
310+
# group_vars/cis_hosts.yml
311+
stig:
312+
- profile_name: 'CIS Rocky Linux 9'
313+
profile_version: 'v2.0.0' # or "latest"
314+
also_use_controls_disabled_by_default: False
315+
control_name_include: # use regular expressions here
316+
- '^1'
317+
- '^2'
318+
- '^3'
319+
- '^4'
320+
- '^5'
321+
- '^6'
322+
control_name_exclude:
323+
- '^1\.9'
324+
325+
.. code-block:: text
326+
327+
# playbook.yml
328+
- hosts:
329+
- 'cis_hosts'
330+
roles:
331+
- role: 'stig'
332+
333+
.. code-block:: bash
334+
335+
ansible-playbook --inventory=path/to/hosts.yml path/to/playbook.yml --extra-vars="ansible_ssh_user=root"

0 commit comments

Comments
 (0)