Migrated from github.com/shafiqalibhai/ansible-os-hardening http://dev-sec.io/
  • Jinja 92.9%
  • Ruby 3.9%
  • Dockerfile 3.2%
Find a file
2026-04-27 22:56:19 +00:00
defaults add martian sysctl parameter 2018-01-03 10:43:13 +01:00
meta Update syntax to 2.4 2018-01-23 14:55:36 -05:00
tasks Merge branch 'master' into master 2018-01-31 19:47:10 +01:00
templates Add support for Amazon Linux 2018-01-04 16:08:08 -05:00
vars Add support for Amazon Linux 2018-01-04 16:08:08 -05:00
.gitattributes update changelog 2017-06-28 16:00:41 +02:00
.gitignore use new docker images 2017-01-22 16:05:45 +01:00
.kitchen.vagrant.yml update vagrnat boxes 2018-01-03 10:43:13 +01:00
.kitchen.yml remove 12.04 support 2017-06-27 15:03:22 +02:00
.travis.yml temporary remove oracle7 from travis 2018-01-02 18:53:23 +01:00
ansible.cfg Fix ansible.cfg 2017-07-07 11:48:53 +10:00
CHANGELOG.md update changelog 2018-01-03 21:01:33 +01:00
CONTRIBUTING.md Add correct CONTRIB-file 2015-06-26 16:48:56 +00:00
default.yml Prevent disabling of filesystems via whitelist 2017-11-01 14:10:15 +01:00
Dockerfile Add Dockerfile: ansible runner with the os-hardening role installed 2026-04-27 22:56:19 +00:00
Gemfile use new docker images 2017-01-22 16:05:45 +01:00
kitchen_vagrant_block.rb update min ansible version 2017-02-28 21:34:35 +01:00
Rakefile add changelog generator 2015-12-06 16:55:59 +01:00
README.md Update README with comprehensive project information 2026-04-27 20:32:45 +00:00
TODO.md Update readme, todo, changelog, vars 2015-06-23 23:58:40 +02:00

ansible-os-hardening

Overview

This roles provides numerous security-related configurations, providing all-round base protection. It is intended to be compliant with the DevSec Linux Baseline.

Detected project types: Ruby, Ansible role.

This repository was migrated from upstream source github.com/shafiqalibhai/ansible-os-hardening and is preserved here for archival, reference, or continued local development.

At a glance

  • Default branch: master
  • Visibility: public
  • Size: 345 KB
  • Created: 2026-04-27
  • Last updated: 2026-04-27
  • Stars / Forks / Open issues: 0 / 0 / 0

Languages

Language Bytes Share
Jinja 20,164 bytes 95.9%
Ruby 857 bytes 4.1%

Repository structure

  • defaults/
  • meta/
  • tasks/
  • templates/
  • vars/
  • .gitattributes (625 B)
  • .gitignore (28 B)
  • .kitchen.vagrant.yml (1,592 B)
  • .kitchen.yml (1,714 B)
  • .travis.yml (1,916 B)
  • ansible.cfg (564 B)
  • CHANGELOG.md (20,367 B)
  • CONTRIBUTING.md (4,043 B)
  • default.yml (2,566 B)
  • Gemfile (358 B)
  • kitchen_vagrant_block.rb (164 B)
  • Rakefile (335 B)
  • README.md (9,257 B)
  • TODO.md (197 B)

Getting started

Clone the repository:

git clone https://forgejo.deployview.com/ssa/ansible-os-hardening.git
cd ansible-os-hardening

Installation

bundle install
ansible-galaxy install -r requirements.yml
ansible-playbook playbook.yml

Usage

Include this role/collection in a playbook and run with ansible-playbook. See defaults/main.yml (if present) for configurable variables.

Original README

The content below is preserved from the previous README. Headings have been demoted so they don't compete with the new top-level sections.

os-hardening (Ansible Role)

Build Status Gitter Chat Ansible Galaxy

Description

This roles provides numerous security-related configurations, providing all-round base protection. It is intended to be compliant with the DevSec Linux Baseline.

It configures:

  • Configures package management e.g. allows only signed packages
  • Remove packages with known issues
  • Configures pam and pam_limits module
  • Shadow password suite configuration
  • Configures system path permissions
  • Disable core dumps via soft limits
  • Restrict Root Logins to System Console
  • Set SUIDs
  • Configures kernel parameters via sysctl

It will not:

  • Update system packages
  • Install security patches

Requirements

  • Ansible 2.4.2

Warning

If you're using inspec to test your machines after applying this role, please make sure to add the connecting user to the os_ignore_users-variable. Otherwise inspec will fail. For more information, see issue #124.

Variables

