Puppet Class: st2::auth::ldap

Inherits:
st2
Defined in:
manifests/auth/ldap.pp

Summary

Auth class to configure and setup LDAP Based Authentication

Overview

For information on parameters see the backend documentation

Examples:

Instantiate via st2 (Active Directory)

class { 'st2':
  auth_backend        => 'ldap',
  auth_backend_config => {
    host            => 'ldap.domain.tld',
    bind_dn         => 'cn=ldap_stackstorm,ou=service accounts,dc=domain,dc=tld',
    base_dn         => 'dc=domain,dc=tld',
    scope           => 'subtree',
    id_attr         => 'username',
    bind_pw         => 'some_password',
    group_dns       => ['"cn=stackstorm_users,ou=groups,dc=domain,dc=tld"'],
    account_pattern => 'userPrincipalName={username}',
  },
}

Instantiate via Hiera (Active Directory)

st2::auth_backend: "ldap"
st2::auth_backend_config:
  host: "ldaps.domain.tld"
  use_tls: false
  use_ssl: true
  port: 636
  bind_dn: 'cn=ldap_stackstorm,ou=service accounts,dc=domain,dc=tld'
  bind_pw: 'some_password'
  chase_referrals: false
  base_dn: 'dc=domain,dc=tld'
  group_dns:
    - '"cn=stackstorm_users,ou=groups,dc=domain,dc=tld"'
  scope: "subtree"
  id_attr: "username"
  account_pattern: "userPrincipalName={username}"

Parameters:

  • conf_file (Any) (defaults to: $st2::conf_file)

    The path where st2 config is stored

  • host (Any) (defaults to: '')

    URI of the LDAP server. Format: <protocol>://<hostname>[:port] (protocol: ldap or ldaps)

  • use_tls (Any) (defaults to: false)

    Boolean parameter to set if tls is required. Should be set to false using ldaps in the uri. (default: false)

  • use_ssl (Any) (defaults to: false)

    Boolean parameter to set if ssl is required. Should be set to true using ldaps in the uri. (default: false)

  • port (Any) (defaults to: 389)

    Integer port to be used for LDAP connection Should be set to false using ldaps in the uri. (default: 389)

  • bind_dn (Any) (defaults to: '')

    DN user to bind to LDAP. If an empty string, an anonymous bind is performed. To use the user supplied username in the bind_dn, use the {username} placeholder in string.

  • bind_pw (Any) (defaults to: '')

    DN password. Use the {password} placeholder in the string to use the user supplied password.

  • base_dn (Any) (defaults to: '')

    Base DN to search for all users/groups entries.

  • group_dns (Any) (defaults to: undef)

    DN of groups user must be member of to be granted access

  • chase_referrals (Any) (defaults to: true)

    Boolean parameter to set whether to chase referrals. (default: true)

  • scope (Any) (defaults to: 'subtree')

    Search scope (base, onelevel, or subtree) (default: subtree)

  • id_attr (Any) (defaults to: 'uid')

    Field name of the user ID attribute (default: uid)

  • account_pattern (Any) (defaults to: undef)

    LDAP subtree pattern to match user. The user’s username is escaped and interpolated into this string

  • group_pattern (Any) (defaults to: undef)

    LDAP subtree pattern for user groups. Both user_dn and username are escaped and then interpolated into this string



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
# File 'manifests/auth/ldap.pp', line 73

class st2::auth::ldap (
  $conf_file       = $st2::conf_file,
  $host            = '',
  $use_tls         = false,
  $use_ssl         = false,
  $port            = 389,
  $bind_dn         = '',
  $bind_pw         = '',
  $base_dn         = '',
  $group_dns       = undef,
  $chase_referrals = true,
  $scope           = 'subtree',
  $id_attr         = 'uid',
  $account_pattern = undef,
  $group_pattern   = undef,
) inherits st2 {
  include st2::auth::common

  $_use_tls = bool2str($use_tls)
  $_use_ssl = bool2str($use_ssl)
  $_chase_refs = bool2str($chase_referrals)
  if $account_pattern != undef and $group_pattern != undef {
    $_kwargs = @("LDAPARGS"/L)
      {"host": "${host}", "use_tls": ${_use_tls},\
      "bind_dn": "${bind_dn}", "bind_password": "${bind_pw}",\
      "chase_referrals": ${_chase_refs}, "base_ou": "${base_dn}",\
      "group_dns": ${group_dns}, "use_ssl": ${_use_ssl}, "port": ${port},\
      "scope": "${scope}", "id_attr": "${id_attr}",\
      "account_pattern": "${account_pattern}", "group_pattern": "${group_pattern}"}
      | - LDAPARGS
  }
  elsif $account_pattern != undef {
    $_kwargs = @("LDAPARGS"/L)
      {"host": "${host}", "use_tls": ${_use_tls},\
      "bind_dn": "${bind_dn}", "bind_password": "${bind_pw}",\
      "chase_referrals": ${_chase_refs}, "base_ou": "${base_dn}",\
      "group_dns": ${group_dns}, "use_ssl": ${_use_ssl}, "port": ${port},\
      "scope": "${scope}", "id_attr": "${id_attr}",\
      "account_pattern": "${account_pattern}"}
      | - LDAPARGS
  }
  elsif $group_pattern != undef {
    $_kwargs = @("LDAPARGS"/L)
      {"host": "${host}", "use_tls": ${_use_tls},\
      "bind_dn": "${bind_dn}", "bind_password": "${bind_pw}",\
      "chase_referrals": ${_chase_refs}, "base_ou": "${base_dn}",\
      "group_dns": ${group_dns}, "use_ssl": ${_use_ssl}, "port": ${port},\
      "scope": "${scope}", "id_attr": "${id_attr}",\
      "group_pattern": "${group_pattern}"}
      | - LDAPARGS
  }
  else {
    $_kwargs = @("LDAPARGS"/L)
      {"host": "${host}", "use_tls": ${_use_tls},\
      "bind_dn": "${bind_dn}", "bind_password": "${bind_pw}",\
      "chase_referrals": ${_chase_refs}, "base_ou": "${base_dn}",\
      "group_dns": ${group_dns}, "use_ssl": ${_use_ssl}, "port": ${port},\
      "scope": "${scope}", "id_attr": "${id_attr}"}
      | - LDAPARGS
  }

  # config
  ini_setting { 'auth_backend':
    ensure  => present,
    path    => $conf_file,
    section => 'auth',
    setting => 'backend',
    value   => 'ldap',
    tag     => 'st2::config',
  }
  ini_setting { 'auth_backend_kwargs':
    ensure  => present,
    path    => $conf_file,
    section => 'auth',
    setting => 'backend_kwargs',
    value   => $_kwargs,
    tag     => 'st2::config',
  }

  # install package dependency
  $_dep_pkgs = $facts['os']['family'] ? {
    'Debian' => ['gcc', 'libldap2-dev'],
    'RedHat' => ['gcc', 'openldap-devel'],
    default  => undef,
  }
  ensure_packages($_dep_pkgs,
                  {
                    'ensure' => 'present',
                  })

  # dependencies
  Package<| tag == 'st2::server::packages' |>
  -> Package[$_dep_pkgs]
  ~> Service['st2auth']
}