Giter VIP home page Giter VIP logo

ansible-role-hardening's Introduction

Ansible Role for Server Hardening

This is an Ansible role designed to enhance the security of servers running on AlmaLinux, Debian, or Ubuntu.

It's systemd focused and requires Ansible version 2.15 or higher.

The role supports the following operating systems:

For those using AWS or Azure, there are also hardened Ubuntu Amazon Machine Images (AMIs) and Azure virtual machine images available.

These are available in the konstruktoid/hardened-images repository. These images are built using Packer and this Ansible role is used for configuration.

Note

Do not use this role without first testing in a non-operational environment.

Note

There is a SLSA artifact present under the slsa action workflow for verification.

Dependencies

None.

Examples

Requirements

---
roles:
  - name: konstruktoid.hardening
    version: v2.0.4
    src: https://github.com/konstruktoid/ansible-role-hardening.git
    scm: git

Playbook

---
- name: Import and use the hardening role
  hosts: localhost
  any_errors_fatal: true
  tasks:
    - name: Import the hardening role
      ansible.builtin.import_role:
        name: konstruktoid.hardening
      vars:
        sshd_admin_net:
          - 10.0.2.0/24
          - 192.168.0.0/24
          - 192.168.1.0/24
        suid_sgid_permissions: false

Local playbook using git checkout

---
- name: Checkout and configure konstrukoid.hardening
  hosts: localhost
  any_errors_fatal: true
  tasks:
    - name: Clone hardening repository
      become: true
      tags:
        - always
      block:
        - name: Install git
          ansible.builtin.package:
            name: git
            state: present

        - name: Checkout konstruktoid.hardening
          become: true
          ansible.builtin.git:
            repo: https://github.com/konstruktoid/ansible-role-hardening
            dest: /etc/ansible/roles/konstruktoid.hardening
            version: v2.0.4

        - name: Remove git
          ansible.builtin.package:
            name: git
            state: absent

    - name: Include the hardening role
      ansible.builtin.include_role:
        name: konstruktoid.hardening
      vars:
        sshd_allow_groups:
          - ubuntu
          - vagrant
        sshd_login_grace_time: 60
        sshd_max_auth_tries: 10
        sshd_use_dns: false
        sshd_update_moduli: true

Note regarding UFW firewall rules

Instead of resetting ufw every run and by doing so causing network traffic disruption, the role deletes every ufw rule without comment: ansible managed task parameter and value.

The role also sets default deny policies, which means that firewall rules needs to be created for any additional ports except those specified in the sshd_ports and ufw_outgoing_traffic variables.

Task Execution and Structure

See STRUCTURE.md for tree of the role structure.

Role testing

See TESTING.md.

Role Variables with defaults

./defaults/main/aide.yml

manage_aide: true

aide_checksums: sha512

If manage_aide: true, then AIDE will be installed and configured.

aide_checksums modifies the AIDE Checksums variable. Note that the Checksums variable might not be present depending on distribution.

aide.conf(5)

./defaults/main/auditd.yml

manage_auditd: true

auditd_apply_audit_rules: true
auditd_action_mail_acct: root
auditd_admin_space_left_action: suspend
auditd_disk_error_action: suspend
auditd_disk_full_action: suspend
auditd_enable_flag: 2
auditd_flush: incremental_async
auditd_max_log_file: 20
auditd_max_log_file_action: rotate
auditd_mode: 1
auditd_num_logs: 5
auditd_space_left: 75
auditd_space_left_action: email
grub_audit_backlog_cmdline: audit_backlog_limit=8192
grub_audit_cmdline: audit=1

If manage_auditd: true, then the Linux Audit System will configured and enabled at boot using GRUB.

When auditd_apply_audit_rules: 'yes', the role applies the auditd rules from the included template file.

auditd_action_mail_acct should be a valid email address or alias.

auditd_admin_space_left_action defines what action to take when the system has detected that it is low on disk space. suspend will cause the audit daemon to stop writing records to the disk.

auditd_enable_flag sets the enabled flag. If 0 is passed, temporarily disable auditing. 1 will enable auditing and 2 will lock the audit configuration.

auditd_flush: sync tells the audit daemon to keep both the data and meta-data fully sync'd with every write to disk.

auditd_max_log_file_action sets what action to take when the system has detected that the max file size limit has been reached. E.g. the rotate option will cause the audit daemon to rotate the logs. The keep_logs option is similar to rotate except it does not use the num_logs setting. This prevents audit logs from being overwritten.

auditd_space_left_action tells the system what action to take when the system has detected that it is low on disk space. email means that it will send a warning to the email account specified in action_mail_acct as well as sending the message to syslog.

auditd_mode sets auditd failure mode, 0=silent 1=printk 2=panic.

auditd.conf(5)

./defaults/main/compilers.yml

manage_compilers: true

compilers:
  - as
  - cargo
  - cc
  - cc-[0-9]*
  - clang-[0-9]*
  - gcc
  - gcc-[0-9]*
  - go
  - make
  - rustc

If manage_compilers: true, then the listed compilers will be restricted to the root user.

./defaults/main/crypto_policies.yml

set_crypto_policy: true
crypto_policy: DEFAULT:NO-SHA1

Set and use cryptographic policies if /etc/crypto-policies/config exists and set_crypto_policy: true.

./defaults/main/disablewireless.yml

disable_wireless: false

If true, turn off all wireless interfaces.

./defaults/main/dns.yml

manage_resolved: true

dns:
  - 1.1.1.2
  - 9.9.9.9
fallback_dns:
  - 1.0.0.2
  - 149.112.112.112
dnssec: allow-downgrade
dns_over_tls: opportunistic

If manage_resolved: true, configure systemd-resolved.

IPv4 and IPv6 addresses to use as system and fallback DNS servers. If dnssec is set to "allow-downgrade" DNSSEC validation is attempted, but if the server does not support DNSSEC properly, DNSSEC mode is automatically disabled.

If dns_over_tls is true, all connections to the server will be encrypted if the DNS server supports DNS-over-TLS and has a valid certificate.

./defaults/main/ipv6.yml

disable_ipv6: false
sysctl_net_ipv6_conf_accept_ra_rtr_pref: 0

ipv6_disable_sysctl_settings:
  net.ipv6.conf.all.disable_ipv6: 1
  net.ipv6.conf.default.disable_ipv6: 1

ipv6_sysctl_settings:
  net.ipv6.conf.all.accept_ra: 0
  net.ipv6.conf.all.accept_redirects: 0
  net.ipv6.conf.all.accept_source_route: 0
  net.ipv6.conf.all.forwarding: 0
  net.ipv6.conf.all.use_tempaddr: 2
  net.ipv6.conf.default.accept_ra: 0
  net.ipv6.conf.default.accept_ra_defrtr: 0
  net.ipv6.conf.default.accept_ra_pinfo: 0
  net.ipv6.conf.default.accept_ra_rtr_pref: 0
  net.ipv6.conf.default.accept_redirects: 0
  net.ipv6.conf.default.accept_source_route: 0
  net.ipv6.conf.default.autoconf: 0
  net.ipv6.conf.default.dad_transmits: 0
  net.ipv6.conf.default.max_addresses: 1
  net.ipv6.conf.default.router_solicitations: 0
  net.ipv6.conf.default.use_tempaddr: 2

