Skip to content

Os immutable fs #864

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

Open
wants to merge 453 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
453 commits
Select commit Hold shift + click to select a range
ab23d14
Use Python3 for OpenBSD tests
schurzi Feb 4, 2024
47da0b4
Always update Vagrant Boxes before using
schurzi Feb 4, 2024
3ba5c5a
Skip update if box is not present
schurzi Feb 4, 2024
4e986b8
Skip update if box is not present
schurzi Feb 4, 2024
f9923a0
Block kernel update
schurzi Feb 4, 2024
258d69e
use loop for package names
schurzi Feb 4, 2024
c7d70c6
add more excluded packages
schurzi Feb 4, 2024
f67899a
remove update tasks, since we use updated images
schurzi Feb 5, 2024
ab02662
free space on /boot
schurzi Feb 5, 2024
84ac0bc
add comment
schurzi Feb 5, 2024
3a9d6cc
update changelog
Feb 5, 2024
0ae800f
Update ansible/ansible-lint action to v24 (#745)
renovate[bot] Feb 7, 2024
4bbac6d
update changelog
Feb 7, 2024
4b71f7e
Update dependency ansible-core to v2.16.4
renovate[bot] Feb 26, 2024
59a7a10
update changelog
Feb 27, 2024
a649027
add ssh_pubkey_authentication variable (#749)
debbabi Mar 20, 2024
afdc3dd
update changelog
Mar 20, 2024
c44d05f
Update dependency ansible-core to v2.16.5
renovate[bot] Mar 25, 2024
a968990
update changelog
Mar 25, 2024
a8c43e6
ci: define permissions for enforce-labels workflow
fgreinacher May 6, 2024
365dce4
update changelog
May 9, 2024
0ae5b90
fix spelling
rndmh3ro May 30, 2024
db4a7df
fix spelling
rndmh3ro May 30, 2024
1e7bc3c
update changelog
May 31, 2024
b97fc29
centos7 is eol, remove it (#767)
rndmh3ro May 31, 2024
aee10f6
update mysql_hardening readme
May 31, 2024
25b49d4
update os_hardening readme
May 31, 2024
3a0daa8
update ssh_hardening readme
May 31, 2024
21c1c35
do not force type of ssh_gateway_ports (#765)
rndmh3ro May 31, 2024
0643098
update nginx_hardening readme
May 31, 2024
0376c8f
update changelog
May 31, 2024
c8107b9
centos8 stream is eol (#770)
rndmh3ro Jun 4, 2024
9185556
Prettified Code!
rndmh3ro Jun 4, 2024
9876048
update changelog
Jun 4, 2024
2c14819
disable systemd socket activation (#769)
rndmh3ro Jun 18, 2024
0e07a2a
ssh: explicitly enable or disable the service at boot (#771)
Byh0ki Jun 24, 2024
b4b4dfb
add arg-spec for new variable ssh_server_service_enabled
rndmh3ro Jun 24, 2024
1f964ec
update mysql_hardening readme
Jun 24, 2024
cdba70c
update nginx_hardening readme
Jun 24, 2024
24d2200
update ssh_hardening readme
Jun 24, 2024
5972aba
update os_hardening readme
Jun 24, 2024
5c0b162
Use best-practice preset for renovate (#775)
schurzi Jun 25, 2024
3316bd4
chore(deps): pin dependencies
renovate[bot] Jun 25, 2024
b11a8c7
remove freebsd12
schurzi Jul 2, 2024
44d9aa2
update ssh_hardening readme
Jul 2, 2024
896be2f
Ensure that ssh is installed (#774)
Byh0ki Jul 2, 2024
2678bce
try to fix release workflow
rndmh3ro Jul 3, 2024
daf88b8
try to fix release workflow
rndmh3ro Jul 3, 2024
acd95e3
fix release workflow
schurzi Jul 25, 2024
c4927bf
update changelog
Jul 25, 2024
090eadb
chore(deps): update patrickjahns/version-drafter-action digest to 207…
renovate[bot] Jul 25, 2024
a67070b
update changelog
Jul 25, 2024
45fba20
chore(deps): update actions/setup-python digest to 39cd149 (#778)
renovate[bot] Jul 25, 2024
fbc8db8
update changelog
Jul 25, 2024
d455030
fix ansible-lint
rndmh3ro Jul 25, 2024
7ab5693
chore(deps): update ansible/ansible-lint digest to 95382d3 (#779)
renovate[bot] Jul 25, 2024
62e2cd5
update changelog
Jul 25, 2024
51d249f
Remove deprecated rebuild of initrd
schurzi Jul 28, 2024
ff032e6
Prettified Code!
schurzi Jul 28, 2024
8254689
update changelog
Jul 28, 2024
0c64cd0
Update to current Fedora releases
schurzi Jul 28, 2024
1207db4
Add needed package for tests
schurzi Jul 28, 2024
8d2d66d
Add special vars for Fedora 40
schurzi Jul 29, 2024
12f24ca
update changelog
Jul 30, 2024
1d6c287
Update Debian compatibility (#784)
schurzi Aug 6, 2024
8a42a4a
update ssh_hardening readme
Aug 6, 2024
a0c3cf3
update os_hardening readme
Aug 6, 2024
8f3b2c1
update mysql_hardening readme
Aug 6, 2024
ab62dd3
update changelog
Aug 6, 2024
186a7e4
update nginx_hardening readme
Aug 6, 2024
5b71733
update changelog
Aug 6, 2024
83adb82
update changelog
Aug 6, 2024
4cda21a
update galaxy.yml with new version
Aug 6, 2024
36e25b2
chore(deps): update dependency ansible-core to v2.17.2 (#756)
renovate[bot] Aug 7, 2024
e8f7ca9
update changelog
Aug 7, 2024
a276ea8
chore(deps): update dependency ansible-core to v2.17.3
renovate[bot] Aug 12, 2024
ea66ab7
update changelog
Aug 13, 2024
023de37
chore(deps): update actions/setup-python digest to f677139
renovate[bot] Aug 29, 2024
f7edd07
update changelog
Sep 4, 2024
0f31b06
chore(deps): update ansible/ansible-lint digest to 25f783c (#792)
renovate[bot] Sep 15, 2024
4863cf2
update changelog
Sep 15, 2024
0a6065e
chore(deps): update dependency ansible-core to v2.17.4
renovate[bot] Sep 15, 2024
5b5a213
update changelog
Sep 15, 2024
2eb423e
Use Python venv for VM tests
schurzi Oct 4, 2024
5e64944
Use Python venv for VM tests
schurzi Oct 4, 2024
9873663
add Dependency
schurzi Oct 4, 2024
a24161b
Correct typo
schurzi Oct 4, 2024
a729bfd
update changelog
Oct 4, 2024
b388e03
Remove unused files and variables
schurzi Oct 3, 2024
2b2e1f3
Disable testing of audit in docker
schurzi Oct 3, 2024
d52434a
Disable testing of audit in docker
schurzi Oct 3, 2024
cbc24e5
update os_hardening readme
Oct 4, 2024
9369e0c
update changelog
Oct 4, 2024
83e42f3
Fix Changelog
schurzi Oct 5, 2024
f8314a6
Prettified Code!
schurzi Oct 5, 2024
3ab7de9
update changelog
Oct 5, 2024
f2144c2
Fix Changelog generation by adapting regex
schurzi Oct 5, 2024
becc22b
update changelog
Oct 5, 2024
f7c4dff
feat: :sparkles: Corrected package name (#799)
PapaPeskwo Oct 8, 2024
4efce4a
update changelog
Oct 8, 2024
9482eb7
Don't run tests if the environment is not correct
schurzi Oct 7, 2024
3ddb468
update changelog
Oct 8, 2024
9487e85
chore(deps): update ansible/ansible-lint digest to 3b5bee1
renovate[bot] Sep 19, 2024
817a5c9
chore(deps): update actions/checkout digest to eef6144
renovate[bot] Oct 7, 2024
257be2b
update changelog
Oct 8, 2024
4095997
chore(deps): update dependency ansible-core to v2.17.5
renovate[bot] Oct 8, 2024
464ca24
update changelog
Oct 8, 2024
feaa7be
fix(docs): add 'become: true' to example playbooks. fix #787 (#804)
rndmh3ro Oct 9, 2024
4d26ec5
Prettified Code!
rndmh3ro Oct 9, 2024
813cc1e
update changelog
Oct 9, 2024
64a832b
fixing missing quotes for ssh_permit_tunnel parameter in argument_spe…
vmpr Oct 10, 2024
c0e845e
update ssh_hardening readme
Oct 10, 2024
7266015
update os_hardening readme
Oct 10, 2024
4eae911
update nginx_hardening readme
Oct 10, 2024
0eb54f3
update mysql_hardening readme
Oct 10, 2024
cec1a20
update changelog
Oct 10, 2024
cd8641a
Provide granular noop for ssh configuration (#789)
seven-beep Oct 13, 2024
990fba9
Prettified Code!
rndmh3ro Oct 13, 2024
52f9604
update changelog
Oct 13, 2024
ec58736
fix(ssh_hardening): test setting kex to false, remove wrong default (…
rndmh3ro Oct 13, 2024
ee716c0
update nginx_hardening readme
Oct 13, 2024
06912e4
fix(cicd): test idempotence on ssh custom tests (#807)
rndmh3ro Oct 13, 2024
537fdb3
update changelog
Oct 13, 2024
616f748
update mysql_hardening readme
Oct 13, 2024
1a9420a
update ssh_hardening readme
Oct 13, 2024
6fd4f3c
update os_hardening readme
Oct 13, 2024
38086bc
update changelog
Oct 13, 2024
07cc4cc
feat(ssh): add alpine support (#809)
rndmh3ro Oct 13, 2024
74a8e63
Prettified Code!
rndmh3ro Oct 13, 2024
adb450f
update changelog
Oct 13, 2024
d438927
Pin python dependencies and optimize GitHub Actions
schurzi Oct 21, 2024
f3d95fd
Fix copy&paste error
schurzi Oct 21, 2024
26f2017
Sort matrix builds
schurzi Oct 22, 2024
3785887
Add variable to set name_format for auditd
schurzi Oct 21, 2024
b80ad45
update changelog
Oct 22, 2024
3e0ce73
update mysql_hardening readme
Oct 22, 2024
1324e0d
update os_hardening readme
Oct 22, 2024
957279d
update ssh_hardening readme
Oct 22, 2024
c308a9f
update nginx_hardening readme
Oct 22, 2024
b1163e3
update changelog
Oct 22, 2024
67995b2
update galaxy.yml with new version
Oct 22, 2024
d218cb8
Bump ansible-core from 2.17.5 to 2.17.6 (#820)
dependabot[bot] Nov 6, 2024
b0a40d0
update changelog
Nov 6, 2024
10d27f2
adding switch for ForwardAgent in ssh_config (#818)
Shizzlebix Nov 11, 2024
799be3e
update ssh_hardening readme
Nov 11, 2024
1db943f
update changelog
Nov 11, 2024
eee1435
chore(deps): update actions/setup-python digest to 0b93645
renovate[bot] Oct 24, 2024
7f3b1c2
update changelog
Nov 16, 2024
16f50ee
Disable OpenBSD Tests
schurzi Nov 16, 2024
e027a47
Add space ...
schurzi Nov 16, 2024
4c22482
Update ansible/ansible-lint digest to 44be233
renovate[bot] Nov 13, 2024
813c36d
update changelog
Nov 16, 2024
f053415
chore(deps): update dependency aar-doc to v2.0.1 (#817)
renovate[bot] Nov 16, 2024
0844694
update changelog
Nov 16, 2024
96a0482
chore(deps): update dependency ansible-core to v2.18.0 (#819)
renovate[bot] Nov 16, 2024
18a78ae
update changelog
Nov 16, 2024
17d0bd3
chore(deps): update actions/checkout digest to 11bd719
renovate[bot] Nov 16, 2024
0efc172
update changelog
Nov 22, 2024
41d3b5f
Change installation source for OpenBSD tests
schurzi Nov 30, 2024
3315efb
update changelog
Nov 30, 2024
cf510b2
chore(deps): update dependency ansible-core to v2.18.1 (#829)
renovate[bot] Dec 3, 2024
ae4d362
update changelog
Dec 3, 2024
2d653d6
chore(deps): update dependency molecule to v24.12.0
renovate[bot] Dec 5, 2024
5e5a189
update changelog
Dec 9, 2024
9e2480d
chore(deps): update dependency molecule-plugins to v23.6.0
renovate[bot] Dec 18, 2024
08cc409
chore(deps): update ansible/ansible-lint digest to 4ce8e49
renovate[bot] Dec 12, 2024
16aab5e
update changelog
Dec 23, 2024
d07e648
MOdify PAM to allow SSH Key logins with locked passwords
schurzi Dec 22, 2024
3949aa6
fix errors
schurzi Dec 22, 2024
370468d
Install passlib on executor
schurzi Dec 22, 2024
aa5d873
Make changes portable
schurzi Dec 22, 2024
a571028
Use correct os_family for Suse ...
schurzi Dec 22, 2024
b25f7df
Add docs
schurzi Dec 22, 2024
ac2fd08
Prettified Code!
schurzi Dec 23, 2024
f513b82
update changelog
Dec 23, 2024
883bf18
update galaxy.yml with new version
Dec 23, 2024
a0c3dec
Pin runner image to specific version to decouple from GitHub updates
schurzi Feb 7, 2025
14ce685
minor fixups
schurzi Feb 7, 2025
b24ebe0
minor fixups
schurzi Feb 7, 2025
4704afe
update zypper
schurzi Feb 7, 2025
a96c9c1
update changelog
Feb 7, 2025
6d1a5ad
chore(deps): update dependency ansible-core to v2.18.2 (#843)
renovate[bot] Feb 8, 2025
d727b9d
update changelog
Feb 8, 2025
cae2ae1
chore(deps): update ansible/ansible-lint action to v25
renovate[bot] Feb 8, 2025
df68c16
chore(deps): update actions/setup-python digest to 4237552
renovate[bot] Feb 8, 2025
45c83ff
update changelog
Feb 8, 2025
85910ae
Combine multiple set_fact into jinja filter
Tinyblargon Feb 5, 2025
10122ce
update changelog
Feb 8, 2025
4d26560
chore(deps): update dependency molecule to v25
renovate[bot] Feb 8, 2025
d836f72
Also update plugins
schurzi Feb 8, 2025
bd8ec94
Downgrade molecule
schurzi Feb 8, 2025
2171af9
update changelog
Feb 8, 2025
fe8af6e
Set number of warning days before password expires for existing users
Normo Jan 17, 2025
9f8a858
bump min_ansible_version
schurzi Feb 9, 2025
19b481f
update os_hardening readme
Feb 9, 2025
2f8a411
update ssh_hardening readme
Feb 9, 2025
0ea92a7
update changelog
Feb 9, 2025
ef44496
chore(deps): update ansible/ansible-lint digest to 49ded6a
renovate[bot] Feb 18, 2025
14e30d3
update changelog
Feb 20, 2025
350ef96
chore(deps): update dependency ansible-core to v2.18.3 (#852)
renovate[bot] Feb 24, 2025
ebfdf04
update changelog
Feb 24, 2025
9a613ce
allow seperate password login for sftp
mib1185 Sep 19, 2024
276f569
move `Match Group sftponly` block to the end
mib1185 Feb 25, 2025
a1958b0
update changelog
Feb 25, 2025
45eab65
update galaxy.yml with new version
Feb 26, 2025
e4ffa6b
chore(deps): update artis3n/ansible_galaxy_collection digest to f6110ae
renovate[bot] Mar 1, 2025
3c4875e
update changelog
Mar 10, 2025
023a96b
added os_immutable_fs to os_hardening and ssh_hardening and edited ta…
millerthegorilla Mar 16, 2025
b8c1946
added os_immutable_fs to os_hardening and ssh_hardening and edited ta…
millerthegorilla Mar 16, 2025
8db3cf8
updating and debugging
millerthegorilla Mar 29, 2025
c07091d
updated and debugging
millerthegorilla Mar 29, 2025
f74b865
adding rpm_ostree reboot checks
millerthegorilla Mar 29, 2025
688927d
debugging
millerthegorilla Mar 29, 2025
3679667
debugging
millerthegorilla Mar 29, 2025
85c06aa
debugging
millerthegorilla Mar 29, 2025
e1161e9
debugging
millerthegorilla Mar 30, 2025
5830926
debugging ostree
millerthegorilla Mar 30, 2025
a1b661f
debugging ostree
millerthegorilla Mar 30, 2025
658fbd6
debugging ostree
millerthegorilla Mar 30, 2025
195288c
debugging ostree
millerthegorilla Mar 30, 2025
7e443a3
updated README
millerthegorilla Mar 30, 2025
1d41c85
debugging ssh
millerthegorilla Mar 31, 2025
2e1afe0
debugging ssh role
millerthegorilla Mar 31, 2025
6d1b73c
debugging rpm_ostree_pgks_installed
millerthegorilla Mar 31, 2025
08ade92
debugging os_hardening immutable
millerthegorilla Apr 1, 2025
3b9851b
debugging os_hardening immutable
millerthegorilla Apr 1, 2025
6f5e7a4
debugging os_hardening immutable
millerthegorilla Apr 1, 2025
03328f9
debugged check for reboot in ssh_hardening
millerthegorilla Apr 1, 2025
fd9d38d
Fix: ForwardAgent j2 template space in roles/ssh_hardening/templates/…
AliMehraji Mar 17, 2025
59c7c79
update changelog
Mar 17, 2025
6385535
finished os_hardening and ssh_hardening for immutable systems
millerthegorilla Apr 2, 2025
b1b2112
updated ssh_hardening readme
millerthegorilla Apr 2, 2025
87d7586
debugging ssh_hardening
millerthegorilla Apr 2, 2025
922e43c
debugging ssh_hardening
millerthegorilla Apr 2, 2025
aa3ff10
debugging os_hardening
millerthegorilla Apr 2, 2025
ca241e6
debugging
millerthegorilla Apr 2, 2025
b2dc3cc
changed variable names and added ostree_reboot tag
millerthegorilla Apr 3, 2025
552f348
changed variable names
millerthegorilla Apr 3, 2025
7b9e110
debugged the user_accounts.yml code for os_immutable_fs
millerthegorilla Apr 10, 2025
5756885
chore(deps): update ansible/ansible-lint digest to 6a4fcdb
renovate[bot] Apr 2, 2025
95920ef
update changelog
Apr 3, 2025
88bd71c
chore(deps): update ansible/ansible-lint digest to c16f018
renovate[bot] Apr 3, 2025
65bf233
update changelog
Apr 3, 2025
ae60142
chore(deps): update actions/setup-python digest to 8d9ed9a
renovate[bot] Mar 25, 2025
7f05b68
update changelog
Apr 3, 2025
57add77
chore(deps): update dependency ansible-core to v2.18.4 (#860)
renovate[bot] Apr 4, 2025
ebf9c73
update changelog
Apr 4, 2025
de0d05c
chore(deps): update dependency aar-doc to v2.1.0 (#861)
renovate[bot] Apr 4, 2025
83bcd83
update changelog
Apr 4, 2025
98a6655
fixed failed merge of roles/os_hardening/README.md
millerthegorilla Apr 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions roles/os_hardening/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ Otherwise inspec will fail. For more information, see [issue #124](https://githu

We know that this is the case on Raspberry Pi.

### Using with ostree system, ie coreos/silverblue

If you are using os_hardening with a filesystem that has an immutable filesystem in accordance with the ostree specification, then you can set the variable `os_immutable_fs: true` (default is false).

Behind the scenes, the variable ansible_package_use will be set to the rpm_ostree_pkg module, to allow the generic ansible.builtin.package module to install via that module.

#### reboots
By its nature, ostree needs to be rebooted for packages to be installed, so if any package installs, a reboot will be initiated at the end of the role, and will then wait for the remote to be ready before continuing. To skip the reboot use the --skip-tags switch on the command line with the tag `ostree_reboot`.

Currently os_immutable_fs only selects for Fedora systems, ie iot, silverblue, coreos, kinoite.

#### dependencies
For os_hardening to work, you will need the python-rpm package installed on the control node and 'pip install rpm' in the python prefix from where you are running ansible.

Note that on Coreos remote systems, neither python nor python-rpm is installed as default, so for ansible to work you will have to install both packages on the remote using ansible.builtin.raw, before you use os_hardening.

## Changing sysctl variables

If you want to override sysctl-variables, you can use the `sysctl_overwrite` variable (in older versions you had to override the whole `sysctl_dict`).
Expand Down Expand Up @@ -806,6 +822,24 @@ This role is mostly based on guides by:
- Description: Add list of user to allow creation of .netrc in users homedir
- Type: list of ''
- Required: no
- `os_immutable_fs`
- Default: false
- Description: A boolean set if the root file system is immutable ie rpm-ostree
- Type:
- Required: no
- `ansible_package_use`:
- Default: "{{ (os_immutable_fs |bool) |ternary('community.general.rpm_ostree_pkg', '') }}"
- Description: a string that indicates which package manager to use to ansible.builtin.package
that must be to the rpm_ostree_pkg module when the os is immutable, as the default of
atomic_container is both deprecated and incorrect.
- Type: str
- Required: no
- `rpm_ostree_needs_reboot`:
- Default: false
- Description: A variable used to indicate to a reboot task when the remote should be rebooted
to handle package installation on rpm_ostree systems. Used internally for os_immutable_fs.
- Type: bool
- Required: no
- `os_pam_enabled`
- Default: `True`
- Description: Set to false to disable installing and configuring pam.
Expand Down
15 changes: 15 additions & 0 deletions roles/os_hardening/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,21 @@ argument_specs:
default: '[]'
type: list
description: A list of filesystems that should not be disabled
os_immutable_fs:
default: false
type: bool
description: A boolean set if the root file system is immutable ie rpm-ostree
ansible_package_use:
default: "{{ (os_immutable_fs |bool) |ternary('community.general.rpm_ostree_pkg', '') }}"
type: str
description: a string that indicates which package manager to use to ansible.builtin.package
that must be set when the os is immutable, as the default of atomic_container is both
deprecated and incorrect.
os_ostree_needs_reboot:
default: false
type: bool
description: A variable used to indicate to a reboot task when the remote should be rebooted
to handle package installation on ostree systems.
os_hardening_enabled:
default: true
type: bool
Expand Down
4 changes: 4 additions & 0 deletions roles/os_hardening/tasks/auditd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
ansible.builtin.package:
name: "{{ auditd_package }}"
state: present
register: os_ostree_pkgs_installed
tags: auditd

- set_fact:
os_ostree_needs_reboot: os_ostree_pkgs_installed.results[0].needs_reboot is true | bool

- name: Configure auditd | package-08
ansible.builtin.template:
Expand Down
8 changes: 8 additions & 0 deletions roles/os_hardening/tasks/hardening.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@
when:
- ansible_facts.os_family == 'RedHat'
- os_yum_enabled | bool
- not os_immutable_fs

- name: Import tasks to configure ostree systems
ansible.builtin.import_tasks: rpm_ostree.yml
tags: yum
when:
- ansible_facts.os_family == 'RedHat'
- os_immutable_fs | bool

- name: Import tasks to configure apt
ansible.builtin.import_tasks: apt.yml
Expand Down
17 changes: 17 additions & 0 deletions roles/os_hardening/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,20 @@
when: os_hardening_enabled | bool
tags:
- always

- name: Reboot if ostree_immutable needs_reboot is true
ansible.builtin.reboot:
msg: "Rebooting to install packages"
pre_reboot_delay: 0
when:
- os_immutable_fs | bool
- os_ostree_needs_reboot | bool
tags: ostree_reboot

- name: Wait for ostree system to be up
ansible.builtin.wait_for_connection:
delay: 20
when:
- os_immutable_fs | bool
- os_ostree_needs_reboot | bool
tags: ostree_reboot
4 changes: 3 additions & 1 deletion roles/os_hardening/tasks/minimize_access.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@
owner: root
group: root
mode: "0750"
when: '"change_user" not in os_security_users_allow'
when:
- '"change_user" not in os_security_users_allow'
- not os_immutable_fs | bool

# we have to define this combined variable here, because when defining it
# in the defaults like this:
Expand Down
1 change: 1 addition & 0 deletions roles/os_hardening/tasks/minimize_access_fs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
mode: "{{ mount.mode }}"
when:
- mountpoint_exists.stat.exists | bool
- not os_immutable_fs | bool

- name: "Register changed mountpoints"
ansible.builtin.set_fact:
Expand Down
4 changes: 4 additions & 0 deletions roles/os_hardening/tasks/modprobe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
ansible.builtin.package:
name: "{{ modprobe_package }}"
state: present
register: os_ostree_pkgs_installed

- set_fact:
os_ostree_needs_reboot: os_ostree_pkgs_installed.results[0].needs_reboot is true | bool

- name: Check if efi is installed
ansible.builtin.stat:
Expand Down
1 change: 1 addition & 0 deletions roles/os_hardening/tasks/pam.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
state: absent
when:
- ansible_facts.os_family != 'Archlinux'
- not os_immutable_fs | bool

- name: Import tasks for Debian PAM
ansible.builtin.import_tasks: pam_debian.yml
Expand Down
1 change: 1 addition & 0 deletions roles/os_hardening/tasks/pam_rhel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
state: present
when:
- os_auth_pam_sssd_enable | bool
- not os_immutable_fs | bool

- name: Configure passwdqc and faillock via central system-auth config
ansible.builtin.template:
Expand Down
11 changes: 11 additions & 0 deletions roles/os_hardening/tasks/rpm_ostree.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# configuration tasks for rpm_ostree systems
# selected when os_immutable_fs == true
# basic tasks taken from ./yum.yml
- name: Remove deprecated or insecure packages | package-01 - package-09
community.general.rpm_ostree_pkg:
name: "{{ os_security_packages_list }}"
state: absent
when:
- os_immutable_fs
- os_security_packages_clean | bool
9 changes: 7 additions & 2 deletions roles/os_hardening/tasks/user_accounts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
shell: '{{ os_nologin_shell_path }}'
createhome: false
loop: "{{ system_users }}"
when:
- not os_immutable_fs # fedora atomic-hosts have os_nologin as standard and nss-altfiles causes issues
- (system_users is defined) and (system_users | length > 0)
# https://github.com/dev-sec/ansible-collection-hardening/issues/857

- name: Lock passwords from linux system accounts
ansible.builtin.user:
Expand All @@ -98,8 +102,9 @@
createhome: false
loop: "{{ system_users }}"
when:
- getent_shadow[item][0] is not match("\!") # password hashes containing illegal characters like "!" are unusable already (locked)

- (system_users is defined) and (system_users | length > 0) # https://github.com/dev-sec/ansible-collection-hardening/issues/857
- (getent_shadow[item][0] is defined and getent_shadow[item][0] is not match("\!")) # password hashes containing illegal characters like "!" are unusable already (locked)

- name: Limit access to home directories of regular (non-system, non-root) accounts
ansible.builtin.file:
mode: "0700"
Expand Down
4 changes: 3 additions & 1 deletion roles/os_hardening/tasks/yum.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@
ansible.builtin.dnf:
name: "{{ os_security_packages_list }}"
state: absent
when: os_security_packages_clean | bool
when:
- os_security_packages_clean | bool
- not os_immutable_fs
4 changes: 4 additions & 0 deletions roles/os_hardening/vars/Fedora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,7 @@ modprobe_package: module-init-tools
auditd_package: audit

hidepid_option: "2" # allowed values: 0, 1, 2

os_immutable_fs: false
ansible_package_use: "{{ (os_immutable_fs |bool) |ternary('community.general.rpm_ostree_pkg', '') }}"
os_ostree_needs_reboot: false
23 changes: 22 additions & 1 deletion roles/ssh_hardening/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ Since Debian 12 and Ubuntu 22.04 the ssh-daemon is not running by default anymor
We revert this change to its traditional behaviour.
For more information, see [this issue](https://github.com/dev-sec/ansible-collection-hardening/issues/763).

### Using with ostree system, ie coreos/silverblue

If you are using ssh_hardening with a filesystem that has an immutable filesystem in accordance with the ostree specification, then you can set the variable `ssh_immutable_fs: true` (default is false).

Behind the scenes, the variable ansible_package_use will be set to rpm_ostree_pkg, to allow the generic ansible.builtin.package module to install via that module.

#### reboots
By its nature, ostree needs to be rebooted for packages to be installed, so if any package installs, a reboot will be initiated at the end of the role, and will then wait for the remote to be ready before continuing. To skip the reboot use the --skip-tags switch on the command line with the tag `ostree_reboot`.

Currently ssh_immutable_fs only selects for Fedora systems, ie iot, silverblue, coreos, kinoite.

#### dependencies
For os_hardening to work, you will need the python-rpm package installed on the control node and 'pip install rpm' in the python prefix from where you are running ansible.

Note that on Coreos remote systems, neither python nor python-rpm is installed as default, so for ansible to work you will have to install both packages on the remote using ansible.builtin.raw, before you use ssh_hardening. You will also need to specify the following in your playbook with reference to the ssh_hardening role:
`ssh_authorized_keys_file: '.ssh/authorized_keys.d/ignition'`

<!-- BEGIN_ANSIBLE_DOCS -->

## Supported Operating Systems
Expand Down Expand Up @@ -474,7 +491,11 @@ For more information, see [this issue](https://github.com/dev-sec/ansible-collec
- Description: The facility code that is used when logging messages from sshd.
- Type: str
- Required: no

- `ssh_immutable_fs`:
- Default: false
- Description: A boolean set if the root file system is immutable ie rpm-ostree
- Type: bool
- Required: no
## Dependencies

None.
Expand Down
15 changes: 15 additions & 0 deletions roles/ssh_hardening/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,18 @@ argument_specs:
ssh_forward_agent:
default: 'no'
description: Enables the ssh forward agent for the Cli if set to 'yes'
ssh_immutable_fs:
default: false
type: bool
description: A boolean set if the root file system is immutable ie rpm-ostree
ansible_package_use:
default: "{{ (ssh_immutable_fs |bool) |ternary('community.general.rpm_ostree_pkg', '') }}"
type: str
description: a string that indicates to ansible.builtin.package which package manager to use,
that must be set when the os is immutable, as the default of atomic_container is both
deprecated and incorrect. Used internally by ssh_immutable_fs.
ssh_ostree_needs_reboot:
default: false
type: bool
description: A variable used to indicate to a reboot task when the remote should be rebooted
to handle package installation on rpm_ostree systems. Used internally by ssh_immutable_fs.
5 changes: 5 additions & 0 deletions roles/ssh_hardening/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
loop: "{{ ssh_pkgs }}"
loop_control:
loop_var: pkg
register: ssh_ostree_pkgs_installed

- name: Indicate ssh_ostree_needs_reboot
ansible.builtin.set_fact:
ssh_ostree_needs_reboot: ssh_ostree_pkgs_installed.results[0].needs_reboot is true | bool

# see https://github.com/dev-sec/ansible-collection-hardening/issues/763
- name: Change Debian/Ubuntu systems so ssh starts traditionally instead of socket-activated
Expand Down
17 changes: 17 additions & 0 deletions roles/ssh_hardening/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,20 @@
apply:
become: true
when: ssh_hardening_enabled | bool

- name: Reboot if ostree_immutable needs_reboot is true
ansible.builtin.reboot:
msg: "Rebooting to install packages"
pre_reboot_delay: 0
when:
- ssh_ostree_needs_reboot | bool
- ssh_immutable_fs | bool
tags: ostree_reboot

- name: Wait for ostree system to be up
ansible.builtin.wait_for_connection:
delay: 20
when:
- ssh_ostree_needs_reboot | bool
- ssh_immutable_fs | bool
tags: ostree_reboot
5 changes: 5 additions & 0 deletions roles/ssh_hardening/tasks/selinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
ansible.builtin.package:
name: "{{ ssh_selinux_packages }}"
state: present
register: ssh_ostree_pkgs_installed

- name: Indicate ssh_ostree_needs_reboot
ansible.builtin.set_fact:
ssh_ostree_needs_reboot: ssh_ostree_pkgs_installed.results[0].needs_reboot is true | bool

- name: Authorize the following ports for selinux - {{ ssh_server_ports }}
community.general.seport:
Expand Down
4 changes: 4 additions & 0 deletions roles/ssh_hardening/vars/Fedora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ sshd_moduli_file: /etc/ssh/moduli
# disable CRYPTO_POLICY to take settings from sshd configuration
# see: https://access.redhat.com/solutions/4410591
sshd_disable_crypto_policy: true

ssh_immutable_fs: false
ansible_package_use: "{{ (ssh_immutable_fs |bool) |ternary('community.general.rpm_ostree_pkg', '') }}"
ssh_ostree_needs_reboot: false