Puppet Class: ssh::server

Defined in:
modules/ssh/manifests/server.pp

Summary

manage the ssh server daemon and config

Overview

Parameters:

  • listen_ports (Array[Stdlib::Port]) (defaults to: [22])

    the ports to listen on

  • listen_addresses (Array[Stdlib::IP::Address]) (defaults to: [])

    an array of addresses to listen on

  • permit_root (Ssh::Config::PermitRootLogin) (defaults to: true)

    if true allow root logins

  • authorized_keys_file (Array[Stdlib::Unixpath]) (defaults to: ['/etc/ssh/userkeys/%u', '/etc/ssh/userkeys/%u.d/cumin'])

    space seperated list of authorized keys files

  • authorized_keys_command (Optional[Stdlib::Unixpath]) (defaults to: undef)

    command to run for authorized keys

  • authorized_keys_command_user (Optional[String[1]]) (defaults to: undef)

    user to run authorized_keys_command as

  • disable_nist_kex (Boolean) (defaults to: true)

    Allow uses to temporarily opt out of nist kex disabling

  • explicit_macs (Boolean) (defaults to: true)

    Allow users to opt out of more secure MACs

  • enable_hba (Boolean) (defaults to: false)

    enable host based authentication

  • enable_kerberos (Boolean) (defaults to: false)

    enable kerberos

  • disable_agent_forwarding (Boolean) (defaults to: true)

    disable agent forwarding

  • max_sessions (Optional[Integer]) (defaults to: undef)

    allow users to override the maximum number ops sessions

  • max_startups (Optional[String[1]]) (defaults to: undef)

    allow users to override the maximum number ops startups

  • gateway_ports (Boolean) (defaults to: false)

    if true set sshd_config GatewayPorts to yes

  • accept_env (Array[String[1]]) (defaults to: ['LANG', 'LC_*'])

    array of elements for AcceptEnv config

  • match_config (Array[Ssh::Match]) (defaults to: [])

    a list of additional configs to apply to specific matches. see Ssh::Match for the data structure

  • enabled_key_types (Array[Ssh::KeyType]) (defaults to: ['rsa', 'ecdsa', 'ed25519'])

    server key types to enable, if not provided via $host_keys

  • puppetserver_ca_host_certs (Boolean) (defaults to: false)

    if true, puppetserver ca signed host certs will be made available

  • trusted_user_ca_keys (Array[String[1]]) (defaults to: [])

    array of trusted user ca keys

  • host_keys (Ssh::HostKeys) (defaults to: {})

    array of ssh host key structs

  • host_certs (Ssh::HostCerts) (defaults to: {})

    array of ssh host cert structs

  • authorized_principals_file (Optional[Stdlib::Unixpath]) (defaults to: undef)

    path name to file



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'modules/ssh/manifests/server.pp', line 25

