2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
7 Licensed to the Apache Software Foundation (ASF) under one or more
8 contributor license agreements. See the NOTICE file distributed with
9 this work for additional information regarding copyright ownership.
10 The ASF licenses this file to You under the Apache License, Version 2.0
11 (the "License"); you may not use this file except in compliance with
12 the License. You may obtain a copy of the License at
14 http://www.apache.org/licenses/LICENSE-2.0
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
23 <modulesynopsis metafile="mod_authnz_fcgi.xml.meta">
25 <name>mod_authnz_fcgi</name>
26 <description>Allows a FastCGI authorizer application to handle Apache
27 httpd authentication and authorization</description>
28 <status>Extension</status>
29 <sourcefile>mod_authnz_fcgi.c</sourcefile>
30 <identifier>authnz_fcgi_module</identifier>
31 <compatibility>Available in version 2.4.10 and later</compatibility>
34 <p>This module allows FastCGI authorizer applications to
35 authenticate users and authorize access to resources. It supports
36 generic FastCGI authorizers which participate in a single phase
37 for authentication and authorization as well as Apache httpd-specific
38 authenticators and authorizors which participate in one or both
41 <p>FastCGI authorizers can authenticate using user id and password,
42 such as for Basic authentication, or can authenticate using arbitrary
46 <seealso><a href="../howto/auth.html">Authentication, Authorization,
47 and Access Control</a></seealso>
48 <seealso><module>mod_auth_basic</module></seealso>
49 <seealso><program>fcgistarter</program></seealso>
50 <seealso><module>mod_proxy_fcgi</module></seealso>
52 <section id="invocations"><title>Invocation modes</title>
54 <p>The invocation modes for FastCGI authorizers supported by this
55 module are distinguished by two characteristics, <em>type</em> and
56 auth <em>mechanism</em>.</p>
58 <p><em>Type</em> is simply <code>authn</code> for authentication,
59 <code>authz</code> for authorization, or <code>authnz</code> for
60 combined authentication and authorization.</p>
62 <p>Auth <em>mechanism</em> refers to the Apache httpd configuration
63 mechanisms and processing phases, and can be <code>
64 AuthBasicProvider</code>, <code>Require</code>, or <code>
65 check_user_id</code>. The first two of these
66 correspond to the directives used to enable participation in the
67 appropriate processing phase.</p>
69 <p>Descriptions of each mode:</p>
72 <dt><em>Type</em> <code>authn</code>, <em>mechanism</em>
73 <code>AuthBasicProvider</code></dt>
76 <code>FCGI_ROLE</code> is set to <code>AUTHORIZER</code> and
77 <code>FCGI_APACHE_ROLE</code> is set to <code>AUTHENTICATOR</code>.
78 The application must be defined as provider type <em>authn</em>
79 using <directive module="mod_authnz_fcgi">
80 AuthnzFcgiDefineProvider</directive> and enabled with
81 <directive module="mod_auth_basic">AuthBasicProvider</directive>.
82 When invoked, the application is
83 expected to authenticate the client using the provided user id and
84 password. Example application:
86 <highlight language="perl">
89 while (FCGI::accept >= 0) {
90 die if $ENV{'FCGI_APACHE_ROLE'} ne "AUTHENTICATOR";
91 die if $ENV{'FCGI_ROLE'} ne "AUTHORIZER";
92 die if !$ENV{'REMOTE_PASSWD'};
93 die if !$ENV{'REMOTE_USER'};
95 print STDERR "This text is written to the web server error log.\n";
97 if ( ($ENV{'REMOTE_USER' } eq "foo" || $ENV{'REMOTE_USER'} eq "foo1") &&
98 $ENV{'REMOTE_PASSWD'} eq "bar" ) {
99 print "Status: 200\n";
100 print "Variable-AUTHN_1: authn_01\n";
101 print "Variable-AUTHN_2: authn_02\n";
105 print "Status: 401\n\n";
110 Example configuration:
111 <highlight language="config">
112 AuthnzFcgiDefineProvider authn FooAuthn fcgi://localhost:10102/
113 <Location "/protected/">
115 AuthName "Restricted"
116 AuthBasicProvider FooAuthn
122 <dt><em>Type</em> <code>authz</code>, <em>mechanism</em>
123 <code>Require</code></dt>
124 <dd>In this mode, <code>FCGI_ROLE</code> is set to <code>
125 AUTHORIZER</code> and <code>FCGI_APACHE_ROLE</code> is set to
126 <code>AUTHORIZER</code>. The application must be defined as
127 provider type <em>authz</em> using <directive module="mod_authnz_fcgi">
128 AuthnzFcgiDefineProvider</directive>. When invoked, the application
129 is expected to authorize the client using the provided user id and other
130 request data. Example application:
131 <highlight language="perl">
134 while (FCGI::accept >= 0) {
135 die if $ENV{'FCGI_APACHE_ROLE'} ne "AUTHORIZER";
136 die if $ENV{'FCGI_ROLE'} ne "AUTHORIZER";
137 die if $ENV{'REMOTE_PASSWD'};
139 print STDERR "This text is written to the web server error log.\n";
141 if ($ENV{'REMOTE_USER'} eq "foo1") {
142 print "Status: 200\n";
143 print "Variable-AUTHZ_1: authz_01\n";
144 print "Variable-AUTHZ_2: authz_02\n";
148 print "Status: 403\n\n";
153 Example configuration:
154 <highlight language="config">
155 AuthnzFcgiDefineProvider authz FooAuthz fcgi://localhost:10103/
156 <Location "/protected/">
159 AuthBasicProvider ...
165 <dt><em>Type</em> <code>authnz</code>, <em>mechanism</em>
166 <code>AuthBasicProvider</code> <em>+</em> <code>Require</code></dt>
168 <dd>In this mode, which supports the web server-agnostic FastCGI
169 <code>AUTHORIZER</code> protocol, <code>FCGI_ROLE</code> is set to
170 <code>AUTHORIZER</code> and <code>FCGI_APACHE_ROLE</code> is not set.
171 The application must be defined as provider type <em>authnz</em>
172 using <directive module="mod_authnz_fcgi">
173 AuthnzFcgiDefineProvider</directive>. The application is expected to
174 handle both authentication and authorization in the same invocation
175 using the user id, password, and other request data. The invocation
176 occurs during the Apache httpd API authentication phase. If the
177 application returns 200 and the same provider is invoked during the
178 authorization phase (via <directive>Require</directive>), mod_authnz_fcgi
179 will return success for the authorization phase without invoking the
180 application. Example application:
181 <highlight language="perl">
184 while (FCGI::accept >= 0) {
185 die if $ENV{'FCGI_APACHE_ROLE'};
186 die if $ENV{'FCGI_ROLE'} ne "AUTHORIZER";
187 die if !$ENV{'REMOTE_PASSWD'};
188 die if !$ENV{'REMOTE_USER'};
190 print STDERR "This text is written to the web server error log.\n";
192 if ( ($ENV{'REMOTE_USER' } eq "foo" || $ENV{'REMOTE_USER'} eq "foo1") &&
193 $ENV{'REMOTE_PASSWD'} eq "bar" &&
194 $ENV{'REQUEST_URI'} =~ m%/bar/.*%) {
195 print "Status: 200\n";
196 print "Variable-AUTHNZ_1: authnz_01\n";
197 print "Variable-AUTHNZ_2: authnz_02\n";
201 print "Status: 401\n\n";
206 Example configuration:
207 <highlight language="config">
208 AuthnzFcgiDefineProvider authnz FooAuthnz fcgi://localhost:10103/
209 <Location "/protected/">
211 AuthName "Restricted"
212 AuthBasicProvider FooAuthnz
218 <dt><em>Type</em> <code>authn</code>, <em>mechanism</em>
219 <code>check_user_id</code></dt>
221 <dd>In this mode, <code>FCGI_ROLE</code> is set to <code>
222 AUTHORIZER</code> and <code>FCGI_APACHE_ROLE</code> is set to
223 <code>AUTHENTICATOR</code>. The application must be defined as
224 provider type <em>authn</em> using <directive module="mod_authnz_fcgi">
225 AuthnzFcgiDefineProvider</directive>. <directive
226 module="mod_authnz_fcgi">AuthnzFcgiCheckAuthnProvider</directive>
227 specifies when it is called. Example application:
228 <highlight language="perl">
231 while (FCGI::accept >= 0) {
232 die if $ENV{'FCGI_APACHE_ROLE'} ne "AUTHENTICATOR";
233 die if $ENV{'FCGI_ROLE'} ne "AUTHORIZER";
235 # This authorizer assumes that the RequireBasicAuth option of
236 # AuthnzFcgiCheckAuthnProvider is On:
237 die if !$ENV{'REMOTE_PASSWD'};
238 die if !$ENV{'REMOTE_USER'};
240 print STDERR "This text is written to the web server error log.\n";
242 if ( ($ENV{'REMOTE_USER' } eq "foo" || $ENV{'REMOTE_USER'} eq "foo1") &&
243 $ENV{'REMOTE_PASSWD'} eq "bar" ) {
244 print "Status: 200\n";
245 print "Variable-AUTHNZ_1: authnz_01\n";
246 print "Variable-AUTHNZ_2: authnz_02\n";
250 print "Status: 401\n\n";
251 # If a response body is written here, it will be returned to
257 Example configuration:
258 <highlight language="config">
259 AuthnzFcgiDefineProvider authn FooAuthn fcgi://localhost:10103/
260 <Location "/protected/">
263 AuthnzFcgiCheckAuthnProvider FooAuthn \
265 RequireBasicAuth Off \
266 UserExpr "%{reqenv:REMOTE_USER}"
276 <section id="examples"><title>Additional examples</title>
279 <li>If your application supports the separate authentication and
280 authorization roles (<code>AUTHENTICATOR</code> and <code>AUTHORIZER</code>), define
281 separate providers as follows, even if they map to the same
284 <highlight language="config">
285 AuthnzFcgiDefineProvider authn FooAuthn fcgi://localhost:10102/
286 AuthnzFcgiDefineProvider authz FooAuthz fcgi://localhost:10102/
289 Specify the authn provider on
290 <directive module="mod_auth_basic">AuthBasicProvider</directive>
291 and the authz provider on
292 <directive module="mod_authz_core">Require</directive>:
294 <highlight language="config">
296 AuthName "Restricted"
297 AuthBasicProvider FooAuthn
302 <li>If your application supports the generic <code>AUTHORIZER</code> role
303 (authentication and authorizer in one invocation), define a
304 single provider as follows:
306 <highlight language="config">
307 AuthnzFcgiDefineProvider authnz FooAuthnz fcgi://localhost:10103/
310 Specify the authnz provider on both <directive>AuthBasicProvider</directive>
311 and <directive>Require</directive>:
313 <highlight language="config">
315 AuthName "Restricted"
316 AuthBasicProvider FooAuthnz
323 <section id="limitations"><title>Limitations</title>
325 <p>The following are potential features which are not currently
329 <dt>Apache httpd access checker</dt>
330 <dd>The Apache httpd API <em>access check</em> phase is a separate
331 phase from authentication and authorization. Some other FastCGI
332 implementations implement this phase, which is denoted by the
333 setting of <code>FCGI_APACHE_ROLE</code> to <code>ACCESS_CHECKER</code>.</dd>
335 <dt>Local (Unix) sockets or pipes</dt>
336 <dd>Only TCP sockets are currently supported.</dd>
338 <dt>Support for mod_authn_socache</dt>
339 <dd>mod_authn_socache interaction should be implemented for
340 applications which participate in Apache httpd-style
343 <dt>Support for digest authentication using AuthDigestProvider</dt>
344 <dd>This is expected to be a permanent limitation as there is
345 no authorizer flow for retrieving a hash.</dd>
347 <dt>Application process management</dt>
348 <dd>This is expected to be permanently out of scope for
349 this module. Application processes must be controlled by
350 other means. For example, <program>fcgistarter</program> can be used to
353 <dt>AP_AUTH_INTERNAL_PER_URI</dt>
354 <dd>All providers are currently registered as
355 AP_AUTH_INTERNAL_PER_CONF, which means that checks are not
356 performed again for internal subrequests with the same
357 access control configuration as the initial request.</dd>
359 <dt>Protocol data charset conversion</dt>
360 <dd>If mod_authnz_fcgi runs in an EBCDIC compilation
361 environment, all FastCGI protocol data is written in EBCDIC
362 and expected to be received in EBCDIC.</dd>
364 <dt>Multiple requests per connection</dt>
365 <dd>Currently the connection to the FastCGI authorizer is
366 closed after every phase of processing. For example, if the
367 authorizer handles separate <em>authn</em> and <em>authz</em>
368 phases then two connections will be used.</dd>
371 <dd>URIs from clients can't be mapped, such as with the <directive>
372 ProxyPass</directive> used with FastCGI responders.</dd>
378 <section id="logging"><title>Logging</title>
381 <li>Processing errors are logged at log level <code>error</code>
383 <li>Messages written by the application are logged at log
384 level <code>warn</code>.</li>
385 <li>General messages for debugging are logged at log level
386 <code>debug</code>.</li>
387 <li>Environment variables passed to the application are
388 logged at log level <code>trace2</code>. The value of the
389 <code>REMOTE_PASSWD</code> variable will be obscured,
390 but <strong>any other sensitive data will be visible in the
392 <li>All I/O between the module and the FastCGI application,
393 including all environment variables, will be logged in printable
394 and hex format at log level <code>trace5</code>. <strong>All
395 sensitive data will be visible in the log.</strong></li>
398 <p><directive module="core">LogLevel</directive> can be used
399 to configure a log level specific to mod_authnz_fcgi. For
402 <highlight language="config">
403 LogLevel info authnz_fcgi:trace8
409 <name>AuthnzFcgiDefineProvider</name>
410 <description>Defines a FastCGI application as a provider for
411 authentication and/or authorization</description>
412 <syntax>AuthnzFcgiDefineProvider <em>type</em> <em>provider-name</em>
413 <em>backend-address</em></syntax>
414 <default>none</default>
415 <contextlist><context>server config</context></contextlist>
417 <p>This directive is used to define a FastCGI application as
418 a provider for a particular phase of authentication or
422 <dt><em>type</em></dt>
423 <dd>This must be set to <em>authn</em> for authentication,
424 <em>authz</em> for authorization, or <em>authnz</em> for
425 a generic FastCGI authorizer which performs both checks.</dd>
427 <dt><em>provider-name</em></dt>
428 <dd>This is used to assign a name to the provider which is
429 used in other directives such as
430 <directive module="mod_auth_basic">AuthBasicProvider</directive>
432 <directive module="mod_authz_core">Require</directive>.</dd>
434 <dt><em>backend-address</em></dt>
435 <dd>This specifies the address of the application, in the form
436 <em>fcgi://hostname:port/</em>. The application process(es)
437 must be managed independently, such as with
438 <program>fcgistarter</program>.</dd>
444 <name>AuthnzFcgiCheckAuthnProvider</name>
445 <description>Enables a FastCGI application to handle the check_authn
446 authentication hook.</description>
447 <syntax>AuthnzFcgiCheckAuthnProvider <em>provider-name</em>|<code>None</code>
448 <em>option</em> ...</syntax>
449 <default>none</default>
450 <contextlist><context>directory</context></contextlist>
452 <p>This directive is used to enable a FastCGI authorizer to
453 handle a specific processing phase of authentication or
456 <p>Some capabilities of FastCGI authorizers require enablement
457 using this directive instead of
458 <directive>AuthBasicProvider</directive>:</p>
461 <li>Non-Basic authentication; generally, determining the user
462 id of the client and returning it from the authorizer; see the
463 <code>UserExpr</code> option below</li>
464 <li>Selecting a custom response code; for a non-200 response
465 from the authorizer, the code from the authorizer will be the
466 status of the response</li>
467 <li>Setting the body of a non-200 response; if the authorizer
468 provides a response body with a non-200 response, that body
469 will be returned to the client; up to 8192 bytes of text are
474 <dt><em>provider-name</em></dt>
475 <dd>This is the name of a provider defined with <directive>
476 AuthnzFcgiDefineProvider</directive>.</dd>
478 <dt><code>None</code></dt>
479 <dd>Specify <code>None</code> to disable a provider enabled
480 with this directive in an outer scope, such as in a parent
483 <dt><em>option</em></dt>
484 <dd>The following options are supported:
487 <dt>Authoritative On|Off (default On)</dt>
488 <dd>This controls whether or not other modules are allowed
489 to run when this module has a FastCGI authorizer configured
490 and it fails the request.</dd>
492 <dt>DefaultUser <em>userid</em></dt>
493 <dd>When the authorizer returns success and <code>UserExpr</code>
494 is configured and evaluates to an empty string (e.g., authorizer
495 didn't return a variable), this value will be used as the user
496 id. This is typically used when the authorizer has a concept of
497 guest, or unauthenticated, users and guest users are mapped to
498 some specific user id for logging and other purposes.</dd>
500 <dt>RequireBasicAuth On|Off (default Off)</dt>
501 <dd>This controls whether or not Basic auth is required
502 before passing the request to the authorizer. If required,
503 the authorizer won't be invoked without a user id and
504 password; 401 will be returned for a request without that.</dd>
506 <dt>UserExpr <em>expr</em> (no default)</dt>
507 <dd>When Basic authentication isn't provided by the client
508 and the authorizer determines the user, this expression,
509 evaluated after calling the authorizer, determines the
510 user. The expression follows <a href="../expr.html">
511 ap_expr syntax</a> and must resolve to a string. A typical
512 use is to reference a <code>Variable-<em>XXX</em></code>
513 setting returned by the authorizer using an option like
514 <code>UserExpr "%{reqenv:<em>XXX</em>}"</code>. If
515 this option is specified and the user id can't be retrieved
516 using the expression after a successful authentication, the
517 request will be rejected with a 500 error.</dd>