If disable_ipv6: true, IPv6 will be disabled and related sysctl settings configured.

ipv6_sysctl_settings is the sysctl configuration used if the host is using IPv6.

sysctl.conf

./defaults/main/journal.yml

rsyslog_filecreatemode: "0640"

journald_compress: true
journald_forwardtosyslog: false
journald_storage: persistent

rsyslog_filecreatemode sets the creation mode with which rsyslogd creates new files, see rsconf1_filecreatemode.

journald_compress can take a boolean value. If enabled (the default), data objects are compressed before they are written to the file system.

journald_storage controls where to store journal data. One of volatile, persistent, auto and none.

journald_forwardtosyslog control whether log messages received by the journal daemon shall be forwarded to a traditional syslog daemon.

See journald.conf for more information.

./defaults/main/kernel.yml

allow_virtual_system_calls: true
enable_page_poisoning: true
page_table_isolation: true
slub_debugger_poisoning: false

allow_virtual_system_calls will allow virtual system calls if true else no vsyscall mapping will be set, see CONFIG_LEGACY_VSYSCALL_NONE.

enable_page_poisoning: true will enable CONFIG_PAGE_POISONING

page_table_isolation is a countermeasure against attacks on the shared user/kernel address space, see CONFIG_PAGE_TABLE_ISOLATION

slub_debugger_poisoning, if set to true, prevents many types of use-after-free vulnerabilities and it also prevents leak of data and detection of corrupted memory. See Short users guide for SLUB.

./defaults/main/limits.yml

limit_nofile_hard: 1024
limit_nofile_soft: 512
limit_nproc_hard: 1024
limit_nproc_soft: 512

Set maximum number of processes and open files.

./defaults/main/misc.yml

reboot_ubuntu: false
redhat_signing_keys:
  - 567E347AD0044ADE55BA8A5F199E2F91FD431D51
  - 47DB287789B21722B6D95DDE5326810137017186
epel7_signing_keys:
  - 91E97D7C4A5E96F17F3E888F6A2FAEA2352C64E5
epel8_signing_keys:
  - 94E279EB8D8F25B21810ADF121EA45AB2F86D6A1
epel9_signing_keys:
  - FF8AD1344597106ECE813B918A3872BF3228467C

If reboot_ubuntu: true an Ubuntu node will be rebooted if required.

redhat_signing_keys are the RedHat Product Signing Keys.

The epel7_signing_keys, epel8_signing_keys and epel9_signing_keys are release specific Fedora EPEL signing keys.

./defaults/main/module_blocklists.yml

fs_modules_blocklist:
  - cramfs
  - freevxfs
  - hfs
  - hfsplus
  - jffs2
  - squashfs
  - udf

misc_modules_blocklist:
  - bluetooth
  - bnep
  - btusb
  - can
  - cpia2
  - firewire-core
  - floppy
  - ksmbd
  - n_hdlc
  - net-pf-31
  - pcspkr
  - soundcore
  - thunderbolt
  - usb-midi
  - usb-storage
  - uvcvideo
  - v4l2_common

net_modules_blocklist:
  - atm
  - dccp
  - sctp
  - rds
  - tipc

Kernel modules to be blacklisted and disabled using a fake install.

Note

Disabling the usb-storage module will disable all USB storage devices. If such devices are needed USBGuard, or a similar tool, should be configured accordingly.

./defaults/main/mount.yml

hide_pid: 2
process_group: root

hide_pid sets /proc/<pid>/ access mode.

The process_group setting configures the group authorized to learn processes information otherwise prohibited by hidepid=.

/proc mount options

./defaults/main/ntp.yml

manage_timesyncd: true

fallback_ntp:
  - ntp.netnod.se
  - ntp.ubuntu.com
ntp:
  - 2.pool.ntp.org
  - time.nist.gov

If manage_timesyncd: true, then configure systemd timesyncd, otherwise installing a NTP client is recommended.

./defaults/main/packagemgmt.yml

apt_hardening_options:
  - Acquire::AllowDowngradeToInsecureRepositories "false";
  - Acquire::AllowInsecureRepositories "false";
  - Acquire::http::AllowRedirect "false";
  - APT::Get::AllowUnauthenticated "false";
  - APT::Get::AutomaticRemove "true";
  - APT::Install-Recommends "false";
  - APT::Install-Suggests "false";
  - APT::Periodic::AutocleanInterval "7";
  - APT::Sandbox::Seccomp "1";
  - Unattended-Upgrade::Remove-Unused-Dependencies "true";
  - Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";

Configure the APT suite of tools.

./defaults/main/packages.yml

automatic_updates: true
system_upgrade: true

packages_blocklist:
  - apport*
  - autofs
  - avahi*
  - avahi-*
  - beep
  - git
  - pastebinit
  - popularity-contest
  - prelink
  - rpcbind
  - rsh*
  - rsync
  - talk*
  - telnet*
  - tftp*
  - tuned
  - whoopsie
  - xinetd
  - yp-tools
  - ypbind

packages_debian:
  - acct
  - apparmor-profiles
  - apparmor-utils
  - apt-show-versions
  - audispd-plugins
  - auditd
  - cracklib-runtime
  - debsums
  - gnupg2
  - haveged
  - libpam-apparmor
  - libpam-cap
  - libpam-modules
  - libpam-pwquality
  - libpam-tmpdir
  - lsb-release
  - needrestart
  - openssh-server
  - postfix
  - rsyslog
  - sysstat
  - systemd-journal-remote
  - tcpd
  - vlock
  - wamerican

packages_redhat:
  - audispd-plugins
  - audit
  - cracklib
  - gnupg2
  - haveged
  - libpwquality
  - openssh-server
  - needrestart
  - postfix
  - psacct
  - python3-dnf-plugin-post-transaction-actions
  - rsyslog
  - rsyslog-gnutls
  - systemd-journal-remote
  - vlock
  - words

packages_ubuntu:
  - fwupd
  - secureboot-db
  - snapd

automatic_updates: true will install and configure dnf-automatic or unattended-upgrades, depending on the distribution.

system_upgrade: true will run apt upgrade or dnf update if required.

Packages to be installed depending of distribution and packages to be removed (packages_blocklist).

./defaults/main/password.yml

manage_faillock: true

faillock:
  admin_group: []
  audit: true
  deny: 5
  dir: /var/run/faillock
  even_deny_root: true
  fail_interval: 900
  local_users_only: true
  no_log_info: false
  nodelay: true
  root_unlock_time: 600
  silent: false
  unlock_time: 600

