]> git.donarmstrong.com Git - dsa-puppet.git/blob - modules/stunnel4/manifests/init.pp
And stunnel client support
[dsa-puppet.git] / modules / stunnel4 / manifests / init.pp
1 class stunnel4 {
2     define stunnel_generic($client, $verify, $cafile, $crlfile=false, $accept, $connect, $local=false) {
3         file {
4             "/etc/stunnel/puppet-${name}.conf":
5                 content => template("stunnel4/stunnel.conf.erb"),
6                 notify  => Exec['restart_stunnel'],
7                 ;
8         }
9     }
10
11     # define an stunnel listener, listening for SSL connections on $accept,
12     # connecting to plaintext service $connect using local source address $local
13     #
14     # unfortunately stunnel is really bad about verifying its peer,
15     # all we can be certain of is that they are signed by our CA,
16     # not who they are.  So do not use in places where the identity of
17     # the caller is important.  Use dsa-portforwarder for that.
18     define stunnel_server($accept, $connect, $local = "127.0.0.1") {
19         stunnel_generic {
20             "${name}":
21                 client => false,
22                 verify => 2,
23                 cafile => "/etc/exim4/ssl/ca.crt",
24                 crlfile => "/etc/exim4/ssl/crl.crt",
25                 accept => "${accept}",
26                 connect => "${connect}",
27                 ;
28         }
29         @ferm::rule {
30             "stunnel-${name}":
31                 description => "stunnel ${name}",
32                 rule => "&TCP_UDP_SERVICE(${accept})",
33                 domain => "(ip ip6)",
34                 ;
35         }
36     }
37     define stunnel_client($accept, $connecthost, $connectport) {
38         file {
39             "/etc/stunnel/puppet-${name}-peer.pem":
40                 # source  => "puppet:///modules/exim/certs/${connecthost}.crt",
41                 content => generate("/bin/cat", "/etc/puppet/modules/exim/files/certs/${connecthost}.crt",
42                                                 "/etc/puppet/modules/exim/files/certs/ca.crt"),
43                 notify  => Exec['restart_stunnel'],
44                 ;
45         }
46         stunnel_generic {
47             "${name}":
48                 client => true,
49                 verify => 3,
50                 cafile => "/etc/stunnel/puppet-${name}-peer.pem",
51                 accept => "${accept}",
52                 connect => "${connecthost}:${connectport}",
53                 require => [ File["/etc/stunnel/puppet-${name}-peer.pem"] ],
54                 ;
55         }
56     }
57
58
59     package {
60         "stunnel4": ensure => installed;
61     }
62
63     file {
64         "/etc/stunnel/stunnel.conf":
65             ensure => absent,
66             ;
67     }
68
69     exec {
70         "enable_stunnel4":
71                 command => "sed -i -e 's/^ENABLED=/#&/; \$a ENABLED=1 # added by puppet' /etc/default/stunnel4",
72                 unless => "grep -q '^ENABLED=1' /etc/default/stunnel4",
73                 require => [ Package['stunnel4'] ],
74                 ;
75         "restart_stunnel":
76                 command => "env -i /etc/init.d/stunnel4 restart",
77                 require => [ File['/etc/stunnel/stunnel.conf'], Exec['enable_stunnel4'], Package['stunnel4'] ],
78                 refreshonly => true,
79                 ;
80     }
81 }
82
83 # vim:set et:
84 # vim:set sts=4 ts=4:
85 # vim:set shiftwidth=4: