Puppet Class: profile::conftool::requestctl_client

Defined in:
modules/profile/manifests/conftool/requestctl_client.pp

Summary

profile to install conftool requestctl plugin

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • conftool_prefix (String) (defaults to: lookup('conftool_prefix')) —

    the conftool prefix

  • root_token (String) (defaults to: lookup('profile::conftool::hiddenparma::root_token')) —

    the root token to use for requestctl

  • admin_groups (Array[String]) (defaults to: lookup('profile::conftool::requestctl_client::admin_groups', { 'default_value' => ['ops'] })) —

    the groups whose members should have requestctl credentials installed in their home directories. Defaults to ['ops'].

  • username_overrides (Hash[String, String]) (defaults to: lookup('profile::conftool::requestctl_client::username_overrides', { 'default_value' => {} })) —

    a hash mapping of real names to ldap cns, which are the username you find in HP's api token system



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
# File 'modules/profile/manifests/conftool/requestctl_client.pp', line 7

class profile::conftool::requestctl_client (
    String $conftool_prefix = lookup('conftool_prefix'),
    String $root_token = lookup('profile::conftool::hiddenparma::root_token'),
    Array[String] $admin_groups = lookup('profile::conftool::requestctl_client::admin_groups', { 'default_value' => ['ops'] }),
    Hash[String, String] $username_overrides = lookup('profile::conftool::requestctl_client::username_overrides', { 'default_value' => {} }),
) {
    require profile::conftool::client

    # This is a copy of the file contained in the scripts/ directory of the
    # HIDDENPARMA repository:
    # https://gitlab.wikimedia.org/repos/sre/hiddenparma/-/blob/main/scripts/requestctl_cli.py
    file { '/usr/bin/requestctl':
        ensure => file,
        mode   => '0755',
        source => 'puppet:///modules/profile/conftool/requestctl_cli.original.py',
    }
    file { '/usr/local/bin/requestctl-checkip':
        ensure => file,
        owner  => 'root',
        mode   => '0555',
        source => 'puppet:///modules/profile/conftool/requestctl_checkip.py',
    }

    ## Credentials management

    # Ensure everyone in the admin groups group has their api token in their home directory.
    # If even one user in the groups doesn't have an api token, puppet will fail.
    # While this might seem harsh, it's the only way to ensure people get onboarded correctly.
    $admin_module_path = get_module_path('admin')
    $admin_data = loadyaml("${admin_module_path}/data/data.yaml")
    $admin_group_data = $admin_data['groups']

    $admin_users = $admin_data['users']
    # Create a set of shell username => realname pairs, to use in downloading the credentials.
    $all_users = $admin_groups.reduce([]) |$acc, $grp| {
        unless $grp in $admin_group_data {
            fail("${grp}, declared in profile::conftool::requestctl_client::admin_groups, does not exist.")
        }
        $admin_group_data[$grp]['members'] + $acc
    }.unique()
    file { '/etc/conftool/requestctl_credentials.json':
        ensure  => file,
        mode    => '0600',
        owner   => 'root',
        group   => 'root',
        content => stdlib::to_json($all_users),
    }
    # A lot of people probably still have the muscle memory of using "sudo" when running requestctl. We need that to keep
    # working. We might want a better solution later.
    file { '/root/.requestctl':
        ensure  => file,
        mode    => '0400',
        owner   => 'root',
        group   => 'root',
        content => "${root_token}\n",
    }

    file { '/usr/local/bin/generate-requestctl-credentials':
        ensure => file,
        owner  => 'root',
        group  => 'root',
        mode   => '0544',
        source => 'puppet:///modules/profile/conftool/generate_requestctl_credentials.py',
    }

    $ldap_base   = 'ou=people,dc=wikimedia,dc=org'
    $ldap_server = "ldap://ldap-ro.${::site}.wikimedia.org"
    stdlib::ensure_packages(['python3-ldap3'])

    systemd::timer::job { 'requestctl-credential-refresh':
        ensure      => present,
        description => 'Refresh requestctl API credentials for all users',
        interval    => { 'start' => 'OnUnitInactiveSec', 'interval' => '1h' },
        command     => "/usr/local/bin/generate-requestctl-credentials --ldap-base ${ldap_base} --ldap-server ${ldap_server} /etc/conftool/requestctl_credentials.json",
        user        => 'root',
        group       => 'root',
        require     => File['/etc/conftool/requestctl_credentials.json', '/usr/local/bin/generate-requestctl-credentials'],
    }
}