class ssh::server (
    Array[Stdlib::Port]          $listen_ports                 = [22],
    Array[Stdlib::IP::Address]   $listen_addresses             = [],
    Ssh::Config::PermitRootLogin $permit_root                  = true,
    Array[Stdlib::Unixpath]      $authorized_keys_file         = ['/etc/ssh/userkeys/%u', '/etc/ssh/userkeys/%u.d/cumin'],
    Optional[Stdlib::Unixpath]   $authorized_keys_command      = undef,
    Optional[String[1]]          $authorized_keys_command_user = undef,
    Boolean                      $disable_nist_kex             = true,
    Boolean                      $explicit_macs                = true,
    Boolean                      $enable_hba                   = false,
    Boolean                      $enable_kerberos              = false,
    Boolean                      $disable_agent_forwarding     = true,
    Optional[Integer]            $max_sessions                 = undef,
    Optional[String[1]]          $max_startups                 = undef,
    Boolean                      $gateway_ports                = false,
    Array[String[1]]             $accept_env                   = ['LANG', 'LC_*'],
    Array[Ssh::Match]            $match_config                 = [],
    Array[Ssh::KeyType]          $enabled_key_types            = ['rsa', 'ecdsa', 'ed25519'],
    Boolean                      $puppetserver_ca_host_certs   = false,
    Array[String[1]]             $trusted_user_ca_keys         = [],
    Ssh::HostKeys                $host_keys                    = {},
    Ssh::HostCerts               $host_certs                   = {},
    Optional[Stdlib::Unixpath]   $authorized_principals_file   = undef,
) {
    if $puppetserver_ca_host_certs and length($host_certs) > 0 {
        fail('Specify only one of $puppetserver_ca_host_certs or $host_certs')
    }

    $_permit_root = $permit_root ? {
        String  => $permit_root,
        false   => 'no',
        default => 'yes',
    }

    if length($host_keys) > 0 {
        $key_types = keys($host_keys)
    } else {
        $key_types = $enabled_key_types
    }

    # Starting with Bookworm ChallengeResponseAuthentication is a deprecated
    # alias for KbdInteractiveAuthentication, in older Debian releases
    # KbdInteractiveAuthentication is derived from the config setting for
    # ChallengeResponseAuthentication, so only set it instead.
    if debian::codename::ge('bookworm') {
        $disable_keyboard = 'KbdInteractiveAuthentication no'
    } else {
        $disable_keyboard = 'ChallengeResponseAuthentication no'
    }

    # we use the legacy facts here specificaly because we override them in
    # modules/base/lib/facter/interface_primary.rb
    # Although the networking.ip fact now points to a sensible fact
    # networking.ip6 still points to IMO the wrong address.
    # related: https://tickets.puppetlabs.com/browse/FACT-2907
    # related: https://tickets.puppetlabs.com/browse/FACT-2843
    $aliases = [
        $facts['networking']['hostname'],
        $facts['ipaddress'],
        $facts['ipaddress6'],
    ].filter |$x| { $x =~ NotUndef }

    if $puppetserver_ca_host_certs {
        if ssh::ssh_ca_key_available() {
            $ssh_ca_key_available = true
            $enabled_key_types.each |Ssh::KeyType $type| {
                ssh::server::ca_signed_hostkey { "/etc/ssh/ssh_host_${type}_key-cert.pub":
                    hosts  => [$facts['networking']['fqdn']] + $aliases,
                    type   => $type,
                    notify => Service['ssh'],
                }
            }
        } else {
            $ssh_ca_key_available = false
            warning('ssh::server: puppetserver_ca_host_certs is true but no CA keys are available')
        }
    }

    if length($trusted_user_ca_keys) > 0 {
        file { '/etc/ssh/trusted_user_ca_keys.pub':
            ensure  => file,
            owner   => 'root',
            group   => 'root',
            mode    => '0444',
            content => "${join($trusted_user_ca_keys, "\n")}\n",
        }
    }

    package { 'openssh-server':
        ensure => present,
    }

    service { 'ssh':
        ensure    => running,
        subscribe => File['/etc/ssh/sshd_config'],
    }

    profile::auto_restarts::service { 'ssh': }

    file { '/etc/ssh/userkeys':
        ensure  => directory,
        owner   => 'root',
        group   => 'root',
        mode    => '0444',
        recurse => true,
        purge   => true,
    }

    # The privilege separation dir for sshd must exist for sshd's
    # config validation command to complete successfully
    file { '/run/sshd':
        ensure => directory,
        owner  => 'root',
        group  => 'root',
        mode   => '0755',
    }

    file { '/etc/ssh/sshd_config':
        ensure       => file,
        owner        => 'root',
        group        => 'root',
        mode         => '0444',
        content      => template('ssh/sshd_config.erb'),
        validate_cmd => '/usr/sbin/sshd -t -f %',
        require      => Package['openssh-server'],
    }

    if wmflib::have_puppetdb() {
        @@sshkey { $facts['networking']['fqdn']:
            ensure       => present,
            type         => 'ecdsa-sha2-nistp256',
            key          => $facts['ssh']['ecdsa']['key'],
            host_aliases => $aliases,
        }
    }

    $host_keys.each |$type, $key| {
        file { "/etc/ssh/ssh_host_${type}_key":
            ensure  => file,
            owner   => 'root',
            group   => 'root',
            mode    => '0400',
            content => "${key}\n",
        }
    }

    if length($host_certs) > 0 {
        if sort(keys($host_certs)) != sort($key_types) {
                fail('Keys for $host_certs and $key_types do not match!')
        }
        $host_certs.each |$type, $key| {
            file { "/etc/ssh/ssh_host_${type}_key-cert.pub":
                ensure  => file,
                owner   => 'root',
                group   => 'root',
                mode    => '0440',
                content => "${key}\n",
            }
        }
    }
}