Puppet Class: profile::idm

Defined in:
modules/profile/manifests/idm.pp

Overview

Parameters:

  • service_fqdn (Stdlib::Fqdn) (defaults to: lookup('profile::idm::service_fqdn'))
  • django_secret_key (String) (defaults to: lookup('profile::idm::server::django_secret_key'))
  • django_mysql_db_host (String) (defaults to: lookup('profile::idm::server::django_mysql_db_host'))
  • django_mysql_db_password (String) (defaults to: lookup('profile::idm::server::django_mysql_db_password'))
  • django_mysql_db_user (String) (defaults to: lookup('profile::idm::server::django_mysql_db_user', {'default_value' => 'idm'}))
  • django_mysql_db_name (String) (defaults to: lookup('profile::idm::server::django_mysql_db_name', {'default_value' => 'idm'}))
  • deploy_user (String) (defaults to: lookup('profile::idm::deploy_user', {'default_value' => 'www-data'}))
  • uwsgi_process_count (Integer) (defaults to: lookup('profile::idm::uwsgi_process_count', {'default_value' => 4}))
  • install_via_git (Boolean) (defaults to: lookup('profile::idm::install_via_git', {'default_value' => false}))
  • production (Boolean) (defaults to: lookup('profile::idm::production', {'default_value' => false}))
  • envoy_termination (Boolean) (defaults to: lookup('profile::idm::envoy_termination', {'default_value' => false}))
  • apereo_cas (Apereo_cas::Urls) (defaults to: lookup('apereo_cas'))
  • ldap_config (Hash) (defaults to: lookup('ldap'))
  • ldap_dn (String) (defaults to: lookup('profile::idm::ldap_dn'))
  • ldap_dn_password (String) (defaults to: lookup('profile::idm::ldap_dn_password'))
  • oidc_key (Optional[String[1]]) (defaults to: lookup('profile::idm::oidc_service'))
  • oidc_secret (Optional[String[1]]) (defaults to: lookup('profile::idm::oidc_secret'))
  • mediawiki_key (Optional[String[1]]) (defaults to: lookup('profile::idm::mediawiki_key'))
  • mediawiki_secret (Optional[String[1]]) (defaults to: lookup('profile::idm::mediawiki_secret'))
  • mediawiki_callback (Optional[String[1]]) (defaults to: lookup('profile::idm::mediaback_callback'))
  • redis_master (Stdlib::Fqdn) (defaults to: lookup('profile::idm::redis_master'))
  • redis_replicas (Array[Stdlib::Fqdn]) (defaults to: lookup('profile::idm::redis_replicas', {'default_value' => []}))
  • redis_password (String) (defaults to: lookup('profile::idm::redis_password', {'default_value' => 'secret'}))
  • redis_port (Stdlib::Port) (defaults to: lookup('profile::idm::redis_port', {'default_value' => 6973}))
  • redis_maxmem (Integer) (defaults to: lookup('profile::idm::redis_maxmem', {'default_value' => 1610612736 }))
  • enable_monitoring (Boolean) (defaults to: lookup('profile::idm::enable_monitoring'))
  • config_template (String) (defaults to: lookup('profile::idm::config_template', {'default_value' => 'idm/idm-django-settings.erb'}))


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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'modules/profile/manifests/idm.pp', line 3

