|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * authentication/configuring-ldap-failover.adoc |
| 4 | + |
| 5 | +[id='sssd-configuring-apache-{context}'] |
| 6 | += Configuring Apache to use SSSD |
| 7 | + |
| 8 | +.Procedure |
| 9 | + |
| 10 | +. Create a *_/etc/pam.d/openshift_* file that contains the |
| 11 | +following contents: |
| 12 | ++ |
| 13 | +---- |
| 14 | +auth required pam_sss.so |
| 15 | +account required pam_sss.so |
| 16 | +---- |
| 17 | ++ |
| 18 | +This configuration enables PAM, the pluggable authentication module, to use |
| 19 | +`pam_sss.so` to determine authentication and access control when an |
| 20 | +authentication request is issued for the `openshift` stack. |
| 21 | + |
| 22 | +. Edit the *_/etc/httpd/conf.modules.d/55-authnz_pam.conf_* file and uncomment |
| 23 | + the following line: |
| 24 | ++ |
| 25 | +---- |
| 26 | +LoadModule authnz_pam_module modules/mod_authnz_pam.so |
| 27 | +---- |
| 28 | + |
| 29 | +. To configure the Apache *_httpd.conf_* file for remote basic authentication, |
| 30 | +create the *_openshift-remote-basic-auth.conf_* file in the |
| 31 | +*_/etc/httpd/conf.d_* directory. Use the following template to provide your |
| 32 | +required settings and values: |
| 33 | ++ |
| 34 | +[IMPORTANT] |
| 35 | +==== |
| 36 | +Carefully review the template and customize its contents to fit your |
| 37 | +environment. |
| 38 | +==== |
| 39 | ++ |
| 40 | +---- |
| 41 | +LoadModule request_module modules/mod_request.so |
| 42 | +LoadModule php7_module modules/libphp7.so |
| 43 | +
|
| 44 | +# Nothing needs to be served over HTTP. This virtual host simply redirects to |
| 45 | +# HTTPS. |
| 46 | +<VirtualHost *:80> |
| 47 | + DocumentRoot /var/www/html |
| 48 | + RewriteEngine On |
| 49 | + RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R,L] |
| 50 | +</VirtualHost> |
| 51 | +
|
| 52 | +<VirtualHost *:443> |
| 53 | + # This needs to match the certificates you generated. See the CN and X509v3 |
| 54 | + # Subject Alternative Name in the output of: |
| 55 | + # openssl x509 -text -in /etc/pki/tls/certs/remote-basic.example.com.crt |
| 56 | + ServerName remote-basic.example.com |
| 57 | +
|
| 58 | + DocumentRoot /var/www/html |
| 59 | +
|
| 60 | + # Secure all connections with TLS |
| 61 | + SSLEngine on |
| 62 | + SSLCertificateFile /etc/pki/tls/certs/remote-basic.example.com.crt |
| 63 | + SSLCertificateKeyFile /etc/pki/tls/private/remote-basic.example.com.key |
| 64 | + SSLCACertificateFile /etc/pki/CA/certs/ca.crt |
| 65 | +
|
| 66 | + # Require that TLS clients provide a valid certificate |
| 67 | + SSLVerifyClient require |
| 68 | + SSLVerifyDepth 10 |
| 69 | +
|
| 70 | + # Other SSL options that may be useful |
| 71 | + # SSLCertificateChainFile ... |
| 72 | + # SSLCARevocationFile ... |
| 73 | +
|
| 74 | + # Send logs to a specific location to make them easier to find |
| 75 | + ErrorLog logs/remote_basic_error_log |
| 76 | + TransferLog logs/remote_basic_access_log |
| 77 | + LogLevel warn |
| 78 | +
|
| 79 | + # PHP script that turns the Apache REMOTE_USER env var |
| 80 | + # into a JSON formatted response that OpenShift understands |
| 81 | + <Location /check_user.php> |
| 82 | + # all requests not using SSL are denied |
| 83 | + SSLRequireSSL |
| 84 | + # denies access when SSLRequireSSL is applied |
| 85 | + SSLOptions +StrictRequire |
| 86 | + # Require both a valid basic auth user (so REMOTE_USER is always set) |
| 87 | + # and that the CN of the TLS client matches that of the OpenShift master |
| 88 | + <RequireAll> |
| 89 | + Require valid-user |
| 90 | + Require expr %{SSL_CLIENT_S_DN_CN} == 'system:openshift-master' |
| 91 | + </RequireAll> |
| 92 | + # Use basic auth since OpenShift will call this endpoint with a basic challenge |
| 93 | + AuthType Basic |
| 94 | + AuthName openshift |
| 95 | + AuthBasicProvider PAM |
| 96 | + AuthPAMService openshift |
| 97 | + |
| 98 | + # Store attributes in environment variables. Specify the email attribute that |
| 99 | + # you confirmed. |
| 100 | + LookupOutput Env |
| 101 | + LookupUserAttr mail REMOTE_USER_MAIL |
| 102 | + LookupUserGECOS REMOTE_USER_DISPLAY_NAME |
| 103 | +
|
| 104 | + # Other options that might be useful |
| 105 | +
|
| 106 | + # While REMOTE_USER is used as the sub field and serves as the immutable ID, |
| 107 | + # REMOTE_USER_PREFERRED_USERNAME could be used to have a different username |
| 108 | + # LookupUserAttr <attr_name> REMOTE_USER_PREFERRED_USERNAME |
| 109 | +
|
| 110 | + # Group support may be added in a future release |
| 111 | + # LookupUserGroupsIter REMOTE_USER_GROUP |
| 112 | + </Location> |
| 113 | +
|
| 114 | + # Deny everything else |
| 115 | + <Location ~ "^((?!\/check_user\.php).)*$"> |
| 116 | + Deny from all |
| 117 | + </Location> |
| 118 | +</VirtualHost> |
| 119 | +---- |
| 120 | + |
| 121 | +. Create the *_check_user.php_* script in the *_/var/www/html_* directory. |
| 122 | +Include the following code: |
| 123 | ++ |
| 124 | +---- |
| 125 | +<?php |
| 126 | +// Get the user based on the Apache var, this should always be |
| 127 | +// set because we 'Require valid-user' in the configuration |
| 128 | +$user = apache_getenv('REMOTE_USER'); |
| 129 | +
|
| 130 | +// However, we assume it may not be set and |
| 131 | +// build an error response by default |
| 132 | +$data = array( |
| 133 | + 'error' => 'remote PAM authentication failed' |
| 134 | +); |
| 135 | +
|
| 136 | +// Build a success response if we have a user |
| 137 | +if (!empty($user)) { |
| 138 | + $data = array( |
| 139 | + 'sub' => $user |
| 140 | + ); |
| 141 | + // Map of optional environment variables to optional JSON fields |
| 142 | + $env_map = array( |
| 143 | + 'REMOTE_USER_MAIL' => 'email', |
| 144 | + 'REMOTE_USER_DISPLAY_NAME' => 'name', |
| 145 | + 'REMOTE_USER_PREFERRED_USERNAME' => 'preferred_username' |
| 146 | + ); |
| 147 | +
|
| 148 | + // Add all non-empty environment variables to JSON data |
| 149 | + foreach ($env_map as $env_name => $json_name) { |
| 150 | + $env_data = apache_getenv($env_name); |
| 151 | + if (!empty($env_data)) { |
| 152 | + $data[$json_name] = $env_data; |
| 153 | + } |
| 154 | + } |
| 155 | +} |
| 156 | +
|
| 157 | +// We always output JSON from this script |
| 158 | +header('Content-Type: application/json', true); |
| 159 | +
|
| 160 | +// Write the response as JSON |
| 161 | +echo json_encode($data); |
| 162 | +?> |
| 163 | +---- |
| 164 | + |
| 165 | +. Enable Apache to load the module. Modify the |
| 166 | +*_/etc/httpd/conf.modules.d/55-lookup_identity.conf_* file and uncomment the |
| 167 | +following line: |
| 168 | ++ |
| 169 | +---- |
| 170 | +LoadModule lookup_identity_module modules/mod_lookup_identity.so |
| 171 | +---- |
| 172 | + |
| 173 | +. Set an SELinux boolean so that SElinux allows Apache to connect to SSSD over |
| 174 | +D-BUS: |
| 175 | ++ |
| 176 | +---- |
| 177 | +# setsebool -P httpd_dbus_sssd on |
| 178 | +---- |
| 179 | + |
| 180 | +. Set a boolean to tell SELinux that it is acceptable for Apache to contact the |
| 181 | +PAM subsystem: |
| 182 | ++ |
| 183 | +---- |
| 184 | +# setsebool -P allow_httpd_mod_auth_pam on |
| 185 | +---- |
| 186 | + |
| 187 | +. Start Apache: |
| 188 | ++ |
| 189 | +---- |
| 190 | +# systemctl start httpd.service |
| 191 | +---- |
0 commit comments