Example Apache HTTPD configuration for basic identity providers
You can use CGI scripting in Apache HTTPD to configure a remote authentication server that returns JSON responses for basic identity providers in Red Hat OpenShift Container Platform.
The following is an example of an Apache VirtualHost configuration file.
<VirtualHost *:443>
# CGI Scripts in here
DocumentRoot /var/www/cgi-bin
# SSL Directives
SSLEngine on
SSLCipherSuite PROFILE=SYSTEM
SSLProxyCipherSuite PROFILE=SYSTEM
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
# Configure HTTPD to execute scripts
ScriptAlias /basic /var/www/cgi-bin
# Handles a failed login attempt
ErrorDocument 401 /basic/fail.cgi
# Handles authentication
<Location /basic/login.cgi>
AuthType Basic
AuthName "Please Log In"
AuthBasicProvider file
AuthUserFile /etc/httpd/conf/passwords
Require valid-user
</Location>
</VirtualHost>
The following is an example of a login.cgi CGI script file.
#!/bin/bash
echo "Content-Type: application/json"
echo ""
echo '{"sub":"userid", "name":"'$REMOTE_USER'"}'
exit 0
The following is an example of a fail.cgi CGI script file.
#!/bin/bash
echo "Content-Type: application/json"
echo ""
echo '{"error": "Login failure"}'
exit 0
File requirements
These are the requirements for the files you create on an Apache HTTPD web server:
-
The
login.cgiandfail.cgiCGI script files must be executable. Use thechmod +xcommand on both files. -
If SELinux is enabled, the
login.cgiandfail.cgiCGI script files must have proper SELinux security contexts. Run therestorecon -RFv /var/www/cgi-bincommand, or ensure that the context is thehttpd_sys_script_exec_tSELinux type by using thels -laZcommand. -
The
login.cgiCGI script file runs only when the user successfully logs in according to theRequireandAuthApache configuration directives. -
The
fail.cgiCGI script file runs when the user fails to log in and returns anHTTP 401HTTP status code.