Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Breaking Changes

* **role:sshd, playbook:setup_basic**: sshd turns new connections away earlier while many logins are pending (`MaxStartups 10:30:60` instead of the OpenSSH default `10:30:100`), as the CIS Benchmarks require, and `MaxStartups` is configurable with `sshd__max_startups__host_var` / `sshd__max_startups__group_var`. A `MaxStartups` set through `sshd__raw` no longer takes effect, move it to the variable. Hosts with many simultaneous SSH logins need a higher value, for example `'100:30:200'` on GitLab hosts ([#723](https://github.com/Linuxfabrik/lfops/issues/723)).
* **role:grav, playbook:setup_grav**: The code of Grav, its configuration, pages, plugins and themes belong to `root`, so a hole in Grav or a plugin can no longer plant code in the site. The web server only writes `assets`, `backup`, `cache`, `images`, `logs`, `tmp`, `user/accounts` and `user/data`, and only these keep the SELinux type `httpd_sys_rw_content_t`. Grav, its plugins and themes are updated as `root` by `grav-selfupgrade-<instance>.timer` and `grav-update-<instance>.timer`, which replace `grav-selfupgrade.timer` and `grav-update.timer`, so several Grav sites on one host are each updated. Run other `bin/gpm` commands with `grav-gpm <installation directory> <arguments>` instead of `sudo -u apache bin/gpm`, which now fails, and deploy content below `user/` as `root`. The role no longer installs the Admin Panel, which could not save anything anymore, and drops `grav__skip_admin` and `grav__users`; it lists the Admin Panel plugins still installed at the end of the play, for you to remove. The vHost no longer accepts `POST`, and `setup_grav` no longer sets the SELinux boolean `httpd_can_network_connect`, which keeps its current value.
* **role:apache_httpd**: The `proxy` vHost template waits 30 instead of 5 seconds for the backend, so slower responses no longer end in a 502, and a hanging backend holds the connection longer. Set `conf_proxy_timeout: 5` on the vHost to keep the previous value.
* **role:icingaweb2, playbook:setup_icinga2_master**: IcingaWeb2 accepts selections of up to 500 objects and has 5 minutes for long requests such as PDF exports. A reverse proxy in front of it needs `apache_httpd__conf_limit_request_field_size` and `apache_httpd__conf_limit_request_line` set to `131072` as well.
Expand Down
2 changes: 2 additions & 0 deletions extensions/molecule/sshd/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- name: 'Converge sshd playbook'
ansible.builtin.import_playbook: 'linuxfabrik.lfops.sshd'
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Neither the default of the role (10:30:60) nor the one of OpenSSH (10:30:100), so verify.yml
# can prove that the value from the inventory reaches sshd. The host variable has to win over
# the group variable.
sshd__max_startups__group_var: '20:30:120'
sshd__max_startups__host_var: '100:30:200'
18 changes: 18 additions & 0 deletions extensions/molecule/sshd/inventory/hosts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# yamllint disable rule:empty-values

# Map the playbook's target group (playbooks/sshd.yml: hosts: lfops_sshd) onto the
# shared systems_under_test host set.
lfops_sshd:
children:
systems_under_test:

systems_under_test:
hosts:
debian12-vm:
debian13-vm:
rocky8-vm:
rocky9-vm:
rocky10-vm:
ubuntu2204-vm:
ubuntu2404-vm:
ubuntu2604-vm:
2 changes: 2 additions & 0 deletions extensions/molecule/sshd/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Molecule scenario marker for the 'sshd' scenario, run with
# `molecule test --scenario-name sshd`.
36 changes: 36 additions & 0 deletions extensions/molecule/sshd/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
- name: 'Verify the sshd role configured sshd'
hosts: 'systems_under_test'
gather_facts: false
tasks:

- name: 'Gather the distribution facts'
ansible.builtin.setup:
gather_subset:
- '!all'

- name: 'Gather the service facts'
ansible.builtin.service_facts: # yamllint disable-line rule:empty-values

# The daemon unit is ssh.service on Debian and Ubuntu, sshd.service on the Red Hat family.
- name: 'Assert that the sshd service is running and enabled'
ansible.builtin.assert:
that:
- 'ansible_facts["services"][__molecule__sshd_unit]["state"] == "running"'
- 'ansible_facts["services"][__molecule__sshd_unit]["status"] == "enabled"'
fail_msg: '{{ ansible_facts["services"][__molecule__sshd_unit] | to_json }}'
vars:
__molecule__sshd_unit: '{{ (ansible_facts["os_family"] == "Debian") | ternary("ssh.service", "sshd.service") }}'

# Ask sshd for its effective configuration instead of reading the file: sshd uses the first
# value it reads, so a drop-in of the distribution that sets the option would win over the
# deployed sshd_config and pass a file check.
- name: 'sshd -T'
ansible.builtin.command: 'sshd -T'
changed_when: false
register: '__molecule__sshd_effective_config_result'

- name: 'Assert that sshd uses the MaxStartups of the host variable'
ansible.builtin.assert:
that:
- '"maxstartups 100:30:200" in __molecule__sshd_effective_config_result["stdout_lines"]'
fail_msg: '{{ __molecule__sshd_effective_config_result["stdout_lines"] | select("search", "^maxstartups") | list }}'
1 change: 1 addition & 0 deletions roles/gitlab_ce/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This role installs and configures [GitLab CE](https://about.gitlab.com/), includ
## How the Role Behaves

* `gitlab-dump.service` runs with `Nice=19`, best-effort IO priority 7 and `CPUWeight=` / `IOWeight=` of `20` (systemd default: `100`), so the dump does not slow down the application on a busy host. The weights only take effect under contention. `IOWeight=` only has an effect on block devices that use the BFQ IO scheduler; with `none` or `mq-deadline`, as on a RHEL 9 VM with virtio disks, it is ignored.
* The role does not configure sshd. Git over SSH opens one connection per `git fetch` or `git push`, so CI jobs or scripts that update many repositories at once exceed the `MaxStartups` of the [sshd](https://github.com/Linuxfabrik/lfops/tree/main/roles/sshd) role, and sshd refuses some of them. Set `sshd__max_startups__group_var: '100:30:200'` for GitLab hosts in the inventory, the value the [GitLab documentation](https://docs.gitlab.com/topics/git/troubleshooting_git/) suggests.


## Known Limitations
Expand Down
14 changes: 12 additions & 2 deletions roles/sshd/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Ansible Role linuxfabrik.lfops.sshd

This role deploys `/etc/ssh/sshd_config` for [OpenSSH](https://www.openssh.com/) (the standard SSH server on Linux). It exposes the most commonly tuned options as variables (port, address family, password / GSSAPI / root login, log level, forwarding, session limits, sftp subsystem) plus a `sshd__raw` escape hatch for `Match` blocks etc.
This role deploys `/etc/ssh/sshd_config` for [OpenSSH](https://www.openssh.com/) (the standard SSH server on Linux). It exposes the most commonly tuned options as variables (port, address family, password / GSSAPI / root login, log level, forwarding, session and connection limits, sftp subsystem) plus a `sshd__raw` escape hatch for `Match` blocks etc.

Note that the role templates the full `sshd_config`, since not all options can be overwritten in `/etc/ssh/sshd_config.d/` (e.g. `Subsystem 'sftp' already defined`). The only exception is `00-linuxfabrik.conf` on RHEL 9 and newer, which sets `GSSAPIAuthentication` and `X11Forwarding`, as the `50-redhat.conf` of the package would win otherwise.

Expand All @@ -12,12 +12,14 @@ The option descriptions below are condensed from `sshd_config(5)`.

## How the Role Behaves

The role ships hardened defaults for several options that differ from the OpenSSH (or distribution) defaults: root may not log in, `X11Forwarding`, agent forwarding and TCP keepalives are off, `MaxAuthTries` and `ClientAliveCountMax` are stricter, an unresponsive client is disconnected after `ClientAliveInterval` × `ClientAliveCountMax` seconds (30 by default), and `LogLevel` is `VERBOSE` (which logs the key fingerprint used for each login). These follow the CIS Benchmarks. Each is overridable via the variables below.
The role ships hardened defaults for several options that differ from the OpenSSH (or distribution) defaults: root may not log in, `X11Forwarding`, agent forwarding and TCP keepalives are off, `MaxAuthTries`, `MaxStartups` and `ClientAliveCountMax` are stricter, an unresponsive client is disconnected after `ClientAliveInterval` × `ClientAliveCountMax` seconds (30 by default), and `LogLevel` is `VERBOSE` (which logs the key fingerprint used for each login). These follow the CIS Benchmarks. Each is overridable via the variables below.

`PermitRootLogin` defaults to `no`. Before it deploys `sshd_config`, the role checks which user Ansible logs in as over SSH. If that is root and `sshd__permit_root_login` does not admit root logins with a key, the run aborts before anything is changed, since the reload would lock Ansible out of the host. Log in as an unprivileged user with sudo (see the [login](https://github.com/Linuxfabrik/lfops/tree/main/roles/login) role), or set `sshd__permit_root_login: 'prohibit-password'` for hosts that Ansible has to reach as root.

`MaxAuthTries` defaults to `3`. Every public key an SSH agent offers counts as one attempt, so a client with more than three keys loaded in its agent may be rejected before the matching key is tried. In that case use `IdentitiesOnly yes` / an explicit `IdentityFile` on the client, or raise `sshd__max_auth_tries`.

`MaxStartups` defaults to `10:30:60`. It limits the connections that have not authenticated yet, across all clients: from 10 such connections on, sshd refuses every new one with a probability of 30%, rising to 100% at 60. A host that many clients log in to at the same moment, such as a Git server with CI jobs, reaches this limit with legitimate logins, which then fail before authentication (`Connection closed by remote host` or `Not allowed at this time` on the client, `drop connection ... past MaxStartups` in the log of sshd). Raise `sshd__max_startups__host_var` / `sshd__max_startups__group_var` on such hosts. sshd uses the first value it reads, so a `MaxStartups` in `sshd__raw` has no effect.

On Debian and Ubuntu the SSH daemon unit is `ssh.service` and OpenSSH ships socket activation (`ssh.socket`) enabled by default. The role manages the daemon through its service unit like on Red Hat, so on these systems it disables and stops `ssh.socket` and enables `ssh.service` instead. Red Hat-family systems for which no version-specific template exists (in particular Fedora) fall back to the generic `RedHat` template.


Expand Down Expand Up @@ -98,6 +100,13 @@ Any [LFOps playbook](https://github.com/Linuxfabrik/lfops/blob/main/playbooks/RE
* Type: Number.
* Default: `10`

`sshd__max_startups__host_var` / `sshd__max_startups__group_var`

* Maximum number of concurrent connections that have not authenticated yet, as `start:rate:full`: from `start` such connections on, sshd refuses a new one with a probability of `rate` percent, which rises linearly to 100% at `full`. A single number refuses every connection above it. See "How the Role Behaves".
* Type: String.
* Default: `'10:30:60'`
* Deviates from the upstream default `10:30:100`: fewer pending logins can keep sshd busy before it turns new ones away. The CIS Benchmarks require `10:30:60` or stricter.

`sshd__password_authentication`

* Specifies whether password authentication is allowed.
Expand Down Expand Up @@ -172,6 +181,7 @@ sshd__gssapi_authentication: false
sshd__log_level__host_var: 'VERBOSE'
sshd__max_auth_tries: 3
sshd__max_sessions: 10
sshd__max_startups__host_var: '100:30:200'
sshd__password_authentication: false
sshd__permit_root_login: 'prohibit-password'
sshd__port: 22
Expand Down
10 changes: 10 additions & 0 deletions roles/sshd/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ sshd__log_level__host_var: ''
sshd__log_level__role_var: 'VERBOSE'
sshd__max_auth_tries: 3
sshd__max_sessions: 10
sshd__max_startups__combined_var: '{{
sshd__max_startups__host_var if (sshd__max_startups__host_var | string | length) else
sshd__max_startups__group_var if (sshd__max_startups__group_var | string | length) else
sshd__max_startups__dependent_var if (sshd__max_startups__dependent_var | string | length) else
sshd__max_startups__role_var
}}'
sshd__max_startups__dependent_var: ''
sshd__max_startups__group_var: ''
sshd__max_startups__host_var: ''
sshd__max_startups__role_var: '10:30:60' # upstream default: 10:30:100
sshd__password_authentication: false
sshd__permit_root_login: 'no' # upstream default: 'prohibit-password'
sshd__port: 22
Expand Down
24 changes: 24 additions & 0 deletions roles/sshd/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,30 @@ argument_specs:
Maximum number of open shell, login or subsystem sessions
permitted per network connection.

sshd__max_startups__dependent_var:
type: 'str'
required: false
default: ''
description: >-
Dependent-role override for `MaxStartups`. See
`sshd__max_startups__host_var` in the README.

sshd__max_startups__group_var:
type: 'str'
required: false
default: ''
description: >-
Group-level override for `MaxStartups`. See
`sshd__max_startups__host_var` in the README.

sshd__max_startups__host_var:
type: 'str'
required: false
default: ''
description: >-
Host-level override for `MaxStartups`. See
`sshd__max_startups__host_var` in the README.

sshd__password_authentication:
type: 'bool'
required: false
Expand Down
25 changes: 25 additions & 0 deletions roles/sshd/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,31 @@
- 'always'


- block:

# sshd refuses to start with an invalid MaxStartups (servconf.c, `Invalid MaxStartups spec`),
# and the handler would only notice after sshd_config has been replaced.
- name: 'Check variable constraints'
ansible.builtin.assert:
that:
- 'sshd__max_startups__combined_var | string is match("^[0-9]+(:[0-9]+:[0-9]+)?$")'
- '__sshd__max_startups_parts[0] >= 1'
- '__sshd__max_startups_parts | length == 1 or (
__sshd__max_startups_parts[0] <= __sshd__max_startups_parts[2] and
__sshd__max_startups_parts[1] >= 1 and
__sshd__max_startups_parts[1] <= 100
)'
quiet: true
fail_msg: >-
sshd__max_startups must be a number or `start:rate:full` with start <= full and a rate
between 1 and 100, got "{{ sshd__max_startups__combined_var }}".
vars:
__sshd__max_startups_parts: '{{ sshd__max_startups__combined_var | string | split(":") | map("int") | list }}'

tags:
- 'always'


- name: 'Run the preflight checks'
ansible.builtin.import_tasks: 'preflight.yml'

Expand Down
4 changes: 2 additions & 2 deletions roles/sshd/templates/etc/ssh/Debian12-sshd_config.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# {{ ansible_managed }}
# 2026101601
# 2026111301

# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
Expand Down Expand Up @@ -102,7 +102,7 @@ ClientAliveInterval {{ sshd__client_alive_interval }}
ClientAliveCountMax {{ sshd__client_alive_count_max }}
UseDNS {{ sshd__use_dns | bool | ternary("yes", "no") }}
#PidFile /run/sshd.pid
#MaxStartups 10:30:100
MaxStartups {{ sshd__max_startups__combined_var }}
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
Expand Down
4 changes: 2 additions & 2 deletions roles/sshd/templates/etc/ssh/Debian13-sshd_config.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# {{ ansible_managed }}
# 2026101601
# 2026111301

# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
Expand Down Expand Up @@ -104,7 +104,7 @@ ClientAliveInterval {{ sshd__client_alive_interval }}
ClientAliveCountMax {{ sshd__client_alive_count_max }}
UseDNS {{ sshd__use_dns | bool | ternary('yes', 'no') }}
#PidFile /run/sshd.pid
#MaxStartups 10:30:100
MaxStartups {{ sshd__max_startups__combined_var }}
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
Expand Down
4 changes: 2 additions & 2 deletions roles/sshd/templates/etc/ssh/RedHat-sshd_config.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# {{ ansible_managed }}
# 2026101601
# 2026111301

# $OpenBSD: sshd_config,v 1.104 2021/07/02 05:11:21 dtucker Exp $

Expand Down Expand Up @@ -114,7 +114,7 @@ ClientAliveInterval {{ sshd__client_alive_interval }}
ClientAliveCountMax {{ sshd__client_alive_count_max }}
UseDNS {{ sshd__use_dns | bool | ternary("yes", "no") }}
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
MaxStartups {{ sshd__max_startups__combined_var }}
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
Expand Down
4 changes: 2 additions & 2 deletions roles/sshd/templates/etc/ssh/RedHat10-sshd_config.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# {{ ansible_managed }}
# 2026101601
# 2026111301

# $OpenBSD: sshd_config,v 1.104 2021/07/02 05:11:21 dtucker Exp $

Expand Down Expand Up @@ -114,7 +114,7 @@ ClientAliveInterval {{ sshd__client_alive_interval }}
ClientAliveCountMax {{ sshd__client_alive_count_max }}
UseDNS {{ sshd__use_dns | bool | ternary("yes", "no") }}
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
MaxStartups {{ sshd__max_startups__combined_var }}
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
Expand Down
4 changes: 2 additions & 2 deletions roles/sshd/templates/etc/ssh/RedHat8-sshd_config.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# {{ ansible_managed }}
# 2026101601
# 2026111301

# $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $

Expand Down Expand Up @@ -124,7 +124,7 @@ ClientAliveInterval {{ sshd__client_alive_interval }}
ClientAliveCountMax {{ sshd__client_alive_count_max }}
UseDNS {{ sshd__use_dns | bool | ternary("yes", "no") }}
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
MaxStartups {{ sshd__max_startups__combined_var }}
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
Expand Down
4 changes: 2 additions & 2 deletions roles/sshd/templates/etc/ssh/RedHat9-sshd_config.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# {{ ansible_managed }}
# 2026101601
# 2026111301

# $OpenBSD: sshd_config,v 1.104 2021/07/02 05:11:21 dtucker Exp $

Expand Down Expand Up @@ -114,7 +114,7 @@ ClientAliveInterval {{ sshd__client_alive_interval }}
ClientAliveCountMax {{ sshd__client_alive_count_max }}
UseDNS {{ sshd__use_dns | bool | ternary("yes", "no") }}
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
MaxStartups {{ sshd__max_startups__combined_var }}
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
Expand Down
4 changes: 2 additions & 2 deletions roles/sshd/templates/etc/ssh/Ubuntu22-sshd_config.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# {{ ansible_managed }}
# 2026101601
# 2026111301

# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
Expand Down Expand Up @@ -104,7 +104,7 @@ ClientAliveInterval {{ sshd__client_alive_interval }}
ClientAliveCountMax {{ sshd__client_alive_count_max }}
UseDNS {{ sshd__use_dns | bool | ternary('yes', 'no') }}
#PidFile /run/sshd.pid
#MaxStartups 10:30:100
MaxStartups {{ sshd__max_startups__combined_var }}
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
Expand Down
4 changes: 2 additions & 2 deletions roles/sshd/templates/etc/ssh/Ubuntu24-sshd_config.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# {{ ansible_managed }}
# 2026101601
# 2026111301

# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
Expand Down Expand Up @@ -104,7 +104,7 @@ ClientAliveInterval {{ sshd__client_alive_interval }}
ClientAliveCountMax {{ sshd__client_alive_count_max }}
UseDNS {{ sshd__use_dns | bool | ternary('yes', 'no') }}
#PidFile /run/sshd.pid
#MaxStartups 10:30:100
MaxStartups {{ sshd__max_startups__combined_var }}
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
Expand Down
4 changes: 2 additions & 2 deletions roles/sshd/templates/etc/ssh/Ubuntu26-sshd_config.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# {{ ansible_managed }}
# 2026101601
# 2026111301

# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
Expand Down Expand Up @@ -104,7 +104,7 @@ ClientAliveInterval {{ sshd__client_alive_interval }}
ClientAliveCountMax {{ sshd__client_alive_count_max }}
UseDNS {{ sshd__use_dns | bool | ternary('yes', 'no') }}
#PidFile /run/sshd.pid
#MaxStartups 10:30:100
MaxStartups {{ sshd__max_startups__combined_var }}
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
Expand Down
Loading