login_defs:
  login_retries: 5
  login_timeout: 60
  pass_max_days: 60
  pass_min_days: 1
  pass_warn_age: 7

password_remember: 5

pwquality:
  dcredit: -1
  dictcheck: 1
  dictpath: ""
  difok: 8
  enforce_for_root: true
  enforcing: 1
  gecoscheck: 1
  lcredit: -1
  local_users_only: true
  maxclassrepeat: 4
  maxrepeat: 3
  minclass: 4
  minlen: 15
  ocredit: -1
  retry: 3
  ucredit: -1
  usercheck: 1
  usersubstr: 3

manage_faillock: true will enable the faillock library.

password_remember set the size of the password history that the user will not be able to reuse.

Configure the pam_faillock library.

Configure the login.defs configuration.

Configure the libpwquality library.

./defaults/main/rkhunter.yml

manage_rkhunter: true

rkhunter_allow_ssh_prot_v1: false
rkhunter_allow_ssh_root_user: false
rkhunter_mirrors_mode: "0"
rkhunter_update_mirrors: true
rkhunter_web_cmd: curl -fsSL

If manage_rkhunter: true, then configure rkhunter.

./defaults/main/sshd.yml

manage_ssh: true

sshd_accept_env: LANG LC_*
sshd_admin_net:
  - 192.168.0.0/24
  - 192.168.1.0/24
sshd_allow_agent_forwarding: false
sshd_allow_groups:
  - sudo
sshd_allow_tcp_forwarding: false
sshd_allow_users:
  - "{{ ansible_user | default(lookup('ansible.builtin.env', 'USER')) }}"
sshd_authentication_methods: any
sshd_authorized_principals_file: /etc/ssh/auth_principals/%u
sshd_banner: /etc/issue.net
sshd_ca_signature_algorithms:
  - ecdsa-sha2-nistp256
  - ecdsa-sha2-nistp384
  - ecdsa-sha2-nistp521
  - ssh-ed25519
  - rsa-sha2-256
  - rsa-sha2-512
  - ssh-rsa
sshd_kbd_interactive_authentication: false
sshd_ciphers:
  - [email protected]
  - [email protected]
  - aes256-ctr
sshd_client_alive_count_max: 1
sshd_client_alive_interval: 200
sshd_compression: false
sshd_config_d_force_clear: false
sshd_config_force_replace: false
sshd_debian_banner: false
sshd_deny_groups: []
sshd_deny_users: []
sshd_gssapi_authentication: false
sshd_host_key_algorithms:
  - [email protected]
  - [email protected]
  - ssh-ed25519
  - ssh-rsa
  - [email protected]
  - [email protected]
  - [email protected]
  - ecdsa-sha2-nistp521
  - ecdsa-sha2-nistp384
  - ecdsa-sha2-nistp256
sshd_host_keys_files: []
sshd_host_keys_group: root
sshd_host_keys_mode: "0600"
sshd_host_keys_owner: root
sshd_hostbased_authentication: false
sshd_ignore_rhosts: true
sshd_ignore_user_known_hosts: true
sshd_kerberos_authentication: false
sshd_kex_algorithms:
  - [email protected]
  - ecdh-sha2-nistp521
  - ecdh-sha2-nistp384
  - ecdh-sha2-nistp256
  - diffie-hellman-group-exchange-sha256
sshd_listen:
  - "0.0.0.0"
sshd_log_level: VERBOSE
sshd_login_grace_time: 20
sshd_macs:
  - [email protected]
  - [email protected]
  - hmac-sha2-512
  - hmac-sha2-256
sshd_match_addresses: {}
sshd_match_groups: {}
sshd_match_local_ports: {}
sshd_match_users: {}
sshd_max_auth_tries: 3
sshd_max_sessions: 3
sshd_max_startups: 10:30:60
sshd_password_authentication: false
sshd_permit_empty_passwords: false
sshd_permit_root_login: false
sshd_permit_tunnel: false
sshd_permit_user_environment: false
sshd_ports:
  - 22
sshd_print_last_log: true
sshd_print_motd: false
sshd_print_pam_motd: false
sshd_rekey_limit: 512M 1h
sshd_required_ecdsa_size: 521
sshd_required_rsa_size: 4096
sshd_sftp_enabled: true
sshd_sftp_only_chroot: true
sshd_sftp_only_chroot_dir: "%h"
sshd_sftp_only_group: ""
sshd_sftp_subsystem: internal-sftp -f LOCAL6 -l INFO
sshd_strict_modes: true
sshd_syslog_facility: AUTH
sshd_tcp_keep_alive: false
sshd_trusted_user_ca_keys_base64: ""
sshd_trusted_user_ca_keys_file: /etc/ssh/trusted-user-ca-keys.pem
sshd_update_moduli: false
sshd_use_dns: false
sshd_use_pam: true
sshd_use_privilege_separation: sandbox
sshd_x11_forwarding: false

If manage_ssh: true the SSH client and the SSH daemon will be configured.

Note

CASignatureAlgorithms, Ciphers, HostKeyAlgorithms, KexAlgorithms and MACs will be configured as defined by cryptographic policies if /etc/crypto-policies/config exists and set_crypto_policy: true.

For a explanation of the options not described below, please read https://man.openbsd.org/sshd_config.

Only the network(s) defined in sshd_admin_net are allowed to connect to sshd_ports. Note that additional rules need to be set up in order to allow access to additional services.

OpenSSH login is allowed only for users whose primary group or supplementary group list matches one of the patterns in sshd_allow_groups. OpenSSH login is also allowed for users in sshd_allow_users. To do the opposite and deny access, use the sshd_deny_groups and sshd_deny_users parameters, which in turn have priority over the previous parameters.

sshd_allow_agent_forwarding specifies whether ssh-agent(1) forwarding is permitted.

sshd_allow_tcp_forwarding specifies whether TCP forwarding is permitted. The available options are true or all to allow TCP forwarding, false to prevent all TCP forwarding, local to allow local (from the perspective of ssh(1)) forwarding only or remote to allow remote forwarding only.

sshd_authentication_methods specifies the authentication methods that must be successfully completed in order to grant access to a user.

sshd_log_level gives the verbosity level that is used when logging messages.

sshd_max_auth_tries and sshd_max_sessions specifies the maximum number of SSH authentication attempt s permitted per connection and the maximum number of open shell, login or subsystem (e.g. sftp) sessions permitted per network connection.

sshd_password_authentication specifies whether password authentication is allowed.

sshd_ports specifies the port(s) number that sshd(8) listens on.

sshd_required_rsa_size, RequiredRSASize, will only be set if SSH version is higher than 9.1.

sshd_config_d_force_clear force clear directory /etc/ssh/sshd_config.d. Default: false.

sshd_config_force_replace force replace configuration file /etc/ssh/sshd_config. Default: false.

