Skip to content

Commit d30f22f

Browse files
authored
Merge pull request #21 from alivx/ali_JanFix
General improvement ⚡️
2 parents 838ad62 + f6e3080 commit d30f22f

9 files changed

+172
-23
lines changed

README.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,14 @@ ansible-playbook -i host run.yaml -t section2 -t 6.1.1
138138
* Note:
139139
When run an individual task be sure from the dependencies between tasks, for example, if you run tag **4.1.1.2 Ensure auditd service is enabled** before running **4.1.1.1 Ensure auditd is installed** you will get an error at the run time.
140140

141-
Points with ~~Tilda~~ not implemented yet, currently I'm working on it.
142-
143-
141+
* Points with ~~Tilda~~ not implemented yet, currently I'm working on it.
142+
* make sure to select one time service, for me I use ntp, but you can use other service such as [`systemd-timesyncd`,`ntp`,`chrony`] under the settings `defaults/main.yaml`
143+
> Testing
144+
> 11/1/2020 Tested on AWS EC2 ubuntu 20.04 LTS [Pass]
145+
> 11/1/2020 Tested on local Ubuntu 20.04 LTS server [Pass]
144146

147+
* Before run make sure to update user list under `defaults/main.yaml` on `list_of_os_users` + `allowed_users`
148+
* `Make` sure to set the right subnet under `defaults/main.yaml` on `allowd_hosts`
145149

146150
_________________
147151

@@ -200,9 +204,9 @@ _________________
200204

201205
**1.5 Secure Boot Settings**
202206

203-
- ~~1.5.1 Ensure bootloader password is set (Automated)~~
207+
- 1.5.1 Ensure bootloader password is set (Automated)
204208
- 1.5.2 Ensure permissions on bootloader config are configured - (Automated)
205-
- ~~1.5.3 Ensure authentication required for single user mode (Automated)~~
209+
- 1.5.3 Ensure authentication required for single user mode (Automated)
206210

207211
**1.6 Additional Process Hardening**
208212
- 1.6.1 Ensure XD/NX support is enabled (Automated)
@@ -235,8 +239,8 @@ _________________
235239
- 2.2 Special Purpose Services
236240
- 2.2.1 Time Synchronization
237241
- 2.2.1.1 Ensure time synchronization is in use (Automated)
238-
- ~~2.2.1.2 Ensure systemd-timesyncd is configured (Manual)~~
239-
- ~~2.2.1.3 Ensure chrony is configured (Automated)~~
242+
- 2.2.1.2 Ensure systemd-timesyncd is configured (Manual)
243+
- 2.2.1.3 Ensure chrony is configured (Automated)
240244
- 2.2.1.4 Ensure ntp is configured (Automated)
241245
- 2.2.2 Ensure X Window System is not installed (Automated)
242246
- 2.2.3 Ensure Avahi Server is not installed (Automated)

defaults/main.yml

+28-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ set_root_password: yes
1919
root_password: r00tP4ssw0rd
2020

2121
# Section 2 Settings
22+
23+
#Setting for systemd-timesyncd
24+
enable_systemdtimesyncd: no #If you enable this make sure to disable NTP below, only one time service must be run in the server
25+
timesync_timezone: Etc/UTC
26+
timesync_fallback_ntp_hosts:
27+
- 0.pool.ntp.org
28+
- 1.pool.ntp.org
29+
- 2.pool.ntp.org
30+
- 3.pool.ntp.org
31+
32+
#Setting for NTP
33+
enableNTP: yes
2234
time_synchronization_package_name: ntp
2335
time_synchronization_servers:
2436
- uri: "time1.google.com"
@@ -29,6 +41,19 @@ time_synchronization_servers:
2941
config: "iburst"
3042
- uri: "time4.google.com"
3143
config: "iburst"
44+
45+
# Setting for chrony
46+
chronyEnable: no
47+
chrony_driftfile: /var/lib/chrony/chrony.drift
48+
chronyservers_preferred: []
49+
chronyservers:
50+
- 0.pool.ntp.org
51+
- 1.pool.ntp.org
52+
- 2.pool.ntp.org
53+
- 3.pool.ntp.org
54+
chrony_keys: /etc/chrony/chrony.keys
55+
chrony_log_dir: /var/log/chrony
56+
3257
web_server_name: nginx
3358
remove_HTTPserver: no
3459
remove_xinetd: yes
@@ -87,7 +112,7 @@ ssh_MACs: "[email protected],[email protected],hmac-sha2
87112
## 5.2.14 Ensure only strong Key Exchange algorithms are used
88113
ssh_key_algorithms: "curve25519-sha256,[email protected],diffie-hellman-group14-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256"
89114
## 5.2.17 Ensure SSH access is limited
90-
allowed_users: ali saleh baker root #Put None or list of users space between each user
115+
allowed_users: ubuntu root #Put None or list of users space between each user
91116
allowed_groups: None
92117
deny_users: None
93118
deny_groups: None
@@ -101,7 +126,7 @@ pass_warn_age: 7
101126
pass_min_days: 1
102127
## 5.4.1.1 Ensure password expiration is 365 days or less
103128
list_of_os_users:
104-
- ali
129+
- ubuntu
105130
## 5.4.1.4 Ensure inactive password lock is 30 days or less
106131
##Note: A value of -1 would disable this setting
107132
account_inactive: 30
@@ -111,7 +136,7 @@ shell_timeout_sec: 900
111136
# Section 6
112137
withoutOwnerFileDirOwner: root
113138
withoutGroupFilesDirGroup: root
114-
outputfiles: /home/ali/ #Output dir of some command
139+
outputfiles: /root/ #Output dir of some command
115140
disable_autofs: true
116141
disable_usb: true
117142
install_apparmor: true

