|
| 1 | +# @summary |
| 2 | +# Installs OpenVPN Access Server and configures LDAP + default groups. |
| 3 | +# |
| 4 | +# @param version |
| 5 | +# Sets version lock for OpenVPN package. |
| 6 | +# |
| 7 | +# @param bind_pw |
| 8 | +# Optional. LDAP bind password for OpenVPN Access Server. |
| 9 | +# |
| 10 | +class profile::core::openvpnas ( |
| 11 | + String[1] $version, |
| 12 | + Optional[String[1]] $bind_pw = undef, |
| 13 | +) { |
| 14 | + include profile::core::letsencrypt |
| 15 | + |
| 16 | + # Host FQDN |
| 17 | + $fqdn = fact('networking.fqdn') |
| 18 | + |
| 19 | + # Signed Certificate Location |
| 20 | + $le_root = "/etc/letsencrypt/live/${fqdn}" |
| 21 | + |
| 22 | + $ldap_pw = pick($bind_pw, 'testpassword') |
| 23 | + |
| 24 | + # Generate and sign certificate |
| 25 | + letsencrypt::certonly { $fqdn: |
| 26 | + plugin => 'dns-route53', |
| 27 | + manage_cron => true, |
| 28 | + } |
| 29 | + |
| 30 | + # Configure OpenVPN Access Server |
| 31 | + class { 'openvpnas': |
| 32 | + manage_repo => true, |
| 33 | + version => $version, |
| 34 | + versionlock_enable => true, |
| 35 | + versionlock_release => '1.el9', |
| 36 | + manage_service => true, |
| 37 | + manage_web_certs => true, |
| 38 | + cert_source_path => $le_root, |
| 39 | + require => Letsencrypt::Certonly[$fqdn], |
| 40 | + |
| 41 | + config => { |
| 42 | + # Define LDAP settings FIRST |
| 43 | + 'auth.ldap.0.enable' => 'true', |
| 44 | + 'auth.ldap.0.name' => 'Rubin LDAP Servers', |
| 45 | + 'auth.ldap.0.server.0.host' => 'ipa1.cp.lsst.org', |
| 46 | + 'auth.ldap.0.server.1.host' => 'ipa1.ls.lsst.org', |
| 47 | + 'auth.ldap.0.bind_dn' => 'uid=svc_openvpnas,cn=users,cn=accounts,dc=lsst,dc=cloud', |
| 48 | + 'auth.ldap.0.bind_pw' => $ldap_pw, |
| 49 | + 'auth.ldap.0.users_base_dn' => 'cn=accounts,dc=lsst,dc=cloud', |
| 50 | + 'auth.ldap.0.add_req' => 'memberOf=cn=vpn,cn=groups,cn=accounts,dc=lsst,dc=cloud', |
| 51 | + 'auth.ldap.0.user_exists_check' => 'true', |
| 52 | + 'auth.ldap.0.use_ssl' => 'never', |
| 53 | + 'auth.ldap.0.ssl_verify' => 'internal', |
| 54 | + 'auth.ldap.0.timeout' => '4', |
| 55 | + 'auth.ldap.0.uname_attr' => 'uid', |
| 56 | + 'auth.ldap.0.def_group' => 'vpn-default', |
| 57 | + 'vpn.server.group_default' => 'vpn-default', |
| 58 | + 'auth.local.0.enable' => 'false', |
| 59 | + }, |
| 60 | + } |
| 61 | + |
| 62 | + # Set the authentication module type AFTER LDAP servers are defined |
| 63 | + exec { 'set-auth-module-ldap': |
| 64 | + command => '/usr/local/openvpn_as/scripts/sacli -k auth.module.type -v ldap ConfigPut && /usr/local/openvpn_as/scripts/sacli start', |
| 65 | + path => ['/usr/local/openvpn_as/scripts', '/usr/bin', '/usr/local/bin'], |
| 66 | + unless => '/usr/local/openvpn_as/scripts/sacli ConfigQuery | grep -q \'"auth.module.type": "ldap"\'', |
| 67 | + require => Class['openvpnas'], |
| 68 | + } |
| 69 | + |
| 70 | + # Create vpn-it and vpn-default groups |
| 71 | + exec { 'create_openvpn_groups': |
| 72 | + command => '/usr/local/openvpn_as/scripts/sacli --user vpn-it --key "type" --value "group" UserPropPut && |
| 73 | + /usr/local/openvpn_as/scripts/sacli --user vpn-it --key "group_declare" --value "true" UserPropPut && |
| 74 | + /usr/local/openvpn_as/scripts/sacli --user vpn-default --key "type" --value "group" UserPropPut && |
| 75 | + /usr/local/openvpn_as/scripts/sacli --user vpn-default --key "group_declare" --value "true" UserPropPut && |
| 76 | + /usr/local/openvpn_as/scripts/sacli start', |
| 77 | + path => ['/usr/local/openvpn_as/scripts', '/usr/bin', '/usr/local/bin'], |
| 78 | + unless => '/usr/local/openvpn_as/scripts/sacli UserPropGet | grep -q "vpn-default"', |
| 79 | + require => Exec['set-auth-module-ldap'], |
| 80 | + } |
| 81 | + |
| 82 | + # Grant admin role to vpn-it |
| 83 | + exec { 'grant_admin_to_vpn_it': |
| 84 | + command => '/usr/local/openvpn_as/scripts/sacli --user vpn-it --key "prop_superuser" --value "true" UserPropPut && /usr/local/openvpn_as/scripts/sacli start', |
| 85 | + path => ['/usr/local/openvpn_as/scripts', '/usr/bin', '/usr/local/bin'], |
| 86 | + unless => '/usr/local/openvpn_as/scripts/sacli --pfilt vpn-it UserPropGet | grep -q "prop_superuser.*:.*true"', |
| 87 | + require => Exec['create_openvpn_groups'], |
| 88 | + } |
| 89 | +} |
0 commit comments