<-
Apache > HTTP Server > Documentation > Modules

Apache Module mod_authnz_fcgi 1y3k55

Available Languages:  fr 

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

Summary 6m2os

This module allows FastCGI authorizer applications to authenticate s and authorize access to resources. It s 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 id and , such as for Basic authentication, or can authenticate using arbitrary mechanisms.

 Apache!

Topics 2c136y

Directives 1a4l6m

Bugfix checklist 4i2533

See also 27136x

top

Invocation modes 3i3973

The invocation modes for FastCGI authorizers ed 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 AuthBasirovider, Require, or check__id. The first two of these correspond to the directives used to enable participation in the appropriate processing phase.

Descriptions of each mode:

Type authn, mechanism AuthBasirovider
In this mode, FCGI_ROLE is set to AUTHORIZER and FCGI_APACHE_ROLE is set to AUTHENTICATOR. The application must be defined as provider type authn using AuthBasirovider. When invoked, the application is expected to authenticate the client using the provided id and . 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_WD'};
    die if !$ENV{'REMOTE_'};

    print STDERR "This text is written to the web server error log.\n";

    if ( ($ENV{'REMOTE_' } eq "foo" || $ENV{'REMOTE_'} eq "foo1") &&
        $ENV{'REMOTE_WD'} 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"
  AuthBasirovider FooAuthn
  Require ...
</Location>
Type authz, mechanism Require
In this mode, FCGI_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 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_WD'};

    print STDERR "This text is written to the web server error log.\n";

    if ($ENV{'REMOTE_'} 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 ...
  AuthBasirovider ...
  Require FooAuthz
</Location>
Type authnz, mechanism AuthBasirovider + Require
In this mode, which s the web server-agnostic FastCGI AUTHORIZER 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 id, , 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_WD'};
    die if !$ENV{'REMOTE_'};

    print STDERR "This text is written to the web server error log.\n";

    if ( ($ENV{'REMOTE_' } eq "foo" || $ENV{'REMOTE_'} eq "foo1") &&
        $ENV{'REMOTE_WD'} 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"
  AuthBasirovider FooAuthnz
  Require FooAuthnz
</Location>
Type authn, mechanism check__id
In this mode, FCGI_ROLE is set to AUTHORIZER and FCGI_APACHE_ROLE is set to AUTHENTICATOR. The application must be defined as provider type authn using 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_WD'};
    die if !$ENV{'REMOTE_'};

    print STDERR "This text is written to the web server error log.\n";

    if ( ($ENV{'REMOTE_' } eq "foo" || $ENV{'REMOTE_'} eq "foo1") &&
        $ENV{'REMOTE_WD'} 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 \
                               Expr "%{reqenv:REMOTE_}"
  Require ...
</Location>
top

Additional examples v2jo

  1. If your application s the separate authentication and authorization roles (AUTHENTICATOR and AUTHORIZER), define separate providers as follows, even if they map to the same application:
    AuthnzFcgiDefineProvider authn  FooAuthn  fcgi://localhost:10102/
    AuthnzFcgiDefineProvider authz  FooAuthz  fcgi://localhost:10102/
    Specify the authn provider on Require:
    AuthType Basic
    AuthName "Restricted"
    AuthBasirovider FooAuthn
    Require FooAuthz
  2. If your application s the generic AUTHORIZER role (authentication and authorizer in one invocation), define a single provider as follows:
    AuthnzFcgiDefineProvider authnz FooAuthnz fcgi://localhost:10103/
    Specify the authnz provider on both AuthBasirovider and Require:
    AuthType Basic
    AuthName "Restricted"
    AuthBasirovider FooAuthnz
    Require FooAuthnz
top

Limitations 1q3r6p

The following are potential features which are not currently implemented:

Apache httpd access checker
The Apache httpd API access check phase is a separate phase from authentication and authorization. Some other FastCGI implementations implement this phase, which is denoted by the setting of FCGI_APACHE_ROLE to ACCESS_CHECKER.
Local (Unix) sockets or pipes
Only T sockets are currently ed.
for mod_authn_socache
mod_authn_socache interaction should be implemented for applications which participate in Apache httpd-style authentication.
for digest authentication using AuthDigestProvider
This is expected to be a permanent limitation as there is no authorizer flow for retrieving a hash.
Application process management
This is expected to be permanently out of scope for this module. Application processes must be controlled by other means. For example, fcgistarter can be used to start them.
AP_AUTH_INTERNAL_PER_URI
All providers are currently ed as AP_AUTH_INTERNAL_PER_CONF, which means that checks are not performed again for internal subrequests with the same access control configuration as the initial request.
Protocol data charset conversion
If mod_authnz_fcgi runs in an EBCDIC compilation environment, all FastCGI protocol data is written in EBCDIC and expected to be received in EBCDIC.
Multiple requests per connection
Currently the connection to the FastCGI authorizer is closed after every phase of processing. For example, if the authorizer handles separate authn and authz phases then two connections will be used.
URI Mapping
URIs from clients can't be mapped, such as with the Proxy used with FastCGI responders.
top

Logging 3t6c50

  1. Processing errors are logged at log level error and higher.
  2. Messages written by the application are logged at log level warn.
  3. General messages for debugging are logged at log level debug.
  4. Environment variables ed to the application are logged at log level trace2. The value of the REMOTE_WD variable will be obscured, but any other sensitive data will be visible in the log.
  5. All I/O between the module and the FastCGI application, including all environment variables, will be logged in printable and hex format at log level trace5. All sensitive data will be visible in the log.

LogLevel can be used to configure a log level specific to mod_authnz_fcgi. For example:

LogLevel info authnz_fcgi:trace8
top

AuthnzFcgiCheckAuthnProvider Directive 1n4s1t

Description: Enables a FastCGI application to handle the check_authn authentication hook.
Syntax: AuthnzFcgiCheckAuthnProvider provider-name|None option ...
Default: none
Context: directory
Status: Extension
Module: mod_authnz_fcgi

This directive is used to enable a FastCGI authorizer to handle a specific processing phase of authentication or authorization.

Some capabilities of FastCGI authorizers require enablement using this directive instead of AuthBasirovider:

provider-name
This is the name of a provider defined with AuthnzFcgiDefineProvider.
None
Specify None to disable a provider enabled with this directive in an outer scope, such as in a parent directory.
option
The following options are ed:
Authoritative On|Off (default On)
This controls whether or not other modules are allowed to run when this module has a FastCGI authorizer configured and it fails the request.
Default id
When the authorizer returns success and Expr is configured and evaluates to an empty string (e.g., authorizer didn't return a variable), this value will be used as the id. This is typically used when the authorizer has a concept of guest, or unauthenticated, s and guest s are mapped to some specific id for logging and other purposes.
RequireBasicAuth On|Off (default Off)
This controls whether or not Basic auth is required before ing the request to the authorizer. If required, the authorizer won't be invoked without a id and ; 401 will be returned for a request without that.
Expr expr (no default)
When Basic authentication isn't provided by the client and the authorizer determines the , this expression, evaluated after calling the authorizer, determines the . The expression follows ap_expr syntax and must resolve to a string. A typical use is to reference a Variable-XXX setting returned by the authorizer using an option like Expr "%{reqenv:XXX}". If this option is specified and the id can't be retrieved using the expression after a successful authentication, the request will be rejected with a 500 error.
top

AuthnzFcgiDefineProvider Directive 3y1h2w

Description: Defines a FastCGI application as a provider for authentication and/or authorization
Syntax: AuthnzFcgiDefineProvider type provider-name backend-address
Default: none
Context: server config
Status: Extension
Module: mod_authnz_fcgi

This directive is used to define a FastCGI application as a provider for a particular phase of authentication or authorization.

type
This must be set to authn for authentication, authz for authorization, or authnz for a generic FastCGI authorizer which performs both checks.
provider-name
This is used to assign a name to the provider which is used in other directives such as Require.
backend-address
This specifies the address of the application, in the form fcgi://hostname:port/. The application process(es) must be managed independently, such as with fcgistarter.

Available Languages:  fr 

top

Comments 2p1l6j

Notice:
This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed by our s if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Libera.chat, or sent to our mailing lists.