Note

By default, the role checks whether the directory /etc/ssh/sshd_config.d exists and whether it is linked via the Include parameter in the /etc/ssh/sshd_config file, if so, an additional configuration file is created in / etc/ssh/sshd_config.d, if not, the /etc/ssh/sshd_config file is overwritten.

Warning

If any sshd_match_(users|groups|addresses|local_ports) or sshd_sftp_only_group parameters is set, the value true will be implicit.

sshd_host_keys_files host keys for sshd. If empty ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_ec dsa_key', '/etc/ssh/ssh_host_ed25519_key'] will be used, as far as supported by the installed sshd version.

sshd_host_keys_owner set owner of host keys for sshd.

sshd_host_keys_group set group of host keys for sshd.

sshd_host_keys_mode set permission of host keys for sshd.

sshd_match_users add a conditional block for users. If all of the criteria on the Match line are satisfied, the rules/parameters defined on the following lines override those set in the global section of th e config file, until either another Match line or the end of the file.

Expected configuration structure:

sshd_match_users:
  - user: <username>
    rules:
      - <parameter sshd> <value>
      - <parameter sshd> <value>

Example, allow ubuntu user access through password authentication and allow ansible user access without a banner:

sshd_match_users:
  - user: ubuntu
    rules:
      - AllowUsers ubuntu
      - AuthenticationMethods password
      - PasswordAuthentication yes
  - user: ansible
    rules:
      - AllowUsers ansible
      - Banner none

sshd_match_groups add a conditional block for groups. More details and examples in the parameter description sshd_match_users.

Expected configuration structure:

sshd_match_groups:
  - group: <groupname>
    rules:
      - <parameter sshd> <value>
      - <parameter sshd> <value>

sshd_match_addresses add a conditional block for adddresses. More details and examples in the parameter description sshd_match_users.

Expected configuration structure:

sshd_match_addresses:
  - address: <ip>
    rules:
      - <parameter sshd> <value>
      - <parameter sshd> <value>

sshd_match_local_ports add a conditional block for ports. More details and examples in the parameter description sshd_match_users.

Expected configuration structure:

sshd_match_ports:
  - port: <port>
    rules:
      - <parameter sshd> <value>
      - <parameter sshd> <value>

sshd_print_pam_motd specifies whether printing of the MOTD via pam.

sshd_sftp_enabled specifies whether enabled sftp configuration.

sshd_sftp_subsystem sets the subsystem for file transfer daemon.

sshd_sftp_only_group specifies the name of the group that will have access restricted to the sftp service only.

sshd_sftp_only_chroot specifies group access will be via chroot isolation.

sshd_sftp_only_chroot_dir specifies the chroot directory. Accepts the tokens %% (a literal %), %h (home directory of the user), and %u (username).

sshd_syslog_facility sets the facility code that is used when logging messages from sshd.

sshd_update_moduli, if set to true, will download a updated moduli file from the konstruktoid/ssh-moduli repository.

./defaults/main/suid_sgid_blocklist.yml

suid_sgid_permissions: true
suid_sgid_blocklist:
  - 7z
  - aa-exec
  - ab
  - agetty
  - alpine
  - ansible-playbook
  - ansible-test
  - aoss
  - apt
  - apt-get
  [...]

If suid_sgid_permissions: true loop through suid_sgid_blocklist and remove any SUID/SGID permissions.

A complete file list is available in defaults/main/suid_sgid_blocklist.yml and is based on the work by @GTFOBins.

./defaults/main/sysctl.yml

manage_sysctl: true
sysctl_conf_dir: "{{ '/usr/lib/sysctl.d' if usr_lib_sysctl_d_dir else '/etc/sysctl.d' }}"

sysctl_dev_tty_ldisc_autoload: 0

ipv4_sysctl_settings:
  net.ipv4.conf.all.accept_redirects: 0
  net.ipv4.conf.all.accept_source_route: 0
  net.ipv4.conf.all.log_martians: 1
  net.ipv4.conf.all.rp_filter: 1
  net.ipv4.conf.all.secure_redirects: 0
  net.ipv4.conf.all.send_redirects: 0
  net.ipv4.conf.all.shared_media: 0
  net.ipv4.conf.default.accept_redirects: 0
  net.ipv4.conf.default.accept_source_route: 0
  net.ipv4.conf.default.log_martians: 1
  net.ipv4.conf.default.rp_filter: 1
  net.ipv4.conf.default.secure_redirects: 0
  net.ipv4.conf.default.send_redirects: 0
  net.ipv4.conf.default.shared_media: 0
  net.ipv4.icmp_echo_ignore_broadcasts: 1
  net.ipv4.icmp_ignore_bogus_error_responses: 1
  net.ipv4.ip_forward: 0
  net.ipv4.tcp_challenge_ack_limit: 2147483647
  net.ipv4.tcp_invalid_ratelimit: 500
  net.ipv4.tcp_max_syn_backlog: 20480
  net.ipv4.tcp_rfc1337: 1
  net.ipv4.tcp_syn_retries: 5
  net.ipv4.tcp_synack_retries: 2
  net.ipv4.tcp_syncookies: 1

generic_sysctl_settings:
  fs.protected_fifos: 2
  fs.protected_hardlinks: 1
  fs.protected_symlinks: 1
  fs.suid_dumpable: 0
  kernel.core_pattern: "|/bin/false"
  kernel.core_uses_pid: 1
  kernel.dmesg_restrict: 1
  kernel.kptr_restrict: 2
  kernel.panic: 60
  kernel.panic_on_oops: 60
  kernel.perf_event_paranoid: 3
  kernel.randomize_va_space: 2
  kernel.sysrq: 0
  kernel.unprivileged_bpf_disabled: 1
  kernel.yama.ptrace_scope: 2
  net.core.bpf_jit_harden: 2
  user.max_user_namespaces: 62967

conntrack_sysctl_settings:
  net.netfilter.nf_conntrack_max: 2000000
  net.netfilter.nf_conntrack_tcp_loose: 0

If manage_sysctl: true, then update the sysctl configuration.

sysctl_conf_dir is where the sysctl configuration will be placed.

See sysctl.conf and the kernel documentation.

./defaults/main/templates.yml