files/templates/chrony.conf.j2

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# {{ ansible_managed }}
2+
3+
driftfile {{ chrony_driftfile }}
4+
5+
{% for server in chronyservers_preferred %}
6+
{% if server is search('pool') %}
7+
pool {{ server }} iburst prefer
8+
{% else %}
9+
server {{ server }} iburst prefer
10+
{% endif %}
11+
{% endfor %}
12+
{% for server in chronyservers %}
13+
{% if server is search('pool') %}
14+
pool {{ server }} iburst
15+
{% else %}
16+
server {{ server }} iburst
17+
{% endif %}
18+
{% endfor %}
19+
20+
# Ignore stratum in source selection.
21+
stratumweight 0
22+
23+
# Record the rate at which the system clock gains/losses time.
24+
driftfile {{ chrony_driftfile }}
25+
26+
# Enable kernel RTC synchronization.
27+
rtcsync
28+
29+
# This directive tells 'chronyd' to parse the 'adjtime' file to find out if the
30+
# real-time clock keeps local time or UTC. It overrides the 'rtconutc' directive.
31+
hwclockfile /etc/adjtime
32+
33+
# In first three updates step the system clock instead of slew
34+
# if the adjustment is larger than 10 seconds.
35+
makestep 10 3
36+
37+
# Stop bad estimates upsetting machine clock.
38+
maxupdateskew 100.0
39+
40+
# Allow NTP client access from local network.
41+
#allow 192.168/16
42+
43+
# Listen for commands only on localhost.
44+
bindcmdaddress 127.0.0.1
45+
bindcmdaddress ::1
46+
47+
# Serve time even if not synchronized to any NTP server.
48+
#local stratum 10
49+
50+
keyfile {{ chrony_keys }}
51+
52+
# Disable logging of client accesses.
53+
noclientlog
54+
55+
# Send a message to syslog if a clock adjustment is larger than 0.5 seconds.
56+
logchange 0.5
57+
58+
logdir {{ chrony_log_dir }}
59+
#log measurements statistics tracking

files/templates/greeter.dconf-defaults.j2

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# {{ ansible_managed }}
12
# These are the options for the greeter session that can be set
23
# through GSettings. Any GSettings setting that is used by the
34
# greeter session can be set here.

files/templates/ntp.conf.j2

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# {{ ansible_managed }}
12
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help
23

34
driftfile /var/lib/ntp/ntp.drift

files/templates/timesyncd.conf.j2

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# {{ ansible_managed }}
2+
[Time]
3+
NTP={{ timesync_ntp_hosts | default("") | join(" ") }}
4+
FallbackNTP={{ timesync_fallback_ntp_hosts | join(" ") }}

handlers/main.yml

+8
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@
2222
service:
2323
name: rsyslog
2424
state: restarted
25+
- name: RestartChronyservice
26+
service:
27+
name: "chrony"
28+
state: restarted
29+
- name: reloadTimesyncd
30+
service:
31+
name: systemd-timesyncd
32+
state: restarted

tasks/section_1_Initial_Setup.yaml

