summaryrefslogtreecommitdiff
path: root/manifests/daemon.pp
blob: 9fa75daca8cea106c18e48d2d5943e1ccc3decec (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
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
# tor::daemon
class tor::daemon inherits tor {

  # config variables
  $data_dir = '/var/tor'
  $config_file = '/etc/tor/torrc'
  $spool_dir = '/var/lib/puppet/modules/tor/torrc.d'

  # packages, user, group
  group { 'debian-tor':
    ensure    => present,
    allowdupe => false,
  }

  Package[ 'tor', 'torsocks' ] {
    require => File[$data_dir],
  }

  user { 'debian-tor':
    allowdupe => false,
    comment   => 'tor user,,,',
    ensure    => present,
    home      => $data_dir,
    shell     => '/bin/sh',
    gid       => 'debian-tor',
    require   => Group['debian-tor'], 
  }

  # directories
  file { "${data_dir}":
    ensure  => directory,
    mode    => 0755,
    owner   => 'debian-tor',
    group   => 'debian-tor',
    require => User['debian-tor'],
  }

  file { '/etc/tor':
    ensure  => directory,
    mode    => 0755,
    owner   => 'debian-tor',
    group   => 'debian-tor',
    require => User['debian-tor'],
  }

  file {"${spool_dir}":
    ensure => directory,
    force => true,
    owner => 'debian-tor', group => 'debian-tor', mode => 0755, 
  }

  # tor configuration file
  concatenated_file { "${config_file}":
    dir    => $spool_dir,
    header => "${spool_dir}/00.header",
    mode   => 0600,
    notify => Service['tor'],
    owner => 'debian-tor', group => 'debian-tor', 
  }

  # config file headers
  file { "${spool_dir}/00.header":
    content => template('tor/torrc.header.erb'),
    require => File["${spool_dir}"],
    notify  => Exec["concat_${config_file}"],
    ensure  => present,
    owner => 'debian-tor', group => 'debian-tor', mode => 0644, 
  }

  # global configurations
  define tor::daemon::global_opts( $log_rules = [ 'notice file /var/log/tor/notices.log' ],
                           $ensure = present ) {
    file { "${spool_dir}/01.global":
      content => template('tor/torrc.global.erb'),
      require => File["${spool_dir}"],
      notify  => Exec["concat_${config_file}"],
      ensure  => $ensure,
      owner => 'debian-tor', group => 'debian-tor', mode => 0644, 
    }
  }

  # socks definition
  define tor::daemon::socks( $socks_port = 0,
                     $socks_listen_addresses = [],
                     $socks_policies = [] ) {
    file { "${spool_dir}/02.socks":
      content => template('tor/torrc.socks.erb'),
      require => File["${spool_dir}"],
      notify  => Exec["concat_${config_file}"],
      ensure  => $ensure,
      owner => 'debian-tor', group => 'debian-tor', mode => 0644, 
    }
  }

  # relay definition
  define tor::daemon::relay( $port                  = 0,
                     $listen_addresses      = [],
                     $relay_bandwidth_rate  = 0,  # KB/s, 0 for no limit.
                     $relay_bandwidth_burst = 0,  # KB/s, 0 for no limit.
                     $accounting_max        = 0,  # GB, 0 for no limit.
                     $accounting_start      = [],
                     $contact_info          = '',
                     $my_family             = '', # TODO: autofill with other relays
                     $bridge_reay           = 0,
                     $ensure                = present ) {
    $nickname = $name
    $address = $hostname

    file { "${spool_dir}/03.relay":
      content => template('tor/torrc.relay.erb'),
      require => File["${spool_dir}"],
      notify  => Exec["concat_${config_file}"],
      ensure  => $ensure,
      owner => 'debian-tor', group => 'debian-tor', mode => 0644, 
    }
  } 

  # control definition
  define tor::daemon::control( $port                    = 0,
                       $hashed_control_password = '',
                       $ensure                  = present ) {
    file { "${spool_dir}/04.control":
      content => template('tor/torrc.control.erb'),
      require => File["${spool_dir}"],
      notify  => Exec["concat_${config_file}"],
      ensure  => $ensure,
      owner => 'debian-tor', group => 'debian-tor', mode => 0600, 
    }
  } 

  # hidden services definition
  define tor::daemon::hidden_service( $ports = [],
                              $ensure = present ) {
    file { "${spool_dir}/05.hidden_service.${name}":
      content => template('tor/torrc.hidden_service.erb'),
      require => File["${spool_dir}"],
      notify  => Exec["concat_${config_file}"],
      ensure  => $ensure,
      owner => 'debian-tor', group => 'debian-tor', mode => 0644, 
    }
  } 
  
  # directory advertising
  define tor::daemon::directory ( $port = 0,
                          $listen_addresses = [],
                          $port_front_page = '',
                          $ensure = present ) {
    file { "${spool_dir}/06.directory":
      content => template('tor/torrc.directory.erb'),
      require => [ File["${spool_dir}"], File['/etc/tor/tor-exit-notice.html'] ],
      notify  => Exec["concat_${config_file}"],
      ensure  => $ensure,
      owner => 'debian-tor', group => 'debian-tor', mode => 0644, 
    }
    file { '/etc/tor/tor-exit-notice.html':
      source  => "puppet://$server/modules/tor/tor-exit-notice",
      require => File['/etc/tor'],
      ensure  => $ensure,
      owner => 'debian-tor', group => 'debian-tor', mode => 0644, 
    }
  } 

  # exit policies
  define tor::daemon::exit_policy( $accept = [],
                           $reject = [],
                           $ensure = present ) {
    file { "${spool_dir}/07.exit_policy.${name}":
      content => template('tor/torrc.exit_policy.erb'),
      require => File["${spool_dir}"],
      notify  => Exec["concat_${config_file}"],
      ensure  => $ensure,
      owner => 'debian-tor', group => 'debian-tor', mode => 0644, 
    }
  } 
}