skriptfabrik.sshd

Ansible角色: sshd

Ansible Galaxy Ansible Role

描述

此角色提供安全的ssh客户端和ssh服务器配置。旨在符合DevSec SSH基线
该角色是arillso.sshd的一个分支。

安装

ansible-galaxy collection install community.crypto
ansible-galaxy install skriptfabrik.sshd

要求

角色变量

ssh_ipv6_enable

如果需要IPv6则为true

ssh_ipv6_enable: '{{ network_ipv6_enable | default(false) }}' # sshd + ssh

ssh_server_enabled

如果ssh服务器(sshd)应该启动并启用则为true

ssh_server_enabled: true # sshd

ssh_use_dns

如果需要DNS解析,查找远程主机名称,默认从6.8版本开始为false,见: http://www.openssh.com/txt/release-6.8

ssh_use_dns: false # sshd

ssh_compression

如果需要压缩则为true或指定值

ssh_compression: false # sshd

ssh_hardening

为哪些组件(客户端和服务器)生成配置。运行没有SSH服务器的客户端时可能有用。

ssh_client_hardening: true # ssh
ssh_server_hardening: true # sshd

ssh_client_password_login

如果为true,则允许使用密码登录

ssh_client_password_login: false # ssh
ssh_server_password_login: false # sshd

ssh_server_ports

ssh服务器应监听的端口

ssh_server_ports: ['22'] # sshd

ssh_client_port

ssh客户端应连接的端口

ssh_client_port: '22' # ssh

ssh_listen_to

ssh服务器应监听的一个或多个IP地址。默认为空,但出于安全原因应配置!

ssh_listen_to: ['0.0.0.0'] # sshd

ssh_host_key_files

启动sshd时查找的主机密钥。

ssh_host_key_files: [] # sshd
#  - path: "{{ sshd_config_path }}/ssh_host_rsa_key"
#    private_key: |
#      xxxxxxxxxxxxx
#      xxxxxxxxxxxxx
#      xxxxxxxxxxxxx
#    public_key: |
#      xxxxxxxxxxxxx
#      xxxxxxxxxxxxx
#      xxxxxxxxxxxxx
#    size: 8192
#    type: rsa

ssh_force_create_host_key_files

强制创建主机密钥文件。

ssh_force_create_host_key_files: false # sshd

ssh_max_auth_retries

指定每个连接允许的最大身份验证尝试次数。一旦失败次数达到该值的一半,额外的失败将被记录。

ssh_max_auth_retries: 2

ssh_client_alive_interval

ssh_client_alive_interval: 300 # sshd

ssh_client_alive_count

ssh_client_alive_count: 3 # sshd

ssh_permit_tunnel

允许SSH隧道

ssh_permit_tunnel: false

ssh_remote_hosts

具有自定义选项的主机。# ssh

ssh_remote_hosts: []

# 示例

ssh_remote_hosts:
  - names: ['example.com', 'example2.com']
    options: ['Port 2222', 'ForwardAgent yes']
  - names: ['example3.com']
    options: ['StrictHostKeyChecking no']

ssh_allow_root_with_key

设置为 "without-password" 或 "yes" 来允许root登录

ssh_allow_root_with_key: 'no' # sshd

ssh_allow_tcp_forwarding

设置为false以禁用TCP转发。设置为true以允许TCP转发。

ssh_allow_tcp_forwarding: false # sshd

ssh_gateway_ports

设置为false以禁用将转发的端口绑定到非回环地址。设置为true以强制绑定到通配符地址。

设置为'clientspecified'以允许客户端指定绑定到哪个地址。

ssh_gateway_ports: false # sshd

ssh_allow_agent_forwarding

设置为false以禁用代理转发。设置为true以允许代理转发。

ssh_allow_agent_forwarding: false # sshd

ssh_pam_support

如果SSH支持PAM则为true

ssh_pam_support: true

ssh_use_pam

设置为false以禁用pam身份验证。

ssh_use_pam: false # sshd

ssh_google_auth

设置为false以禁用谷歌双因素认证

ssh_google_auth: false # sshd

ssh_pam_device

设置为false以禁用pam设备2FA输入

ssh_pam_device: false # sshd

ssh_gssapi_support

如果SSH支持GSSAPI则为true

ssh_gssapi_support: false

ssh_kerberos_support

如果SSH支持Kerberos则为true

ssh_kerberos_support: true

ssh_deny_users

如果指定,当用户名匹配其中一个模式时,登录将被拒绝。

ssh_deny_users: '' # sshd

ssh_allow_users

如果指定,仅允许登录与其中一个模式匹配的用户名。

ssh_allow_users: '' # sshd

ssh_deny_groups

如果指定,当用户的主组或附加组列表匹配其中一个模式时,登录将被拒绝。

ssh_deny_groups: '' # sshd

ssh_allow_groups

如果指定,仅允许登录与用户的主组或附加组列表匹配其中一个模式的用户。

ssh_allow_groups: '' # sshd

ssh_authorized_keys_file

更改包含可用于用户身份验证的公钥的默认文件。

ssh_authorized_keys_file: '' # sshd

ssh_trusted_user_ca_keys_file

指定包含受信任的证书颁发机构公钥的文件,用于签署用户证书。

ssh_trusted_user_ca_keys_file: '' # sshd

ssh_trusted_user_ca_keys

设置用于签署用户证书的受信任的证书颁发机构公钥。

ssh_trusted_user_ca_keys: [] # sshd

示例

ssh_trusted_user_ca_keys:
  - 'ssh-rsa ... comment1'
  - 'ssh-rsa ... comment2'

