Skip to content

Commit d42260e

Browse files
authored
Merge pull request #124 from ansible-lockdown/devel
Release to main
2 parents 6554423 + 60ca683 commit d42260e

File tree

9 files changed

+148
-27
lines changed

9 files changed

+148
-27
lines changed

.github/workflows/devel_pipeline_validation.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
types: [opened, reopened, synchronize]
88
branches:
99
- devel
10+
- benchmark*
1011
paths:
1112
- '**.yml'
1213
- '**.sh'
@@ -27,7 +28,7 @@
2728
jobs:
2829
# This will create messages for first time contributers and direct them to the Discord server
2930
welcome:
30-
runs-on: self-hosted
31+
runs-on: ubuntu-latest
3132

3233
steps:
3334
- uses: actions/first-interaction@main
@@ -70,7 +71,6 @@
7071
echo IAC_BRANCH=main >> $GITHUB_ENV
7172
fi
7273
73-
7474
# Pull in terraform code for linux servers
7575
- name: Clone GitHub IaC plan
7676
uses: actions/checkout@v4

.github/workflows/main_pipeline_validation.yml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
types: [opened, reopened, synchronize]
88
branches:
99
- main
10+
- latest
1011
paths:
1112
- '**.yml'
1213
- '**.sh'
@@ -23,17 +24,6 @@
2324
# A workflow run is made up of one or more jobs
2425
# that can run sequentially or in parallel
2526
jobs:
26-
# This will create messages for first time contributers and direct them to the Discord server
27-
welcome:
28-
runs-on: self-hosted
29-
30-
steps:
31-
- uses: actions/first-interaction@main
32-
with:
33-
repo-token: ${{ secrets.GITHUB_TOKEN }}
34-
pr-message: |-
35-
Congrats on opening your first pull request and thank you for taking the time to help improve Ansible-Lockdown!
36-
Please join in the conversation happening on the [Discord Server](https://www.lockdownenterprise.com/discord) as well.
3727

3828
# This workflow contains a single job that tests the playbook
3929
playbook-test:

.gitignore

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
.env
22
*.log
33
*.retry
4-
.cache
54
.vagrant
65
tests/*redhat-subscription
76
tests/Dockerfile
@@ -10,11 +9,9 @@ tests/Dockerfile
109
packer_cache
1110
delete*
1211
ignore*
13-
test_inv
14-
# temp remove doc while this is built up
15-
doc/
1612
# VSCode
1713
.vscode
14+
vagrant
1815

1916
# Byte-compiled / optimized / DLL files
2017
__pycache__/
@@ -47,9 +44,5 @@ benchparse/
4744
# GitHub Action/Workflow files
4845
.github/
4946

50-
# key types
51-
*.pem
52-
*.ppk
53-
*.key
54-
*.rsa
55-
*.ecdsa
47+
# ansible-lint
48+
.ansible/

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ repos:
3535
- id: detect-secrets
3636

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

4242
- repo: https://github.com/ansible-community/ansible-lint
43-
rev: v25.1.2
43+
rev: v25.2.1
4444
hooks:
4545
- id: ansible-lint
4646
name: Ansible-lint
@@ -59,6 +59,6 @@ repos:
5959
- ansible-core>=2.10.1
6060

6161
- repo: https://github.com/adrienverge/yamllint.git
62-
rev: v1.35.1 # or higher tag
62+
rev: v1.37.0 # or higher tag
6363
hooks:
6464
- id: yamllint

defaults/main.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ amzn2023cis_legacy_boot: false
6868
## are used in ansible
6969
python2_bin: /bin/python2.7
7070

71+
# Create managed not custom local_facts files
72+
create_benchmark_facts: true
73+
ansible_facts_path: /etc/ansible/facts.d
74+
7175
## Benchmark name and profile used by audting control role
7276
# The audit variable can be found at the base
7377
benchmark: AMAZON2023-CIS
@@ -137,6 +141,20 @@ audit_conf_dest: "/opt"
137141
# Where the audit logs are stored
138142
audit_log_dir: '/opt'
139143

144+
## Ability to collect and take audit files moving to a centralised location
145+
# This enables the collection of the files from the host
146+
fetch_audit_output: false
147+
148+
# Method of getting,uploading the summary files
149+
## Ensure access and permissions are avaiable for these to occur.
150+
## options are
151+
# fetch - fetches from server and moves to location on the ansible controller (could be a mount point available to controller)
152+
# copy - copies file to a location available to the managed node
153+
audit_output_collection_method: fetch
154+
155+
# Location to put the audit files
156+
audit_output_destination: /opt/audit_summaries/
157+
140158
### Goss Settings ##
141159
####### END ########
142160

@@ -980,6 +998,11 @@ amzn2023cis_shell_session_timeout:
980998
# CIS states that this value shall never exceed 900 or be equal to 0.
981999
timeout: 600
9821000

1001+
## Control 4.6.5 Ensure default user umask is 027 or more restrictive
1002+
# The following variable specifies the "umask" to set in the `/etc/bashrc` and `/etc/profile` and `/etc/login.defs`.
1003+
# The value needs to be `027` or more restrictive to comply with CIS standards
1004+
amzn2023cis_umask: '027'
1005+
9831006
##
9841007
## Section 5 Control Variables
9851008
##

tasks/fetch_audit_output.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
3+
# Stage to copy audit output to a centralised location
4+
5+
- name: "FETCH_AUDIT_FILES | Fetch files and copy to controller"
6+
when: audit_output_collection_method == "fetch"
7+
ansible.builtin.fetch:
8+
src: "{{ item }}"
9+
dest: "{{ audit_output_destination }}"
10+
flat: true
11+
failed_when: false
12+
register: discovered_audit_fetch_state
13+
loop:
14+
- "{{ pre_audit_outfile }}"
15+
- "{{ post_audit_outfile }}"
16+
become: false
17+
18+
# Added this option for continuity but could be changed by adjusting the variable audit_conf_dest
19+
# Allowing backup to one location
20+
- name: "FETCH_AUDIT_FILES | Copy files to location available to managed node"
21+
when: audit_output_collection_method == "copy"
22+
ansible.builtin.copy:
23+
src: "{{ item }}"
24+
dest: "{{ audit_output_destination }}"
25+
mode: 'u-x,go-wx'
26+
flat: true
27+
failed_when: false
28+
register: discovered_audit_fetch_copy_state
29+
loop:
30+
- pre_audit_outfile
31+
- post_audit_outfile
32+
33+
- name: "FETCH_AUDIT_FILES | Fetch files and copy to controller | Warning if issues with fetch_audit_files"
34+
when:
35+
- (discovered_audit_fetch_state is defined and not discovered_audit_fetch_state.changed) or
36+
(discovered_audit_copy_state is defined and not discovered_audit_copy_state.changed)
37+
block:
38+
- name: "FETCH_AUDIT_FILES | Fetch files and copy to controller | Warning if issues with fetch_audit_files"
39+
ansible.builtin.debug:
40+
msg: "Warning!! Unable to write to localhost {{ audit_output_destination }} for audit file copy"
41+
42+
- name: "FETCH_AUDIT_FILES | Fetch files and copy to controller | Warning if issues with fetch_audit_files"
43+
vars:
44+
warn_control_id: "FETCH_AUDIT_FILES"
45+
ansible.builtin.import_tasks:
46+
file: warning_facts.yml

tasks/main.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,36 @@
163163
tags:
164164
- run_audit
165165

166+
- name: Add ansible file showing Benchmark and levels applied
167+
block:
168+
- name: Create ansible facts directory
169+
ansible.builtin.file:
170+
path: "{{ ansible_facts_path }}"
171+
state: directory
172+
owner: root
173+
group: root
174+
mode: 'u=rwx,go=rx'
175+
176+
- name: Create ansible facts file
177+
ansible.builtin.template:
178+
src: etc/ansible/compliance_facts.j2
179+
dest: "{{ ansible_facts_path }}/compliance_facts.fact"
180+
owner: root
181+
group: root
182+
mode: "u-x,go-wx"
183+
when: create_benchmark_facts
184+
tags:
185+
- always
186+
- benchmark
187+
188+
- name: Fetch audit files
189+
ansible.builtin.import_tasks:
190+
file: fetch_audit_output.yml
191+
when:
192+
- fetch_audit_output
193+
- run_audit
194+
tags: always
195+
166196
- name: Show Audit Summary
167197
when:
168198
- run_audit

tasks/section_4/cis_4.6.x.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
ansible.builtin.replace:
9494
path: "{{ item }}"
9595
regexp: ^(?i)(\s*umask)\s+(?!\d*[2,7]7)\d{3,4}
96-
replace: '\1 027'
96+
replace: '\1 {{ amzn2023cis_umask }}'
9797
loop:
9898
- /etc/bashrc
9999
- /etc/profile
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# CIS Hardening Carried out
2+
# Added as part of ansible-lockdown CIS baseline
3+
# provided by Mindpoint Group - A Tyto Athene Company
4+
5+
[lockdown_details]
6+
# Benchmark release
7+
Benchmark_release = CIS-{{ benchmark_version }}
8+
Benchmark_run_date = {{ '%Y-%m-%d - %H:%M:%S' | ansible.builtin.strftime }}
9+
# If options set (doesn't mean it ran all controls)
10+
level_1_hardening_enabled = {{ amzn2023cis_level_1 }}
11+
level_2_hardening_enabled = {{ amzn2023cis_level_2 }}
12+
13+
{% if ansible_run_tags | length > 0 %}
14+
# If tags used to stipulate run level
15+
{% if 'level1-server' in ansible_run_tags %}
16+
Level_1_Server_tag_run = true
17+
{% endif %}
18+
{% if 'level2-server' in ansible_run_tags %}
19+
Level_2_Server_tag_run = true
20+
{% endif %}
21+
{% if 'level1-workstation' in ansible_run_tags %}
22+
Level_1_workstation_tag_run = true
23+
{% endif %}
24+
{% if 'level2-workstation' in ansible_run_tags %}
25+
Level_2_workstation_tag_run = true
26+
{% endif %}
27+
{% endif %}
28+
29+
[lockdown_audit_details]
30+
{% if run_audit %}
31+
# Audit run
32+
audit_file_local_location = {{ audit_log_dir }}
33+
{% if not audit_only %}
34+
audit_summary = {{ post_audit_results }}
35+
{% endif %}
36+
{% if fetch_audit_output %}
37+
audit_files_centralized_location = {{ audit_output_destination }}
38+
{% endif %}
39+
{% endif %}

0 commit comments

Comments
 (0)