Apache HTTP Server Version 2.4

| Description: | Allows a FastCGI authorizer application to handle Apache httpd authentication and authorization |
|---|---|
| Status: | Extension |
| Module Identifier: | authnz_fcgi_module |
| Source File: | mod_authnz_fcgi.c |
| Compatibility: | Available in version 2.4.10 and later |
This module allows FastCGI authorizer applications to authenticate users and authorize access to resources. It supports generic FastCGI authorizers which participate in a single phase for authentication and authorization as well as Apache httpd-specific authenticators and authorizors which participate in one or both phases.
FastCGI authorizers can authenticate using user id and password, such as for Basic authentication, or can authenticate using arbitrary mechanisms.
The invocation modes for FastCGI authorizers supported by this module are distinguished by two characteristics, type and auth mechanism.
Type is simply authn for authentication,
authz for authorization, or authnz for
combined authentication and authorization.
Auth mechanism refers to the Apache httpd configuration
mechanisms and processing phases, and can be
AuthBasicProvider, Require, or
check_user_id. The first two of these
correspond to the directives used to enable participation in the
appropriate processing phase.
Descriptions of each mode:
authn, mechanism
AuthBasicProviderFCGI_ROLE is set to AUTHORIZER and
FCGI_APACHE_ROLE is set to AUTHENTICATOR.
The application must be defined as provider type authn
using
AuthnzFcgiDefineProvider and enabled with
AuthBasicProvider.
When invoked, the application is
expected to authenticate the client using the provided user id and
password. Example application:
#!/usr/bin/perl
use FCGI;
my $request = FCGI::Request();
while ($request->Accept() >= 0) {
die if $ENV{'FCGI_APACHE_ROLE'} ne "AUTHENTICATOR";
die if $ENV{'FCGI_ROLE'} ne "AUTHORIZER";
die if !$ENV{'REMOTE_PASSWD'};
die if !$ENV{'REMOTE_USER'};
print STDERR "This text is written to the web server error log.\n";
if ( ($ENV{'REMOTE_USER' } eq "foo" || $ENV{'REMOTE_USER'} eq "foo1") &&
$ENV{'REMOTE_PASSWD'} eq "bar" ) {
print "Status: 200\n";
print "Variable-AUTHN_1: authn_01\n";
print "Variable-AUTHN_2: authn_02\n";
print "\n";
}
else {
print "Status: 401\n\n";
}
}
Example configuration:
AuthnzFcgiDefineProvider authn FooAuthn fcgi://localhost:10102/ <Location "/protected/"> AuthType Basic AuthName "Restricted" AuthBasicProvider FooAuthn Require ... </Location>
authz, mechanism
RequireFCGI_ROLE is set to
AUTHORIZER and FCGI_APACHE_ROLE is set to
AUTHORIZER. The application must be defined as
provider type authz using
AuthnzFcgiDefineProvider. When invoked, the application
is expected to authorize the client using the provided user id and other
request data. Example application:
#!/usr/bin/perl
use FCGI;
my $request = FCGI::Request();
while ($request->Accept() >= 0) {
die if $ENV{'FCGI_APACHE_ROLE'} ne "AUTHORIZER";
die if $ENV{'FCGI_ROLE'} ne "AUTHORIZER";
die if $ENV{'REMOTE_PASSWD'};
print STDERR "This text is written to the web server error log.\n";
if ($ENV{'REMOTE_USER'} eq "foo1") {
print "Status: 200\n";
print "Variable-AUTHZ_1: authz_01\n";
print "Variable-AUTHZ_2: authz_02\n";
print "\n";
}
else {
print "Status: 403\n\n";
}
}
Example configuration:
AuthnzFcgiDefineProvider authz FooAuthz fcgi://localhost:10103/ <Location "/protected/"> AuthType ... AuthName ... AuthBasicProvider ... Require FooAuthz </Location>
authnz, mechanism
AuthBasicProvider + RequireAUTHORIZER protocol, FCGI_ROLE is set to
AUTHORIZER and FCGI_APACHE_ROLE is not set.
The application must be defined as provider type authnz
using
AuthnzFcgiDefineProvider. The application is expected to
handle both authentication and authorization in the same invocation
using the user id, password, and other request data. The invocation
occurs during the Apache httpd API authentication phase. If the
application returns 200 and the same provider is invoked during the
authorization phase (via Require), mod_authnz_fcgi
will return success for the authorization phase without invoking the
application. Example application:
#!/usr/bin/perl
use FCGI;
my $request = FCGI::Request();
while ($request->Accept() >= 0) {
die if $ENV{'FCGI_APACHE_ROLE'};
die if $ENV{'FCGI_ROLE'} ne "AUTHORIZER";
die if !$ENV{'REMOTE_PASSWD'};
die if !$ENV{'REMOTE_USER'};
print STDERR "This text is written to the web server error log.\n";
if ( ($ENV{'REMOTE_USER' } eq "foo" || $ENV{'REMOTE_USER'} eq "foo1") &&
$ENV{'REMOTE_PASSWD'} eq "bar" &&
$ENV{'REQUEST_URI'} =~ m%/bar/.*%) {
print "Status: 200\n";
print "Variable-AUTHNZ_1: authnz_01\n";
print "Variable-AUTHNZ_2: authnz_02\n";
print "\n";
}
else {
print "Status: 401\n\n";
}
}
Example configuration:
AuthnzFcgiDefineProvider authnz FooAuthnz fcgi://localhost:10103/ <Location "/protected/"> AuthType Basic AuthName "Restricted" AuthBasicProvider FooAuthnz Require FooAuthnz </Location>
authn, mechanism
check_user_idFCGI_ROLE is set to
AUTHORIZER and FCGI_APACHE_ROLE is set to
AUTHENTICATOR. The application must be defined as
provider type authn using
AuthnzFcgiDefineProvider. AuthnzFcgiCheckAuthnProvider
specifies when it is called. Example application:
#!/usr/bin/perl
use FCGI;
my $request = FCGI::Request();
while ($request->Accept() >= 0) {
die if $ENV{'FCGI_APACHE_ROLE'} ne "AUTHENTICATOR";
die if $ENV{'FCGI_ROLE'} ne "AUTHORIZER";
# This authorizer assumes that the RequireBasicAuth option of
# AuthnzFcgiCheckAuthnProvider is On:
die if !$ENV{'REMOTE_PASSWD'};
die if !$ENV{'REMOTE_USER'};
print STDERR "This text is written to the web server error log.\n";
if ( ($ENV{'REMOTE_USER' } eq "foo" || $ENV{'REMOTE_USER'} eq "foo1") &&
$ENV{'REMOTE_PASSWD'} eq "bar" ) {
print "Status: 200\n";
print "Variable-AUTHNZ_1: authnz_01\n";
print "Variable-AUTHNZ_2: authnz_02\n";
print "\n";
}
else {
print "Status: 401\n\n";
# If a response body is written here, it will be returned to
# the client.
}
}
Example configuration:
AuthnzFcgiDefineProvider authn FooAuthn fcgi://localhost:10103/
<Location "/protected/">
AuthType ...
AuthName ...
AuthnzFcgiCheckAuthnProvider FooAuthn \
Authoritative On \
RequireBasicAuth Off \
UserExpr "%{reqenv:REMOTE_USER}"
Require ...
</Location>