Puppet Class: weston::vnc_server

Inherits:
weston
Inherited by:
weston::vnc_server::export_novnc
Defined in:
manifests/vnc_server.pp

Summary

Setup weston VNC sessions

Overview

Parameters:

  • manage_vnc_start_script (Boolean) (defaults to: true)

    Do we manage the start script?

  • manage_vnc_options_file (Boolean) (defaults to: true)

    Do we manage the vnc options file?

  • manage_vnc_users_file (Boolean) (defaults to: true)

    Do we manage the vnc users file?

  • manage_vnc_polkit_file (Boolean) (defaults to: true)

    Do we manage the vnc polkit file?

  • vnc_start_script (Stdlib::Absolutepath) (defaults to: '/usr/libexec/weston-vnc')

    The script that starts weston in VNC mode

  • vnc_options_file (Stdlib::Absolutepath) (defaults to: '/etc/xdg/weston/vncserver.opts')

    An environment file you can use to inject options

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

    Extra options to set on the VNC server (ie [‘–address=::1’, ‘–disable-transport-layer-security’])

  • vnc_users_file (Stdlib::Absolutepath) (defaults to: '/etc/xdg/weston/vncserver.users')

    A list of which users are using which VNC ports

  • vnc_start_script_mode (String) (defaults to: '0755')

    This should have world exec as it runs as your VNC user

  • vnc_options_file_mode (String) (defaults to: '0644')

    This should have world read so your VNC user can look at it

  • vnc_users_file_mode (String) (defaults to: '0644')

    This should have world read so your VNC user can look at it

  • manage_vnc_services (Boolean) (defaults to: true)

    Should this module manage the VNC server services

  • default_vnc_service_ensure (Optional[Enum['running', 'stopped']]) (defaults to: undef)

    What should the VNC service ensure be by default? NULL works for “no preference”

  • default_vnc_service_enable (Optional[Boolean]) (defaults to: undef)

    What should the VNC service enable be by default? NULL works for “no preference”

  • manage_systemd_unit_file (Boolean) (defaults to: true)

    Should this module setup the systemd template unit

  • systemd_template_startswith (String) (defaults to: 'weston-vncserver')

    What is the ‘unit name’ of the service

  • systemd_template_endswith (String) (defaults to: '.service')

    This should always be ‘.service` unless you’re up to something weird

  • vnc_polkit_file (Stdlib::Absolutepath) (defaults to: '/etc/polkit-1/rules.d/25-puppet-weston-vnc_server.rules')

    A policy kit file you can use to let users restart their own sessions via systemctl –system

  • vnc_polkit_file_mode (String) (defaults to: '0644')

    This should have world read so unpriviledged polkit can check it

  • default_user_can_control_service (Boolean) (defaults to: false)

    Should this module configure polkit so the VNC user can control the system service by default?

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

    Extra users who will automatically be granted polkit rights to the system service by default

  • vnc_sessions (Hash[String, Hash[Enum['displaynumber', 'user_can_control_service', 'comment', 'ensure', 'enable', 'extra_users_can_control_service'], Variant[Array[String], String, Integer, Boolean, Undef]]]) (defaults to: {})

    A hash of VNC servers to setup Format: weston::vnc_server::vnc_sessions:

    userA:
      comment: Sometimes you've gotta write it down
      displaynumber: 1
      ensure: running
      enable: true
      user_can_control_service: true
      extra_users_can_control_service:
        - userB
    userB:
      displaynumber: 5902
      ensure: NULL
      enable: false
      user_can_control_service: false
    


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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'manifests/vnc_server.pp', line 70

class weston::vnc_server (
  Boolean $manage_vnc_start_script = true,
  Stdlib::Absolutepath $vnc_start_script = '/usr/libexec/weston-vnc',
  String $vnc_start_script_mode = '0755',
  Boolean $manage_vnc_options_file = true,
  Stdlib::Absolutepath $vnc_options_file = '/etc/xdg/weston/vncserver.opts',
  String $vnc_options_file_mode = '0644',
  Array[String[1]] $vnc_server_options = [],
  Boolean $manage_vnc_users_file = true,
  Stdlib::Absolutepath $vnc_users_file = '/etc/xdg/weston/vncserver.users',
  String $vnc_users_file_mode = '0644',

  Boolean $manage_systemd_unit_file = true,
  String $systemd_template_startswith = 'weston-vncserver',
  String $systemd_template_endswith = '.service',

  Boolean $manage_vnc_services = true,
  Optional[Enum['running', 'stopped']] $default_vnc_service_ensure = undef,
  Optional[Boolean] $default_vnc_service_enable = undef,

  Boolean $manage_vnc_polkit_file = true,
  Stdlib::Absolutepath $vnc_polkit_file = '/etc/polkit-1/rules.d/25-puppet-weston-vnc_server.rules',
  String $vnc_polkit_file_mode = '0644',
  Boolean $default_user_can_control_service = false,
  Array[String[1]] $default_extra_users_can_control_service = [],

  Hash[String, Hash[Enum['displaynumber', 'user_can_control_service', 'comment', 'ensure', 'enable', 'extra_users_can_control_service'], Variant[Array[String], String, Integer, Boolean, Undef]]] $vnc_sessions = {},
) inherits weston {
  if $manage_vnc_start_script {
    file { $vnc_start_script:
      ensure => 'file',
      owner  => 'root',
      group  => 'root',
      mode   => $vnc_start_script_mode,
      source => 'puppet://modules/modules/weston/usr/libexec/weston-vnc',
    }
  }

  if $manage_vnc_options_file {
    file { $vnc_options_file:
      ensure  => 'file',
      owner   => 'root',
      group   => 'root',
      mode    => $vnc_options_file_mode,
      content => epp('weston/etc/xdg/weston/vncserver.opts.epp', { 'options' => $vnc_server_options }),
    }
  }

  if $manage_vnc_users_file {
    concat { $vnc_users_file:
      owner => 'root',
      group => 'root',
      mode  => $vnc_users_file_mode,
    }
    concat::fragment { 'vnc user file header':
      target  => $vnc_users_file,
      content => "#\n# THIS FILE IS MANAGED BY PUPPET\n#\n\n",
      order   => '01',
    }

    $vnc_sessions.keys.sort.each |$username| {
      unless 'displaynumber' in $vnc_sessions[$username] {
        fail("You must set the 'displaynumber' property for ${username}'s vnc server")
      }
      if 'comment' in $vnc_sessions[$username] {
        $comment = $vnc_sessions[$username]['comment']
      } else {
        $comment = ''
      }

      if 'user_can_control_service' in $vnc_sessions[$username] {
        $user_can_control_service = $vnc_sessions[$username]['user_can_control_service']
      } else {
        $user_can_control_service = $default_user_can_control_service
      }

      if $manage_vnc_polkit_file {
        if $user_can_control_service {
          if 'extra_users_can_control_service' in $vnc_sessions[$username] {
            $extra_users_to_grant = sort(unique(flatten([$default_extra_users_can_control_service, $vnc_sessions[$username]['extra_users_can_control_service']])))
          } else {
            $extra_users_to_grant = sort(unique(flatten([$default_extra_users_can_control_service])))
          }
        } else {
          $extra_users_to_grant = []
        }
      } else {
        $extra_users_to_grant = 'polkit rules for vnc disabled in puppet'
      }

      if $vnc_sessions[$username]['displaynumber'] < 5900 {
        $real_displaynumber = $vnc_sessions[$username]['displaynumber'] + 5900
      } else {
        $real_displaynumber = $vnc_sessions[$username]['displaynumber']
      }

      concat::fragment { "vnc user ${username}":
        target  => $vnc_users_file,
        content => "# ${comment}\n# non-root users who can control service for ${username}: ${extra_users_to_grant}\n:${real_displaynumber}=${username}\n",
      }
    }
  }

  if $manage_systemd_unit_file {
    systemd::manage_unit { "${systemd_template_startswith}@${systemd_template_endswith}":
      ensure        => 'present',
      unit_entry    => {
        'Description' => 'Remote desktop service (VNC) with Weston',
        'After'       => ['syslog.target', 'network.target', 'systemd-user-sessions.service', 'remote-fs.target'],
      },
      service_entry => {
        'Type'           => 'notify',
        'User'           => '%I',
        'PAMName'        => 'login',
        'Environment'    => 'XDG_SESSION_TYPE=wayland',
        'ExecStart'      => "${vnc_start_script} %I",
        'StandardOutput' => 'journal',
        'StandardError'  => 'journal',
      },
      install_entry => {
        'WantedBy' => 'multi-user.target',
      },
    }
  }

  if $manage_vnc_services {
    $vnc_sessions.keys.sort.each |$username| {
      if 'ensure' in $vnc_sessions[$username] {
        $user_vnc_ensure = $vnc_sessions[$username]['ensure']
      } else {
        $user_vnc_ensure = $default_vnc_service_ensure
      }

      if 'enable' in $vnc_sessions[$username] {
        $user_vnc_enable = $vnc_sessions[$username]['enable']
      } else {
        $user_vnc_enable = $default_vnc_service_enable
      }

      if $manage_vnc_start_script and $manage_vnc_options_file {
        service { "${systemd_template_startswith}@${username}${systemd_template_endswith}":
          ensure    => $user_vnc_ensure,
          enable    => $user_vnc_enable,
          subscribe => [File[$vnc_start_script], File[$vnc_options_file]],
        }
      } elsif $manage_vnc_start_script {
        service { "${systemd_template_startswith}@${username}${systemd_template_endswith}":
          ensure    => $user_vnc_ensure,
          enable    => $user_vnc_enable,
          subscribe => File[$vnc_start_script],
        }
      } elsif $manage_vnc_options_file {
        service { "${systemd_template_startswith}@${username}${systemd_template_endswith}":
          ensure    => $user_vnc_ensure,
          enable    => $user_vnc_enable,
          subscribe => File[$vnc_options_file],
        }
      } else {
        service { "${systemd_template_startswith}@${username}${systemd_template_endswith}":
          ensure => $user_vnc_ensure,
          enable => $user_vnc_enable,
        }
      }
    }
  }

  if $manage_vnc_polkit_file {
    concat { $vnc_polkit_file:
      owner => 'root',
      group => 'root',
      mode  => $vnc_polkit_file_mode,
    }

    concat::fragment { 'polkit_header':
      target  => $vnc_polkit_file,
      content => "/* THIS FILE IS MANAGED BY PUPPET */\n",
      order   => '01',
    }

    $vnc_sessions.keys.sort.each |$username| {
      if 'user_can_control_service' in $vnc_sessions[$username] {
        $user_can_control_service = $vnc_sessions[$username]['user_can_control_service']
      } else {
        $user_can_control_service = $default_user_can_control_service
      }

      if $user_can_control_service {
        if 'extra_users_can_control_service' in $vnc_sessions[$username] {
          $extra_users_to_grant = sort(unique(flatten([$default_extra_users_can_control_service, $vnc_sessions[$username]['extra_users_can_control_service'], $username])))
        } else {
          $extra_users_to_grant = sort(unique(flatten([$default_extra_users_can_control_service, $username])))
        }

        concat::fragment { "polkit entry for ${username} vnc service":
          target  => $vnc_polkit_file,
          order   => 20,
          content => epp('weston/etc/polkit-1/rules.d/25-puppet-weston-vnc_server.rules.epp', { 'systemd_template_startswith' => $systemd_template_startswith, 'systemd_template_endswith' => $systemd_template_endswith, 'usernames' => $extra_users_to_grant }),
        }
      }
    }
  }
}