This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

SSH

Setup ssh

Normal setup installs fail2ban, installs the trusted user CA, creates missing RSA, ECDSA and Ed25519 host keys, discovers and signs them, and invokes devsec.hardening.ssh_hardening with those signed certificate paths. The upstream role retains its native tasks and restart handler.

Key creation preserves existing private keys. ssh_host_keys_dir defaults to /etc/ssh and controls creation, discovery and upstream hardening. New RSA keys use ssh_host_rsa_key_size (4096 bits by default), matching the hardening policy before certificates are issued. The ssh_host_keys tag selects key creation alone; upstream hardening retains its existing key-strength policy.

The ssh_hardening_match_user default supplies Match User ansible with AllowTcpForwarding remote, PermitListen none, and AllowStreamLocalForwarding remote through the upstream template. Set ssh_hardening_match_user: [] to omit this match, or replace the list with custom entries. The wrapper explicitly maps this variable to upstream ssh_server_match_user; use the wrapper variable for inventory overrides.

Select normal SSH setup through the owning deployment’s ssh tag and an explicit host limit, for example:

bazel run //infra/ingress/ansible:ansible -- \
  --limit host1.ingress.alwaldend.com --tags ssh

This uses the owner’s authentication and runs the full SSH setup described above, including the native restart handler. The ssh_hardening tag alone skips the required certificate discovery. The upstream template validates its candidate during apply; --check --diff previews do not validate the proposed configuration. The scanner does not invoke this role or change server policy.

Replacing a signed host certificate notifies a role-owned handler. It runs sshd -t before reloading the daemon so new connections receive the renewed certificate even when the hardening configuration is unchanged. The service name follows sshd_service_name when provided, otherwise the OS-family default. Existing sessions survive the reload. This is deployment-time renewal; the role does not install a certificate renewal timer.

1 - Defaults

Defaults for ssh
ssh_hardening_enabled: true
ssh_host_keys_dir: /etc/ssh
ssh_host_rsa_key_size: 4096
# Set to [] to omit the shared Match User default.
ssh_hardening_match_user:
  - user: ansible
    rules:
      - AllowTcpForwarding remote
      - PermitListen none
      - AllowStreamLocalForwarding remote
ssh_vault_mount: ssh/servers
ssh_vault_role: "{{ undefined }}"
ssh_sign_ignore_errors: false
ssh_valid_principals: []