Puppet Class: gitlab

Defined in:
modules/gitlab/manifests/init.pp

Summary

configure and manage gitlab server

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • block_auto_created_users (Boolean) (defaults to: true)

    Blocks users that are automatically created from signing in until they are approved by an administrator.

  • sync_profile_attributes (Array[Gitlab::Attributes]) (defaults to: ['name', 'email', 'location'])

    the attributes to sync

  • omniauth_providers (Hash[String, Gitlab::Omniauth_provider]) (defaults to: {})

    hash of provideres to configure. the key is the label

  • auto_sign_in_with (Optional[Gitlab::Omniauth_providers]) (defaults to: undef)

    automatically redirect to this provider

  • omniauth_identifier (String) (defaults to: 'gitlab_oidc')

    name of the omniauth client identifier

  • ensure (Wmflib::Ensure) (defaults to: 'present')
  • gitlab_domain (Stdlib::Host) (defaults to: $facts['networking']['fqdn'])
  • nginx_listen_port (Stdlib::Port) (defaults to: 443)
  • nginx_listen_addresses (Array[Stdlib::IP::Address]) (defaults to: ['0.0.0.0'])
  • external_url (Stdlib::Httpurl) (defaults to: "https://${gitlab_domain}/")
  • config_dir (Stdlib::Unixpath) (defaults to: '/etc/gitlab')
  • data_dir (Stdlib::Unixpath) (defaults to: '/var/opt/gitlab/git-data')
  • cert_path (Stdlib::Unixpath) (defaults to: "${config_dir}/ssl/${gitlab_domain}.pem")
  • key_path (Stdlib::Unixpath) (defaults to: "${config_dir}/ssl/${gitlab_domain}.key")
  • rails_path (Stdlib::Unixpath) (defaults to: '/opt/gitlab/embedded/service/gitlab-rails')
  • embedded_bin_path (Stdlib::Unixpath) (defaults to: '/opt/gitlab/embedded/bin')
  • listen_https (Boolean) (defaults to: true)
  • enable_backup (Boolean) (defaults to: true)
  • backup_keep_time (Integer[1]) (defaults to: 604800)
  • gitlab_username_changing (Boolean) (defaults to: false)
  • email_enable (Boolean) (defaults to: true)
  • email_from (String) (defaults to: "gitlab@${gitlab_domain}")
  • email_reply_to (String) (defaults to: $email_from)
  • email_name (String) (defaults to: 'Gitlab')
  • default_theme (String) (defaults to: '2')
  • csp_enabled (Boolean) (defaults to: false)
  • csp_report_only (Boolean) (defaults to: false)
  • extra_settings (Hash) (defaults to: {})
  • enable_prometheus (Boolean) (defaults to: false)
  • enable_alertmanager (Boolean) (defaults to: false)
  • default_projects_features (Array[Gitlab::Projects]) (defaults to: [])
  • smtp_enabled (Boolean) (defaults to: true)
  • smtp_port (Integer) (defaults to: 25)
  • exporter_default_listen (Stdlib::IP::Address) (defaults to: '127.0.0.1')
  • ssh_listen_addresses (Array[Stdlib::IP::Address]) (defaults to: ['127.0.0.1', '::1'])
  • exporters (Hash[Gitlab::Exporters,Gitlab::Exporter]) (defaults to: {})
  • monitoring_whitelist (Array[Stdlib::IP::Address]) (defaults to: ['127.0.0.1/32'])
  • enable_secondary_sshd (Boolean) (defaults to: true)
  • install_restore_script (Boolean) (defaults to: true)
  • enable_restore (Boolean) (defaults to: false)
  • backup_dir_data (Stdlib::Unixpath) (defaults to: '/srv/gitlab-backup')
  • backup_dir_config (Stdlib::Unixpath) (defaults to: '/etc/gitlab/config_backup')
  • full_backup_interval (Systemd::Timer::Schedule) (defaults to: {'start' => 'OnCalendar', 'interval' => '*-*-* 00:00:00'})
  • config_backup_interval (Systemd::Timer::Schedule) (defaults to: {'start' => 'OnCalendar', 'interval' => '*-*-* 00:00:00'})
  • partial_backup_interval (Systemd::Timer::Schedule) (defaults to: {'start' => 'OnCalendar', 'interval' => '*-*-* 00:00:00'})
  • restore_interval (Systemd::Timer::Schedule) (defaults to: {'start' => 'OnCalendar', 'interval' => '*-*-* 01:30:00'})
  • manage_host_keys (Boolean) (defaults to: false)
  • letsencrypt_enable (Boolean) (defaults to: false)
  • omniauth_auto_link_saml_user (Boolean) (defaults to: true)
  • enable_ldap_group_sync (Boolean) (defaults to: false)
  • ldap_config (Hash) (defaults to: {})
  • ldap_group_sync_user (String) (defaults to: 'ldapgroupsync')
  • ldap_group_sync_bot (String) (defaults to: 'ldap-sync-bot')
  • ldap_group_sync_bot_token (String) (defaults to: 'ldap-sync-bot-token-not-supplied')
  • ldap_group_sync_interval (Systemd::Timer::Schedule) (defaults to: {'start' => 'OnCalendar', 'interval' => '*:0/15'})
  • thanos_storage_enabled (Boolean) (defaults to: false)
  • thanos_storage_username (String) (defaults to: '')
  • thanos_storage_password (String) (defaults to: '')
  • local_gems_enabled (Boolean) (defaults to: false)
  • local_gems (Hash[Stdlib::Unixpath, Array[String]]) (defaults to: {})
  • max_storage_concurrency (Integer) (defaults to: 4)
  • max_concurrency (Integer) (defaults to: 2)


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
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'modules/gitlab/manifests/init.pp', line 12

