Apache 2 als reverse Proxy mit externen Authorisierungsscript

Es werden folgende Apache Module verwendet: mod_proxy und mod_auth_external (hier koennte auch ein anderes Modul z.B. mod_auth_radius zum einsatz kommen)

Servername intern: hide.int.lan

Servername zur Welt: show.ext.lan

Grundeinstellungen des Webservers

  ServerAdmin admin@ext.lan
  ServerName show-proxy.int.lan
  DocumentRoot "/home/www/show/html-data"
  ErrorLog /home/www/show/log/httpd-error.log
  CustomLog /home/www/show/log/httpd-access.log combined

.

Da die Uebertragung verschluesselt stattfinden soll, aktiviere ich SSL und verwende ein selfsignet Zertifikat.

Listen  192.168.55.13:443
<VirtualHost 192.168.55.13:443>
  #SSL OPTIONEN
  SSLEngine on
  SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP
  SSLCertificateFile /home/www/show/ssl/show.ext.lan.crt
  SSLCertificateKeyFile /home/www/show/ssl/show.ext.lan.key
  SSLOptions +OptRenegotiate

.

Danach aktiviere ich das mod_proxy

  <IfModule mod_proxy.c>
    ProxyPreserveHost On
    ProxyRequests Off
    ProxyVia On
  </IfModule>

.

Bevor man mod_auth_external verwenden kann muss man es vorher definieren. Mehr info zu diesem Apache modul gibt es im Web http://www.unixpapa.com/mod_auth_external.html oder in den Ports /usr/ports/www/mod_auth_external.

  AddExternalAuth show_auth /home/foo/bin/script-auth.pl
  SetExternalAuthMethod show_auth pipe

.

ProxyPass innerhalb von Location wird zwar in der Apachen Dokumentation so beschrieben ist aber wohl seit laengeren kaputt.

Eigentlich sollte ProxyPass...

ProxyPass /error-documents !
ProxyPass / http://hide.int.lan:80/
ProxyPassReverse http://hide.int.lan:80/

.

Innerhalb der Location die hier "/" aussgenommen "/error-documents" definiert wird dann die vorher definierte "show_auth" authentisierung verwendet. ("<Location ~ " ist das gleiche wie LocationMatch)

  <Location ~  "^/(?!error-documents)">
    Order deny,allow
    Allow from all
    AuthType Basic
    AuthName "Authentication"
    AuthExternal show_auth
    require valid-user
  </Location>

.

...innerhalb von Location Tags funktionieren. Deshalb verwende ich das onehin viel flexiblere mod_rewrite zusammen mit mod_proxy.

  RewriteCond %{REQUEST_URI} ^/(?!error-documents)
  RewriteRule ^/(.*) http://hide.int.lan/$1 [P,L]

.

in meinem Fall verwende ich /error-documents/ als lokalen Content das laesst sich natuerlich auch erweitern z.B. mit ^/(?!error-documents|public) als RegExp.

In meinem Beispiel gibt es noch ein modifiziertes ErrorDocument, was damit zu tun hat das die eigentliche Authorisierung von einem RSA-ACE Server kommt, da hier auch Meldungen zurueckgegeben werden die ueber SimpleAuth nicht abgebildet werden koennen (Next Token Mode, new PIN etc.).

  <LocationMatch "^/error-documents">
    Order deny,allow
    Allow from all
  </LocationMatch>
  ErrorDocument 401 /error-documents/error401.html

.

Die ganze Konfiguration nochmal an einem Stueck:

Listen  192.168.55.13:443
<VirtualHost 192.168.55.13:443>
  ServerAdmin admin@ext.lan
  ServerName show-proxy.int.lan
  DocumentRoot "/home/www/show/html-data"
  ErrorLog /home/www/show/log/httpd-error.log
  CustomLog /home/www/show/log/httpd-access.log combined
  #SSL OPTIONEN
  SSLEngine on
  SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP
  SSLCertificateFile /home/www/show/ssl/show.ext.lan.crt
  SSLCertificateKeyFile /home/www/show/ssl/show.ext.lan.key
  SSLOptions +OptRenegotiate
  <IfModule mod_proxy.c>
    ProxyPreserveHost On
    ProxyRequests Off
    ProxyVia On
  </IfModule>
  #external script auth show
  AddExternalAuth show_auth /home/foo/bin/script-auth.pl
  SetExternalAuthMethod show_auth pipe
  RewriteEngine On
  RewriteCond %{REQUEST_URI} ^/(?!error-documents)
  RewriteRule ^/(.*) http://hide.int.lan/$1 [P,L]
  <Location ~  "^/(?!error-documents)">
    Order deny,allow
    Allow from all
    AuthType Basic
    AuthName "Authentication"
    AuthExternal show_auth
    require valid-user
  </Location>
  <Location ~ "^/error-documents">
    Order deny,allow
    Allow from all
  </Location>
  ErrorDocument 401 /error-documents/error401.html
</VirtualHost>

.

Umleiten der unverschluesselten Anfragen

Es soll auf jeden Fall nur Verschluesselt von der Welt auf show.ext.lan zugegriffen werden, deshalb werden anfragen auf dem normalen http Port auf https umgeleitet.

Listen  192.168.55.13:80
<VirtualHost 192.168.55.13:80>
  ServerAdmin admin@ext.lan
  ServerName show.ext.lan
  DocumentRoot "/home/www/show/html-data"
  ErrorLog /home/www/show/log/httpd-error.log
  CustomLog /home/www/show/log/httpd-access.log combined
  #Alle zugriffe sollen auf SSL laufen!
  RewriteEngine On
  RewriteRule ^/(.*)$ https://%{SERVER_NAME}/$1 [R,L]
</VirtualHost>

.

Apache/reverseProxy-simpleAuth-externesAuthScript (last edited 2008-07-14 09:55:40 by localhost)