Compare commits

...
102 Commits
Author SHA1 Message Date
schurzi 99fe8b6969 Merge pull request #594 from dlouzan/fix/type-cast-variables
fix(os_hardening): cast expected int types in pam tasks
2022-10-27 20:43:17 +02:00
Diego Louzán f8295d5248 fix(os_hardening): cast expected int types in pam tasks
Signed-off-by: Diego Louzán <[email protected]>
2022-10-27 16:50:08 +02:00
dev-sec CI a1f75f877b update changelog 2022-10-26 08:33:13 +00:00
schurzi 901923bac2 Merge pull request #588 from dev-sec/support_more_os
Support more os
2022-10-26 10:13:40 +02:00
Martin Schurz c30ef42355 exclude el9 from vm tests
Signed-off-by: Martin Schurz <[email protected]>
2022-10-25 18:59:11 +02:00
Sebastian Gumprich e2b963d711 change baselines back to master
Signed-off-by: Sebastian Gumprich <[email protected]>
2022-10-25 18:59:11 +02:00
Sebastian Gumprich 414efd6125 use correct centos stream images, try to fix prepare step for debian tests
Signed-off-by: Sebastian Gumprich <[email protected]>
2022-10-25 18:59:11 +02:00
Sebastian Gumprich 87a461fc57 use forked mysql-baseline
Signed-off-by: Sebastian Gumprich <[email protected]>
2022-10-25 18:59:11 +02:00
Sebastian Gumprich dac66f4a88 simplify OS-vars files
Signed-off-by: Sebastian Gumprich <[email protected]>
2022-10-25 18:59:11 +02:00
Sebastian Gumprich 3b8b394f10 add ssh-vars for new OS
Signed-off-by: Sebastian Gumprich <[email protected]>
2022-10-25 18:59:11 +02:00
Sebastian Gumprich b27ffd08b0 add mysql-vars for new OS
Signed-off-by: Sebastian Gumprich <[email protected]>
2022-10-25 18:58:53 +02:00
dev-sec CI 8ee946a537 update changelog 2022-10-24 08:04:42 +00:00
Sebastian Gumprich a176443f22 add support for centos stream 8 and 9, rocky 9
Signed-off-by: Sebastian Gumprich <[email protected]>
2022-10-24 10:03:07 +02:00
Sebastian Gumprich 9d75e3b00e test crypto changes from ssh-baseline
Signed-off-by: Sebastian Gumprich <[email protected]>
2022-10-24 10:03:07 +02:00
schurzi a1b80fe657 adopt all current suggestions from ansible-lint (#592) 2022-10-24 09:42:23 +02:00
dev-sec CI 53be805099 update changelog 2022-10-21 09:07:46 +00:00
donestefan 464d8df8e8 add hardening of root user account(s) (#579) 2022-10-21 11:05:43 +02:00
dev-sec CI f1ea1e52f3 update changelog 2022-10-20 13:00:42 +00:00
Benedikt Böhm 802bad48e6 do not manage trusted user ca keys if none exist (#580)
Signed-off-by: Benedikt Böhm <[email protected]>

Signed-off-by: Benedikt Böhm <[email protected]>
2022-10-20 14:44:14 +02:00
dev-sec CI d3acab585e update changelog 2022-09-28 08:54:32 +00:00
Sebastian Gumprich 44489dea5f run tests only on pushes to master or to PRs (#581)
Signed-off-by: Sebastian Gumprich <[email protected]>

Signed-off-by: Sebastian Gumprich <[email protected]>
2022-09-28 10:44:31 +02:00
dev-sec CI 64b5d82c5f update galaxy.yml with new version 2022-09-08 13:03:43 +00:00
dev-sec CI f96c2dd8c9 update changelog 2022-09-08 13:00:02 +00:00
hagenbauer 500cd24beb nginx variables for configuration and owner (#578)
Signed-off-by: [email protected] <[email protected]>

Signed-off-by: [email protected] <[email protected]>
2022-09-08 14:58:10 +02:00
dev-sec CI 3835b2a18c update changelog 2022-09-06 14:38:23 +00:00
Simon Baerlocher 883effef82 add centos >8 Support (#573)
Signed-off-by: Simon Baerlocher <[email protected]>

Signed-off-by: Simon Baerlocher <[email protected]>
2022-09-06 16:31:43 +02:00
dev-sec CI 9cc0b254f6 update galaxy.yml with new version 2022-08-26 13:11:17 +00:00
dev-sec CI 80960d5703 update changelog 2022-08-26 11:46:34 +00:00
Sebastian Gumprich 9ac01fb358 add always-tag to include so other tags can be used (#569)
Signed-off-by: Sebastian Gumprich <[email protected]>

Signed-off-by: Sebastian Gumprich <[email protected]>
2022-08-26 13:45:05 +02:00
Sebastian Gumprich 11d187e62e update supported OS in meta and fix linting (#572)
Signed-off-by: Sebastian Gumprich <[email protected]>

Signed-off-by: Sebastian Gumprich <[email protected]>
2022-08-26 13:44:51 +02:00
Sebastian Gumprich fbea75ad18 only run release actions on upstream-repo (#568)
fixes #566

Signed-off-by: Sebastian Gumprich <[email protected]>

Signed-off-by: Sebastian Gumprich <[email protected]>
2022-08-26 09:40:59 +02:00
dev-sec CI 40913a3e6d update changelog 2022-08-26 07:19:56 +00:00
donestefan 38e1c3bbeb fix misleading comment (#571)
also RHEL6 is not supported anymore
2022-08-26 09:17:54 +02:00
dev-sec CI d981a4e545 update galaxy.yml with new version 2022-08-22 11:19:25 +00:00
dev-sec CI 627634d95f update changelog 2022-08-22 10:41:10 +00:00
Sebastian Gumprich 720d7786b5 fix typo 2022-08-22 12:39:21 +02:00
Sebastian Gumprich 84412e99c2 fix typo 2022-08-22 11:25:08 +02:00
dev-sec CI 516f4cfb01 update changelog 2022-08-22 09:18:59 +00:00
divialth fb8b9142c8 rework filesystem hardening (#555)
* rework filesystem hardening

-  removed a lot duplicated code by using a loop
-  added new hardening options for /tmp
-  added new options "passno" and "dump" for every filesystem.
   currently ansible changed that values to 0 for every fs
   new default depends on fstype, can be overwriten in config
-  removed default fstype in config
   the type will now be autodetected,  can be overwriten in config
-  mount src setting is now optional
   the source will now be autodetected,  can be overwriten in config
-  it will be now checked, if it is really a mount
-  changed fs reload to handler
-  removed check os_auditd_enabled on /var/log/audit

Signed-off-by: divialth <[email protected]>

* fix lint errors

Signed-off-by: divialth <[email protected]>

* implemented the name suggestions

Signed-off-by: divialth <[email protected]>

Signed-off-by: divialth <[email protected]>
2022-08-22 11:16:57 +02:00
dev-sec CI ca266d25df update changelog 2022-08-22 08:05:50 +00:00
schurzi c1cd6c5ac3 change default to allow SFTP (#564)
* change default to allow SFTP

Signed-off-by: Martin Schurz <[email protected]>

* add documentation

Signed-off-by: Martin Schurz <[email protected]>

* diasble sftp for default tests

Signed-off-by: Martin Schurz <[email protected]>

* extend documentation

Signed-off-by: Martin Schurz <[email protected]>

* fix typo

Signed-off-by: Martin Schurz <[email protected]>

* correct ssh version

Signed-off-by: Martin Schurz <[email protected]>

Signed-off-by: Martin Schurz <[email protected]>
2022-08-22 10:03:37 +02:00
dev-sec CI 5e220525cb update changelog 2022-08-17 07:11:00 +00:00
PhilippFunkandPhilipp Funk fd3fc1cfba add option to bypass .netrc check function (#563)
add option to whitelist specific user that need a .netrc file in there home dirs
add test for .netrc files if option os_netrc_enabled is false

Signed-off-by: Philipp Funk <[email protected]>

Signed-off-by: Philipp Funk <[email protected]>
Co-authored-by: Philipp Funk <[email protected]>
2022-08-17 09:09:00 +02:00
dev-sec CI 6aa01f040a update galaxy.yml with new version 2022-08-16 15:27:27 +00:00
dev-sec CI e3b861bc6c update changelog 2022-08-16 15:23:18 +00:00
Sebastian Gumprich 82bb46d7cc update supported OS 2022-08-16 17:21:06 +02:00
dev-sec CI 6777681ab9 update changelog 2022-08-16 14:02:19 +00:00
dev-sec CI 14edb7d015 update changelog 2022-08-16 13:12:51 +00:00
eef8708918 Add full support for Debian 11 (#538)
* Include Debian 11 into Molecule test suites (#527)

Signed-off-by: Daya Adianto <[email protected]>

* Fix Ansible Lint GitHub Action version (#527)

Signed-off-by: Daya Adianto <[email protected]>

* Update .gitignore

Signed-off-by: Daya Adianto <[email protected]>

* mysql_hardening: Use Python 3 as Ansible interpreter (#527)

Signed-off-by: Daya Adianto <[email protected]>

* Note Debian 11 support for os_hardening & nginx_hardening (#527)

Signed-off-by: Daya Adianto <[email protected]>

* Fix lint issues & Ansible Lint configuration in CI

Signed-off-by: Daya Adianto <[email protected]>

* Try to fix YAML lint issues, again

Re-ordered YAML comments at the end of `.yamllint` file.

Signed-off-by: Daya Adianto <[email protected]>

* rm debian9 from tests, add debian 11 where missing

Signed-off-by: Sebastian Gumprich <[email protected]>

* fix mysql molecule tests

Signed-off-by: Sebastian Gumprich <[email protected]>

Signed-off-by: Daya Adianto <[email protected]>
Signed-off-by: Sebastian Gumprich <[email protected]>
Co-authored-by: Sebastian Gumprich <[email protected]>
Co-authored-by: Sebastian Gumprich <[email protected]>
2022-08-16 15:02:27 +02:00
dev-sec CI ebe43504a2 update changelog 2022-08-15 14:03:51 +00:00
Sebastian Gumprich d11595d81a revert debian 9 change, only one tls variable now (#562)
fixes #528

Signed-off-by: Sebastian Gumprich <[email protected]>

Signed-off-by: Sebastian Gumprich <[email protected]>
2022-08-15 16:01:49 +02:00
dev-sec CI beeea1ca66 update changelog 2022-08-15 11:52:04 +00:00
schurzi a806ec8598 add posibility to run ssh_hardening as unprivileged user (#561)
* add VM tests for ssh_hardening

Signed-off-by: Martin Schurz <[email protected]>

* remove VM tests from ssh_hardening

Signed-off-by: Martin Schurz <[email protected]>

* run ssh_hardening test as unprivileged user

Signed-off-by: Martin Schurz <[email protected]>

* add link for documentation

Signed-off-by: Martin Schurz <[email protected]>

* use different config

Signed-off-by: Martin Schurz <[email protected]>

* remove become

Signed-off-by: Martin Schurz <[email protected]>

* re-add become

Signed-off-by: Martin Schurz <[email protected]>

* move become into role

Signed-off-by: Martin Schurz <[email protected]>

* indentation

Signed-off-by: Martin Schurz <[email protected]>

* try args apply

Signed-off-by: Martin Schurz <[email protected]>

* fix linting

Signed-off-by: Martin Schurz <[email protected]>

* add documentation

Signed-off-by: Martin Schurz <[email protected]>

Signed-off-by: Martin Schurz <[email protected]>
2022-08-15 13:19:07 +02:00
dev-sec CI fad6059f6d update changelog 2022-08-15 11:07:07 +00:00
schurzi b56c801574 add basic support for ubuntu22.04 (#554)
Signed-off-by: Martin Schurz <[email protected]>

Signed-off-by: Martin Schurz <[email protected]>
2022-08-15 13:05:09 +02:00
dev-sec CI 7ee757b61c update galaxy.yml with new version 2022-07-26 14:13:14 +00:00
dev-sec CI 1129485e33 update changelog 2022-07-26 13:59:25 +00:00
Benedikt Böhm 2265497e75 Fix broken mode for /var/log/audit (#552)
```
Unable to open /var/log/audit/audit.log (Permission denied)
```

This PR fixes the issue by using the default permission set by auditd (`0700`).

Signed-off-by: Benedikt Böhm <[email protected]>
2022-07-26 15:57:39 +02:00
dev-sec CI 24d3520d69 update changelog 2022-07-15 09:43:19 +00:00
8c82af9c98 Only run hardening if /var/log/audit exists (#550)
* Only run harding if /var/log/audit exists

Signed-off-by: GitHub <[email protected]>

* Update roles/os_hardening/tasks/minimize_access.yml

* add more conditionals to when auditd show be hardened

Signed-off-by: Sebastian Gumprich <[email protected]>

* add more tests to the os-hardening vm tests

Signed-off-by: Sebastian Gumprich <[email protected]>

* Revert "add more tests to the os-hardening vm tests"

This reverts commit c05fe8b520.

Signed-off-by: Sebastian Gumprich <[email protected]>

Co-authored-by: Sebastian Gumprich <[email protected]>
Co-authored-by: Sebastian Gumprich <[email protected]>
2022-07-15 11:41:01 +02:00
dev-sec CI b6f32948ec update galaxy.yml with new version 2022-07-11 21:14:56 +00:00
dev-sec CI 0a25d486a0 update changelog 2022-07-11 19:59:01 +00:00
schurzi e03e435517 Merge pull request #547 from dev-sec/vm_tests
add VM tests for os_hardening
2022-07-11 21:57:21 +02:00
Martin Schurz 27d091e871 reduce testing on vm
Signed-off-by: Martin Schurz <[email protected]>
2022-07-11 16:08:35 +02:00
Martin Schurz c81ce23ed7 disable ctrl+alt+del for vm tests
Signed-off-by: Martin Schurz <[email protected]>
2022-07-11 13:04:14 +02:00
Martin Schurz 72cb97c8d5 remove waivers file from docker test config
Signed-off-by: Martin Schurz <[email protected]>
2022-07-11 12:36:48 +02:00
Martin Schurz edda7075a2 add badge for tests
Signed-off-by: Martin Schurz <[email protected]>
2022-07-11 12:17:34 +02:00
Martin Schurz 0f631c1405 add sysctl exclude
Signed-off-by: Martin Schurz <[email protected]>
2022-07-11 09:39:52 +02:00
Martin Schurz 5d50b5b130 add sysctl exclude
Signed-off-by: Martin Schurz <[email protected]>
2022-07-11 09:32:02 +02:00
Martin Schurz 28baf0d581 add sysctl exclude
Signed-off-by: Martin Schurz <[email protected]>
2022-07-11 09:17:44 +02:00
Martin Schurz 4b519e8b13 add sysctl exclude
Signed-off-by: Martin Schurz <[email protected]>
2022-07-11 09:13:26 +02:00
Martin Schurz 92dc094022 add sysctl exclude
Signed-off-by: Martin Schurz <[email protected]>
2022-07-11 09:05:58 +02:00
Martin Schurz fdc6b333c9 exclude arch
Signed-off-by: Martin Schurz <[email protected]>
2022-07-10 21:30:45 +02:00
Martin Schurz 1825eba27a exclude opensuse
Signed-off-by: Martin Schurz <[email protected]>
2022-07-10 21:08:50 +02:00
Martin Schurz cd45a58683 fix yum gpg-check task
Signed-off-by: Martin Schurz <[email protected]>
2022-07-10 20:22:39 +02:00
Martin Schurz 730510c2a7 add opensuse and arch
Signed-off-by: Martin Schurz <[email protected]>
2022-07-10 15:55:08 +02:00
Martin Schurz fa7f8597d9 fix bug in check for /boot
Signed-off-by: Martin Schurz <[email protected]>
2022-07-10 13:36:19 +02:00
Martin Schurz b6b2d45f09 speedup ansible
Signed-off-by: Martin Schurz <[email protected]>
2022-07-09 15:43:59 +02:00
Martin Schurz 9cfe1f2b9a also harden /boot
Signed-off-by: Martin Schurz <[email protected]>
2022-07-09 15:43:11 +02:00
Martin Schurz e49eacd8ec icrease ressources for test vm
Signed-off-by: Martin Schurz <[email protected]>
2022-07-09 10:42:20 +02:00
Martin Schurz 7535abd882 remove waiver
Signed-off-by: Martin Schurz <[email protected]>
2022-07-09 02:22:35 +02:00
Martin Schurz 400e576984 use correct parameter
Signed-off-by: Martin Schurz <[email protected]>
2022-07-09 01:47:59 +02:00
Martin Schurz 0eddf2872b setup python
Signed-off-by: Martin Schurz <[email protected]>
2022-07-09 01:19:12 +02:00
Martin Schurz 013a554731 force linking
Signed-off-by: Martin Schurz <[email protected]>
2022-07-09 00:59:50 +02:00
Martin Schurz 8f3f724380 call correct molecule task
Signed-off-by: Martin Schurz <[email protected]>
2022-07-09 00:57:26 +02:00
Martin Schurz e742330a41 add testing of os_hardning on vm
Signed-off-by: Martin Schurz <[email protected]>
2022-07-09 00:52:58 +02:00
dev-sec CI b00b38ece6 update changelog 2022-07-08 16:12:57 +00:00
schurzi dd919b5cf6 Merge pull request #546 from dev-sec/linting
Linting
2022-07-08 18:10:32 +02:00
Martin Schurz 21df60a71f fix includes
Signed-off-by: Martin Schurz <[email protected]>
2022-07-08 17:24:07 +02:00
Sebastian Gumprich 73f84ae2a9 fix wrong indentation
Signed-off-by: Sebastian Gumprich <[email protected]>
2022-07-08 16:04:37 +02:00
Sebastian Gumprich bf372f8493 rename tasks file and remove redundant 'verify'
Signed-off-by: Sebastian Gumprich <[email protected]>
2022-07-08 16:04:24 +02:00
Sebastian Gumprich ef89d52f98 remove duplicate file
Signed-off-by: Sebastian Gumprich <[email protected]>
2022-07-07 16:22:10 +02:00
Sebastian Gumprich 9b50392d8a fix linting
Signed-off-by: Sebastian Gumprich <[email protected]>
2022-07-07 16:12:06 +02:00
Sebastian Gumprich 215c50709b tempt 2022-07-07 15:34:28 +02:00
Sebastian Gumprich a8fdf2de0a fix linting errors
Signed-off-by: Sebastian Gumprich <[email protected]>
2022-07-07 14:59:39 +02:00
dev-sec CI 3528fe9f6d update changelog 2022-07-07 10:08:44 +00:00
Martin Schurz 02b9a20fe7 fix release action
Signed-off-by: Martin Schurz <[email protected]>
2022-07-07 12:06:34 +02:00
Martin Schurz f627d2fbfd fix release action
Signed-off-by: Martin Schurz <[email protected]>
2022-07-07 11:27:51 +02:00
rndmh3ro e28e09cd0e Prettified Code! 2022-07-07 07:02:50 +00:00
488ff6a7c3 Harden mountpoints (#531)
* first testing with tasks and variables

Signed-off-by: Ludwig Bayerlein <[email protected]>

* update variables for dir options

Signed-off-by: Ludwig Bayerlein <[email protected]>

* updated permissions and defaults

Signed-off-by: Ludwig Bayerlein <[email protected]>

* fix home dir permissions

Signed-off-by: Ludwig Bayerlein <[email protected]>

* updated tasks with useful variables

Signed-off-by: Ludwig Bayerlein <[email protected]>

* reorder tasks. first remount, then manage fstab and fix permissions on directories. Renaming task names with mountpoints (slashes)

Signed-off-by: Ludwig Bayerlein <[email protected]>

* shorten tasks with list items

Signed-off-by: Ludwig Bayerlein <[email protected]>

* change defaults for /boot directory, because its a bad behaviour, if ansible changes boot entries with a default value

Signed-off-by: Ludwig Bayerlein <[email protected]>

* Update documentation for new parameters to manage mountpoints

Signed-off-by: Ludwig Bayerlein <[email protected]>

* Update roles/os_hardening/tasks/minimize_access.yml

Co-authored-by: Sebastian Gumprich <[email protected]>
Signed-off-by: Ludwig Bayerlein <[email protected]>

* Update roles/os_hardening/tasks/minimize_access.yml

Co-authored-by: Sebastian Gumprich <[email protected]>
Signed-off-by: Ludwig Bayerlein <[email protected]>

* Fix state on every new task

Signed-off-by: Ludwig Bayerlein <[email protected]>

* loop instead of list

Signed-off-by: Ludwig Bayerlein <[email protected]>

* testing remount with register

Signed-off-by: Ludwig Bayerlein <[email protected]>

* add remounts with loop over all changed folders

Signed-off-by: Ludwig Bayerlein <[email protected]>

* testing and solving trouble with variable names

Signed-off-by: Ludwig Bayerlein <[email protected]>

* optimize default permissions for var-log-audit

Signed-off-by: Ludwig Bayerlein <[email protected]>

* optimize default permissions for var-log-audit

Signed-off-by: Ludwig Bayerlein <[email protected]>

* change to new optimizied permissions of var-log-audit

Signed-off-by: Ludwig Bayerlein <[email protected]>

* fix some defaults in fstab to configure as mounted

Signed-off-by: Ludwig Bayerlein <[email protected]>

* add stat and check, if boot folder exists

Signed-off-by: Ludwig Bayerlein <[email protected]>

Co-authored-by: Ludwig Bayerlein <[email protected]>
Co-authored-by: Sebastian Gumprich <[email protected]>
2022-07-07 09:02:25 +02:00
dev-sec CI 0251172cd1 update galaxy.yml with new version 2022-06-29 14:02:54 +00:00
dev-sec CI 9b27a6a0fc update changelog 2022-06-29 13:57:35 +00:00
100 changed files with 1323 additions and 440 deletions

No files matched your search

@@ -6,3 +6,13 @@
exclude_paths:
- .cache/ # implicit unless exclude_paths is defined in config
- .yamllint
- ../molecule/
- ../.github/
skip_list:
- fqcn-builtins
- name[template]
mock_roles:
- geerlingguy.git
- nginxinc.nginx
+8 -42
View File
@@ -1,11 +1,16 @@
---
name: Ansible Lint # feel free to pick your own name
on: [push, pull_request] # yamllint disable-line rule:truthy
on: # yamllint disable-line rule:truthy
# Run CI against all pushes (direct commits, also merged PRs), Pull Requests
push:
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
jobs:
ansible-lint:
runs-on: ubuntu-latest
steps:
@@ -16,43 +21,4 @@ jobs:
# replace "master" with any valid ref
uses: ansible/ansible-lint-action@main
with:
# [required]
# Paths to ansible files (i.e., playbooks, tasks, handlers etc..)
# or valid Ansible directories according to the Ansible role
# directory structure.
# If you want to lint multiple ansible files, use the following syntax
# targets: |
# playbook_1.yml
# playbook_2.yml
targets: "roles/"
# [optional]
# Arguments to override a package and its version to be set explicitly.
# Must follow the example syntax.
# override-deps: |
# ansible==2.9
# ansible-lint==4.2.0
override-deps: |
rich>=9.5.1,<11.0.0
# [optional]
# Arguments to be passed to the ansible-lint
# Options:
# -q quieter, although not silent output
# -p parseable output in the format of pep8
# --parseable-severity parseable output including severity of rule
# -r RULESDIR specify one or more rules directories using one or
# more -r arguments. Any -r flags override the default
# rules in ansiblelint/rules, unless -R is also used.
# -R Use default rules in ansiblelint/rules in addition to
# any extra
# rules directories specified with -r. There is no need
# to specify this if no -r flags are used
# -t TAGS only check rules whose id/tags match these values
# -x SKIP_LIST only check rules whose id/tags do not match these
# values
# --nocolor disable colored output
# --exclude=EXCLUDE_PATHS
# path to directories or files to skip. This option is
# repeatable.
# -c C Specify configuration file to use. Defaults to ".ansible-lint"
args: ""
path: "roles/"
+1
View File
@@ -6,6 +6,7 @@ on: # yamllint disable-line rule:truthy
types: [labeled, unlabeled, opened, edited, synchronize]
jobs:
enforce-label:
if: github.repository == 'dev-sec/ansible-collection-hardening'
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@main
+1
View File
@@ -8,6 +8,7 @@ on: # yamllint disable-line rule:truthy
jobs:
deploy:
if: github.repository == 'dev-sec/ansible-collection-hardening'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
+8 -1
View File
@@ -1,13 +1,16 @@
---
name: "devsec.mysql_hardening"
on: # yamllint disable-line rule:truthy
workflow_dispatch:
push:
branches: [master]
paths:
- 'roles/mysql_hardening/**'
- 'molecule/mysql_hardening/**'
- '.github/workflows/mysql_hardening.yml'
pull_request:
branches: [master]
paths:
- 'roles/mysql_hardening/**'
- 'molecule/mysql_hardening/**'
@@ -23,11 +26,15 @@ jobs:
matrix:
molecule_distro:
- centos7
- centosstream8
- centosstream9
- rocky8
- rocky9
- ubuntu1804
- ubuntu2004
- debian9
- ubuntu2204
- debian10
- debian11
# - amazon # geerlingguy.mysql does not support fedora
# - arch # needs to be fixed
# - opensuse_tumbleweed # needs to be fixed
+7 -1
View File
@@ -3,11 +3,13 @@ name: "devsec.nginx_hardening"
on: # yamllint disable-line rule:truthy
workflow_dispatch:
push:
branches: [master]
paths:
- 'roles/nginx_hardening/**'
- 'molecule/nginx_hardening/**'
- '.github/workflows/nginx_hardening.yml'
pull_request:
branches: [master]
paths:
- 'roles/nginx_hardening/**'
- 'molecule/nginx_hardening/**'
@@ -23,11 +25,15 @@ jobs:
matrix:
molecule_distro:
- centos7
- centosstream8
- centosstream9
- rocky8
- rocky9
- ubuntu1804
- ubuntu2004
- debian9
- ubuntu2204
- debian10
- debian11
- amazon
# - arch # needs to be fixed
# - opensuse_tumbleweed # needs to be fixed
+7 -1
View File
@@ -3,11 +3,13 @@ name: "devsec.os_hardening"
on: # yamllint disable-line rule:truthy
workflow_dispatch:
push:
branches: [master]
paths:
- 'roles/os_hardening/**'
- 'molecule/os_hardening/**'
- '.github/workflows/os_hardening.yml'
pull_request:
branches: [master]
paths:
- 'roles/os_hardening/**'
- 'molecule/os_hardening/**'
@@ -23,11 +25,15 @@ jobs:
matrix:
molecule_distro:
- centos7
- centosstream8
- centosstream9
- rocky8
- rocky9
- ubuntu1804
- ubuntu2004
- debian9
- ubuntu2204
- debian10
- debian11
- amazon
- opensuse_tumbleweed
# - arch # needs to be fixed
+57
View File
@@ -0,0 +1,57 @@
---
name: "devsec.os_hardening VM"
on: # yamllint disable-line rule:truthy
workflow_dispatch:
push:
branches: [master]
paths:
- 'roles/os_hardening/**'
- 'molecule/os_hardening_vm/**'
- '.github/workflows/os_hardening_vm.yml'
pull_request:
branches: [master]
paths:
- 'roles/os_hardening/**'
- 'molecule/os_hardening_vm/**'
- '.github/workflows/os_hardening_vm.yml'
jobs:
build:
runs-on: self-hosted
env:
PY_COLORS: 1
ANSIBLE_FORCE_COLOR: 1
strategy:
fail-fast: false
matrix:
molecule_distro:
- centos7
- centos8s
# - centos9s # problems with vagrant
- rocky8
# - rocky9 # problems with vagrant
- ubuntu1804
- ubuntu2004
- ubuntu2204
- debian10
- debian11
# - opensuse42 # opensuse currently cannot get an ip address
# - arch # arch is currently not supported by cinc-auditor
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
path: ansible_collections/devsec/hardening
submodules: true
- name: Create default collection path symlink
run: |
mkdir -p /home/runner/.ansible
ln -fs /opt/actions-runner/_work/ansible-collection-hardening/ansible-collection-hardening/ansible_collections /home/runner/.ansible/collections
- name: Test with molecule
run: |
molecule --version
molecule test -s os_hardening_vm
env:
MOLECULE_DISTRO: ${{ matrix.molecule_distro }}
working-directory: ansible_collections/devsec/hardening
+2
View File
@@ -4,11 +4,13 @@ name: Prettier markdown files
on: # yamllint disable-line rule:truthy
push:
branches: [master]
paths:
- '**.md'
jobs:
prettier-md:
if: github.repository == 'dev-sec/ansible-collection-hardening'
runs-on: ubuntu-latest
timeout-minutes: 1
+3 -7
View File
@@ -9,12 +9,14 @@ on: # yamllint disable-line rule:truthy
jobs:
generate_changelog:
runs-on: ubuntu-latest
name: create release draft
if: github.repository == 'dev-sec/ansible-collection-hardening'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: master
- name: 'Get Previous tag'
id: previoustag
@@ -50,12 +52,6 @@ jobs:
name: dev-sec CI
email: [email protected]
# do a second checkout to prevent race situation
# changelog gets updated but action works on old commit id
- uses: actions/checkout@v3
with:
ref: master
- name: Generate changelog for the release
run: |
sed '/## \[${{ steps.previoustag.outputs.tag }}\]/Q' CHANGELOG.md > CHANGELOGRELEASE.md
+7 -1
View File
@@ -3,11 +3,13 @@ name: "devsec.ssh_hardening"
on: # yamllint disable-line rule:truthy
workflow_dispatch:
push:
branches: [master]
paths:
- 'roles/ssh_hardening/**'
- 'molecule/ssh_hardening/**'
- '.github/workflows/ssh_hardening.yml'
pull_request:
branches: [master]
paths:
- 'roles/ssh_hardening/**'
- 'molecule/ssh_hardening/**'
@@ -23,12 +25,16 @@ jobs:
matrix:
molecule_distro:
- centos7
- centosstream8
- centosstream9
- rocky8
- rocky9
- fedora
- ubuntu1804
- ubuntu2004
- debian9
- ubuntu2204
- debian10
- debian11
- amazon
# - arch # needs to be fixed
# - opensuse_tumbleweed # baseline is not compatible with suse
@@ -3,11 +3,13 @@ name: "devsec.ssh_hardening with custom tests"
on: # yamllint disable-line rule:truthy
workflow_dispatch:
push:
branches: [master]
paths:
- 'roles/ssh_hardening/**'
- 'molecule/ssh_hardening_custom_tests/**'
- '.github/workflows/ssh_hardening_custom_tests.yml'
pull_request:
branches: [master]
paths:
- 'roles/ssh_hardening/**'
- 'molecule/ssh_hardening_custom_tests/**'
@@ -23,12 +25,16 @@ jobs:
matrix:
molecule_distro:
- centos7
- centosstream8
- centosstream9
- rocky8
- rocky9
- fedora
- ubuntu1804
- ubuntu2004
- debian9
- ubuntu2204
- debian10
- debian11
- amazon
# - arch # needs to be fixed
# - opensuse_tumbleweed # baseline is not compatible with suse
+1
View File
@@ -1,3 +1,4 @@
.kitchen
hosts
Gemfile.lock
.venv
-7
View File
@@ -15,19 +15,12 @@ rules:
commas:
max-spaces-after: -1
level: error
# comments: disable
# comments-indentation: disable
# document-start: disable
empty-lines:
max: 3
level: error
hyphens:
level: error
# indentation: disable
key-duplicates: enable
line-length: disable
# new-line-at-end-of-file: disable
new-lines:
type: unix
# trailing-spaces: disable
# truthy: disable
+138
View File
@@ -1,5 +1,143 @@
# Changelog
## [8.3.0](https://github.com/dev-sec/ansible-collection-hardening/tree/8.3.0) (2022-10-26)
[Full Changelog](https://github.com/dev-sec/ansible-collection-hardening/compare/8.2.0...8.3.0)
**Implemented enhancements:**
- add hardening of root user account\(s\) [\#579](https://github.com/dev-sec/ansible-collection-hardening/pull/579) [[os_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/os_hardening)] ([donestefan](https://github.com/donestefan))
**Fixed bugs:**
- do not manage trusted user ca keys if none exist [\#580](https://github.com/dev-sec/ansible-collection-hardening/pull/580) [[ssh_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/ssh_hardening)] ([hollow](https://github.com/hollow))
**Closed issues:**
- Trying to run the os\_hardening on Debian 11, but fails on privilege escalation [\#587](https://github.com/dev-sec/ansible-collection-hardening/issues/587)
- auditd increasing logfiles [\#586](https://github.com/dev-sec/ansible-collection-hardening/issues/586)
- Path to nginx.conf should be configurable in a variable [\#577](https://github.com/dev-sec/ansible-collection-hardening/issues/577)
**Merged pull requests:**
- adopt all current suggestions from ansible-lint [\#592](https://github.com/dev-sec/ansible-collection-hardening/pull/592) [[mysql_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/mysql_hardening)] [[os_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/os_hardening)] [[ssh_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/ssh_hardening)] ([schurzi](https://github.com/schurzi))
- Support more os [\#588](https://github.com/dev-sec/ansible-collection-hardening/pull/588) [[mysql_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/mysql_hardening)] [[os_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/os_hardening)] [[ssh_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/ssh_hardening)] [[nginx_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/nginx_hardening)] ([rndmh3ro](https://github.com/rndmh3ro))
- run tests only on pushes to master or to PRs [\#581](https://github.com/dev-sec/ansible-collection-hardening/pull/581) [[mysql_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/mysql_hardening)] [[os_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/os_hardening)] [[ssh_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/ssh_hardening)] [[nginx_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/nginx_hardening)] ([rndmh3ro](https://github.com/rndmh3ro))
## [8.2.0](https://github.com/dev-sec/ansible-collection-hardening/tree/8.2.0) (2022-09-08)
[Full Changelog](https://github.com/dev-sec/ansible-collection-hardening/compare/8.1.0...8.2.0)
**Implemented enhancements:**
- Add nginx variables for config-path and owner/group [\#578](https://github.com/dev-sec/ansible-collection-hardening/pull/578) [[nginx_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/nginx_hardening)] ([hagenbauer](https://github.com/hagenbauer))
- add centos \>8 Support [\#573](https://github.com/dev-sec/ansible-collection-hardening/pull/573) [[ssh_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/ssh_hardening)] ([sbaerlocher](https://github.com/sbaerlocher))
- add always-tag to include so other tags can be used [\#569](https://github.com/dev-sec/ansible-collection-hardening/pull/569) [[os_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/os_hardening)] ([rndmh3ro](https://github.com/rndmh3ro))
**Closed issues:**
- Bug using os\_hardening "tags" [\#567](https://github.com/dev-sec/ansible-collection-hardening/issues/567)
## [8.1.0](https://github.com/dev-sec/ansible-collection-hardening/tree/8.1.0) (2022-08-26)
[Full Changelog](https://github.com/dev-sec/ansible-collection-hardening/compare/8.0.0...8.1.0)
**Closed issues:**
- dev-sec CI bot should not update CHANGELOG.md in fork repository [\#566](https://github.com/dev-sec/ansible-collection-hardening/issues/566)
**Merged pull requests:**
- update supported OS in meta and fix linting [\#572](https://github.com/dev-sec/ansible-collection-hardening/pull/572) [[mysql_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/mysql_hardening)] [[os_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/os_hardening)] [[ssh_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/ssh_hardening)] [[nginx_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/nginx_hardening)] ([rndmh3ro](https://github.com/rndmh3ro))
- fix misleading comment [\#571](https://github.com/dev-sec/ansible-collection-hardening/pull/571) [[os_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/os_hardening)] ([donestefan](https://github.com/donestefan))
- only run release actions on upstream-repo [\#568](https://github.com/dev-sec/ansible-collection-hardening/pull/568) ([rndmh3ro](https://github.com/rndmh3ro))
## [8.0.0](https://github.com/dev-sec/ansible-collection-hardening/tree/8.0.0) (2022-08-22)
[Full Changelog](https://github.com/dev-sec/ansible-collection-hardening/compare/7.16.0...8.0.0)
**Breaking changes:**
- change default to allow SFTP [\#564](https://github.com/dev-sec/ansible-collection-hardening/pull/564) [[ssh_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/ssh_hardening)] ([schurzi](https://github.com/schurzi))
**Implemented enhancements:**
- add possibility to keep .netrc files in users homedir [\#563](https://github.com/dev-sec/ansible-collection-hardening/pull/563) [[os_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/os_hardening)] ([PhilippFunk](https://github.com/PhilippFunk))
- rework filesystem hardening [\#555](https://github.com/dev-sec/ansible-collection-hardening/pull/555) [[os_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/os_hardening)] ([divialth](https://github.com/divialth))
**Closed issues:**
- Error in Task 'Create sshd\_config and set permissions to root/600' [\#565](https://github.com/dev-sec/ansible-collection-hardening/issues/565) [[ssh_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/ssh_hardening)]
- \[ssh\_hardening\] Debian 11 - Ansible cannot transfer files [\#557](https://github.com/dev-sec/ansible-collection-hardening/issues/557)
- Add the old SFTP-Reminder to the stable ssh\_hardening role for ansible [\#521](https://github.com/dev-sec/ansible-collection-hardening/issues/521)
## [7.16.0](https://github.com/dev-sec/ansible-collection-hardening/tree/7.16.0) (2022-08-16)
[Full Changelog](https://github.com/dev-sec/ansible-collection-hardening/compare/7.15.1...7.16.0)
**Implemented enhancements:**
- revert debian 9 change, only one tls variable now [\#562](https://github.com/dev-sec/ansible-collection-hardening/pull/562) [[nginx_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/nginx_hardening)] ([rndmh3ro](https://github.com/rndmh3ro))
- add posibility to run ssh\_hardening as unprivileged user [\#561](https://github.com/dev-sec/ansible-collection-hardening/pull/561) [[ssh_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/ssh_hardening)] ([schurzi](https://github.com/schurzi))
- add basic support for ubuntu22.04 [\#554](https://github.com/dev-sec/ansible-collection-hardening/pull/554) [[mysql_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/mysql_hardening)] [[os_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/os_hardening)] [[ssh_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/ssh_hardening)] [[nginx_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/nginx_hardening)] ([schurzi](https://github.com/schurzi))
- Add full support for Debian 11 [\#538](https://github.com/dev-sec/ansible-collection-hardening/pull/538) [[mysql_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/mysql_hardening)] [[os_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/os_hardening)] [[ssh_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/ssh_hardening)] [[nginx_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/nginx_hardening)] ([addianto](https://github.com/addianto))
**Fixed bugs:**
- Replace default 2048 bits RSA keypair fails on Ubuntu 20.04 [\#459](https://github.com/dev-sec/ansible-collection-hardening/issues/459)
**Closed issues:**
- os-hardening: yum gpg-check fails if gpg-check already set [\#556](https://github.com/dev-sec/ansible-collection-hardening/issues/556)
- Ubuntu 22.04 LTS [\#553](https://github.com/dev-sec/ansible-collection-hardening/issues/553)
- Revert nginx ssl-protocol after deprecation of debian9 [\#528](https://github.com/dev-sec/ansible-collection-hardening/issues/528)
- Support for Debian 11 [\#527](https://github.com/dev-sec/ansible-collection-hardening/issues/527)
- Support baseline-control os-14 [\#507](https://github.com/dev-sec/ansible-collection-hardening/issues/507)
## [7.15.1](https://github.com/dev-sec/ansible-collection-hardening/tree/7.15.1) (2022-07-26)
[Full Changelog](https://github.com/dev-sec/ansible-collection-hardening/compare/7.15.0...7.15.1)
**Fixed bugs:**
- Fix broken mode for /var/log/audit [\#552](https://github.com/dev-sec/ansible-collection-hardening/pull/552) [[os_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/os_hardening)] ([hollow](https://github.com/hollow))
**Merged pull requests:**
- Only run hardening if /var/log/audit exists [\#550](https://github.com/dev-sec/ansible-collection-hardening/pull/550) [[os_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/os_hardening)] ([mego22](https://github.com/mego22))
## [7.15.0](https://github.com/dev-sec/ansible-collection-hardening/tree/7.15.0) (2022-07-11)
[Full Changelog](https://github.com/dev-sec/ansible-collection-hardening/compare/7.14.3...7.15.0)
**Implemented enhancements:**
- Harden mountpoints [\#531](https://github.com/dev-sec/ansible-collection-hardening/pull/531) [[os_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/os_hardening)] ([lbayerlein](https://github.com/lbayerlein))
**Fixed bugs:**
- os\_hardening gpg-check enabled fails on success [\#549](https://github.com/dev-sec/ansible-collection-hardening/issues/549) [[os_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/os_hardening)]
- add VM tests for os\_hardening [\#547](https://github.com/dev-sec/ansible-collection-hardening/pull/547) [[os_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/os_hardening)] ([schurzi](https://github.com/schurzi))
- Linting [\#546](https://github.com/dev-sec/ansible-collection-hardening/pull/546) [[mysql_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/mysql_hardening)] [[os_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/os_hardening)] [[ssh_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/ssh_hardening)] [[nginx_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/nginx_hardening)] ([rndmh3ro](https://github.com/rndmh3ro))
## [7.14.3](https://github.com/dev-sec/ansible-collection-hardening/tree/7.14.3) (2022-06-29)
[Full Changelog](https://github.com/dev-sec/ansible-collection-hardening/compare/7.14.2...7.14.3)
**Closed issues:**
- Version 7.14.2 not released to Ansible Galaxy [\#544](https://github.com/dev-sec/ansible-collection-hardening/issues/544)
- os\_hardening role: os\_ignore\_users not described in the Readme's variable topic [\#542](https://github.com/dev-sec/ansible-collection-hardening/issues/542)
- doc: incorrect description for ssh\_client\_alive\_count [\#540](https://github.com/dev-sec/ansible-collection-hardening/issues/540)
- 'legacy' branch is mentioned in README, but apparently doesn't exist [\#539](https://github.com/dev-sec/ansible-collection-hardening/issues/539)
- ansible\_role\_name is undefined [\#532](https://github.com/dev-sec/ansible-collection-hardening/issues/532)
- Can't sudo anymore after hardening [\#518](https://github.com/dev-sec/ansible-collection-hardening/issues/518)
- Any planned official support for RHEL/CentOS Stream 9? [\#517](https://github.com/dev-sec/ansible-collection-hardening/issues/517)
**Merged pull requests:**
- Improve documentation [\#541](https://github.com/dev-sec/ansible-collection-hardening/pull/541) [[ssh_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/ssh_hardening)] ([schurzi](https://github.com/schurzi))
## [7.14.2](https://github.com/dev-sec/ansible-collection-hardening/tree/7.14.2) (2022-02-28)
[Full Changelog](https://github.com/dev-sec/ansible-collection-hardening/compare/7.14.1...7.14.2)
+7 -6
View File
@@ -1,6 +1,7 @@
# Ansible Collection - devsec.hardening
![devsec.os_hardening](https://github.com/dev-sec/ansible-os-hardening/workflows/devsec.os_hardening/badge.svg)
![devsec.os_hardening VM](https://github.com/dev-sec/ansible-os-hardening/workflows/devsec.os_hardening%20VM/badge.svg)
![devsec.ssh_hardening](https://github.com/dev-sec/ansible-os-hardening/workflows/devsec.ssh_hardening/badge.svg)
![devsec.nginx_hardening](https://github.com/dev-sec/ansible-os-hardening/workflows/devsec.nginx_hardening/badge.svg)
![devsec.mysql_hardening](https://github.com/dev-sec/ansible-os-hardening/workflows/devsec.mysql_hardening/badge.svg)
@@ -10,10 +11,10 @@
This collection provides battle tested hardening for:
- Linux operating systems:
- CentOS 7/8
- CentOS 7
- Rocky Linux 8
- Debian 9/10
- Ubuntu 16.04/18.04/20.04
- Debian 10/11
- Ubuntu 18.04/20.04/22.04
- Amazon Linux (some roles supported)
- Arch Linux (some roles supported)
- Fedora (some roles supported)
@@ -37,7 +38,7 @@ The roles are now part of the hardening-collection.
We have kept the old releases of the `os-hardening` role in this repository, so you can find the them by exploring older tags.
The last release of the standalone role was [6.2.0](https://github.com/dev-sec/ansible-collection-hardening/tree/6.2.0).
The other roles are in separate archives repositories
The other roles are in separate archives repositories:
- [apache_hardening](https://github.com/dev-sec/ansible-apache-hardening)
- [mysql_hardening](https://github.com/dev-sec/ansible-mysql-hardening)
@@ -85,8 +86,8 @@ See the [changelog](https://github.com/dev-sec/ansible-os-hardening/tree/master/
Todos:
- Work on [apache_hardening](roles/apache_hardening/) and [windows_hardening](roles/windows_hardening/).
- Add support for more operating systems,
- Work on [apache_hardening](roles/apache_hardening/) and [windows_hardening](roles/windows_hardening/)
- Add support for more operating systems
## More information
+1 -1
View File
@@ -1,6 +1,6 @@
namespace: devsec
name: hardening
version: 7.14.1
version: 8.2.0
readme: README.md
authors:
- dev-sec <[email protected]>
+2
View File
@@ -2,6 +2,8 @@
- name: wrapper playbook for kitchen testing "ansible-mysql-hardening"
hosts: all
become: true
collections:
- devsec.hardening
environment:
http_proxy: "{{ lookup('env', 'http_proxy') | default(omit) }}"
https_proxy: "{{ lookup('env', 'https_proxy') | default(omit) }}"
+16 -1
View File
@@ -8,6 +8,20 @@
https_proxy: "{{ lookup('env', 'https_proxy') | default(omit) }}"
no_proxy: "{{ lookup('env', 'no_proxy') | default(omit) }}"
tasks:
- name: Use Python 3 on Debian 11
set_fact:
ansible_python_interpreter: /usr/bin/python3
when:
- ansible_distribution == 'Debian'
- ansible_distribution_major_version|int >= 11
- name: Use Python 2 on Debian 10
set_fact:
ansible_python_interpreter: /usr/bin/python
when:
- ansible_distribution == 'Debian'
- ansible_distribution_major_version|int == 10
- name: Run the equivalent of "apt-get update && apt-get upgrade"
apt:
name: "*"
@@ -16,7 +30,7 @@
when: ansible_os_family == 'Debian'
- name: install required tools on SuSE
zypper:
community.general.zypper:
name: "python-xml"
state: present
when: ansible_facts.os_family == 'Suse'
@@ -42,6 +56,7 @@
- ansible_distribution != "Ubuntu"
- ansible_distribution_major_version|int < 20
- include_role:
name: dev-sec.mysql
+2 -2
View File
@@ -8,7 +8,7 @@
no_proxy: "{{ lookup('env', 'no_proxy') | default(omit) }}"
tasks:
- name: install required tools on SuSE
zypper:
community.general.zypper:
name: "python-xml"
state: present
when: ansible_facts.os_family == 'Suse'
@@ -17,7 +17,7 @@
package:
name: "python3-apt"
update_cache: true
ignore_errors: true
ignore_errors: true # noqa ignore-errors
- name: Set correct distribution Version for Amazon Linux
set_fact:
+1 -1
View File
@@ -26,8 +26,8 @@
os_security_suid_sgid_blacklist: ['/bin/umount']
os_security_suid_sgid_whitelist: ['/usr/bin/rlogin']
os_filesystem_whitelist: []
os_ctrlaltdel_disabled: true
os_yum_repo_file_whitelist: ['foo.repo']
os_netrc_enabled: false
sysctl_config:
net.ipv4.ip_forward: 0
net.ipv6.conf.all.forwarding: 0
+7 -3
View File
@@ -35,14 +35,14 @@
when: ansible_facts.distribution == 'Fedora'
- name: install required tools on Arch
pacman:
community.general.pacman:
name:
- awk
state: present
update_cache: true
when: ansible_facts.os_family == 'Archlinux'
- name: install required tools on RHEL
- name: install required tools on RHEL # noqa ignore-errors
yum:
name:
- openssh-clients
@@ -56,5 +56,9 @@
changed_when: false
- name: include YUM prepare tasks
include: prepare_yum.yml
include_tasks: prepare_tasks/yum.yml
when: ansible_facts.os_family == 'RedHat'
- name: include YUM prepare tasks
include_tasks: prepare_tasks/netrc.yml
@@ -0,0 +1,9 @@
---
- name: create '.netrc' in /root
ansible.builtin.copy:
dest: '/root/.netrc'
mode: '0600'
content: |
machine localhost
login root
password ipsum
@@ -1,6 +1,6 @@
---
- name: create 'foo' repository
yum_repository:
ansible.builtin.yum_repository:
name: foo
description: mandatory description
baseurl: file:///mandatory-url
@@ -8,7 +8,7 @@
gpgcheck: false
- name: create 'bar' repository
yum_repository:
ansible.builtin.yum_repository:
name: bar
description: mandatory description
baseurl: file:///mandatory-url
+7 -4
View File
@@ -37,12 +37,15 @@
name: procps
when: ansible_facts.os_family == 'Debian'
- name: include netrc tests
include_tasks: verify_tasks/netrc.yml
- name: include PAM tests
include: verify_pam.yml
include_tasks: verify_tasks/pam.yml
when: ansible_facts.distribution in ['Debian', 'Ubuntu'] or ansible_facts.os_family == 'RedHat'
- name: include YUM tests
include: verify_yum.yml
include_tasks: verify_tasks/yum.yml
when: ansible_facts.os_family == 'RedHat'
- name: download cinc-auditor
@@ -54,8 +57,8 @@
- name: install cinc-auditor
shell: "bash /tmp/install.sh -s -- -P cinc-auditor -v 4"
- name: Execute cinc-auditor tests
command: "/opt/cinc-auditor/bin/cinc-auditor exec --no-show-progress --no-color --no-distinct-exit --waiver-file waivers.yaml https://github.com/dev-sec/linux-baseline/archive/refs/heads/master.zip"
- name: Execute cinc-auditor tests # noqa ignore-errors
command: "/opt/cinc-auditor/bin/cinc-auditor exec --no-show-progress --no-color --no-distinct-exit https://github.com/dev-sec/linux-baseline/archive/refs/heads/master.zip"
register: test_results
changed_when: false
ignore_errors: true
@@ -0,0 +1,19 @@
---
- name: test that .netrc in root homedir exists
ansible.builtin.file:
path: '/root/.netrc'
state: file
register: result_test_netrc
- name: output result if .netrc for user root exists
ansible.builtin.assert:
that:
- "result_test_netrc.state == 'file'"
fail_msg: ".netrc in /root/ not present"
success_msg: ".netrc exists in /root/"
- name: delete '.netrc' in /root
ansible.builtin.file:
path: '/root/.netrc'
state: absent
when: result_test_netrc.state == 'file'
-3
View File
@@ -1,3 +0,0 @@
os-14:
run: false
justification: "not yet implemented"
+22
View File
@@ -0,0 +1,22 @@
*******
Docker driver installation guide
*******
Requirements
============
* Docker Engine
Install
=======
Please refer to the `Virtual environment`_ documentation for installation best
practices. If not using a virtual environment, please consider passing the
widely recommended `'--user' flag`_ when invoking ``pip``.
.. _Virtual environment: https://virtualenv.pypa.io/en/latest/
.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site
.. code-block:: bash
$ python3 -m pip install 'molecule[docker]'
+23
View File
@@ -0,0 +1,23 @@
---
- name: wrapper playbook for kitchen testing "ansible-os-hardening" with custom vars for testing
hosts: all
become: true
environment:
http_proxy: "{{ lookup('env', 'http_proxy') | default(omit) }}"
https_proxy: "{{ lookup('env', 'https_proxy') | default(omit) }}"
no_proxy: "{{ lookup('env', 'no_proxy') | default(omit) }}"
collections:
- devsec.hardening
tasks:
- name: override for arch
set_fact:
os_mnt_boot_enabled: false
when: ansible_facts.os_family == 'Archlinux'
- include_role:
name: os_hardening
vars:
os_auth_pam_passwdqc_enable: false
os_auth_lockout_time: 15
os_yum_repo_file_whitelist: ['foo.repo']
os_mnt_boot_enabled: true
os_mnt_boot_src: "/dev/vda1"
+57
View File
@@ -0,0 +1,57 @@
---
dependency:
name: galaxy
options:
role-file: molecule/os_hardening/requirements.yml
driver:
name: vagrant
provider:
name: libvirt
platforms:
- name: instance
box: "generic/${MOLECULE_DISTRO}"
memory: 1024
cpus: 2
provisioner:
name: ansible
env:
ANSIBLE_PIPELINING: "True"
config_options:
defaults:
interpreter_python: auto_silent
callback_whitelist: profile_tasks, timer, yaml
verifier:
name: ansible
env:
ANSIBLE_PIPELINING: "True"
scenario:
create_sequence:
- dependency
- create
- prepare
check_sequence:
- dependency
- destroy
- create
- prepare
- converge
- check
- destroy
converge_sequence:
- dependency
- create
- prepare
- converge
destroy_sequence:
- destroy
test_sequence:
- dependency
- destroy
- syntax
- create
- prepare
- converge
- idempotence
- verify
- destroy
+58
View File
@@ -0,0 +1,58 @@
---
- name: wrapper playbook for kitchen testing "ansible-os-hardening" with custom vars for testing
hosts: all
become: true
collections:
- devsec.hardening
environment:
http_proxy: "{{ lookup('env', 'http_proxy') | default(omit) }}"
https_proxy: "{{ lookup('env', 'https_proxy') | default(omit) }}"
no_proxy: "{{ lookup('env', 'no_proxy') | default(omit) }}"
tasks:
- name: set ansible_python_interpreter to "/usr/bin/python3" on fedora
set_fact:
ansible_python_interpreter: "/usr/bin/python3"
when: ansible_facts.distribution == 'Fedora'
- name: Run the equivalent of "apt-get update && apt-get upgrade"
apt:
update_cache: true
when: ansible_os_family == 'Debian'
- name: install required tools on SuSE
# cannot use zypper module, since it depends on python-xml
shell: "zypper -n install python-xml"
when: ansible_facts.os_family == 'Suse'
- name: install required tools on fedora
dnf:
name:
- python
- findutils
- procps-ng
when: ansible_facts.distribution == 'Fedora'
- name: install required tools on Arch
community.general.pacman:
name:
- awk
state: present
update_cache: true
when: ansible_facts.os_family == 'Archlinux'
- name: install required tools on RHEL # noqa ignore-errors
yum:
name:
- openssh-clients
- openssh
state: present
update_cache: true
ignore_errors: true
- name: create recursing symlink to test minimize access
shell: "rm -f /usr/bin/zzz && ln -s /usr/bin /usr/bin/zzz"
changed_when: false
- name: include YUM prepare tasks
include_tasks: prepare_tasks/yum.yml
when: ansible_facts.os_family == 'RedHat'
@@ -0,0 +1,16 @@
---
- name: create 'foo' repository
ansible.builtin.yum_repository:
name: foo
description: mandatory description
baseurl: file:///mandatory-url
enabled: false
gpgcheck: false
- name: create 'bar' repository
ansible.builtin.yum_repository:
name: bar
description: mandatory description
baseurl: file:///mandatory-url
enabled: false
gpgcheck: false
@@ -0,0 +1,3 @@
---
roles:
- geerlingguy.git
+70
View File
@@ -0,0 +1,70 @@
---
- name: Verify
hosts: all
become: true
environment:
http_proxy: "{{ lookup('env', 'http_proxy') | default(omit) }}"
https_proxy: "{{ lookup('env', 'https_proxy') | default(omit) }}"
no_proxy: "{{ lookup('env', 'no_proxy') | default(omit) }}"
roles:
- geerlingguy.git
tasks:
- name: install fake SuSE-release for cinc compatibility
copy:
content: |
openSUSE Faked Enterprise 2020 (x86_64)
VERSION = 2020
CODENAME = Faked Feature
dest: /etc/SuSE-release
owner: root
group: root
mode: '0444'
when: ansible_facts.os_family == 'Suse'
- name: install git for SuSE since geerlinguy.git does not support it
zypper:
name: git
state: present
when: ansible_facts.os_family == 'Suse'
- name: Run the equivalent of "apt-get update" as a separate step
apt:
update_cache: true
when: ansible_facts.os_family == 'Debian'
- name: install required tools on debian
apt:
name: procps
when: ansible_facts.os_family == 'Debian'
- name: include PAM tests
include_tasks: verify_tasks/pam.yml
when: ansible_facts.distribution in ['Debian', 'Ubuntu'] or ansible_facts.os_family == 'RedHat'
- name: include YUM tests
include_tasks: verify_tasks/yum.yml
when: ansible_facts.os_family == 'RedHat'
- name: download cinc-auditor
get_url:
url: https://omnitruck.cinc.sh/install.sh
dest: /tmp/install.sh
mode: '0775'
- name: install cinc-auditor
shell: "bash /tmp/install.sh -s -- -P cinc-auditor -v 4"
- name: Execute cinc-auditor tests # noqa ignore-errors
command: "/opt/cinc-auditor/bin/cinc-auditor exec --no-show-progress --no-color --no-distinct-exit https://github.com/dev-sec/linux-baseline/archive/refs/heads/master.zip"
register: test_results
changed_when: false
ignore_errors: true
- name: Display details about the cinc-auditor results
debug:
msg: "{{ test_results.stdout_lines }}"
- name: Fail when tests fail
fail:
msg: "Inspec failed to validate"
when: test_results.rc != 0
@@ -0,0 +1,59 @@
---
- name: download pam-tester
get_url:
url: https://github.com/schurzi/pam-tester/releases/download/latest/pam-tester
dest: /bin/pam-tester
mode: 0555
- name: set password for test
set_fact:
test_pw: "myTest!pw"
- name: set locale for test
set_fact:
locale: "en_US.UTF-8"
when:
- ansible_facts.os_family == 'RedHat'
- ansible_facts.distribution_major_version < '8'
- name: create testuser
user:
name: testuser
password: "{{ test_pw | password_hash('sha512') }}"
- name: check successfull login with correct password
shell:
cmd: "pam-tester --user testuser --password {{ test_pw }}"
environment:
TMPDIR: /var/tmp
LC_ALL: "{{ locale | default('C.UTF-8') }}"
LANG: "{{ locale | default('C.UTF-8') }}"
- name: check unsuccessfull login with incorrect password
shell:
cmd: "pam-tester --user testuser --password {{ test_pw }}fail --expectfail"
environment:
TMPDIR: /var/tmp
LC_ALL: "{{ locale | default('C.UTF-8') }}"
LANG: "{{ locale | default('C.UTF-8') }}"
with_sequence: count=6
- name: check unsuccessfull login, with correct password (lockout)
shell:
cmd: "pam-tester --user testuser --password {{ test_pw }} --expectfail"
environment:
TMPDIR: /var/tmp
LC_ALL: "{{ locale | default('C.UTF-8') }}"
LANG: "{{ locale | default('C.UTF-8') }}"
- name: wait for account to unlock
pause:
seconds: 20
- name: check successfull login
shell:
cmd: "pam-tester --user testuser --password {{ test_pw }}"
environment:
TMPDIR: /var/tmp
LC_ALL: "{{ locale | default('C.UTF-8') }}"
LANG: "{{ locale | default('C.UTF-8') }}"
@@ -0,0 +1,8 @@
---
- name: verify 'gpgcheck' was not enabled for 'foo' repository (in whitelist)
command: grep -e 'gpgcheck\s*=\s*0' /etc/yum.repos.d/foo.repo
changed_when: false
- name: verify 'gpgcheck' was enabled for 'bar' repository (not in whitelist)
command: grep -e 'gpgcheck\s*=\s*1' /etc/yum.repos.d/bar.repo
changed_when: false
+2 -1
View File
@@ -1,7 +1,6 @@
---
- name: wrapper playbook for kitchen testing "ansible-ssh-hardening" with default settings
hosts: all
become: true
environment:
http_proxy: "{{ lookup('env', 'http_proxy') | default(omit) }}"
https_proxy: "{{ lookup('env', 'https_proxy') | default(omit) }}"
@@ -11,3 +10,5 @@
tasks:
- include_role:
name: ssh_hardening
vars:
sftp_enabled: false
+6
View File
@@ -29,6 +29,12 @@ provisioner:
defaults:
interpreter_python: auto_silent
callback_whitelist: profile_tasks, timer, yaml
inventory:
host_vars:
# https://molecule.readthedocs.io/en/latest/examples.html#docker-with-non-privileged-user
# setting for the platform instance named 'instance'
instance:
ansible_user: ansible
verifier:
name: ansible
+4 -4
View File
@@ -12,7 +12,7 @@
ansible_python_interpreter: /usr/bin/python3
when: ansible_facts.distribution == 'Fedora'
- name: install packages
- name: install packages # noqa ignore-errors
yum:
name:
- openssh-clients
@@ -22,7 +22,7 @@
update_cache: true
ignore_errors: true
- name: install packages
- name: install packages # noqa ignore-errors
dnf:
name:
- openssh-clients
@@ -32,7 +32,7 @@
update_cache: true
ignore_errors: true
- name: install packages
- name: install packages # noqa ignore-errors
apt:
name:
- openssh-client
@@ -66,7 +66,7 @@
path: "/var/run/sshd"
state: directory
- name: create ssh host keys
- name: create ssh host keys # noqa ignore-errors
command: "ssh-keygen -A"
when: not ((ansible_facts.os_family in ['Oracle Linux', 'RedHat']) and ansible_facts.distribution_major_version < '7') or
ansible_facts.distribution == "Fedora" or
@@ -48,7 +48,6 @@
ssh_print_last_log: true
ssh_banner: true
ssh_server_password_login: true
sftp_enabled: true
sftp_chroot: true
# ssh_server_enabled: false
ssh_server_ports:
@@ -12,7 +12,7 @@
ansible_python_interpreter: /usr/bin/python3
when: ansible_facts.distribution == 'Fedora'
- name: install packages
- name: install packages # noqa ignore-errors
yum:
name:
- openssh-clients
@@ -22,7 +22,7 @@
update_cache: true
ignore_errors: true
- name: install packages
- name: install packages # noqa ignore-errors
dnf:
name:
- openssh-clients
@@ -32,7 +32,7 @@
update_cache: true
ignore_errors: true
- name: install packages
- name: install packages # noqa ignore-errors
apt:
name:
- openssh-client
@@ -66,7 +66,7 @@
path: "/var/run/sshd"
state: directory
- name: create ssh host keys
- name: create ssh host keys # noqa ignore-errors
command: "ssh-keygen -A"
when: not ((ansible_facts.os_family in ['Oracle Linux', 'RedHat']) and ansible_facts.distribution_major_version < '7') or
ansible_facts.distribution == "Fedora" or
+3 -3
View File
@@ -7,11 +7,11 @@ mysql_daemon_enabled: true
mysql_hardening_restart_mysql: true
# general configuration
mysql_hardening_mysql_hardening_conf_file: '{{mysql_hardening_mysql_confd_dir}}/hardening.cnf'
mysql_hardening_mysql_hardening_conf_file: '{{ mysql_hardening_mysql_confd_dir }}/hardening.cnf'
# You have to change this to your own strong enough mysql root password
mysql_root_password: '-----====>SetR00tPa$$wordH3r3!!!<====-----'
# There .my.cnf with mysql root credentials will be installed
mysql_user_home: "{{ ansible_env.HOME}}"
mysql_user_home: "{{ ansible_env.HOME }}"
# ensure the following parameters are set properly
mysql_remove_remote_root: true
@@ -50,4 +50,4 @@ mysql_hardening_options:
# @see https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option-mysqld-secure-file-priv
secure-file-priv: '/tmp'
# @see https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_user
user: '{{mysql_hardening_user}}'
user: '{{ mysql_hardening_user }}'
+6 -4
View File
@@ -8,15 +8,17 @@ galaxy_info:
platforms:
- name: EL
versions:
- 6
- 7
- "7"
- "8"
- name: Ubuntu
versions:
- xenial
- bionic
- focal
- jammy
- name: Debian
versions:
- jessie
- bullseye
- buster
- name: Amazon
- name: Fedora
galaxy_tags:
+2 -2
View File
@@ -18,7 +18,7 @@
when: item is defined and item != ""
loop:
- '{{ mysql_settings.settings.datadir }}'
- '{{ mysql_datadir|default("") }}'
- '{{ mysql_datadir | default("") }}'
- name: Ensure permissions on mysql-logfile are correct
file:
@@ -30,7 +30,7 @@
when: item is defined and item != ""
loop:
- '{{ mysql_settings.settings.log_error }}'
- '{{ mysql_hardening_log_file|default("") }}'
- '{{ mysql_hardening_log_file | default("") }}'
- name: Check mysql configuration-directory exists and has right permissions
file:
+5 -3
View File
@@ -54,17 +54,19 @@
# dict2items and vice versa magic
- name: Drop the secure-auth parameter on MySQL >=8.0.3 (not mariadb)
set_fact:
mysql_hardening_options: "{{ mysql_hardening_options| dict2items | rejectattr('key', 'search', 'secure-auth') | list | items2dict }}"
mysql_hardening_options: "{{ mysql_hardening_options | dict2items | rejectattr('key', 'search', 'secure-auth') | list | items2dict }}"
when:
- mysql_version.version.full is version('8.0.3', '>=')
- mysql_distribution == "mysql"
- include: configure.yml
- name: Include tasks for configuration
import_tasks: configure.yml
when: mysql_hardening_enabled | bool
tags:
- mysql_hardening
- include: mysql_secure_installation.yml
- name: Include tasks to secure mysql installation
import_tasks: mysql_secure_installation.yml
when: mysql_hardening_enabled | bool
tags:
- mysql_hardening
@@ -4,7 +4,7 @@
msg: 'ERROR - you have to change default mysql_root_password'
when: mysql_root_password == '-----====>SetR00tPa$$wordH3r3!!!<====-----'
- name: ensure that the root password is present
- name: Ensure that the root password is present
community.mysql.mysql_user:
name: 'root'
host_all: true
@@ -19,14 +19,14 @@
mode: '0400'
tags: my_cnf
- name: ensure that the test database is absent
- name: Ensure that the test database is absent
community.mysql.mysql_db:
name: test
state: absent
login_unix_socket: "{{ login_unix_socket | default(omit) }}"
when: mysql_remove_test_database
- name: ensure that anonymous users are absent
- name: Ensure that anonymous users are absent
community.mysql.mysql_user:
name: ''
state: absent
@@ -34,7 +34,7 @@
login_unix_socket: "{{ login_unix_socket | default(omit) }}"
when: mysql_remove_anonymous_users
- name: ensure that root can only login from localhost
- name: Ensure that root can only login from localhost
community.mysql.mysql_query:
query:
- DELETE
@@ -46,7 +46,7 @@
login_unix_socket: "{{ login_unix_socket | default(omit) }}"
when: mysql_remove_remote_root
- name: get all users that have no authentication_string on MySQL version >= 5.7.6 or Mariadb version >= 10.4.0
- name: Get all users that have no authentication_string on MySQL version >= 5.7.6 or Mariadb version >= 10.4.0
community.mysql.mysql_query:
query:
- SELECT GROUP_CONCAT(QUOTE(USER), '@', QUOTE(HOST) SEPARATOR ', ') AS users
@@ -62,7 +62,7 @@
- (mysql_distribution == "mysql" and mysql_version.version.full is version('5.7.6', '>=')) or
(mysql_distribution == "mariadb" and mysql_version.version.full is version('10.4.0', '>='))
- name: get all users that have no password or authentication_string on MySQL version < 5.7.6 or Mariadb version < 10.4.0
- name: Get all users that have no password or authentication_string on MySQL version < 5.7.6 or Mariadb version < 10.4.0
community.mysql.mysql_query:
query:
- SELECT GROUP_CONCAT(QUOTE(USER), '@', QUOTE(HOST) SEPARATOR ', ') AS users
@@ -80,21 +80,21 @@
- (mysql_distribution == "mysql" and mysql_version.version.full is version('5.7.6', '<')) or
(mysql_distribution == "mariadb" and mysql_version.version.full is version('10.4.0', '<'))
- name: create a fact for users without password or authentication_string
- name: Create a fact for users without password or authentication_string
set_fact:
users_wo_auth: "{{ mysql_users_wo_passwords_or_auth_string.query_result.0.0 | community.general.json_query('users') }}"
when:
- mysql_users_wo_passwords_or_auth_string.query_result is defined
- mysql_users_wo_passwords_or_auth_string.query_result != "" # noqa empty-string-compare
- name: create a fact for users without password
- name: Create a fact for users without password
set_fact:
users_wo_auth: "{{ mysql_users_wo_passwords.query_result.0.0 | community.general.json_query('users') }}"
when:
- mysql_users_wo_passwords.query_result is defined
- mysql_users_wo_passwords.query_result != "" # noqa empty-string-compare
- name: ensure that there are no users without password or authentication_string
- name: Ensure that there are no users without password or authentication_string
community.mysql.mysql_query:
query:
- "DROP USER {{ users_wo_auth }}"
-9
View File
@@ -1,9 +0,0 @@
---
mysql_daemon: mariadb
mysql_hardening_mysql_conf_file: '/etc/my.cnf'
mysql_hardening_mysql_confd_dir: '/etc/my.cnf.d'
mysql_cnf_owner: 'root' # owner of /etc/mysql/*.cnf files
mysql_cnf_group: 'mysql' # owner of /etc/mysql/*.cnf files
mysql_hardening_group: 'mysql'
-9
View File
@@ -1,9 +0,0 @@
---
mysql_daemon: mariadb
mysql_hardening_mysql_conf_file: '/etc/my.cnf'
mysql_hardening_mysql_confd_dir: '/etc/my.cnf.d'
mysql_cnf_owner: 'root' # owner of /etc/mysql/*.cnf files
mysql_cnf_group: 'mysql' # owner of /etc/mysql/*.cnf files
mysql_hardening_group: 'mysql'
-10
View File
@@ -1,10 +0,0 @@
---
mysql_daemon: mysql
mysql_hardening_mysql_conf_file: '/etc/mysql/my.cnf'
mysql_hardening_mysql_confd_dir: '/etc/mysql/conf.d'
mysql_cnf_owner: 'root' # owner of /etc/mysql/*.cnf files
mysql_cnf_group: 'mysql' # owner of /etc/mysql/*.cnf files
mysql_hardening_group: 'adm'
-10
View File
@@ -1,10 +0,0 @@
---
mysql_daemon: mysql
mysql_hardening_mysql_conf_file: '/etc/mysql/my.cnf'
mysql_hardening_mysql_confd_dir: '/etc/mysql/conf.d'
mysql_cnf_owner: 'root' # owner of /etc/mysql/*.cnf files
mysql_cnf_group: 'mysql' # owner of /etc/mysql/*.cnf files
mysql_hardening_group: 'adm'
+12
View File
@@ -75,6 +75,18 @@ It works with the following nginx-roles, including, but not limited to:
- [nginx_dh_size][]
- Default: `2048`
- Description: Specifies the length of DH parameters for EDH ciphers.
- [nginx_configuration_dir][]
- default: "/etc/nginx"
- Description: The main location for all nginx configuration files
- [nginx_configuration_hardening_dir][]
- default: "/etc/nginx"
- Description: The location for the nginx hardening configuration file (Could be different e.g. when used in jails)
- [nginx_owner_user][]
- default: "root"
- Description: The owner user of the nginx configuration files
- [nginx_owner_group][]
- default: "root"
- Description: The owner group of the nginx configuration files
## Example Playbook
+5
View File
@@ -11,6 +11,10 @@ nginx_client_header_timeout: "10"
nginx_send_timeout: "10"
nginx_limit_conn_zone: "$binary_remote_addr zone=default:10m"
nginx_limit_conn: "default 5"
nginx_configuration_dir: "/etc/nginx"
nginx_configuration_hardening_dir: "/etc/nginx"
nginx_owner_user: "root"
nginx_owner_group: "root"
nginx_add_header:
# avoid clickjacking
- X-Frame-Options SAMEORIGIN
@@ -23,6 +27,7 @@ nginx_add_header:
nginx_set_cookie_flag: "* HttpOnly secure"
nginx_ssl_prefer_server_ciphers: "on"
nginx_ssl_protocols: "TLSv1.2 TLSv1.3"
nginx_ssl_ciphers: "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256"
nginx_ssl_session_tickets: "off"
nginx_dh_size: "4096"
+5 -4
View File
@@ -8,16 +8,17 @@ galaxy_info:
platforms:
- name: EL
versions:
- 6
- 7
- "7"
- "8"
- name: Ubuntu
versions:
- xenial
- bionic
- focal
- jammy
- name: Debian
versions:
- stretch
- buster
- bullseye
galaxy_tags:
- system
- security
+26 -49
View File
@@ -1,100 +1,77 @@
---
- name: Fetch OS dependent variables
include_vars:
file: '{{ item }}'
name: 'os_vars'
with_first_found:
- files:
- '{{ ansible_facts.distribution }}_{{ ansible_facts.distribution_major_version }}.yml'
- '{{ ansible_facts.distribution }}.yml'
- '{{ ansible_facts.os_family }}_{{ ansible_facts.distribution_major_version }}.yml'
- '{{ ansible_facts.os_family }}.yml'
skip: true
tags: always
# we only override variables with our default, if they have not been specified already
# by default the lookup functions finds all varnames containing the string, therefore
# we add ^ and $ to denote start and end of string, so this returns only exact matches
- name: Set OS dependent variables, if not already defined by user # noqa var-naming
set_fact:
'{{ item.key }}': '{{ item.value }}'
when: "not lookup('varnames', '^' + item.key + '$')"
with_dict: '{{ os_vars }}'
tags: always
- name: Create additional configuration
template:
src: "hardening.conf.j2"
dest: "/etc/nginx/conf.d/90.hardening.conf"
dest: "{{ nginx_configuration_dir }}/conf.d/90.hardening.conf"
mode: '0600'
owner: "root"
group: "root"
owner: "{{ nginx_owner_user }}"
group: "{{ nginx_owner_group }}"
notify: Restart nginx
- name: Change configuration in main nginx.conf
lineinfile:
dest: "/etc/nginx/nginx.conf"
dest: "{{ nginx_configuration_dir }}/nginx.conf"
regexp: '^\s*server_tokens'
line: " server_tokens {{ nginx_server_tokens }};"
insertafter: "http {"
mode: '0640'
owner: "root"
group: "root"
owner: "{{ nginx_owner_user }}"
group: "{{ nginx_owner_group }}"
notify: Restart nginx
- name: Change ssl_protocols in main nginx.conf
lineinfile:
dest: "/etc/nginx/nginx.conf"
dest: "{{ nginx_configuration_dir }}/nginx.conf"
regexp: '^\s*ssl_protocols'
line: " ssl_protocols {{ nginx_ssl_protocols }};"
insertafter: "http {"
mode: '0640'
owner: "root"
group: "root"
owner: "{{ nginx_owner_user }}"
group: "{{ nginx_owner_group }}"
notify: Restart nginx
- name: Change ssl_prefer_server_ciphers in main nginx.conf
lineinfile:
dest: "/etc/nginx/nginx.conf"
dest: "{{ nginx_configuration_dir }}/nginx.conf"
regexp: '^\s*ssl_prefer_server_ciphers'
line: " ssl_prefer_server_ciphers {{ nginx_ssl_prefer_server_ciphers }};"
insertafter: "http {"
mode: '0640'
owner: "root"
group: "root"
owner: "{{ nginx_owner_user }}"
group: "{{ nginx_owner_group }}"
notify: Restart nginx
- name: Change client_max_body_size in main nginx.conf
lineinfile:
dest: "/etc/nginx/nginx.conf"
dest: "{{ nginx_configuration_dir }}/nginx.conf"
regexp: '^\s*client_max_body_size'
line: " client_max_body_size {{ nginx_client_max_body_size }};"
insertafter: "http {"
mode: '0640'
owner: "root"
group: "root"
owner: "{{ nginx_owner_user }}"
group: "{{ nginx_owner_group }}"
notify: Restart nginx
- name: Change client_body_buffer_size in main nginx.conf
lineinfile:
dest: "/etc/nginx/nginx.conf"
dest: "{{ nginx_configuration_dir }}/nginx.conf"
regexp: '^\s*client_body_buffer_size'
line: " client_body_buffer_size {{ nginx_client_body_buffer_size }};"
insertafter: "http {"
mode: '0640'
owner: "root"
group: "root"
owner: "{{ nginx_owner_user }}"
group: "{{ nginx_owner_group }}"
notify: Restart nginx
- name: Change keepalive_timeout in main nginx.conf
lineinfile:
dest: "/etc/nginx/nginx.conf"
dest: "{{ nginx_configuration_dir }}/nginx.conf"
regexp: '^\s*keepalive_timeout'
line: " keepalive_timeout {{ nginx_keepalive_timeout }};"
insertafter: "http {"
mode: '0640'
owner: "root"
group: "root"
owner: "{{ nginx_owner_user }}"
group: "{{ nginx_owner_group }}"
notify: Restart nginx
- name: Remove default.conf
@@ -104,14 +81,14 @@
when: nginx_remove_default_site
notify: Restart nginx
loop:
- "/etc/nginx/conf.d/default.conf"
- "/etc/nginx/sites-enabled/default"
- "{{ nginx_configuration_dir }}/conf.d/default.conf"
- "{{ nginx_configuration_dir }}/sites-enabled/default"
- name: Generate dh group
openssl_dhparam:
path: "/etc/nginx/dh{{ nginx_dh_size }}.pem"
path: "{{ nginx_configuration_dir }}/dh{{ nginx_dh_size }}.pem"
size: "{{ nginx_dh_size }}"
mode: '0640'
owner: "root"
group: "root"
owner: "{{ nginx_owner_user }}"
group: "{{ nginx_owner_group }}"
notify: Restart nginx
@@ -11,7 +11,7 @@ limit_conn_zone {{ nginx_limit_conn_zone }};
limit_conn {{ nginx_limit_conn }};
ssl_ciphers '{{ nginx_ssl_ciphers }}';
ssl_session_tickets {{ nginx_ssl_session_tickets }};
ssl_dhparam /etc/nginx/dh{{ nginx_dh_size }}.pem;
ssl_dhparam {{ nginx_configuration_hardening_dir }}/dh{{ nginx_dh_size }}.pem;
{% for header in nginx_add_header %}
add_header {{ header }};
{% endfor %}
-2
View File
@@ -1,2 +0,0 @@
---
nginx_ssl_protocols: "TLSv1.2 TLSv1.3"
-2
View File
@@ -1,2 +0,0 @@
---
nginx_ssl_protocols: "TLSv1.2 TLSv1.3"
-2
View File
@@ -1,2 +0,0 @@
---
nginx_ssl_protocols: "TLSv1.2 TLSv1.3"
-2
View File
@@ -1,2 +0,0 @@
---
nginx_ssl_protocols: "TLSv1.2"
-2
View File
@@ -1,2 +0,0 @@
---
nginx_ssl_protocols: "TLSv1.2 TLSv1.3"
-2
View File
@@ -1,2 +0,0 @@
---
nginx_ssl_protocols: "TLSv1.2 TLSv1.3"
-2
View File
@@ -1,2 +0,0 @@
---
nginx_ssl_protocols: "TLSv1.2 TLSv1.3"
+227 -1
View File
@@ -1,6 +1,7 @@
# devsec.os_hardening
![devsec.os_hardening](https://github.com/dev-sec/ansible-os-hardening/workflows/devsec.os_hardening/badge.svg)
![devsec.os_hardening VM](https://github.com/dev-sec/ansible-os-hardening/workflows/devsec.os_hardening%20VM/badge.svg)
## Looking for the old ansible-os-hardening role?
@@ -229,6 +230,15 @@ We know that this is the case on Raspberry Pi.
- `os_ignore_home_folder_users`
- Default: `lost+found`
- Description: specify user home folders in `/home` that shouldn't be chmodded to 700
- `os_chmod_rootuser_home_folder`
- Default: `true`
- Description: Set to `false` to disable "chmod 700" of root's home folder
- `os_rootuser_pw_ageing`
- Default: `false`
- Description: Set to true to enforce password age settings for root user(s)
- `os_remove_additional_root_users`
- Default: `false`
- Description: When enabled and there are multiple users with UID=0, only "root" will be kept. Others will be deleted.
- `os_cron_enabled`
- Default: `true`
- Description: Set to false to disable installing and configuring cron.
@@ -240,7 +250,7 @@ We know that this is the case on Raspberry Pi.
- Description: Set to false to disable installing and configuring limits.
- `os_login_defs_enabled`
- Default: `true`
- Description: Set to false to disable installing and configuring login_defs.
- Description: Set to false to disable installing and configuring login_defs for newly created users.
- `os_minimize_access_enabled`
- Default: `true`
- Description: Set to false to disable installing and configuring minimize_access.
@@ -286,6 +296,222 @@ We know that this is the case on Raspberry Pi.
- `os_sha_crypt_max_rounds`
- Default: `640000`
- Description: Define the number of maximum SHA rounds. With a lot of rounds brute forcing the password is more difficult. But note also that it more CPU resources will be needed to authenticate users. The values must be inside the 1000-999999999 range.
- `os_mnt_boot_dir_mode`
- Default: `0700`
- Description: Set default perimissions for /boot
- `os_mnt_boot_enabled`
- Default: `false`
- Description: Set to true to configure /boot mountpoint
- `os_mnt_boot_src`
- Default: `''`
- Description: Set mount source for /boot
- `os_mnt_boot_options`
- Default: `rw,nosuid,nodev,noexec`
- Description: Configure mount options for /boot
- `os_mnt_boot_filesystem`
- Default: `""`
- Description: Configure file system for fstab entry /boot. If empty, the current file system type will be used.
- `os_mnt_boot_dump`
- Default: ext3 + ext4 `1` / other `0`
- Description: Configure dump for fstab entry /var/tmp. If empty, the default depends on fstype.
- `os_mnt_boot_passno`
- Default: ext3 + ext4 `2` / other `0`
- Description: Configure passno for fstab entry /var/tmp. If empty, the default depends on fstype.
- `os_mnt_dev_dir_mode`
- Default: `0755`
- Description: Set default perimissions for /dev
- `os_mnt_dev_enabled`
- Default: `true`
- Description: Set to false to ignore /dev mountpoint
- `os_mnt_dev_src`
- Default: `devtmpfs`
- Description: Set mount source for /dev
- `os_mnt_dev_options`
- Default: `'rw,nosuid,noexec'`
- Description: Configure mount options for /dev
- `os_mnt_dev_filesystem`
- Default: `devtmpfs`
- Description: Configure file system for fstab entry /dev
- `os_mnt_dev_dump`
- Default: `0`
- Description: Configure dump for fstab entry /var/tmp.
- `os_mnt_dev_passno`
- Default: `0`
- Description: Configure passno for fstab entry /var/tmp.
- `os_mnt_dev_shm_dir_mode`
- Default: `1777`
- Description: Set default perimissions for /dev/shm
- `os_mnt_dev_shm_enabled`
- Default: `true`
- Description: Set to false to ignore /dev/shm mountpoint
- `os_mnt_dev_shm_src`
- Default: `tmpfs`
- Description: Set mount source for /dev/shm
- `os_mnt_dev_shm_options`
- Default: `rw,nosuid,nodev,noexec`
- Description: Configure mount options for /dev/shm
- `os_mnt_dev_shm_filesystem`
- Default: `tmpfs`
- Description: Configure file system for fstab entry /dev/shm
- `os_mnt_dev_shm_dump`
- Default: `0`
- Description: Configure dump for fstab entry /var/tmp.
- `os_mnt_dev_shm_passno`
- Default: `0`
- Description: Configure passno for fstab entry /var/tmp.
- `os_mnt_home_dir_mode`
- Default: `0755`
- Description: Set default perimissions for /home
- `os_mnt_home_enabled`
- Default: `false`
- Description: Set to true to configure /home mountpoint
- `os_mnt_home_src`
- Default: `""`
- Description: Set mount source for /home. If empty, the current file system source device will be used.
- `os_mnt_home_options`
- Default: `rw,nosuid,nodev`
- Description: Configure mount options for /home
- `os_mnt_home_filesystem`
- Default: `""`
- Description: Configure file system for fstab entry /home. If empty, the current file system type will be used.
- `os_mnt_home_dump`
- Default: ext3 + ext4 `1` / other `0`
- Description: Configure dump for fstab entry /var/tmp. If empty, the default depends on fstype.
- `os_mnt_home_passno`
- Default: ext3 + ext4 `2` / other `0`
- Description: Configure passno for fstab entry /var/tmp. If empty, the default depends on fstype.
- `os_mnt_run_dir_mode`
- Default: `0755`
- Description: Set default perimissions for /run
- `os_mnt_run_enabled`
- Default: `true`
- Description: Set to false to ignore /run mountpoint
- `os_mnt_run_src`
- Default: `tmpfs`
- Description: Set mount source for /run
- `os_mnt_run_options`
- Default: `rw,nosuid,nodev`
- Description: Configure mount options for /run
- `os_mnt_run_filesystem`
- Default: `tmpfs`
- Description: Configure file system for fstab entry /run
- `os_mnt_run_dump`
- Default: `0`
- Description: Configure dump for fstab entry /var/tmp.
- `os_mnt_run_passno`
- Default: `0`
- Description: Configure passno for fstab entry /var/tmp.
- `os_mnt_tmp_dir_mode`
- Default: `1777`
- Description: Set default perimissions for /tmp
- `os_mnt_tmp_enabled`
- Default: `false`
- Description: Set to true to configure /tmp mountpoint
- `os_mnt_tmp_src`
- Default: `""`
- Description: Set mount source for /tmp. If empty, the current file system source device will be used.
- `os_mnt_tmp_options`
- Default: `rw,nosuid,nodev,noexec`
- Description: Configure mount options for /tmp
- `os_mnt_tmp_filesystem`
- Default: `""`
- Description: Configure file system for fstab entry /tmp. If empty, the current file system type will be used.
- `os_mnt_tmp_dump`
- Default: ext3 + ext4 `1` / other `0`
- Description: Configure dump for fstab entry /var/tmp. If empty, the default depends on fstype.
- `os_mnt_tmp_passno`
- Default: ext3 + ext4 `2` / other `0`
- Description: Configure passno for fstab entry /var/tmp. If empty, the default depends on fstype.
- `os_mnt_var_dir_mode`
- Default: `0755`
- Description: Set default perimissions for /var
- `os_mnt_var_enabled`
- Default: `false`
- Description: Set to true to configure /var mountpoint
- `os_mnt_var_src`
- Default: `""`
- Description: Set mount source for /var. If empty, the current file system source device will be used.
- `os_mnt_var_options`
- Default: `rw,nosuid,nodev`
- Description: Configure mount options for /var
- `os_mnt_var_filesystem`
- Default: `""`
- Description: Configure file system for fstab entry /var. If empty, the current file system type will be used.
- `os_mnt_var_dump`
- Default: ext3 + ext4 `1` / other `0`
- Description: Configure dump for fstab entry /var/tmp. If empty, the default depends on fstype.
- `os_mnt_var_passno`
- Default: ext3 + ext4 `2` / other `0`
- Description: Configure passno for fstab entry /var/tmp. If empty, the default depends on fstype.
- `os_mnt_var_log_dir_mode`
- Default: `0755`
- Description: Set default perimissions for /var/log
- `os_mnt_var_log_enabled`
- Default: `false`
- Description: Set to true to configure /var/log mountpoint
- `os_mnt_var_log_src`
- Default: `""`
- Description: Set mount source for /var/log. If empty, the current file system source device will be used.
- `os_mnt_var_log_options`
- Default: `rw,nosuid,nodev,noexec`
- Description: Configure mount options for /var/log
- `os_mnt_var_log_filesystem`
- Default: `""`
- Description: Configure file system for fstab entry /var/log. If empty, the current file system type will be used.
- `os_mnt_var_log_dump`
- Default: ext3 + ext4 `1` / other `0`
- Description: Configure dump for fstab entry /var/tmp. If empty, the default depends on fstype.
- `os_mnt_var_log_passno`
- Default: ext3 + ext4 `2` / other `0`
- Description: Configure passno for fstab entry /var/tmp. If empty, the default depends on fstype.
- `os_mnt_var_log_audit_dir_mode`
- Default: `0640`
- Description: Set default perimissions for /var/log/audit
- `os_mnt_var_log_audit_enabled`
- Default: `false`
- Description: Set to true to configure /var/log/audit mountpoint
- `os_mnt_var_log_audit_src`
- Default: `""`
- Description: Set mount source for /var/log/audit. If empty, the current file system source device will be used.
- `os_mnt_var_log_audit_options`
- Default: `rw,nosuid,nodev,noexec`
- Description: Configure mount options for /var/log/audit
- `os_mnt_var_log_audit_filesystem`
- Default: `""`
- Description: Configure file system for fstab entry /var/log/audit. If empty, the current file system type will be used.
- `os_mnt_var_log_audit_dump`
- Default: ext3 + ext4 `1` / other `0`
- Description: Configure dump for fstab entry /var/tmp. If empty, the default depends on fstype.
- `os_mnt_var_log_audit_passno`
- Default: ext3 + ext4 `2` / other `0`
- Description: Configure passno for fstab entry /var/tmp. If empty, the default depends on fstype.
- `os_mnt_var_tmp_dir_mode`
- Default: `1777`
- Description: Set default perimissions for /var/tmp
- `os_mnt_var_tmp_enabled`
- Default: `false`
- Description: Set to true to configure /var/tmp mountpoint
- `os_mnt_var_tmp_src`
- Default: `""`
- Description: Set mount source for /var/tmp. If empty, the current file system source device will be used.
- `os_mnt_var_tmp_options`
- Default: `rw,nosuid,nodev,noexec`
- Description: Configure mount options for /var/tmp
- `os_mnt_var_tmp_filesystem`
- Default: `""`
- Description: Configure file system for fstab entry /var/tmp. If empty, the current file system type will be used.
- `os_mnt_var_tmp_dump`
- Default: ext3 + ext4 `1` / other `0`
- Description: Configure dump for fstab entry /var/tmp. If empty, the default depends on fstype.
- `os_mnt_var_tmp_passno`
- Default: ext3 + ext4 `2` / other `0`
- Description: Configure passno for fstab entry /var/tmp. If empty, the default depends on fstype.
- `os_netrc_enabled`
- Default: `True`
- Description: Configure filesystem for existence of .netrc file in homedir
- `os_netrc_whitelist_user`
- Default: ``
- Description: Add list of user to allow creation of .netrc in users homedir
## Packages
+97 -3
View File
@@ -9,19 +9,27 @@ os_auth_lockout_time: 600 # Seconds (600 = 10min)
os_auth_timeout: 60
os_auth_allow_homeless: false
os_auth_pam_passwdqc_enable: true
os_auth_pam_passwdqc_options: 'min=disabled,disabled,16,12,8' # Used in RHEL6
os_auth_pam_passwdqc_options: 'min=disabled,disabled,16,12,8' # Used in Debian
os_auth_pam_pwquality_options: 'try_first_pass retry=3 authtok_type=' # Used in RHEL7 and RHEL8
os_auth_root_ttys: [console, tty1, tty2, tty3, tty4, tty5, tty6]
os_chfn_restrict: ''
# Set to false to disable chmod /home folders to 700
# Set to false to disable chmod userhome folders to 700
os_chmod_rootuser_home_folder: true
os_chmod_home_folders: true
# May contain: change_user
os_security_users_allow: []
# Specify user home folders in /home that shouldn't be chmodded to 700
os_ignore_home_folder_users: ['lost+found']
# Set to false to disable password age enforcement on existing users
os_rootuser_pw_ageing: false
# When enabled and there are multiple users with UID=0, only "root" will be kept. Others will be deleted.
os_remove_additional_root_users: false
# Specify system accounts whose login should not be disabled and password not changed
os_ignore_users: ['vagrant', 'kitchen']
os_security_kernel_enable_module_loading: true
@@ -338,7 +346,7 @@ os_ctrlaltdel_disabled: false
# Set to false to disable installing and configuring limits.
os_limits_enabled: true
# Set to false to disable installing and configuring login_defs.
# Set to false to disable installing and configuring login_defs for newly created users.
os_login_defs_enabled: true
# Set to false to disable installing and configuring minimize_access.
@@ -385,3 +393,89 @@ os_selinux_enabled: true
# The values must be inside the 1000-999999999 range.
os_sha_crypt_min_rounds: "640000"
os_sha_crypt_max_rounds: "640000"
os_mnt_boot_dir_mode: '0700'
os_mnt_boot_enabled: false
os_mnt_boot_src: ""
os_mnt_boot_options: 'rw,nosuid,nodev,noexec'
os_mnt_boot_filesystem: ""
os_mnt_boot_dump: ""
os_mnt_boot_passno: ""
os_mnt_dev_dir_mode: '0755'
os_mnt_dev_enabled: true
os_mnt_dev_src: "devtmpfs"
os_mnt_dev_options: 'rw,nosuid,noexec'
os_mnt_dev_filesystem: "devtmpfs"
os_mnt_dev_dump: ""
os_mnt_dev_passno: ""
os_mnt_dev_shm_dir_mode: '1777'
os_mnt_dev_shm_enabled: true
os_mnt_dev_shm_src: "tmpfs"
os_mnt_dev_shm_options: 'rw,nosuid,nodev,noexec'
os_mnt_dev_shm_filesystem: "tmpfs"
os_mnt_dev_shm_dump: ""
os_mnt_dev_shm_passno: ""
os_mnt_home_dir_mode: '0755'
os_mnt_home_enabled: false
os_mnt_home_src: ""
os_mnt_home_options: 'rw,nosuid,nodev'
os_mnt_home_filesystem: ""
os_mnt_home_dump: ""
os_mnt_home_passno: ""
os_mnt_run_dir_mode: '0755'
os_mnt_run_enabled: true
os_mnt_run_src: "tmpfs"
os_mnt_run_options: 'rw,nosuid,nodev'
os_mnt_run_filesystem: "tmpfs"
os_mnt_run_dump: ""
os_mnt_run_passno: ""
os_mnt_tmp_dir_mode: '1777'
os_mnt_tmp_enabled: false
os_mnt_tmp_src: ""
os_mnt_tmp_options: 'rw,nosuid,nodev,noexec'
os_mnt_tmp_filesystem: ""
os_mnt_tmp_dump: ""
os_mnt_tmp_passno: ""
os_mnt_var_dir_mode: '0755'
os_mnt_var_enabled: false
os_mnt_var_src: ""
os_mnt_var_options: 'rw,nosuid,nodev'
os_mnt_var_filesystem: ""
os_mnt_var_dump: ""
os_mnt_var_passno: ""
os_mnt_var_log_dir_mode: '0755'
os_mnt_var_log_enabled: false
os_mnt_var_log_src: ""
os_mnt_var_log_options: 'rw,nosuid,nodev,noexec'
os_mnt_var_log_filesystem: ""
os_mnt_var_log_dump: ""
os_mnt_var_log_passno: ""
os_mnt_var_log_audit_dir_mode: '0700'
os_mnt_var_log_audit_enabled: false
os_mnt_var_log_audit_src: ""
os_mnt_var_log_audit_options: 'rw,nosuid,nodev,noexec'
os_mnt_var_log_audit_filesystem: ""
os_mnt_var_log_audit_dump: ""
os_mnt_var_log_audit_passno: ""
os_mnt_var_tmp_dir_mode: '1777'
os_mnt_var_tmp_enabled: false
os_mnt_var_tmp_src: ""
os_mnt_var_tmp_options: 'rw,nosuid,nodev,noexec'
os_mnt_var_tmp_filesystem: ""
os_mnt_var_tmp_dump: ""
os_mnt_var_tmp_passno: ""
#
# .netrc User whitelist
# keep .netrc file for users in whitelist
os_netrc_enabled: true
os_netrc_whitelist_user: []
+8 -2
View File
@@ -2,7 +2,7 @@
- name: Update-initramfs
command: 'update-initramfs -u'
- name: restart-auditd
- name: Restart auditd
command:
cmd: 'service auditd restart' # rhel: see: https://access.redhat.com/solutions/2664811
warn: false # sadly 'service' module fails in that case also by using 'use: service'
@@ -10,4 +10,10 @@
- name: Reload systemd
systemd:
daemon_reload: yes
daemon_reload: true
- name: Remount filesystems
mount:
path: "{{ item }}"
state: remounted
loop: "{{ mountpoints_changed }}"
+7 -6
View File
@@ -8,21 +8,22 @@ galaxy_info:
platforms:
- name: EL
versions:
- 7
- 8
- "7"
- "8"
- name: Ubuntu
versions:
- xenial
- bionic
- focal
- jammy
- name: Debian
versions:
- stretch
- buster
- bullseye
- name: Amazon
- name: Fedora
- name: Archlinux
- name: ArchLinux
- name: SmartOS
- name: openSUSE
- name: opensuse
galaxy_tags:
- system
- security
+1 -1
View File
@@ -12,5 +12,5 @@
owner: 'root'
group: 'root'
mode: '0640'
notify: 'restart-auditd'
notify: Restart auditd
tags: auditd
+2 -2
View File
@@ -2,6 +2,6 @@
- name: Disable CTRL-ALT-DEL
systemd:
name: ctrl-alt-del.target
masked: yes
daemon_reload: yes
masked: true
daemon_reload: true
when: ansible_service_mgr == "systemd"
+39 -17
View File
@@ -22,75 +22,97 @@
with_dict: '{{ os_vars }}'
tags: always
- import_tasks: auditd.yml
- name: Import tasks for auditd
import_tasks: auditd.yml
tags: auditd
when: os_auditd_enabled | bool
- import_tasks: cron.yml
- name: Import tasks for cron
import_tasks: cron.yml
tags: cron
when: os_cron_enabled | bool
- import_tasks: ctrlaltdel.yml
- name: Import tasks to configure ctrl+alt+del
import_tasks: ctrlaltdel.yml
tags: ctrlaltdel
when: os_ctrlaltdel_disabled | bool
- import_tasks: limits.yml
- name: Import tasks to configure limits
import_tasks: limits.yml
tags: limits
when: os_limits_enabled | bool
- import_tasks: login_defs.yml
- name: Import tasks to configure login_defs
import_tasks: login_defs.yml
tags: login_defs
when: os_login_defs_enabled | bool
- import_tasks: minimize_access.yml
- name: Import tasks to minimize access permissions
import_tasks: minimize_access.yml
tags: minimize_access
when: os_minimize_access_enabled | bool
- import_tasks: pam.yml
- name: Import tasks to configure PAM
import_tasks: pam.yml
tags: pam
when: os_pam_enabled | bool
- import_tasks: modprobe.yml
- name: Import tasks to configure modules
import_tasks: modprobe.yml
tags: modprobe
when: os_modprobe_enabled | bool
- import_tasks: profile.yml
- name: Import tasks to configure profile
import_tasks: profile.yml
tags: profile
when: os_profile_enabled | bool
- import_tasks: securetty.yml
- name: Import tasks to configure securetty
import_tasks: securetty.yml
tags: securetty
when: os_securetty_enabled | bool
- import_tasks: suid_sgid.yml
- name: Import tasks to set suid and sgid
import_tasks: suid_sgid.yml
when: os_security_suid_sgid_enforce | bool
tags: suid_sgid
- import_tasks: sysctl.yml
- name: Import tasks to configure sysctl
import_tasks: sysctl.yml
tags: sysctl
when: os_sysctl_enabled | bool
- import_tasks: user_accounts.yml
- name: Import tasks to harden user accounts
import_tasks: user_accounts.yml
tags: user_accounts
when: os_user_accounts_enabled | bool
- import_tasks: rhosts.yml
- name: Import tasks to configure rhosts
import_tasks: rhosts.yml
tags: rhosts
when: os_rhosts_enabled | bool
- import_tasks: yum.yml
- name: Import tasks to configure netrc
import_tasks: netrc.yml
tags: netrc
when: os_netrc_enabled | bool
- name: Import tasks to configure yum
import_tasks: yum.yml
tags: yum
when:
- ansible_facts.os_family == 'RedHat'
- os_yum_enabled | bool
- import_tasks: apt.yml
- name: Import tasks to configure apt
import_tasks: apt.yml
tags: apt
when:
- ansible_facts.os_family == 'Debian'
- os_apt_enabled | bool
- import_tasks: selinux.yml
- name: Import tasks to configure selinux
import_tasks: selinux.yml
tags: selinux
when:
- ansible_facts.selinux.status == 'enabled'
+17 -18
View File
@@ -1,5 +1,6 @@
---
- name: disable coredumps
- name: Disable coredumps
when: not os_security_kernel_enable_core_dump | bool
block:
- name: Create limits.d-directory if it does not exist | sysctl-31a, sysctl-31b
file:
@@ -28,7 +29,7 @@
modification_time: preserve
access_time: preserve
- name: create coredump.conf.d-directory if it does not exist
- name: Create coredump.conf.d-directory if it does not exist
file:
path: '/etc/systemd/coredump.conf.d'
owner: root
@@ -37,7 +38,7 @@
state: directory
when: ansible_service_mgr == "systemd"
- name: create custom.conf for disabling coredumps
- name: Create custom.conf for disabling coredumps
template:
src: 'etc/systemd/coredump.conf.d/coredumps.conf.j2'
dest: '/etc/systemd/coredump.conf.d/custom.conf'
@@ -47,19 +48,17 @@
when: ansible_service_mgr == "systemd"
notify: Reload systemd
when: not os_security_kernel_enable_core_dump | bool
- name: enable coredumps
block:
- name: Remove coredump.conf.d directory with files
file:
path: /etc/systemd/coredump.conf.d
state: absent
when: ansible_service_mgr == "systemd"
notify: Reload systemd
- name: Remove 10.hardcore.conf config file
file:
path: /etc/security/limits.d/10.hardcore.conf
state: absent
- name: Enable coredumps
when: os_security_kernel_enable_core_dump | bool
block:
- name: Remove coredump.conf.d directory with files
file:
path: /etc/systemd/coredump.conf.d
state: absent
when: ansible_service_mgr == "systemd"
notify: Reload systemd
- name: Remove 10.hardcore.conf config file
file:
path: /etc/security/limits.d/10.hardcore.conf
state: absent
+4 -1
View File
@@ -1,3 +1,6 @@
---
- include_tasks: hardening.yml
- name: Include hardening tasks
include_tasks: hardening.yml
when: os_hardening_enabled | bool
tags:
- always
+25 -1
View File
@@ -6,7 +6,7 @@
# also see: https://github.com/dev-sec/ansible-os-hardening/issues/219
- name: Find files with write-permissions for group
shell: "find -L {{ item }} -perm /go+w -type f" # noqa command-instead-of-shell
with_flattened:
with_community.general.flattened:
- '/usr/local/sbin'
- '/usr/local/bin'
- '/usr/sbin'
@@ -80,3 +80,27 @@
fstype: proc
opts: '{{ proc_mnt_options }}'
state: mounted
- name: Generate list of current available mounted filesystems on the system
set_fact:
mountpoints_list: "{{ ansible_mounts | map(attribute='mount') | list }}"
- name: Append special devices list to valid mountpoint list
set_fact:
mountpoints_list: "{{ mountpoints_list + ['/dev', '/dev/shm', '/run'] }}"
- name: Minimize access for filesystems
include_tasks: minimize_access_fs.yml
loop:
- { path: '/boot', src: '{{ os_mnt_boot_src }}', fstype: '{{ os_mnt_boot_filesystem }}', opts: '{{ os_mnt_boot_options }}', enabled: "{{ os_mnt_boot_enabled }}", mode: "{{ os_mnt_boot_dir_mode }}", dump: "{{ os_mnt_boot_dump }}", passno: "{{ os_mnt_boot_passno }}" }
- { path: '/dev', src: '{{ os_mnt_dev_src }}', fstype: '{{ os_mnt_dev_filesystem }}', opts: '{{ os_mnt_dev_options }}', enabled: "{{ os_mnt_dev_enabled }}", mode: "{{ os_mnt_dev_dir_mode }}", dump: "{{ os_mnt_dev_dump }}", passno: "{{ os_mnt_dev_passno }}" }
- { path: '/dev/shm', src: '{{ os_mnt_dev_shm_src }}', fstype: '{{ os_mnt_dev_shm_filesystem }}', opts: '{{ os_mnt_dev_shm_options }}', enabled: "{{ os_mnt_dev_shm_enabled }}", mode: "{{ os_mnt_dev_shm_dir_mode }}", dump: "{{ os_mnt_dev_shm_dump }}", passno: "{{ os_mnt_dev_shm_passno }}" }
- { path: '/home', src: '{{ os_mnt_home_src }}', fstype: '{{ os_mnt_home_filesystem }}', opts: '{{ os_mnt_home_options }}', enabled: "{{ os_mnt_home_enabled }}", mode: "{{ os_mnt_home_dir_mode }}", dump: "{{ os_mnt_home_dump }}", passno: "{{ os_mnt_home_passno }}" }
- { path: '/run', src: '{{ os_mnt_run_src }}', fstype: '{{ os_mnt_run_filesystem }}', opts: '{{ os_mnt_run_options }}', enabled: "{{ os_mnt_run_enabled }}", mode: "{{ os_mnt_run_dir_mode }}", dump: "{{ os_mnt_run_dump }}", passno: "{{ os_mnt_run_passno }}" }
- { path: '/tmp', src: '{{ os_mnt_tmp_src }}', fstype: '{{ os_mnt_tmp_filesystem }}', opts: '{{ os_mnt_tmp_options }}', enabled: "{{ os_mnt_tmp_enabled }}", mode: "{{ os_mnt_tmp_dir_mode }}", dump: "{{ os_mnt_tmp_dump }}", passno: "{{ os_mnt_tmp_passno }}" }
- { path: '/var', src: '{{ os_mnt_var_src }}', fstype: '{{ os_mnt_var_filesystem }}', opts: '{{ os_mnt_var_options }}', enabled: "{{ os_mnt_var_enabled }}", mode: "{{ os_mnt_var_dir_mode }}", dump: "{{ os_mnt_var_dump }}", passno: "{{ os_mnt_var_passno }}" }
- { path: '/var/log', src: '{{ os_mnt_var_log_src }}', fstype: '{{ os_mnt_var_log_filesystem }}', opts: '{{ os_mnt_var_log_options }}', enabled: "{{ os_mnt_var_log_enabled }}", mode: "{{ os_mnt_var_log_dir_mode }}", dump: "{{ os_mnt_var_log_dump }}", passno: "{{ os_mnt_var_log_passno }}" }
- { path: '/var/log/audit', src: '{{ os_mnt_var_log_audit_src }}', fstype: '{{ os_mnt_var_log_audit_filesystem }}', opts: '{{ os_mnt_var_log_audit_options }}', enabled: "{{ os_mnt_var_log_audit_enabled }}", mode: "{{ os_mnt_var_log_audit_dir_mode }}", dump: "{{ os_mnt_var_log_audit_dump }}", passno: "{{ os_mnt_var_log_audit_passno }}" }
- { path: '/var/tmp', src: '{{ os_mnt_var_tmp_src }}', fstype: '{{ os_mnt_var_tmp_filesystem }}', opts: '{{ os_mnt_var_tmp_options }}', enabled: "{{ os_mnt_var_tmp_enabled }}", mode: "{{ os_mnt_var_tmp_dir_mode }}", dump: "{{ os_mnt_var_tmp_dump }}", passno: "{{ os_mnt_var_tmp_passno }}" }
loop_control:
loop_var: mount
@@ -0,0 +1,36 @@
---
- name: "Configure mount {{ mount.path }} with hardened options"
mount:
path: "{{ mount.path }}"
src: "{{ mount.src | default(mountinfo.device, true) }}"
fstype: "{{ mount.fstype | default(mountinfo.fstype, true) }}"
opts: "{{ mount.opts }}"
dump: "{{ mount.dump | default('1' if mount.fstype | default(mountinfo.fstype, true) in ['ext3', 'ext4'] else '0', true) }}"
passno: "{{ mount.passno | default('2' if mount.fstype | default(mountinfo.fstype, true) in ['ext3', 'ext4'] else '0', true) }}"
state: present
register: mountpoint
when:
- mount.enabled | bool
- mount.path in mountpoints_list
vars:
mountinfo: "{{ ansible_mounts | selectattr('mount', 'equalto', mount.path) | list | first | default(None) }}"
notify: Remount filesystems
- name: "Check if {{ mount.path }} exists"
stat:
path: "{{ mount.path }}"
register: mountpoint_exists
- name: "Harden permissions for {{ mount.path }} directory"
file:
dest: "{{ mount.path }}"
owner: 'root'
group: 'root'
mode: "{{ mount.mode }}"
when:
- mountpoint_exists.stat.exists | bool
- name: "Register changed mountpoints"
set_fact:
mountpoints_changed: "{{ mountpoints_changed | default([]) + [mount.path] }}"
when: mountpoint.changed # noqa no-handler
+13
View File
@@ -0,0 +1,13 @@
---
- name: Get user accounts | os-09
command: "awk -F: '{print $1}' /etc/passwd"
changed_when: false
check_mode: false
register: users_accounts
- name: Delete .netrc-files from system | os-09
file:
dest: '~{{ item }}/.netrc'
state: 'absent'
loop: '{{ users_accounts.stdout_lines | flatten | default([]) }}'
when: item not in os_netrc_whitelist_user
+4 -2
View File
@@ -17,11 +17,13 @@
when:
- ansible_facts.os_family != 'Archlinux'
- import_tasks: pam_debian.yml
- name: Import tasks for Debian PAM
import_tasks: pam_debian.yml
when:
- ansible_facts.os_family == 'Debian'
- import_tasks: pam_rhel.yml
- name: Import tasks for RedHat PAM
import_tasks: pam_rhel.yml
when:
- ansible_facts.os_family == 'RedHat'
+14 -14
View File
@@ -22,9 +22,12 @@
name: 'libpam-modules'
state: 'present'
when:
- os_auth_retries > 0
- os_auth_retries|int > 0
- name: Manage tally on Debian stable
when:
- "'libpam-modules' in ansible_facts.packages"
- "ansible_facts.packages['libpam-modules'][0].version is version('1.4.0', '<')"
block:
- name: Configure tally2
template:
@@ -34,26 +37,26 @@
owner: 'root'
group: 'root'
when:
- os_auth_retries > 0
- os_auth_retries|int > 0
- name: Delete tally2 when retries is 0
file:
path: '{{ tally2_path }}'
state: 'absent'
when:
- os_auth_retries == 0
when:
- "'libpam-modules' in ansible_facts.packages"
- "ansible_facts.packages['libpam-modules'][0].version is version('1.4.0', '<')"
- os_auth_retries|int == 0
- name: Manage tally/faillock on Debian unstable
when:
- "'libpam-modules' in ansible_facts.packages"
- "ansible_facts.packages['libpam-modules'][0].version is version('1.4.0', '>=')"
block:
- name: Delete tally2
file:
path: '{{ tally2_path }}'
state: 'absent'
- name: create tally directory
- name: Create tally directory
file:
path: '/var/run/faillock'
state: 'directory'
@@ -77,7 +80,7 @@
owner: 'root'
group: 'root'
when:
- os_auth_retries > 0
- os_auth_retries|int > 0
- name: Configure faillock pam authfail
template:
@@ -87,24 +90,21 @@
owner: 'root'
group: 'root'
when:
- os_auth_retries > 0
- os_auth_retries|int > 0
- name: Delete faillock when retries is 0
file:
path: '/usr/share/pam-configs/faillock'
state: 'absent'
when:
- os_auth_retries == 0
- os_auth_retries|int == 0
- name: Delete faillock authfail when retries is 0
file:
path: '/usr/share/pam-configs/faillock_authfail'
state: 'absent'
when:
- os_auth_retries == 0
when:
- "'libpam-modules' in ansible_facts.packages"
- "ansible_facts.packages['libpam-modules'][0].version is version('1.4.0', '>=')"
- os_auth_retries|int == 0
- name: Update pam on Debian systems
command: 'pam-auth-update --package'
+1 -7
View File
@@ -9,15 +9,9 @@
file:
dest: '~{{ item }}/.rhosts'
state: 'absent'
with_flattened: '{{ users_accounts.stdout_lines | default([]) }}'
loop: '{{ users_accounts.stdout_lines | flatten | default([]) }}'
- name: Delete hosts.equiv from system | os-01
file:
dest: '/etc/hosts.equiv'
state: 'absent'
- name: Delete .netrc-files from system | os-09
file:
dest: '~{{ item }}/.netrc'
state: 'absent'
with_flattened: '{{ users_accounts.stdout_lines | default([]) }}'
+2 -2
View File
@@ -6,7 +6,7 @@
state: 'file'
follow: 'yes'
failed_when: false
with_flattened:
with_community.general.flattened:
- '{{ os_security_suid_sgid_system_blacklist }}'
- '{{ os_security_suid_sgid_blacklist }}'
@@ -27,6 +27,6 @@
mode: 'a-s'
state: 'file'
follow: 'yes'
with_flattened:
with_community.general.flattened:
- '{{ suid | default([]) | difference(os_security_suid_sgid_whitelist) }}'
when: os_security_suid_sgid_remove_from_unknown | bool
+2 -1
View File
@@ -42,6 +42,7 @@
register: initramfs
- name: Change sysctls
when: ansible_virtualization_type not in ['docker', 'lxc', 'openvz']
block:
- name: Create a combined sysctl-dict if os-dependent sysctls are defined
set_fact:
@@ -68,7 +69,7 @@
reload: true
ignoreerrors: true
with_dict: '{{ sysctl_config }}'
when: ansible_virtualization_type not in ['docker', 'lxc', 'openvz']
when: item.key not in sysctl_unsupported_entries | default()
- name: Apply ufw defaults
template:
+45 -4
View File
@@ -1,4 +1,45 @@
---
- name: Read local linux user database
getent:
database: passwd
# creates a dict for each user containing UID/HOMEDIR etc...
when: getent_passwd is undefined # skip this task if "getent" has run before
- name: Extract root account(s) from local user database
loop: "{{ getent_passwd.keys() | list }}"
when:
- getent_passwd[item][1]|int == 0
set_fact:
root_users: "{{ root_users | default([]) + [item] }}"
- name: Set ownership of root user home directory(s) to 0700
file:
mode: 0700
owner: "{{ item }}"
path: "{{ getent_passwd[item][4] }}"
state: directory
loop: "{{ root_users }}"
when:
- os_chmod_rootuser_home_folder | bool
- name: Set password ageing for root user(s)
user:
name: "{{ item }}"
password_expire_min: "{{ os_auth_pw_min_age }}"
password_expire_max: "{{ os_auth_pw_max_age }}"
loop: "{{ root_users }}"
when: os_rootuser_pw_ageing|bool
- name: Remove additional users with UID=0 ("root" user is not touched)
user:
name: "{{ item }}"
state: absent
loop: "{{ root_users }}"
when:
- os_remove_additional_root_users|bool
- root_users|length > 1
- item != "root"
- name: Get UID_MIN from login.defs
shell: awk '/^\s*UID_MIN\s*([0-9]*).*?$/ {print $2}' /etc/login.defs
args:
@@ -25,7 +66,7 @@
when: uid_max is not defined
- name: Get all system accounts
command: awk -F'':'' '{ if ( $3 <= {{ uid_max|quote }} ) print $1}' /etc/passwd
command: awk -F'':'' '{ if ( $3 <= {{ uid_max | quote }} ) print $1}' /etc/passwd
args:
removes: /etc/passwd
changed_when: false
@@ -43,10 +84,10 @@
shell: '{{ os_nologin_shell_path }}'
password: '*'
createhome: false
with_flattened:
with_community.general.flattened:
- '{{ sys_accs_cond | default([]) | difference(os_ignore_users) | list }}'
- name: get all home directories in /home, but skip ignored users
- name: Get all home directories in /home, but skip ignored users
find:
paths: /home/
recurse: false
@@ -55,7 +96,7 @@
register: home_directories
when: os_chmod_home_folders | bool
- name: set ownership of /home directories to 0700
- name: Set ownership of /home directories to 0700
file:
mode: 0700
path: "{{ item.path }}"
+1 -1
View File
@@ -37,7 +37,7 @@
replace: 'gpgcheck=1'
mode: '0644'
register: status
failed_when: status.rc is defined and status.rc != 257
failed_when: status.rc is defined and status.rc not in (257, 0)
loop:
- '/etc/yum.conf'
- '/etc/dnf/dnf.conf'
@@ -4,7 +4,7 @@
#%PAM-1.0
auth required pam_env.so
auth required pam_faildelay.so delay=2000000
{% if os_auth_retries > 0 %}
{% if os_auth_retries|int > 0 %}
auth required pam_faillock.so preauth silent audit even_deny_root deny={{ os_auth_retries }} unlock_time={{ os_auth_lockout_time }}
{% endif %}
{% if (os_auth_pam_sssd_enable | bool) %}
@@ -16,12 +16,12 @@ auth sufficient pam_unix.so nullok try_first_pass
auth [default=1 ignore=ignore success=ok] pam_succeed_if.so uid >= 1000 quiet
auth sufficient pam_sss.so forward_pass
{% endif %}
{% if os_auth_retries > 0 %}
{% if os_auth_retries|int > 0 %}
auth required pam_faillock.so authfail audit even_deny_root deny={{ os_auth_retries }} unlock_time={{ os_auth_lockout_time }}
{% endif %}
auth required pam_deny.so
{% if os_auth_retries > 0 %}
{% if os_auth_retries|int > 0 %}
account required pam_faillock.so
{% endif %}
account required pam_unix.so
+1 -1
View File
@@ -33,7 +33,7 @@ os_auth_sub_gid_min: 100000
os_auth_sub_gid_max: 600100000
os_auth_sub_gid_count: 65536
os_auth_pam_sssd_enable: false
os_auth_pam_sssd_enable: true
# defaults for useradd
os_useradd_mail_dir: /var/spool/mail
+4
View File
@@ -43,3 +43,7 @@ modprobe_package: 'module-init-tools'
auditd_package: 'audit'
hidepid_option: '0' # allowed values: 0, 1, 2
sysctl_unsupported_entries:
- 'fs.protected_fifos'
- 'fs.protected_regular'
-45
View File
@@ -1,45 +0,0 @@
---
os_packages_pam_ccreds: 'pam_ccreds'
os_nologin_shell_path: '/sbin/nologin'
# Different distros use different standards for /etc/shadow perms, e.g.
# RHEL derivatives use root:root 0000, whereas Debian-based use root:shadow 0640.
# You must provide key/value pairs for owner, group, and mode if overriding.
os_shadow_perms:
owner: root
group: root
mode: '0000'
os_passwd_perms:
owner: root
group: root
mode: '0644'
os_env_umask: '077'
os_auth_uid_min: 1000
os_auth_uid_max: 60000
os_auth_gid_min: 1000
os_auth_gid_max: 60000
os_auth_sys_uid_min: 201
os_auth_sys_uid_max: 999
os_auth_sys_gid_min: 201
os_auth_sys_gid_max: 999
os_auth_sub_uid_min: 100000
os_auth_sub_uid_max: 600100000
os_auth_sub_uid_count: 65536
os_auth_sub_gid_min: 100000
os_auth_sub_gid_max: 600100000
os_auth_sub_gid_count: 65536
os_auth_pam_sssd_enable: true
# defaults for useradd
os_useradd_mail_dir: /var/spool/mail
os_useradd_create_home: true
modprobe_package: 'module-init-tools'
auditd_package: 'audit'
hidepid_option: '2' # allowed values: 0, 1, 2
-45
View File
@@ -1,45 +0,0 @@
---
os_packages_pam_ccreds: 'pam_ccreds'
os_nologin_shell_path: '/sbin/nologin'
# Different distros use different standards for /etc/shadow perms, e.g.
# RHEL derivatives use root:root 0000, whereas Debian-based use root:shadow 0640.
# You must provide key/value pairs for owner, group, and mode if overriding.
os_shadow_perms:
owner: root
group: root
mode: '0000'
os_passwd_perms:
owner: root
group: root
mode: '0644'
os_env_umask: '077'
os_auth_uid_min: 1000
os_auth_uid_max: 60000
os_auth_gid_min: 1000
os_auth_gid_max: 60000
os_auth_sys_uid_min: 201
os_auth_sys_uid_max: 999
os_auth_sys_gid_min: 201
os_auth_sys_gid_max: 999
os_auth_sub_uid_min: 100000
os_auth_sub_uid_max: 600100000
os_auth_sub_uid_count: 65536
os_auth_sub_gid_min: 100000
os_auth_sub_gid_max: 600100000
os_auth_sub_gid_count: 65536
os_auth_pam_sssd_enable: true
# defaults for useradd
os_useradd_mail_dir: /var/spool/mail
os_useradd_create_home: true
modprobe_package: 'module-init-tools'
auditd_package: 'audit'
hidepid_option: '2' # allowed values: 0, 1, 2
+9 -2
View File
@@ -11,6 +11,9 @@ Warning: This role disables root-login on the target server! Please make sure yo
## Requirements
- Ansible >= 2.9
- root-privileges on the target system
As this role requires root-privileges, we added `become: true` to all tasks. So please make sure you run the role as root or as a user with become-privileges.
## Role Variables
@@ -123,8 +126,8 @@ Warning: This role disables root-login on the target server! Please make sure yo
- Default: `false`
- Description: false to disable display of last login information.
- `sftp_enabled`
- Default: `false`
- Description: true to enable sftp configuration.
- Default: `true`
- Description: false to disable sftp configuration.
- `sftp_umask`
- Default: `'0027'`
- Description: Specifies the umask for sftp.
@@ -269,6 +272,10 @@ Example playbook:
- "AcceptEnv LANG"
```
## After using the role Ansibles template/copy/file module does not work anymore
If you use this role to disable SFTP (`sftp_enabled: false`) you will get errors. Ansible uses by default SFTP to transfer files to the remote hosts. You have to set `scp_if_ssh = True` in your ansible.cfg. This way Ansible uses SCP to copy files. If your control node uses OpenSSH version 9.0 or above, you also need to set `scp_extra_args = "-O"`, since starting with that version the `scp` utility also defaults to using SFTP.
## Changing the default port and idempotency
This role uses the default port 22 or the port configured in the inventory to connect to the server. If the default `ssh` port is changed via `ssh_server_ports`, once the ssh server is restarted, it will still try to connect using the previous port. In order to run this role again on the same server the inventory will have to be updated to use the new ssh port.
+2 -2
View File
@@ -158,8 +158,8 @@ ssh_banner_path: '/etc/ssh/banner.txt'
# false to disable distribution version leakage during initial protocol handshake
ssh_print_debian_banner: false # sshd (Debian OS family only)
# true to enable sftp configuration
sftp_enabled: false
# false to disable sftp configuration
sftp_enabled: true
# false to disable sftp chroot
sftp_chroot: true
+7 -6
View File
@@ -8,21 +8,22 @@ galaxy_info:
platforms:
- name: EL
versions:
- 7
- 8
- "7"
- "8"
- name: Ubuntu
versions:
- xenial
- bionic
- focal
- jammy
- name: Debian
versions:
- stretch
- buster
- bullseye
- name: Amazon
- name: Fedora
- name: Archlinux
- name: ArchLinux
- name: SmartOS
- name: openSUSE
- name: opensuse
galaxy_tags:
- system
- security
@@ -22,6 +22,6 @@
src: 'authorized_principals.j2'
dest: '{{ item.path }}'
mode: '{{ item.filemode | default("600") }}'
owner: '{{ item.owner| default(ssh_owner) }}'
owner: '{{ item.owner | default(ssh_owner) }}'
group: '{{ item.group | default(ssh_group) }}'
loop: '{{ ssh_authorized_principals }}'
+3 -1
View File
@@ -110,7 +110,9 @@
- name: Include tasks to setup ca keys and principals
include_tasks: ca_keys_and_principals.yml
when: ssh_trusted_user_ca_keys_file | length > 0
when:
- ssh_trusted_user_ca_keys_file | length > 0
- ssh_trusted_user_ca_keys | length > 0
- name: Include selinux specific tasks
include_tasks: selinux.yml
+5 -1
View File
@@ -1,3 +1,7 @@
---
- include_tasks: hardening.yml
- name: Include hardening tasks
include_tasks: hardening.yml
args:
apply:
become: true
when: ssh_hardening_enabled | bool
+5 -4
View File
@@ -24,7 +24,8 @@
# The following tasks only get executed when selinux is in state enforcing,
# UsePam is 'no' and the ssh_password module is not installed. See this issue for
# more info: https://github.com/hardening-io/ansible-ssh-hardening/issues/23
- when:
- name: Run selinux tasks
when:
- not (ssh_use_pam | bool)
- ('ssh_password' not in ssh_password_module.stdout)
block:
@@ -44,13 +45,13 @@
group: 'root'
mode: '0600'
- name: Check and compile policy
- name: Check and compile policy # noqa no-changed-when
command: checkmodule -M -m -o {{ ssh_custom_selinux_dir }}/ssh_password.mod {{ ssh_custom_selinux_dir }}/ssh_password
- name: Create selinux policy module package
- name: Create selinux policy module package # noqa no-changed-when
command: semodule_package -o {{ ssh_custom_selinux_dir }}/ssh_password.pp -m {{ ssh_custom_selinux_dir }}/ssh_password.mod
- name: Install selinux policy
- name: Install selinux policy # noqa no-changed-when
command: semodule -i {{ ssh_custom_selinux_dir }}/ssh_password.pp
+1 -1
View File
@@ -7,7 +7,7 @@ ssh_group: root
ssh_host_keys_owner: 'root'
ssh_host_keys_group: 'ssh_keys'
ssh_selinux_packages:
- policycoreutils-python
- policycoreutils-python-utils
- checkpolicy
# true if SSH support Kerberos
@@ -7,7 +7,7 @@ ssh_group: root
ssh_host_keys_owner: 'root'
ssh_host_keys_group: 'ssh_keys'
ssh_selinux_packages:
- python3-policycoreutils
- policycoreutils-python
- checkpolicy
# true if SSH support Kerberos
-23
View File
@@ -1,23 +0,0 @@
---
sshd_path: /usr/sbin/sshd
ssh_host_keys_dir: '/etc/ssh'
sshd_service_name: sshd
ssh_owner: root
ssh_group: root
ssh_host_keys_owner: 'root'
ssh_host_keys_group: 'ssh_keys'
ssh_selinux_packages:
- python3-policycoreutils
- checkpolicy
# true if SSH support Kerberos
ssh_kerberos_support: true
# true if SSH has PAM support
ssh_pam_support: true
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