class gitlab (
    Wmflib::Ensure   $ensure                                    = 'present',
    Stdlib::Host     $gitlab_domain                             = $facts['networking']['fqdn'],
    Stdlib::Port     $nginx_listen_port                         = 443,
    Array[Stdlib::IP::Address] $nginx_listen_addresses          = ['0.0.0.0'],
    Stdlib::Httpurl  $external_url                              = "https://${gitlab_domain}/",
    Stdlib::Unixpath $config_dir                                = '/etc/gitlab',
    Stdlib::Unixpath $data_dir                                  = '/var/opt/gitlab/git-data',
    Stdlib::Unixpath $cert_path                                 = "${config_dir}/ssl/${gitlab_domain}.pem",
    Stdlib::Unixpath $key_path                                  = "${config_dir}/ssl/${gitlab_domain}.key",
    Stdlib::Unixpath $rails_path                                = '/opt/gitlab/embedded/service/gitlab-rails',
    Stdlib::Unixpath $embedded_bin_path                         = '/opt/gitlab/embedded/bin',
    Boolean          $listen_https                              = true,
    Boolean          $enable_backup                             = true,
    Integer[1]       $backup_keep_time                          = 604800,
    Boolean          $gitlab_username_changing                  = false,
    Boolean          $email_enable                              = true,
    String           $email_from                                = "gitlab@${gitlab_domain}",
    String           $email_reply_to                            = $email_from,
    String           $email_name                                = 'Gitlab',
    # TODO: should this be int?
    String           $default_theme                             = '2',
    Boolean          $csp_enabled                               = false,
    Boolean          $csp_report_only                           = false,
    Hash             $extra_settings                            = {},
    Boolean          $enable_prometheus                         = false,
    Boolean          $enable_alertmanager                       = false,
    Array[Gitlab::Projects] $default_projects_features          = [],
    Boolean          $smtp_enabled                              = true,
    Integer          $smtp_port                                 = 25,
    Stdlib::IP::Address $exporter_default_listen                = '127.0.0.1',
    Array[Stdlib::IP::Address] $ssh_listen_addresses            = ['127.0.0.1', '::1'],
    Hash[Gitlab::Exporters,Gitlab::Exporter] $exporters         = {},
    Array[Stdlib::IP::Address] $monitoring_whitelist            = ['127.0.0.1/32'],
    Boolean          $enable_secondary_sshd                     = true,
    Boolean          $install_restore_script                    = true,
    Boolean          $enable_restore                            = false,
    Stdlib::Unixpath $backup_dir_data                           = '/srv/gitlab-backup',
    Stdlib::Unixpath $backup_dir_config                         = '/etc/gitlab/config_backup',
    Systemd::Timer::Schedule $full_backup_interval              = {'start' => 'OnCalendar', 'interval' => '*-*-* 00:00:00'},
    Systemd::Timer::Schedule $config_backup_interval            = {'start' => 'OnCalendar', 'interval' => '*-*-* 00:00:00'},
    Systemd::Timer::Schedule $partial_backup_interval           = {'start' => 'OnCalendar', 'interval' => '*-*-* 00:00:00'},
    Systemd::Timer::Schedule $restore_interval                  = {'start' => 'OnCalendar', 'interval' => '*-*-* 01:30:00'},
    Boolean $manage_host_keys                                   = false,
    Boolean                           $block_auto_created_users = true,
    Array[Gitlab::Attributes]          $sync_profile_attributes = ['name', 'email', 'location'],
    Hash[String, Gitlab::Omniauth_provider] $omniauth_providers = {},
    Optional[Gitlab::Omniauth_providers]    $auto_sign_in_with  = undef,
    Boolean           $letsencrypt_enable                       = false,
    String            $omniauth_identifier                      = 'gitlab_oidc',
    Boolean           $omniauth_auto_link_saml_user             = true,
    Boolean                  $enable_ldap_group_sync            = false,
    Hash                     $ldap_config                       = {},
    String                   $ldap_group_sync_user              = 'ldapgroupsync',
    String                   $ldap_group_sync_bot               = 'ldap-sync-bot',
    String                   $ldap_group_sync_bot_token         = 'ldap-sync-bot-token-not-supplied',
    Systemd::Timer::Schedule $ldap_group_sync_interval          = {'start' => 'OnCalendar', 'interval' => '*:0/15'},
    Boolean                  $thanos_storage_enabled            = false,
    String                   $thanos_storage_username           = '',
    String                   $thanos_storage_password           = '',
    Boolean                  $local_gems_enabled                = false,
    Hash[Stdlib::Unixpath, Array[String]] $local_gems           = {},
    Integer           $max_storage_concurrency                  = 4,
    Integer           $max_concurrency                          = 2,

) {
    $oidc_defaults = {
        'scope'                        => ['openid','profile','email'],
        'response_type'                => 'code',
        'discovery'                    => true,
        'client_auth_method'           => 'query',
        'uid_field'                    => 'sub',
        'send_scope_to_token_endpoint' => 'false',
        'pkce'                         => 'true',
        # TODO: the documents add the name filed to the args but
        # i suspect its a big in the docs
        'name'                         => 'openid_connect',
        'client_options'               => {
            'identifier' => $omniauth_identifier,
        },
    }

    $_omniauth_providers = $omniauth_providers.map |$label, $args| {
        case $args {
            Gitlab::Omniauth_provider::OIDC: {
                if $args['client_options'].has_key('secret') {
                    {
                        'label' => $label,
                        'name'  => 'openid_connect',
                        'args'  => deep_merge($args, $oidc_defaults),
                    }
                } else {
                    warning("provider ${label} has no secret will not configure")
                }
            }
            default: { fail("omniauth_provider (${label}) is unsupported") }
        }
    }.filter |$item| { !$item.empty }
    $configured_providers = $_omniauth_providers.map |$provider| { $provider['name'] }.sort.unique

    systemd::sysuser { 'git':
      id          => '915:915',
      description => 'git used by GitLab',
      home_dir    => '/var/opt/gitlab',
      allow_login => true,
    }

    apt::package_from_component{'gitlab-ce':
        component => 'thirdparty/gitlab-bullseye',
    }

    wmflib::dir::mkdir_p("${config_dir}/ssl", {
        owner => 'root',
        group => 'root',
        mode  => '0500',
    })

    file {'/etc/gitlab/gitlab.rb':
        ensure  => $ensure,
        owner   => 'root',
        group   => 'root',
        mode    => '0400',
        content => template('gitlab/gitlab.rb.erb'),
        notify  => Exec['Reconfigure GitLab'],
    }

    $gemfile_local_ensure = $local_gems_enabled ? {
        true    => $ensure,
        default => 'absent',
    }

    file { "${rails_path}/Gemfile.local":
        ensure  => stdlib::ensure($gemfile_local_ensure),
        owner   => 'root',
        group   => 'root',
        mode    => '0644',
        content => template('gitlab/Gemfile.local.erb'),
        require => Package['gitlab-ce'],
        notify  => Exec['Recreate GitLab Gemfile.local.lock'],
    }

    # Generate a Gemfile.local.lock, starting with Gemfile.lock as a base to
    # avoid attempts to resolve/update newer versions of upstream gem dependencies
    exec { 'Recreate GitLab Gemfile.local.lock':
        command     => "/bin/sh -c \"/usr/bin/cp Gemfile.lock Gemfile.local.lock && ${embedded_bin_path}/bundle lock --local\"",
        cwd         => $rails_path,
        environment => [
            'BUNDLE_GEMFILE=Gemfile.local',
            'BUNDLE_IGNORE_CONFIG=1',
        ],
        refreshonly => true,
        onlyif      => '/usr/bin/test -e Gemfile.local',
        require     => Package['gitlab-ce'],
        notify      => Service['gitlab-ce'],
    }

    # From: https://github.com/voxpupuli/puppet-gitlab/blob/master/manifests/service.pp
    exec { 'Reconfigure GitLab':
        command     => '/bin/sh -c "unset LD_LIBRARY_PATH; /usr/bin/gitlab-ctl reconfigure"',
        refreshonly => true,
        timeout     => 1800,
        logoutput   => true,
        tries       => 5,
        require     => Package['gitlab-ce'],
        notify      => Service['gitlab-ce'],
    }

    service{ 'gitlab-ce':
        ensure  => stdlib::ensure($ensure, 'service'),
        start   => '/usr/bin/gitlab-ctl start',
        restart => '/usr/bin/gitlab-ctl restart',
        stop    => '/usr/bin/gitlab-ctl stop',
        status  => '/usr/bin/gitlab-ctl status',
        require => Package['gitlab-ce'],
    }

    # enable backups on active GitLab server
    $ensure_backup = $enable_backup.bool2str('present','absent')
    class { 'gitlab::backup':
        full_ensure             => $ensure_backup,
        partial_ensure          => $ensure_backup,
        config_ensure           => $ensure_backup,
        backup_dir_data         => $backup_dir_data,
        backup_dir_config       => $backup_dir_config,
        backup_keep_time        => $backup_keep_time,
        full_backup_interval    => $full_backup_interval,
        partial_backup_interval => $partial_backup_interval,
        config_backup_interval  => $config_backup_interval,
        max_concurrency         => $max_concurrency,
        max_storage_concurrency => $max_storage_concurrency,
    }

    # Theses parameters are installed by gitlab when the package is updated
    # However we purge this directory in puppet as such we need to add them here
    # TODO: Ensure theses values actually make sense
    sysctl::parameters {'omnibus-gitlab':
        priority => 90,
        values   => {
            'kernel.sem'    => '250 32000 32 262',
            'kernel.shmall' => 4194304,
            'kernel.shmmax' => 17179869184,
        },
    }

    # enable dedicated sshd for GitLab
    $ensure_sshd = $enable_secondary_sshd.bool2str('present','absent')
    class { 'gitlab::ssh' :
        ensure               => $ensure_sshd,
        ssh_listen_addresses => $ssh_listen_addresses,
        manage_host_keys     => $manage_host_keys,
        gitlab_domain        => $gitlab_domain,
    }

    # enable automated restore from backup (for replica)
    $ensure_restore_script = $install_restore_script.bool2str('present','absent')
    $ensure_restore = $enable_restore.bool2str('present','absent')
    class { 'gitlab::restore' :
        ensure_restore_script => $ensure_restore_script,
        ensure_restore        => $ensure_restore,
        restore_dir_data      => $backup_dir_data,
        restore_interval      => $restore_interval,
    }

    # Install configuration file for gitlab backup partition layout.
    file {'/opt/gitlab-backup-raid.cfg':
        mode   => '0744' ,
        owner  => 'root',
        group  => 'root',
        source => 'puppet:///modules/gitlab/gitlab-backup-raid.cfg';
    }

    # Install scipt to configure backup partition layout and raid.
    # This script is executed manually while provisioning a new GitLab instance.
    file {'/opt/provision-backup-fs.sh':
        mode   => '0744' ,
        owner  => 'root',
        group  => 'root',
        source => 'puppet:///modules/gitlab/provision-backup-fs.sh';
    }

    ### Group management stuff
    ensure_packages('python3-ldap')

    $ensure_ldap_group_sync = $enable_ldap_group_sync.bool2str('present','absent')
    systemd::sysuser { $ldap_group_sync_user:
        ensure      => $ensure_ldap_group_sync,
        description => 'sync-gitlab-group-with-ldap user',
    }

    # NOTE: Gitlab needs to be operational for this to work.
    $ensure_gitlab_settings = $enable_ldap_group_sync.bool2str('latest','absent')
    git::clone { 'repos/releng/gitlab-settings':
        ensure        => $ensure_gitlab_settings,
        update_method => 'checkout',
        git_tag       => 'v1.3.0',
        directory     => '/srv/gitlab-settings',
        source        => 'gitlab',
        owner         => $ldap_group_sync_user,
        group         => $ldap_group_sync_user,
        require       => Systemd::Sysuser[$ldap_group_sync_user],
    }

    $ldap_url = "ldaps://${ldap_config[ro-server]}:636"
    file { "${config_dir}/group-management-config.yaml":
        ensure  => $ensure_ldap_group_sync,
        owner   => $ldap_group_sync_user,
        group   => $ldap_group_sync_user,
        mode    => '0400',
        content => template('gitlab/group-management-config.yaml.erb'),
        require => Systemd::Sysuser[$ldap_group_sync_user],
    }

    $sync_cmd = "/srv/gitlab-settings/group-management/sync-gitlab-group-with-ldap -c ${config_dir}/group-management-config.yaml --yes"
    systemd::timer::job { 'sync-gitlab-group-with-ldap':
        ensure      => $ensure_ldap_group_sync,
        user        => $ldap_group_sync_user,
        description => 'Sync various GitLab groups with their LDAP groups',
        command     => "${sync_cmd} repos/mediawiki wmf ops ; ${sync_cmd} --access-level Owner repos/sre ops",
        interval    => $ldap_group_sync_interval,
        require     => Systemd::Sysuser[$ldap_group_sync_user],
    }
}