+5-6
Original file line numberDiff line numberDiff line change
@@ -748,35 +748,35 @@
748748
# overridden by the user.
749749
- name: 1.6.4 Ensure core dumps are restricted
750750
block:
751-
- name: 1.6.4 Ensure core dumps are restricted
751+
- name: 1.6.4 Ensure core dumps are restricted | sysctl
752752
sysctl:
753753
name: fs.suid_dumpable
754754
value: "0"
755755
state: present
756756
reload: true
757757
sysctl_set: true
758758
ignoreerrors: true
759-
- name: 1.6.4 Ensure core dumps are restricted
759+
- name: 1.6.4 Ensure core dumps are restricted | limits.conf
760760
lineinfile:
761761
dest: /etc/security/limits.conf
762762
line: "* hard core 0"
763763
regexp: '(^#)?\*\s+hard\s+core\s+[0-9]+'
764764
state: present
765765
create: true
766766
insertbefore: "# End of file"
767-
- name: 1.6.4 Ensure core dumps are restricted
767+
- name: 1.6.4 Ensure core dumps are restricted | apt
768768
apt:
769769
name: systemd-coredump
770770
state: present
771-
- name: 1.6.4 Ensure core dumps are restricted
771+
- name: 1.6.4 Ensure core dumps are restricted | coredump.conf
772772
lineinfile:
773773
dest: /etc/systemd/coredump.conf
774774
line: "Storage=none"
775775
regexp: '(^#)?\s*Storage\s*='
776776
state: present
777777
create: true
778778
insertbefore: "# End of file"
779-
- name: 1.6.4 Ensure core dumps are restricted
779+
- name: 1.6.4 Ensure core dumps are restricted | coredump.conf
780780
lineinfile:
781781
dest: /etc/systemd/coredump.conf
782782
line: "ProcessSizeMax=0"
@@ -824,7 +824,6 @@
824824
dest: /etc/default/grub
825825
regexp: '^(GRUB_CMDLINE_LINUX=(?!.*apparmor)\"[^\"]*)(\".*)'
826826
replace: '\1 apparmor=1 security=apparmor\2'
827-
follow: true
828827
register: output_1_7_1_2
829828
- name: 1.7.1.2 Ensure AppArmor is enabled in the bootloader configuration | reload
830829
shell: |

tasks/section_2_Services.yaml

+55-7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
name: "ntp"
5959
state: started
6060
enabled: true
61+
when: "{{enableNTP}}"
62+
6163
tags:
6264
- section2
6365
- level_1_server
@@ -72,17 +74,54 @@
7274
# This recommendation only applies if timesyncd is in use on the system
7375
# Only one time synchronization method should be in use on the system
7476
- name: 2.2.1.2 Ensure systemd-timesyncd is configured
75-
debug:
76-
msg: Skip this, since we are using ntp
77+
block:
78+
- name: 2.2.1.2 Ensure systemd-timesyncd is configured | install systemd-timesyncd
79+
apt:
80+
name: systemd-timesyncd
81+
state: present
82+
- name: 2.2.1.2 Ensure systemd-timesyncd is configured | set timezone
83+
timezone:
84+
name: "{{ timesync_timezone }}"
85+
- name: 2.2.1.2 Ensure systemd-timesyncd is configured | Configure systemd-timesyncd
86+
template:
87+
src: files/templates/timesyncd.conf.j2
88+
dest: /etc/systemd/timesyncd.conf
89+
mode: 0644
90+
owner: root
91+
group: root
92+
notify: reloadTimesyncd
93+
- name: 2.2.1.2 Ensure systemd-timesyncd is configured | Start and enable systemd-timesyncd
94+
service:
95+
name: systemd-timesyncd.service
96+
enabled: yes
97+
state: started
98+
when: "{{enable_systemdtimesyncd}} == True"
7799
tags:
78100
- section2
79101
- level_1_server
80102
- level_1_workstation
81103
- 2.2.1.2
82104
# 2.2.1.3 Ensure chrony is configured
83105
- name: 2.2.1.3 Ensure chrony is configured
84-
debug:
85-
msg: Skip this, since we are using ntp
106+
block:
107+
- name: 2.2.1.3 Ensure chrony is configured | Install Chrony
108+
apt:
109+
name: "chrony"
110+
state: present
111+
- name: 2.2.1.3 Ensure chrony is configured | Start Chrony service
112+
service:
113+
name: "chrony"
114+
state: started
115+
enabled: yes
116+
- name: 2.2.1.3 Ensure chrony is configured | Generate configuration
117+
template:
118+
src: files/templates/chrony.conf.j2
119+
dest: "/etc/chrony/chrony.conf"
120+
owner: root
121+
group: root
122+
mode: 0644
123+
notify: RestartChronyservice
124+
when: "{{chronyEnable}} == True"
86125
tags:
87126
- section2
88127
- level_1_server
@@ -452,9 +491,18 @@
452491
msg: >
453492
Run the following command:
454493
$ lsof -i -P -n | grep -v "(ESTABLISHED)"
455-
Review the output to ensure that all services listed are required on the system. If a listed
456-
service is not required, remove the package containing the service. If the package
457-
containing a non-essential service is required, stop and mask the non-essential service.
494+
Review the output to ensure that all services listed are required on the system. If a listed
495+
service is not required, remove the package containing the service. If the package
496+
containing a non-essential service is required, stop and mask the non-essential service.
497+
Code Meaning
498+
S File size differs.
499+
M File mode differs (includes permissions and file type).
500+
5 The MD5 checksum differs.
501+
D The major and minor version numbers differ on a device file.
502+
L A mismatch occurs in a link.
503+
U The file ownership differs.
504+
G The file group owner differs.
505+
T The file time (mtime) differs.
458506
tags:
459507
- section2
460508
- level_1_server

0 commit comments

Comments
 (0)