class profile::idm(
    Stdlib::Fqdn        $service_fqdn              = lookup('profile::idm::service_fqdn'),
    String              $django_secret_key         = lookup('profile::idm::server::django_secret_key'),
    String              $django_mysql_db_host      = lookup('profile::idm::server::django_mysql_db_host'),
    String              $django_mysql_db_password  = lookup('profile::idm::server::django_mysql_db_password'),
    String              $django_mysql_db_user      = lookup('profile::idm::server::django_mysql_db_user', {'default_value' => 'idm'}),
    String              $django_mysql_db_name      = lookup('profile::idm::server::django_mysql_db_name', {'default_value' => 'idm'}),
    String              $deploy_user               = lookup('profile::idm::deploy_user', {'default_value'                  => 'www-data'}),
    Integer             $uwsgi_process_count       = lookup('profile::idm::uwsgi_process_count', {'default_value'          => 4}),
    Boolean             $install_via_git           = lookup('profile::idm::install_via_git', {'default_value'              => false}),
    Boolean             $production                = lookup('profile::idm::production', {'default_value'                   => false}),
    Boolean             $envoy_termination         = lookup('profile::idm::envoy_termination', {'default_value'            => false}),
    Apereo_cas::Urls    $apereo_cas                = lookup('apereo_cas'),
    Hash                $ldap_config               = lookup('ldap'),
    String              $ldap_dn                   = lookup('profile::idm::ldap_dn'),
    String              $ldap_dn_password          = lookup('profile::idm::ldap_dn_password'),
    Optional[String[1]] $oidc_key                  = lookup('profile::idm::oidc_service'),
    Optional[String[1]] $oidc_secret               = lookup('profile::idm::oidc_secret'),
    Optional[String[1]] $mediawiki_key             = lookup('profile::idm::mediawiki_key'),
    Optional[String[1]] $mediawiki_secret          = lookup('profile::idm::mediawiki_secret'),
    Optional[String[1]] $mediawiki_callback        = lookup('profile::idm::mediaback_callback'),
    Stdlib::Fqdn        $redis_master              = lookup('profile::idm::redis_master'),
    Array[Stdlib::Fqdn] $redis_replicas            = lookup('profile::idm::redis_replicas', {'default_value'               => []}),
    String              $redis_password            = lookup('profile::idm::redis_password', {'default_value'               => 'secret'}),
    Stdlib::Port        $redis_port                = lookup('profile::idm::redis_port', {'default_value'                   => 6973}),
    Integer             $redis_maxmem              = lookup('profile::idm::redis_maxmem', {'default_value'                 => 1610612736 }),
    Boolean             $enable_monitoring         = lookup('profile::idm::enable_monitoring'),
    String              $config_template           = lookup('profile::idm::config_template', {'default_value'              => 'idm/idm-django-settings.erb'})
) {

    ensure_packages(['python3-django-uwsgi'])

    $etc_dir = '/etc/bitu'
    $base_dir = '/srv/idm'
    $log_dir = '/var/log/idm'
    $media_dir = "${base_dir}/media"
    $static_dir = "${base_dir}/static"
    $project = 'bitu'
    $uwsgi_socket = "/run/uwsgi/${project}.sock"

    $production_str = $production.bool2str('production', 'staging')

    if $oidc_key {
    $oidc_endpoint = $apereo_cas[$production_str]['oidc_endpoint']
        $oidc = { key      => $oidc_key,
                  secret   => $oidc_secret,
                  endpoint => $oidc_endpoint }
    }

    if $mediawiki_callback {
        $mediawiki = { key => $mediawiki_key, secret => $mediawiki_secret, callback => $mediawiki_callback }
    }

    include passwords::ldap::production
    class{ 'sslcert::dhparam': }

    if $envoy_termination {
      include profile::tlsproxy::envoy
      $firewall_port = 443
      profile::auto_restarts::service { 'envoyproxy': }
    } else {
      # In Cloud VPS we use the shared web proxy for tls termination
      $firewall_port = 80
    }

    firewall::service { 'idm_http':
        proto => 'tcp',
        port  => $firewall_port,
    }

    file { [$base_dir, $static_dir, $media_dir, $etc_dir, $log_dir] :
        ensure => directory,
        owner  => $deploy_user,
        group  => $deploy_user,
    }

    $logs = ['idm', 'django']

    $logs.each |$log| {
        file { $log:
        ensure => file,
        path   => "${log_dir}/${log}.log",
        owner  => $deploy_user,
        group  => $deploy_user,
        }
    }


    $logs.each |$log| {
        logrotate::rule { "bitu-${log}":
        ensure        => present,
        file_glob     => "${log_dir}/${log}.log",
        frequency     => 'daily',
        not_if_empty  => true,
        copy_truncate => true,
        max_age       => 30,
        rotate        => 30,
        date_ext      => true,
        compress      => true,
        missing_ok    => true,
        no_create     => true,
        }
    }


    # Django configuration
    file { "${etc_dir}/settings.py":
        ensure  => present,
        content => template($config_template),
        owner   => $deploy_user,
        group   => $deploy_user,
        notify  => Service['uwsgi-bitu', 'rq-bitu'],
    }

    class { 'idm::redis':
        redis_master   => $redis_master,
        redis_replicas => $redis_replicas,
        redis_password => $redis_password,
        redis_port     => $redis_port,
        redis_maxmem   => $redis_maxmem,
    }


    if $install_via_git {
        class { 'idm::deployment':
            project             => $project,
            base_dir            => $base_dir,
            deploy_user         => $deploy_user,
            redis_master        => $redis_master,
            uwsgi_process_count => $uwsgi_process_count,

        }
    } else {
        ensure_packages(['python3-bitu', 'python3-mysqldb', 'python3-bs4'])

        # Enable Bitu uwsgi app.
        file { '/etc/uwsgi/apps-enabled/bitu.ini':
            ensure => 'link',
            target => '/etc/uwsgi/apps-available/bitu.ini',
        }

        # The systemd services is shipped with the Debian package,
        # but we need the services to be available to Puppet to be
        # used with Notify on configuration changes.
        service { 'uwsgi-bitu':
            ensure => 'running',
            enable => true
        }

        service { 'rq-bitu':
            ensure => stdlib::ensure($facts['networking']['fqdn'] == $redis_master, 'service'),
            enable => ($facts['networking']['fqdn'] == $redis_master)
        }

    }

    # Bitu is managed via a dedicated systemd unit (uwsgi-bitu.service),
    # mask the generic uwsgi unit which gets auto-translated based on the init.d script
    # shipped in the uwsgi Debian package
    systemd::mask { 'mask_default_uwsgi_bitu':
        unit => 'uwsgi.service',
    }

    class {'httpd':
        modules => ['proxy_http', 'proxy', 'proxy_uwsgi', 'remoteip']
    }

    httpd::site { 'idm':
        ensure  => present,
        content => template('idm/idm-apache-config.erb'),
    }

    $job_state = ($facts['networking']['fqdn'] == $redis_master).bool2str('present', 'absent')
    class { 'idm::jobs':
        present => $job_state,
        user    => $deploy_user
    }

    profile::auto_restarts::service { 'apache2':}
    profile::auto_restarts::service { 'rq-bitu':
        ensure => $job_state,
    }

    if $enable_monitoring {
        prometheus::blackbox::check::http { $service_fqdn:
            team               => 'infrastructure-foundations',
            severity           => 'critical',
            path               => '/signup/',
            force_tls          => true,
            status_matches     => [200],
            body_regex_matches => ['signup'],
            follow_redirects   => true,
            probe_runbook      => 'https://wikitech.wikimedia.org/wiki/IDM/Runbook'
        }
    }
}