Name Default Value Description
os_desktop_enable false true if this is a desktop system, ie Xorg, KDE/GNOME/Unity/etc
os_env_extra_user_paths [] add additional paths to the user's PATH variable (default is empty).
os_env_umask 027 set default permissions for new files to 750
os_auth_pw_max_age 60 maximum password age (set to 99999 to effectively disable it)
os_auth_pw_min_age 7 minimum password age (before allowing any other password change)
os_auth_retries 5 the maximum number of authentication attempts, before the account is locked for some time
os_auth_lockout_time 600 time in seconds that needs to pass, if the account was locked due to too many failed authentication attempts
os_auth_timeout 60 authentication timeout in seconds, so login will exit if this time passes
os_auth_allow_homeless false true if to allow users without home to login
os_auth_pam_passwdqc_enable true true if you want to use strong password checking in PAM using passwdqc
os_auth_pam_passwdqc_options "min=disabled,disabled,16,12,8" set to any option line (as a string) that you want to pass to passwdqc
os_security_users_allow [] list of things, that a user is allowed to do. May contain change_user.
os_security_kernel_enable_module_loading true true if you want to allowed to change kernel modules once the system is running (eg modprobe, rmmod)
os_security_kernel_enable_core_dump false kernel is crashing or otherwise misbehaving and a kernel core dump is created
os_security_suid_sgid_enforce true true if you want to reduce SUID/SGID bits. There is already a list of items which are searched for configured, but you can also add your own
os_security_suid_sgid_blacklist [] a list of paths which should have their SUID/SGID bits removed
os_security_suid_sgid_whitelist [] a list of paths which should not have their SUID/SGID bits altered
os_security_suid_sgid_remove_from_unknown false true if you want to remove SUID/SGID bits from any file, that is not explicitly configured in a blacklist. This will make every Ansible-run search through the mounted filesystems looking for SUID/SGID bits that are not configured in the default and user blacklist. If it finds an SUID/SGID bit, it will be removed, unless this file is in your whitelist.
os_security_packages_clean' true removes packages with known issues. See section packages.
ufw_manage_defaults true true means apply all settings with ufw_ prefix
ufw_ipt_sysctl '' by default it disables IPT_SYSCTL in /etc/default/ufw. If you want to overwrite /etc/sysctl.conf values using ufw - set it to your sysctl dictionary, for example /etc/ufw/sysctl.conf
ufw_default_input_policy DROP set default input policy of ufw to DROP
ufw_default_output_policy ACCEPT set default output policy of ufw to ACCEPT
ufw_default_forward_policy DROP set default forward policy of ufw to DROP

Packages

We remove the following packages:

  • xinetd (NSA, Chapter 3.2.1)
  • inetd (NSA, Chapter 3.2.1)
  • tftp-server (NSA, Chapter 3.2.5)
  • ypserv (NSA, Chapter 3.2.4)
  • telnet-server (NSA, Chapter 3.2.2)
  • rsh-server (NSA, Chapter 3.2.3)
  • prelink (open-scap)

Disabled filesystems

We disable the following filesystems, because they're most likely not used:

  • "cramfs"
  • "freevxfs"
  • "jffs2"
  • "hfs"
  • "hfsplus"
  • "squashfs"
  • "udf"
  • "vfat"

To prevent some of the filesystems from being disabled, add them to the os_filesystem_whitelist variable.

Example Playbook

- hosts: localhost
  roles:
    - dev-sec.os-hardening

Changing sysctl variables

+If you want to overwrite sysctl-variables, you can use the sysctl_overwrite variable (in older versions you had to overwrite the whole sysctl_dict). +So for example if you want to change the IPv4 traffic forwarding variable to 1, do it like this:

    - hosts: localhost
      roles:
        - dev-sec.os-hardening
      vars:
        sysctl_overwrite:
          # Disable IPv4 traffic forwarding.
          net.ipv4.ip_forward: 1

Alternatively you can change Ansible's hash-behaviour to merge, then you only have to overwrite the single hash you need to. But please be aware that changing the hash-behaviour changes it for all your playbooks and is not recommended by Ansible.

Local Testing

The preferred way of locally testing the role is to use Docker. You will have to install Docker on your system. See Get started for a Docker package suitable to for your system.

You can also use vagrant and Virtualbox or VMWare to run tests locally. You will have to install Virtualbox and Vagrant on your system. See Vagrant Downloads for a vagrant package suitable for your system. For all our tests we use test-kitchen. If you are not familiar with test-kitchen please have a look at their guide.

Next install test-kitchen:

### Install dependencies
gem install bundler
bundle install

Testing with Docker

### fast test on one machine
bundle exec kitchen test default-ubuntu-1404

### test on all machines
bundle exec kitchen test

### for development
bundle exec kitchen create default-ubuntu-1404
bundle exec kitchen converge default-ubuntu-1404

Testing with Virtualbox

### fast test on one machine
KITCHEN_YAML=".kitchen.vagrant.yml" bundle exec kitchen test default-ubuntu-1404

### test on all machines
KITCHEN_YAML=".kitchen.vagrant.yml" bundle exec kitchen test

### for development
KITCHEN_YAML=".kitchen.vagrant.yml" bundle exec kitchen create default-ubuntu-1404
KITCHEN_YAML=".kitchen.vagrant.yml" bundle exec kitchen converge default-ubuntu-1404

For more information see test-kitchen

Contributors + Kudos

...

This role is mostly based on guides by:

Thanks to all of you!

Contributing

See contributor guideline.

License and Author

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Contributing

Contributions are welcome. The typical workflow is:

  1. Open an issue describing the change you'd like to make.
  2. Fork the repository (or create a feature branch if you have write access).
  3. Commit your changes with clear, descriptive messages.
  4. Open a pull request against the master branch.

Please follow the existing code style and include tests or reproduction steps where relevant.

License

No LICENSE file is currently present in this repository. Treat the contents as all rights reserved by the author until an explicit license is added. If you intend to share or accept contributions, consider adding an OSI-approved license such as MIT, Apache-2.0, or GPL-3.0.

Repository

  • Browse: https://forgejo.deployview.com/ssa/ansible-os-hardening
  • Clone (HTTPS): https://forgejo.deployview.com/ssa/ansible-os-hardening.git
  • Clone (SSH): ssh://git@forgejo.deployview.com:30143/ssa/ansible-os-hardening.git
  • Upstream / origin: github.com/shafiqalibhai/ansible-os-hardening

This README was generated automatically based on repository metadata, contents, and any prior README content. Edit any section above to add project-specific detail.