Skip to content

Commit a14f30a

Browse files
authored
Merge pull request #308 from ansible-lockdown/devel
Final main release v1r13 - Jan24 -updated
2 parents 48e6bc9 + c984790 commit a14f30a

File tree

8 files changed

+73
-30
lines changed

8 files changed

+73
-30
lines changed

.ansible-lint

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ skip_list:
1919
- '602'
2020
- '208'
2121
use_default_rules: true
22+
rulesdir:
23+
- ./rules/
2224
verbosity: 0

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ci:
77

88
repos:
99
- repo: https://github.com/pre-commit/pre-commit-hooks
10-
rev: v4.6.0
10+
rev: v5.0.0
1111
hooks:
1212
# Safety
1313
- id: detect-aws-credentials
@@ -35,12 +35,12 @@ repos:
3535
- id: detect-secrets
3636

3737
- repo: https://github.com/gitleaks/gitleaks
38-
rev: v8.18.4
38+
rev: v8.21.1
3939
hooks:
4040
- id: gitleaks
4141

4242
- repo: https://github.com/ansible-community/ansible-lint
43-
rev: v24.7.0
43+
rev: v24.9.2
4444
hooks:
4545
- id: ansible-lint
4646
name: Ansible-lint

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ This contains rewrites and ID reference changes as per STIG documentation.
5858

5959
This can be turned on or off within the defaults/main.yml file with the variable rhel7cis_run_audit. The value is false by default, please refer to the wiki for more details. The defaults file also populates the goss checks to check only the controls that have been enabled in the ansible role.
6060

61-
This is a much quicker, very lightweight, checking (where possible) config compliance and live/running settings.
61+
This is a quick, very lightweight, check (where possible) of config compliance and live/running settings.
6262

63-
A new form of auditing has been developed, by using a small (12MB) go binary called [goss](https://github.com/goss-org/goss) along with the relevant configurations to check. Without the need for infrastructure or other tooling.
63+
A form of auditing has been developed, by using a small (12MB) go binary called [goss](https://github.com/goss-org/goss) along with the relevant configurations to check. Without the need for infrastructure or other tooling.
6464
This audit will not only check the config has the correct setting but aims to capture if it is running with that configuration also trying to remove [false positives](https://www.mindpointgroup.com/blog/is-compliance-scanning-still-relevant/) in the process.
6565

6666
## Documentation
@@ -83,9 +83,8 @@ The following packages must be installed on the controlling host/host where ansi
8383

8484
- python2-passlib (or just passlib, if using python3)
8585
- python-lxml
86-
- python-xmltodict
8786

88-
Package 'python-xmltodict' is required if you enable the OpenSCAP tool installation and run a report. Packages python(2)-passlib are required for tasks with custom filters or modules. These are all required on the controller host that executes Ansible.
87+
Packages python(2)-passlib are required for tasks with custom filters or modules. These are all required on the controller host that executes Ansible.
8988

9089
## Role Variables
9190

filter_plugins/xml2json.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

handlers/main.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,3 @@
174174
when:
175175
- "'dconf' in ansible_facts.packages"
176176
- rhel8stig_always_configure_dconf
177-
178-
- name: prereport score
179-
ansible.builtin.debug:
180-
msg: "Pre-run OpenSCAP score is {{ rhel8stig_prescanresults.Benchmark.TestResult.score['#text'] }}"
181-
when: rhel8stig_oscap_scan
182-
183-
- name: postreport score
184-
ansible.builtin.debug:
185-
msg: "Post-run OpenSCAP score is {{ rhel8stig_postscanresults.Benchmark.TestResult.score['#text'] }}"
186-
when: rhel8stig_oscap_scan

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
passlib
22
lxml
3-
xmltodict
43
jmespath
54
yamllint

rules/tag.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""Implementation of TagRule."""
2+
3+
from __future__ import annotations
4+
5+
import re
6+
from typing import TYPE_CHECKING
7+
8+
from ansiblelint.constants import LINE_NUMBER_KEY
9+
from ansiblelint.file_utils import Lintable
10+
from ansiblelint.rules import AnsibleLintRule, TransformMixin
11+
12+
if TYPE_CHECKING:
13+
from ansiblelint.errors import MatchError
14+
from ansiblelint.utils import Task
15+
16+
17+
class TagRule(AnsibleLintRule, TransformMixin):
18+
"""Rule for checking task tags."""
19+
20+
id = "tag"
21+
description = (
22+
"All task tags should have distinct names"
23+
"and templates in tags should be avoided."
24+
)
25+
severity = "MEDIUM"
26+
tags = ["idiom"]
27+
_re_templated = re.compile(r"^.*\{\{.*\}\}.*$")
28+
_ids = {
29+
"tag[no-duplicate]": "Tasks should not duplicate tags.",
30+
"tag[no-template]": "Tasks should not use Jinja templates in tags.",
31+
}
32+
33+
def matchtask(
34+
self,
35+
task: Task,
36+
file: Lintable | None = None,
37+
) -> list[MatchError]:
38+
results: list[MatchError] = []
39+
if file and file.failed():
40+
return results
41+
tags = task.get("tags")
42+
if tags:
43+
if len(tags) != len(set(tags)):
44+
results.append(
45+
self.create_matcherror(
46+
message="Tasks should not duplicate tags.",
47+
lineno=task[LINE_NUMBER_KEY],
48+
tag="tag[no-duplicate]",
49+
filename=file,
50+
),
51+
)
52+
for tag in tags:
53+
if self._re_templated.match(tag):
54+
results.append(
55+
self.create_matcherror(
56+
message="Tasks should not use Jinja templates in tags.",
57+
lineno=task[LINE_NUMBER_KEY],
58+
tag="tag[no-template]",
59+
filename=file,
60+
),
61+
)
62+
break
63+
return results

tasks/fix-cat2.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2733,7 +2733,6 @@
27332733
tags:
27342734
- RHEL-08-010830
27352735
- CAT2
2736-
- V-230330
27372736
- CCI-000366
27382737
- SRG-OS-000480-GPOS-00229
27392738
- SV-230330r858713_rule
@@ -5973,7 +5972,8 @@
59735972
- SV-230505r744020_rule
59745973
- V-230505
59755974
- firewall
5976-
- "{{ rhel8stig_firewall_service }}"
5975+
- iptables
5976+
- firewalld
59775977

59785978
- name: "MEDIUM | RHEL-08-040101 | PATCH | A firewall must be active on RHEL 8"
59795979
block:

0 commit comments

Comments
 (0)