adduser_conf_template: etc/adduser.conf.j2
common_account_template: etc/pam.d/common-account.j2
common_auth_template: etc/pam.d/common-auth.j2
common_password_template: etc/pam.d/common-password.j2
coredump_conf_template: etc/systemd/coredump.conf.j2
faillock_conf_template: etc/security/faillock.conf.j2
hardening_rules_template: etc/audit/rules.d/hardening.rules.j2
hosts_allow_template: etc/hosts.allow.j2
hosts_deny_template: etc/hosts.deny.j2
initpath_sh_template: etc/profile.d/initpath.sh.j2
issue_template: etc/issue.j2
journald_conf_template: etc/systemd/journald.conf.j2
limits_conf_template: etc/security/limits.conf.j2
login_defs_template: etc/login.defs.j2
login_template: etc/pam.d/login.j2
logind_conf_template: etc/systemd/logind.conf.j2
logrotate_conf_template: etc/logrotate.conf.j2
motd_template: etc/motd.j2
pwquality_conf_template: etc/security/pwquality.conf.j2
resolved_conf_template: etc/systemd/resolved.conf.j2
rkhunter_template: etc/default/rkhunter.j2
ssh_config_template: etc/ssh/ssh_config.j2
sshd_config_template: etc/ssh/sshd_config.j2
sysctl_ipv6_config_template: etc/sysctl/sysctl.ipv6.conf.j2
sysctl_main_config_template: etc/sysctl/sysctl.main.conf.j2
system_conf_template: etc/systemd/system.conf.j2
timesyncd_conf_template: etc/systemd/timesyncd.conf.j2
tmp_mount_template: etc/systemd/tmp.mount.j2
user_conf_template: etc/systemd/user.conf.j2
useradd_template: etc/default/useradd.j2

Paths in order to support overriding the default role templates.

./defaults/main/ufw.yml

manage_ufw: true

ufw_outgoing_traffic:
  - 22
  - 53
  - 80
  - 123
  - 443
  - 853

ufw_rate_limit: false

manage_ufw: true installs and configures ufw with related rules. Set it to false in order to install and configure a firewall manually.

ufw_outgoing_traffic opens the specific ufw ports, allowing outgoing traffic.

ufw_rate_limit, if true, will set connection rate limiting on all available physical network interfaces.

./defaults/main/umask.yml

session_timeout: 900
umask_value: "077"

session_timeout sets, in seconds, the TMOUT environment variable.

umask_value sets the default umask value.

./defaults/main/usbguard.yml

manage_usbguard: true

usbguard_configuration_file: /etc/usbguard/usbguard-daemon.conf
usbguard_rulefile: /etc/usbguard/rules.conf

usbguard_auditbackend: LinuxAudit
usbguard_auditfilepath: /var/log/usbguard/usbguard-audit.log
usbguard_authorizeddefault: none
usbguard_devicemanagerbackend: uevent
usbguard_deviceruleswithport: false
usbguard_hidepii: false
usbguard_implicitpolicytarget: block
usbguard_inserteddevicepolicy: apply-policy
usbguard_ipcaccesscontrolfiles: /etc/usbguard/IPCAccessControl.d/
usbguard_ipcallowedgroups:
  - plugdev
  - root
  - wheel
usbguard_ipcallowedusers:
  - root
usbguard_presentcontrollerpolicy: keep
usbguard_presentdevicepolicy: apply-policy
usbguard_restorecontrollerdevicestate: false

manage_usbguard: true installs and configures USBGuard.

A policy will be generated if any rules can be listed and a policy doesn't yet exist.

See the configuration documentation regarding the available options.

./defaults/main/users.yml

delete_users:
  - games
  - gnats
  - irc
  - list
  - news
  - sync
  - uucp

Users to be removed.

Recommended Reading

Comparing the DISA STIG and CIS Benchmark values

Center for Internet Security Linux Benchmarks

Common Configuration Enumeration

DISA Security Technical Implementation Guides

SCAP Security Guides

Security focused systemd configuration

Contributing

Do you want to contribute? Great! Contributions are always welcome, no matter how large or small. If you found something odd, feel free to submit a issue, improve the code by creating a pull request, or by sponsoring this project.

License

Apache License Version 2.0

Author Information

https://github.com/konstruktoid

ansible-role-hardening's People

Contributors

andersuno avatar asiebelt avatar cleberb avatar dependabot[bot] avatar devspyrosv avatar extremeshok avatar gimiki avatar jdaln avatar koendg avatar konstruktoid avatar markdumay avatar mgoodness avatar polachz avatar renovate-bot avatar renovate[bot] avatar scadu avatar sgnsys3 avatar step-security-bot avatar triat avatar zigarn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansible-role-hardening's Issues

[BUG] When running on Debian, all tasks with installing or uninstalling packages are failing

Thank you for your great repo!

Describe the bug
Using this playbook:

---
- hosts: www
  user: root
  any_errors_fatal: true
  tasks:
    - include_role:
        name: konstruktoid.hardening
      vars:
        - sshd_admin_net:
            - 1.2.3.0/24
        - ufw_outgoing_traffic:
            - 22
            - 53
            - 80
            - 123
            - 443
            - 853
            - 3128
            - 10051

To success this task, I need to manually remove/install packages. All apt commands ends with:

TASK [konstruktoid.hardening : debian family package installation] ***********************************************************
fatal: [1.2.3.4]: FAILED! => {"changed": false, "cmd": "None -y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold install audispd-plugins -o APT::Install-Recommends=no", "msg": "[Errno 2] No such file or directory: b'None': b'None'", "rc": 2}

Not sure why apt is not found and 'None' is used.

Expected behavior
Packages should be installed/deinstalled

System (lsb_release -a or similar):
ansible client and server:

No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 10 (buster)
Release:        10
Codename:       buster

Additional context
Tried to create other playbook just to install/deinstall packages by apt and everything works.
So it must be some defaults inside your tree but I was not able to find it.

[BUG] dnf cannot install the best update candidate