ssh_authorized_principals_file

指定包含被允许的主体的文件。仅在设置了ssh_trusted_user_ca_keys_file时使用。

ssh_authorized_principals_file: '' # sshd

示例

ssh_authorized_principals_file: '/etc/ssh/auth_principals/%u'

%h 被替换为被验证用户的主目录,%u被替换为该用户的用户名。扩展后,该路径视为绝对路径或相对于用户主目录的路径。

ssh_authorized_principals

包含文件路径和授权主体的哈希列表。仅在设置了ssh_authorized_principals_file时使用。

ssh_authorized_principals: [] # sshd

示例

ssh_authorized_principals:
  - {
      path: '/etc/ssh/auth_principals/root',
      principals: ['root'],
      owner: '{{ ssh_owner }}',
      group: '{{ ssh_group }}',
      directoryowner: '{{ ssh_owner }}',
      directorygroup: '{{ ssh_group}}',
    }
  - {
      path: '/etc/ssh/auth_principals/myuser',
      principals: ['masteradmin', 'webserver'],
    }

ssh_print_motd

设置为false以禁用打印欢迎信息(MOTD)

ssh_print_motd: false # sshd

ssh_print_last_log

设置为false以禁用显示最后登录信息

ssh_print_last_log: false # sshd

ssh_banner

设置为false以禁用在允许身份验证之前服务 /etc/ssh/banner.txt

ssh_banner: false # sshd

ssh_print_debian_banner

设置为false以禁用在初始协议握手期间泄露发行版版本信息

ssh_print_debian_banner: false # sshd (仅限Debian OS系列)

ssh_sftp_enabled

设置为true以启用sftp配置

ssh_sftp_enabled: '{{ sftp_enabled | default(false) }}'

ssh_sftp_chroot

设置为false以禁用sftp chroot

ssh_sftp_chroot: '{{ sftp_chroot | default(true) }}'

ssh_sftp_chroot_dir

更改默认的sftp chroot位置

ssh_sftp_chroot_dir: "{{ sftp_chroot_dir | default('/home/%u') }}"

如果为true,则允许SFTP的密码登录

ssh_server_sftp_password_login: false
ssh_server_sftp_password_login: true

ssh_client_roaming

启用实验性的客户端漫游

ssh_client_roaming: false

ssh_server_match_user

哈希列表(包含用户和规则),用于生成用户匹配的配置块。

ssh_server_match_user: false # sshd

ssh_server_match_group

哈希列表(包含组和规则),用于生成组匹配的配置块。

ssh_server_match_group: false # sshd

ssh_server_match_address

哈希列表(包含地址/子网和规则),用于生成地址匹配的配置块。

ssh_server_match_address: false # sshd

ssh_server_permit_environment_vars

ssh_server_permit_environment_vars: false

ssh_max_startups

最大并发未认证连接到SSH守护程序的数量

ssh_max_startups: '10:30:100' # sshd

ssh_ps53

ssh_ps53: 'yes'

ssh_ps59

ssh_ps59: 'sandbox'

ssh_macs

ssh_macs: []

ssh_ciphers

ssh_ciphers: []

ssh_kex

ssh_kex: []

ssh_macs_53_default

ssh_macs_53_default:
  - hmac-ripemd160
  - hmac-sha1

ssh_macs_59_default

ssh_macs_59_default:
  - hmac-sha2-512
  - hmac-sha2-256
  - hmac-ripemd160

ssh_macs_66_default

ssh_macs_66_default:
  - [email protected]
  - [email protected]
  - [email protected]
  - hmac-sha2-512
  - hmac-sha2-256

ssh_macs_76_default

ssh_macs_76_default:
  - [email protected]
  - [email protected]
  - [email protected]
  - hmac-sha2-512
  - hmac-sha2-256

ssh_ciphers_53_default

ssh_ciphers_53_default:
  - aes256-ctr
  - aes192-ctr
  - aes128-ctr

ssh_ciphers_66_default

ssh_ciphers_66_default:
  - [email protected]
  - [email protected]
  - [email protected]
  - aes256-ctr
  - aes192-ctr
  - aes128-ctr

ssh_kex_59_default

ssh_kex_59_default:
  - diffie-hellman-group-exchange-sha256

ssh_kex_66_default

ssh_kex_66_default:
  - [email protected]
  - diffie-hellman-group-exchange-sha256

ssh_custom_selinux_dir

存储ssh_password策略的目录

ssh_custom_selinux_dir: '/etc/selinux/local-policies'

sshd_moduli_file: '/etc/ssh/moduli'
sshd_moduli_minimum: 2048

ssh_challengeresponseauthentication

禁用挑战响应身份验证

ssh_challengeresponseauthentication: false

ssh_server_revoked_keys

一组ssh服务器永不接受的公钥列表

ssh_server_revoked_keys: []

ssh_hardening_enabled

设置为false以将角色变为无操作。使用 Ansible角色依赖机制时很有用。

ssh_hardening_enabled: true

ssh_custom_options

SSH客户端配置文件的自定义选项

ssh_custom_options: []

sshd_custom_options

SSH守护程序配置文件的自定义选项

sshd_custom_options: []

依赖

示例剧本

- hosts: all
  roles:
    - skriptfabrik.sshd

作者

许可证

该项目采用MIT许可证。

版权

(c) 2022, skriptfabrik GmbH

关于项目

This role provides secure ssh-client and ssh-server configurations. It is intended to be compliant with the DevSec SSH Baseline.

安装
ansible-galaxy install skriptfabrik.sshd
许可证
mit
下载
2.8k