Defined Type: autossh::tunnel

Defined in:
manifests/tunnel.pp

Overview

Class: autossh::tunnel

Defines an ssh tunnel resource. This class is run on the node that ‘initiates’ the ssh tunnel and

* creates the 'autossh' configuration file
* creates a system 'init' script.
* starts/restarts the service as required.

Parameters

$user: The user account to use to run the ssh tunnel $tunnel_type: The tunnel direction. (forward –> local port to

remote port, backward = remote port --> local port)

$port: The local port to be used for the tunnel. $hostport: The remote port to be used for the tunnel. $remote_ssh_host: The remote host to connect to. $remote_ssh_port: The remote ssh port to connect to. $monitor_port: Used by autossh to test the state of connections

via an echo.

$enable: Enable/Disable this service. $pubkey: The public key to be used for this service.

(installed on remote host via exported resource)

$enable_host_ssh_config: enable host specific configs $ssh_reuse_established_connections = $enable_ssh_reuse: default enable

reuse of already established ssh connections, if any.
Requires openssh > 5.5.

$ssh_enable_compression = enable/disable compression $ssh_ciphers = set chiper path from lest to most expensive ssh_stricthostkeychecking = enable/disable strict host key checking $ssh_tcpkeepalives: enable/disable tcp keepalives

Variables

Examples

autossh::tunnel  { 'testtunnel':
  user            => 'autossh',
  tunnel_type     => 'backward',
  port            => '25',
  hostport        => '25',
  remote_ssh_host => 'server1.foo.bar',
  remort_ssh_port => '22',
  monitor_port    => '0',
  enable          => true,
  pubkey          => 'ssh-dss IOUEOWDOQ...'
}

Authors

Jason Ball <jason@ball.net> Aimon Bustardo – forked from github.com/aimonb/puppet-autossh.git

Copyright 2014 Jason Ball.

Parameters:

  • port (Any)
  • hostport (Any)
  • remote_ssh_host (Any)
  • remote_ssh_user (Any) (defaults to: $autossh::params::remote_ssh_user)
  • bind (Any) (defaults to: $autossh::params::bind)
  • forward_host (Any) (defaults to: $autossh::params::forward_host)
  • user (Any) (defaults to: $autossh::params::user)
  • tunnel_type (Any) (defaults to: $autossh::params::tunnel_type)
  • remote_ssh_port (Any) (defaults to: $autossh::params::remote_ssh_port)
  • monitor_port (Any) (defaults to: $autossh::params::monitor_port)
  • enable (Any) (defaults to: $autossh::params::enable)
  • pubkey (Any) (defaults to: $autossh::params::pubkey)
  • enable_host_ssh_config (Any) (defaults to: false)
  • ssh_reuse_established_connections (Any) (defaults to: $autossh::params::ssh_reuse_established_connections)
  • ssh_enable_compression (Any) (defaults to: $autossh::params::ssh_enable_compression)
  • ssh_ciphers (Any) (defaults to: $autossh::params::ssh_ciphers)
  • ssh_stricthostkeychecking (Any) (defaults to: $autossh::params::ssh_stricthostkeychecking)
  • ssh_tcpkeepalives (Any) (defaults to: $autossh::params::ssh_tcpkeepalives)


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
# File 'manifests/tunnel.pp', line 58

define autossh::tunnel(
  $port,
  $hostport,
  $remote_ssh_host,
  $remote_ssh_user  = $autossh::params::remote_ssh_user,
  $bind             = $autossh::params::bind,
  $forward_host     = $autossh::params::forward_host,
  $user             = $autossh::params::user,
  $tunnel_type      = $autossh::params::tunnel_type,
  $remote_ssh_port  = $autossh::params::remote_ssh_port,
  $monitor_port     = $autossh::params::monitor_port,
  $enable           = $autossh::params::enable,
  $pubkey           = $autossh::params::pubkey,
  $enable_host_ssh_config = false,
  $ssh_reuse_established_connections =
    $autossh::params::ssh_reuse_established_connections,
  $ssh_enable_compression = $autossh::params::ssh_enable_compression,
  $ssh_ciphers            = $autossh::params::ssh_ciphers,
  $ssh_stricthostkeychecking = $autossh::params::ssh_stricthostkeychecking,
  $ssh_tcpkeepalives = $autossh::params::ssh_tcpkeepalives,
){
  $tun_name     = $title
  $tunnel_args  = $tunnel_type ? {
    'reverse' => "-M ${monitor_port} -f -N -R",
    'forward' => "-M ${monitor_port} -f -N -L"
  }

  file{"autossh-${tun_name}_conf":
    ensure  => 'present',
    path    => "/etc/autossh/autossh-${tun_name}.conf",
    mode    => '0660',
    owner   => $user,
    group   => $user,
    content => template('autossh/autossh.conf.erb'),
  }

  #
  # User sysV or systemd init depending on the OS
  #
  case $::osfamily {
    /RedHat/: {
      case $::operatingsystemmajrelease {
        /5|6/: {
          file{"autossh-${tun_name}-init":
            ensure  => 'present',
            path    => "/etc/init.d/autossh-${tun_name}",
            mode    => '0750',
            owner   => 'root',
            group   => 'root',
            content => template('autossh/autossh.init.sysv.erb'),
            notify  => Service["autossh-${tun_name}"],
          }
        } # case rhel 5|6

        /7/: {
          file{"systemd-service-${tun_name}":
            ensure  => 'present',
            path    => "/etc/systemd/system/autossh-${tun_name}.service",
            mode    => '0750',
            owner   => 'root',
            group   => 'root',
            content => template('autossh/autossh.service.erb'),
            notify  => Service["autossh-${tun_name}"],
          }
        }

        default: {
        }
      }
    } # case Redhat

    default: {
    } # default
  } # end case osfamily

  service{"autossh-${tun_name}":
    ensure  =>  $enable,
    enable  =>  $enable,
    require => Package['autossh']
  }

  ## Define remote endpoints
  @@autossh::tunnel_endpoint {
    "tunnel-enpoint-${remote_ssh_host}-${port}":
    user         => $user,
    port         => $hostport,
    monitor_port => $monitor_port,
    host         => $remote_ssh_host,
    pubkey       => $pubkey,
    enable       => $enable,
  }

  ##
  ## Host Settings -- only the first declaraion applies...
  ## as the filter is host specific, not host_port match...
  ##
  if $enable_host_ssh_config {
    if ! defined(Concat::Fragment["home_${user}_ssh_config_${remote_ssh_host}"])
    {
      concat::fragment { "home_${user}_ssh_config_${remote_ssh_host}":
        target  => "/home/${user}/.ssh/config",
        content => template('autossh/config.erb'),
        order   => 1,
      }
    }
  }
}