Use nobest (https://docs.ansible.com/ansible/latest/collections/ansible/builtin/dnf_module.html#parameter-nobest)

fatal: [arctic]: FAILED! => {"changed": false, "failures": [], "msg": "Depsolve Error occurred: \n Problem: cannot install both openssl-libs-1:1.1.1k-7.el8_6.x86_64 and openssl-libs-1:1.1.1k-6.el8_5.x86_64\n  - package openssl-1:1.1.1k-7.el8_6.x86_64 requires openssl-libs(x86-64) = 1:1.1.1k-7.el8_6, but none of the providers can be installed\n  - cannot install the best update candidate for package openssl-libs-1:1.1.1k-6.el8_5.x86_64\n  - cannot install the best update candidate for package openssl-1:1.1.1k-6.el8_5.x86_64", "rc": 1, "results": []}

Is it expected that the UFW rules block traffic to the multicast domain?

Looking at /var/log/ufw.log, I'm seeing blocked traffic with DST=224.0.0.1

Which, looking that up: https://www.iana.org/assignments/multicast-addresses/multicast-addresses.xhtml

Is a multicast address. From what I'm reading, this is basic network functionality. However, I assume it might be abused for attacks?

Is this to be blocked at all, considering it is such basic functionality?

And if so, is there a way to not log UFW blocks on this specific subnet? Like, tell UFW to not log anything going over 224.0.0.0/24 ?

Not really a bug, I guess, though in terms of functionality and generated logs, is kind of weird to see these show up in the logs. And after a while gets annoying to have to ignore them and look for other stuff in between them.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

ansible-galaxy
requirements.yml
  • ansible.posix 1.5.4
  • community.crypto 2.19.0
  • community.general 8.6.0
dockerfile
action-lint/Dockerfile
github-actions
.github/workflows/dependency-review.yml
  • step-security/harden-runner v2.7.0@63c24ba6bd7ba022e95695ff85de572c04a18142
  • actions/checkout v4.1.4@0ad4b8fadaa221de15dcec353f45205ec38ea70b
  • actions/dependency-review-action v4.2.5@5bbc3ba658137598168acb2ab73b21c432dd411b
.github/workflows/issues.yml
  • step-security/harden-runner v2.7.0@63c24ba6bd7ba022e95695ff85de572c04a18142
  • pozil/auto-assign-issue v1.14.0@65947009a243e6b3993edeef4e64df3ca85d760c
.github/workflows/lint.yml
  • step-security/harden-runner v2.7.0@63c24ba6bd7ba022e95695ff85de572c04a18142
  • actions/checkout v4.1.4@0ad4b8fadaa221de15dcec353f45205ec38ea70b
  • ansible/ansible-lint-action eb92667e07cc18e1d115ff02e5f07126310cec11
.github/workflows/molecule.yml
  • actions/checkout v4
.github/workflows/schedlint.yml
  • step-security/harden-runner v2.7.0@63c24ba6bd7ba022e95695ff85de572c04a18142
  • actions/checkout v4.1.4@0ad4b8fadaa221de15dcec353f45205ec38ea70b
  • ansible/ansible-lint-action eb92667e07cc18e1d115ff02e5f07126310cec11
.github/workflows/schedmainlint.yml
  • step-security/harden-runner v2.7.0@63c24ba6bd7ba022e95695ff85de572c04a18142
  • actions/checkout v4.1.4@0ad4b8fadaa221de15dcec353f45205ec38ea70b
.github/workflows/scorecards.yml
  • step-security/harden-runner v2.7.0@63c24ba6bd7ba022e95695ff85de572c04a18142
  • actions/checkout v4.1.4@0ad4b8fadaa221de15dcec353f45205ec38ea70b
  • ossf/scorecard-action v2.3.1@0864cf19026789058feabb7e87baa5f140aac736
  • actions/upload-artifact v4.3.3@65462800fd760344b1a7b4382951275a0abb4808
  • github/codeql-action v3.25.3@d39d31e687223d841ef683f52467bd88e9b21c14
.github/workflows/slsa.yml
  • step-security/harden-runner v2.7.0@63c24ba6bd7ba022e95695ff85de572c04a18142
  • actions/checkout v4.1.4@0ad4b8fadaa221de15dcec353f45205ec38ea70b
  • actions/upload-artifact v4.3.3@65462800fd760344b1a7b4382951275a0abb4808
  • slsa-framework/slsa-github-generator v2.0.0
  • actions/download-artifact v4.1.7@65a9edc5881444af0b9093a5e628f2fe47ea3b2e
  • softprops/action-gh-release v2.0.4@9d7c94cfd0a1f3ed45544c887983e9fa900f0564
pip_requirements
requirements-dev.txt

  • Check this box to trigger a request for Renovate to run again on this repository

Compatibility with Ubuntu Core with Raspberry Pi/Cloudflared/PiHole

Hey, this seems like a really cool script so thanks! I am wondering if I would be able to use this with a Raspberry Pi with PiHole and cloudflared installed as well. I realize this is a general question. Are there any modules included in this that might impact a PiHole setup? I notice there are DNS configurations but the PiHole needs to manage those itself.

Possibly incomplete compiler handling

(I am not an Ansible person by any stretch of the imagination) this does not seem to account for the (not uncommon) case when one might have more than one version of a compiler (or multiple compilers) installed (even in a server context).

$ ls -l /usr/bin/cc /usr/bin/gcc /usr/bin/gcc-? /usr/bin/clang-?
lrwxrwxrwx 1 root root 20 Feb 24  2018 /usr/bin/cc -> /etc/alternatives/cc
lrwxrwxrwx 1 root root 23 Jan 31  2020 /usr/bin/clang-9 -> ../lib/llvm-9/bin/clang
lrwxrwxrwx 1 root root  5 May 20  2019 /usr/bin/gcc -> gcc-7
lrwxrwxrwx 1 root root 22 Dec  4  2019 /usr/bin/gcc-7 -> x86_64-linux-gnu-gcc-7
lrwxrwxrwx 1 root root 22 Mar 10  2020 /usr/bin/gcc-8 -> x86_64-linux-gnu-gcc-8

As far as I understand this task (or whatever it is called :) would leave gcc-8 in this example open (granted, locked-down as mitigates that). However, I suppose Clang would also need to be accounted for, as it doesn't necessarily need to use GNU as, so the current state completely misses it.

You might plausibly consider including Rust and Go on this list as well, "just in case".

On platforms where supported (deb-derived), using dpkg-statoverride would probably be a good thing. Don't know if RPM and friends have similar facilities.

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

[Feature] - detection of virtual host

There is an detection of BIOS and if it is VMware, open-vm-tools are installed automatically.
For hosts virtualized by kvm, name of BIOS is SeaBIOS.
If BIOS is SeaBIOS or ansible_chassis_vendor is QEMU, open-vm-tools should be installed too.

    "ansible_architecture": "x86_64",
        "ansible_bios_date": "04/01/2014",
        "ansible_bios_vendor": "SeaBIOS",
        "ansible_bios_version": "rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org",
        "ansible_board_asset_tag": "NA",
        "ansible_board_name": "NA",
        "ansible_board_serial": "NA",
        "ansible_board_vendor": "NA",
        "ansible_board_version": "NA",
        "ansible_chassis_asset_tag": "NA",
        "ansible_chassis_serial": "NA",
        "ansible_chassis_vendor": "QEMU",
        "ansible_chassis_version": "pc-i440fx-5.2",

[BUG] Failed to install python3-pexpect

Describe the bug

TASK [konstruktoid.hardening : install python3-pexpect]

fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to update apt cache: W:Updating from such a repository can't be done securely, and is therefore disabled by default., W:See apt-secure(8) manpage for repository creation and user configuration details., E:The repository 'http://ppa.launchpad.net/certbot/certbot/ubuntu focal Release' does not have a Release file."}

To Reproduce

---
- hosts: localhost
  any_errors_fatal: true
  tasks:
    - name: include the hardening role
      include_role:
        name: konstruktoid.hardening
      vars:
        ansible_sudo_pass: NeuroLF!
        ansible_ssh_user: positrigo
        block_blacklisted: true
        sshd_admin_net:
          - 10.0.2.0/24
          - 192.168.0.0/24
          - 192.168.1.0/24
        suid_sgid_permissions: true

ansible-playbook playbook.yml

Expected behavior
Works. Doesn't throw error.

System (lsb_release -a or similar):
Ubuntu 20.04.3 LTS

[BUG] faillock setup completely locks me out of POPos system

Describe the bug
After running this playbook: https://github.com/konstruktoid/ansible-role-hardening/blob/master/tasks/password.yml

I couldn't log in anymore after a reboot.

The login screen would flicker and give the message "that didn't work".

entering the password showed everything in cleartext.

Going to the console also fails. I can only enter the username, it hangs for a few seconds, and then says "login failed" and asks for a username again.

SSH also fails.

Be it my user or root, nothing works.

To Reproduce
Run the playbook on Popos 20.04 or Ubuntu 20.04

Expected behavior
For this not to happen.

System (lsb_release -a or similar):

$ lsb_release -a
No LSB modules are available.
Distributor ID: Pop
Description:    Pop!_OS 20.04 LTS
Release:        20.04
Codename:       focal

path playbook includes /snap/bin which doesn't exist is squashfs is blocked

See here: https://github.com/konstruktoid/ansible-role-hardening/blob/master/tasks/path.yml

Includes /snap/bin

Snap uses squashfs to mount its programs.

Now, as part of another playbook, squashfs is blocked. See here: https://github.com/konstruktoid/ansible-role-hardening/blob/master/tasks/disablefs.yml

Where a list is blocked, list found here: https://github.com/konstruktoid/ansible-role-hardening/blob/master/defaults/main/module_blocklists.yml

It appears to not make sense that /snap/bin is included, as blocking squashfs means snap cannot run, I would think.

So I'd suggest removing it.

make sshd config ClientAliveInterval configurable

I'd like to use a custom ClientAliveInterval in the sshd_config. I'm using commands that might take up to 10m to complete, and the current default configuration (5m) disconnects the session in the middle.

[BUG]

Describe the bug
In Debian 11.0.0 users can no longer login to the console, switch user with su or perform elivated commands with sudo after play name: common-auth in tasks/password.yml is run. The user can sudo if named in sudoers, but not if the group is named only. Login via SSH still functions correctly.

To Reproduce
Run role on Debian 11.0.0 or just play name: common-auth in tasks/password.yml then attempt to perform su from any non-root user to any other user, or perform any sudo command as a user in the sudo group with %sudo in /etc/sudoers.

Expected behavior
Console login, su and sudo function as normal.

Additional context
Fresh install on bare metal. This result is guaranteed every time.

[BUG] Missing tag in fact garthering

Describe the bug
Registering of variable is missing tag so if we run playbook only with tag sshd, it fails that variable sshd_config_d_exists does not exists

To Reproduce

ansible-playbook -t sshd ./hardenize.yml

Expected behavior
sshconfig.yml needs to add tags:

- name: check if sshd_config.d exits
  stat:
    path: /etc/ssh/sshd_config.d
  register: sshd_config_d_exists
  tags:
    - sshd
    - sshd_config

[BUG] - missing libpam-cap package to install as mandatory

Describe the bug
After hardenize, pam complains about missing library:
Apr 28 17:11:19 fcpa-fc-cz saslauthd[737]: PAM unable to dlopen(pam_cap.so): /lib/security/pam_cap.so: cannot open shared object file: No such file or directory

Seems that pam_cap is referenced in hardening template common-auth.j2 but it is not installed as mandatory package

Expected behavior
add libpam-cap to required debian packages

OSCAP scan false positives

Hallo.

I have checked hardened VM instance of the RHEL/CentOS8 by OSCAP security scanner with the CIS Red Hat Enterprise Linux 8 Benchmark policy.

I have got many notices related to the auditd config. They are caused in many cases only by improper line check (for example it expects auid=unset instead of the auid=-1)

I have changed the hardening.rules.j2 to remove these problems. But I can ask you if you use some simmilar checks. Maybe my fix will repair Centos/Rhel 8 but can brings Centos 7 or other OS to the trouble....

So can be better to make decision if you can include these changes to the role. When the answer i yes, then please specify if you can do that globally or can you provide different file versions for different OS families and OS versions.

Looking forward to your answer

Best Regards, Zdenek

[BUG] Login failure in-between when running hardening role

Thanks @konstruktoid for this great repo!
I am new to security on linux systems. This doesnt seem to be a bug but my lack of knowledge/understanding. Can you help me what am i missing here?

Describe the bug
When running the hardening role, many hardening tasks complete well but after finishing 'common-auth' task... I get 'incorrect sudo password' while running next task 'common-account' and all subsequent tasks fail.

To Reproduce
Both master and hosts node are running Ubuntu 20.04.2 LTS on oracle vm virtual box for testing. have created user named ubuntu with sudo privileges on both machines and also part of sudo group. Calling your hardening role from playbook with command:
ansible-playbook playbook_harden.yaml -kK

Playbook_harden.yaml code:

- hosts: dbserver2
  become: true
  roles:
    - konstruktoid.hardening

Expected behavior
Should be able to run all hardening tasks

System (lsb_release -a or similar):
Ubuntu 20.04.2 LTS

Additional context
some logs:

TASK [konstruktoid.hardening : check if ssh_config.d exits] ********************
ok: [dbserver2]

TASK [konstruktoid.hardening : configure ssh client] ***************************
changed: [dbserver2]

TASK [konstruktoid.hardening : common-password] ********************************
changed: [dbserver2]

TASK [konstruktoid.hardening : common-auth] ************************************
changed: [dbserver2]

TASK [konstruktoid.hardening : common-account] *********************************
fatal: [dbserver2]: FAILED! => {"msg": "Incorrect sudo password"}

RUNNING HANDLER [konstruktoid.hardening : restart sysctl] **********************

Lynis question

Thanks very much for your hard work on this repo, I just recently switched to linux in general. I plan to run a Lubuntu VPS which doesn't interact with the outside world but allows an admin to remote desktop in.

I spent a few weeks reading linux books and learning about various hardening techniques and mainly UFW. Then I discovered ansible and found this repo, I was very intrigued to see if a script can perform a '1 click' hardening of the entire system.

I did get a few errors running your script but most of the results seemed to go ok. I rebooted the system and it seems to be fine although I had some concerns, avahi is gone but what about bluetooth service? does a server really need bluetooth lol? seems like a security nightmare to me, but then again I have very little experience in security in general.

My other concern was that I ran Lynis and there was a huge amount of UNSAFE, WARNING and so on. My OCD is really triggering me and thinking I should have a 100% Lynis score but the hardening index is only 87.

Please can you let me know is your script enough to make a server secure on a VPS? I am just so paranoid about these things.

Thanks

Use aide.wrapper in 24_aide.yml

I have been working with your Ansible project and it has been a great tool. I wanted to provide a suggestion for the tasks/24_aide.yml. (This is based on testing I am doing on a clean install of Ubuntu 16.04.5) You install the aidecheck.service that references the use of /usr/bin/aide.wrapper to run. Looking at that wrapper script, it points to a specific configuration at /var/lib/aide/aide.conf.default. In the "initialize aide" task in 24_aide.yml, you initialize the db using the regular aide command. In the instance I am testing with, aide by itself does not have a configuration associated with it. You may want to change the shell line of that task to instead be:

shell: aide.wrapper --init -B 'database_out=file:/var/lib/aide/aide.db.gz'

Output of aide -v showing no configuration (last line):

Aide 0.16a2-19-g16ed855

Compiled with the following options:

WITH_MMAP
WITH_POSIX_ACL
WITH_SELINUX
WITH_XATTR
WITH_E2FSATTRS
WITH_LSTAT64
WITH_READDIR64
WITH_ZLIB
WITH_MHASH
WITH_AUDIT
CONFIG_FILE = "/dev/null"

[BUG] Pam module tally2 deprecated

Describe the bug
Unable to login remotely after applying the role on a Debian Bullseye (Debian 11) from in the Vultr instance server type library.

It seems that the pam module tally2 has been deprecated and needs to be replaces with faillock module. At least that's what the Redhat team is doing: dev-sec/ansible-collection-hardening#377

To Reproduce
Apply the role and try to log in using ssh.

In the file /var/log/auth.log the following entries can be found:

Oct 30 09:58:08 poc-cis sshd[2012]: Connection from xyz.xyz.xyz.xyz port 51416 on zyx.zyx.zyx.zyx port 22 rdomain ""
Oct 30 09:58:08 poc-cis sshd[2012]: PAM unable to dlopen(pam_tally2.so): /lib/security/pam_tally2.so: cannot open shared object file: No such file or directory
Oct 30 09:58:08 poc-cis sshd[2012]: PAM adding faulty module: pam_tally2.so

Expected behavior
Successful login using ssh.

System (lsb_release -a or similar):
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye

Additional context
I'm using packer to create the image, but I believe it's not relevant for this bug.

[BUG] The remark about modprobe in README

Describe the bug
A section in the readme says

Setting block_blacklisted: true will actually block, or disable, any blacklisted kernel modules. The reasoning behind this is that a blacklisted module can still be loaded manually with modprobe module_name. Using install module_name /bin/true prevents this.

It won't actually block or disable loading of modules. It will block modprobe, that's true enough, but there's still insmod, which will not even bat an eye on modprobe's configuration. While insmod may get a tad bit tedious with modules that have dependencies, it's still perfectly possible to load any module with it. A casual reader, or perhaps someone less familiar with Linux, might misconstrue the statement as "module disabled for good", whereas in reality it's more like "automatic loading of module" is disabled for good (even if the "automatic loading" is somewhat of the manual persuasion - I'm sure you get what I'm saying).

The only way to really disable modules (that I know of, anyway) is kernel.modules_disabled. It however is global and irreversible (without a reboot).

An alternative method might be truly deleting the offending modules from the file system and using dpkg --path-exclude (/etc/dpkg/dpkg.cfg.d/ droplets) where available - I'm assuming other package managers must have similar facilities.

[QUESTION] Why set CtrlAltDelBurstAction=none in /etc/systemd/system.conf?

Describe the bug

efff947 introduces CtrlAltDelBurstAction=none in /etc/systemd/system.conf

https://manpages.debian.org/bullseye/systemd/systemd-system.conf.5.en.html says:

CtrlAltDelBurstAction=
Defines what action will be performed if user presses Ctrl-Alt-Delete more than 7 times in 2s. Can be set to "reboot-force", "poweroff-force", "reboot-immediate", "poweroff-immediate" or disabled with "none". Defaults to "reboot-force".

I would like to know possible security implications of leaving this to the default value (reboot-force). As far as I can see, this only opens up to this possible attack:

  • a malicious user with keyboard access can reboot the machine and cause a denial of service

Correct? Or are there other reasons to set this option to none ?

[Q] Reason for disabling dccp sctp rds tipc kernel modules?

Hi,

I traced back the addition of net_modules_blocklist to 6000ef9. From this commit I cannot tell why these particular modules (dccp, sctp, rds, tipc) were disabled.

What is the reason for disabling these modules? Is it a generic "disable what you don't need" task (in which case it might be better to leave the default list empty, as the modules could be in use on some systems)? Or is there a specific problem/security risk related to dccp/sctp/rds/tipc modules?

Thanks for this interesting role, I am learning from it and mixing it with https://github.com/dev-sec/ansible-collection-hardening/ and https://github.com/nodiscc/xsrv/tree/master/roles/common

[BUG] [EC2] [GRUB] [UBUNTU] "The conditional check 'item.mode|int > 0400' failed".

Describe the bug
Hi!
Hardening fails on:

 amazon-ebs: TASK [konstruktoid.hardening : set grub config permissions] ********************�[0m
�[0;32m    amazon-ebs: fatal: [default]: FAILED! => {"msg": "The conditional check 'item.mode|int > 0400' failed. The error was: template error while templating string: expected token 'end of statement block', got 'integer'. String: {% if item.mode|int > 0400 %} True {% else %} False {% endif %}\n\nThe error appears to be in '/root/.ansible/roles/konstruktoid.hardening/tasks/post.yml': line 15, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: set grub config permissions\n  ^ here\n"}�[0m

On a server:

stat -c "%a %n" /boot/grub/grub.cfg
444 /boot/grub/grub.cfg
stat -c "%a %n" /boot/grub/grubenv
644 /boot/grub/grubenv
ls /boot/grub/
default           fonts/            gfxblacklist.txt  grub.cfg          grubenv           i386-pc/          locale/           menu.lst          menu.lst~         unicode.pf2

To Reproduce
Running the playbook v1.3.2 on an AWS ubuntu EC2 instance

Expected behavior
Ansible finds the grub config files and set them to 400

System (lsb_release -a or similar):

Distributor ID: Ubuntu
Release:        20.04
Codename:       focal

Additional context

Is there anything we can do to override this in settings?

THANKS! :)

[QUESTION] Question about PAM hardening

Question about PAM hardening

Hallo.

I have a problem on CentOS 8.3 with new user login.

I have created new user after role is applied, but user is not able to login on the console

Due this I have started analyze the PAM modifications provided by the role

At first, i have found that role copied

  • common-auth
  • common-password
  • common-account

files on all platforms, but seems that on RedHat family these files are not used (included) by other pam config files. Then are really necessary to be copied here?

Why on RHEL family the sugroup is defined? Is here idea to use it as a wheel replacement or something else?

Thank you for your answers.

ZP

New release for ansible-galaxy

Hey @konstruktoid,

What is the usual release cycle that you try to follow for ansible-galaxy? I've faced the issue described here #100 and saw that you solved the issue in a recent commit.

Unfortunately, this is not released yet and I wanted to know if I'd better organize my code to use git clone or can I use ansible-galaxy, hopping for a release soon?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.