aboutsummaryrefslogtreecommitdiff
path: root/manifests/subsystems/ssh.pp
blob: f15931d54f8a47936332da3e59e6c159f6339f86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
# Base class
class ssh_folder {
  if !defined(File["${home}/.ssh"]) {
    file { "${home}/.ssh":
      ensure  => directory,
      owner   => $owner,
      group   => $group,
      mode    => 0700,
    }
  }
}

# Manage ssh config for a particular user
define ssh_config($owner, $home = '/home/$owner', $ssh_localhost_auth = false) {
  include ssh_folder

  file { "${home}/.ssh/config":
    ensure  => present,
    owner   => $owner,
    group   => $group,
    mode    => 0600,
    require => File["${home}/.ssh"],
  }

  # The NoHostAuthenticationForLocalhost ssh option might be useful
  # for automated deployment environments so your ikiwiki user doesn't
  # get stuck with the fingerprint confirmation prompt when pushing
  # content via ssh in the first time it runs.
  line { 'NoHostAuthenticationForLocalhost-${owner}':
    file   => "${home}/.ssh/config",
    line   => "NoHostAuthenticationForLocalhost yes",
    ensure => $ssh_localhost_auth ? {
      'auto'        => present,
      'fingerprint' => absent,
      default       => absent,
    },
  }
}

# Manage known_hosts for a particular user
define ssh_known_host($owner, $home = '/home/$owner', $ssh_localhost_auth = false) {
  include ssh_folder

  file { "${home}/.ssh/known_hosts":
    ensure  => present,
    owner   => $owner,
    group   => $group,
    mode    => 0600,
    require => File["${home}/.ssh"],
  }

  # You can choose to include the host's fingeprints
  # directly into the known_hosts file.
  if $::sshrsakey != '' {
    line { 'known_hosts-localhost-rsa-${owner}':
      file   => "${home}/.ssh/known_hosts",
      line   => "localhost ssh-rsa ${::sshrsakey}",
      ensure => $ssh_localhost_auth ? {
        'fingerprint' => present,
        'auto'        => undef,
        default       => undef,
      },
    }
  }

  if $::sshdsakey != '' {
    line { 'known_hosts-localhost-dsa-${owner}':
      file   => "${home}/.ssh/known_hosts",
      line   => "localhost ssh-dss ${::sshdsakey}",
      ensure => $ssh_localhost_auth ? {
        'fingerprint' => present,
        'auto'        => undef,
        default       => undef,
      },
    }
  }

  if $::sshecdsakey != '' {
    line { 'known_hosts-localhost-ecdsa-${owner}':
      file   => "${home}/.ssh/known_hosts",
      line   => "localhost ecdsa-sha2-nistp256 ${::sshedsakey}",
      ensure => $ssh_localhost_auth ? {
        'fingerprint' => present,
        'auto'        => undef,
        default       => undef,
      },
    }
  }
}

define ssh_create_key($owner, $group, $keyfile = 'id_rsa', $home = '/home/$owner') {
  include ssh_folder

  exec { "ssh-keygen-${owner}":
    command => "ssh-keygen -t rsa -P '' -f ${home}/.ssh/${keyfile}",
    creates => "${home}/.ssh/${keyfile}",
    user    => $owner,
    group   => $group,
    require => File["${home}/.ssh"],
  }
}