summaryrefslogtreecommitdiffstats
path: root/docs/manual/mod/mod_authnz_fcgi.xml
blob: d5d704183f361801167998e2e5f3bec7adc25445 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
<?xml version="1.0"?>
<!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
<?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
<!-- $LastChangedRevision$ -->

<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<modulesynopsis metafile="mod_authnz_fcgi.xml.meta">

<name>mod_authnz_fcgi</name>
<description>Allows a FastCGI authorizer application to handle Apache
httpd authentication and authorization</description>
<status>Extension</status>
<sourcefile>mod_authnz_fcgi.c</sourcefile>
<identifier>authnz_fcgi_module</identifier>
<compatibility>Available in version 2.4.10 and later</compatibility>

<summary>
    <p>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.</p>

    <p>FastCGI authorizers can authenticate using user id and password,
    such as for Basic authentication, or can authenticate using arbitrary
    mechanisms.</p>
</summary>

<seealso><a href="../howto/auth.html">Authentication, Authorization,
and Access Control</a></seealso>
<seealso><module>mod_auth_basic</module></seealso>
<seealso><program>fcgistarter</program></seealso>
<seealso><module>mod_proxy_fcgi</module></seealso>

<section id="invocations"><title>Invocation modes</title>

    <p>The invocation modes for FastCGI authorizers supported by this
    module are distinguished by two characteristics, <em>type</em> and
    auth <em>mechanism</em>.</p>

    <p><em>Type</em> is simply <code>authn</code> for authentication,
    <code>authz</code> for authorization, or <code>authnz</code> for
    combined authentication and authorization.</p>

    <p>Auth <em>mechanism</em> refers to the Apache httpd configuration
    mechanisms and processing phases, and can be <code>
    AuthBasicProvider</code>, <code>Require</code>, or <code>
    check_user_id</code>.  The first two of these
    correspond to the directives used to enable participation in the
    appropriate processing phase.</p>

    <p>Descriptions of each mode:</p>

    <dl>
      <dt><em>Type</em> <code>authn</code>, <em>mechanism</em>
      <code>AuthBasicProvider</code></dt>

      <dd>In this mode,
      <code>FCGI_ROLE</code> is set to <code>AUTHORIZER</code> and
      <code>FCGI_APACHE_ROLE</code> is set to <code>AUTHENTICATOR</code>.
      The application must be defined as provider type <em>authn</em>
      using <directive module="mod_authnz_fcgi">
      AuthnzFcgiDefineProvider</directive> and enabled with
      <directive module="mod_auth_basic">AuthBasicProvider</directive>.
      When invoked, the application is
      expected to authenticate the client using the provided user id and
      password.  Example application:

<highlight language="perl">
#!/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") &amp;&amp;
        $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";
    }
}
</highlight>

      Example configuration:
<highlight language="config">
AuthnzFcgiDefineProvider authn FooAuthn fcgi://localhost:10102/
&lt;Location "/protected/"&gt;
  AuthType Basic
  AuthName "Restricted"
  AuthBasicProvider FooAuthn
  Require ...
&lt;/Location&gt;
</highlight>
      </dd>

      <dt><em>Type</em> <code>authz</code>, <em>mechanism</em>
      <code>Require</code></dt>
      <dd>In this mode, <code>FCGI_ROLE</code> is set to <code>
      AUTHORIZER</code> and <code>FCGI_APACHE_ROLE</code> is set to
      <code>AUTHORIZER</code>.  The application must be defined as
      provider type <em>authz</em> using <directive module="mod_authnz_fcgi">
      AuthnzFcgiDefineProvider</directive>.  When invoked, the application
      is expected to authorize the client using the provided user id and other
      request data.  Example application:
<highlight language="perl">
#!/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";
    }
}
</highlight>

      Example configuration:
<highlight language="config">
AuthnzFcgiDefineProvider authz FooAuthz fcgi://localhost:10103/
&lt;Location "/protected/"&gt;
  AuthType ...
  AuthName ...
  AuthBasicProvider ...
  Require FooAuthz
&lt;/Location&gt;
</highlight>
      </dd>

      <dt><em>Type</em> <code>authnz</code>, <em>mechanism</em>
      <code>AuthBasicProvider</code> <em>+</em> <code>Require</code></dt>

      <dd>In this mode, which supports the web server-agnostic FastCGI
      <code>AUTHORIZER</code> protocol, <code>FCGI_ROLE</code> is set to
      <code>AUTHORIZER</code> and <code>FCGI_APACHE_ROLE</code> is not set.
      The application must be defined as provider type <em>authnz</em>
      using <directive module="mod_authnz_fcgi">
      AuthnzFcgiDefineProvider</directive>.  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 <directive>Require</directive>), mod_authnz_fcgi
      will return success for the authorization phase without invoking the
      application.  Example application:
<highlight language="perl">
#!/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") &amp;&amp;
        $ENV{'REMOTE_PASSWD'} eq "bar" &amp;&amp;
        $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";
    }
}
</highlight>

      Example configuration:
<highlight language="config">
AuthnzFcgiDefineProvider authnz FooAuthnz fcgi://localhost:10103/
&lt;Location "/protected/"&gt;
  AuthType Basic
  AuthName "Restricted"
  AuthBasicProvider FooAuthnz
  Require FooAuthnz
&lt;/Location&gt;
</highlight>
      </dd>

      <dt><em>Type</em> <code>authn</code>, <em>mechanism</em>
      <code>check_user_id</code></dt>

      <dd>In this mode, <code>FCGI_ROLE</code> is set to <code>
      AUTHORIZER</code> and <code>FCGI_APACHE_ROLE</code> is set to
      <code>AUTHENTICATOR</code>.  The application must be defined as
      provider type <em>authn</em> using <directive module="mod_authnz_fcgi">
      AuthnzFcgiDefineProvider</directive>.  <directive
      module="mod_authnz_fcgi">AuthnzFcgiCheckAuthnProvider</directive>
      specifies when it is called.  Example application:
<highlight language="perl">
#!/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") &amp;&amp;
        $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.
    }
}
</highlight>

      Example configuration:
<highlight language="config">
AuthnzFcgiDefineProvider authn FooAuthn fcgi://localhost:10103/
&lt;Location "/protected/"&gt;
  AuthType ...
  AuthName ...
  AuthnzFcgiCheckAuthnProvider FooAuthn \
                               Authoritative On \
                               RequireBasicAuth Off \
                               UserExpr "%{reqenv:REMOTE_USER}"
  Require ...
&lt;/Location&gt;
</highlight>
      </dd>

    </dl>

</section>

<section id="examples"><title>Additional examples</title>

  <ol>
    <li>If your application supports the separate authentication and
    authorization roles (<code>AUTHENTICATOR</code> and <code>AUTHORIZER</code>), define
    separate providers as follows, even if they map to the same
    application:

<highlight language="config">
AuthnzFcgiDefineProvider authn  FooAuthn  fcgi://localhost:10102/
AuthnzFcgiDefineProvider authz  FooAuthz  fcgi://localhost:10102/
</highlight>

    Specify the authn provider on
    <directive module="mod_auth_basic">AuthBasicProvider</directive>
    and the authz provider on
    <directive module="mod_authz_core">Require</directive>:

<highlight language="config">
AuthType Basic
AuthName "Restricted"
AuthBasicProvider FooAuthn
Require FooAuthz
</highlight>
    </li>

    <li>If your application supports the generic <code>AUTHORIZER</code> role
    (authentication and authorizer in one invocation), define a
    single provider as follows:

<highlight language="config">
AuthnzFcgiDefineProvider authnz FooAuthnz fcgi://localhost:10103/
</highlight>

    Specify the authnz provider on both <directive>AuthBasicProvider</directive>
    and <directive>Require</directive>:

<highlight language="config">
AuthType Basic
AuthName "Restricted"
AuthBasicProvider FooAuthnz
Require FooAuthnz
</highlight>
    </li>
</ol>
</section>

<section id="limitations"><title>Limitations</title>

    <p>The following are potential features which are not currently
    implemented:</p>

    <dl>
      <dt>Apache httpd access checker</dt>
      <dd>The Apache httpd API <em>access check</em> phase is a separate
      phase from authentication and authorization.  Some other FastCGI
      implementations implement this phase, which is denoted by the
      setting of <code>FCGI_APACHE_ROLE</code> to <code>ACCESS_CHECKER</code>.</dd>

      <dt>Local (Unix) sockets or pipes</dt>
      <dd>Only TCP sockets are currently supported.</dd>

      <dt>Support for mod_authn_socache</dt>
      <dd>mod_authn_socache interaction should be implemented for
      applications which participate in Apache httpd-style
      authentication.</dd>

      <dt>Support for digest authentication using AuthDigestProvider</dt>
      <dd>This is expected to be a permanent limitation as there is
      no authorizer flow for retrieving a hash.</dd>

      <dt>Application process management</dt>
      <dd>This is expected to be permanently out of scope for
      this module.  Application processes must be controlled by
      other means.  For example, <program>fcgistarter</program> can be used to
      start them.</dd>

      <dt>AP_AUTH_INTERNAL_PER_URI</dt>
      <dd>All providers are currently registered 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.</dd>

      <dt>Protocol data charset conversion</dt>
      <dd>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.</dd>

      <dt>Multiple requests per connection</dt>
      <dd>Currently the connection to the FastCGI authorizer is
      closed after every phase of processing.  For example, if the
      authorizer handles separate <em>authn</em> and <em>authz</em>
      phases then two connections will be used.</dd>

      <dt>URI Mapping</dt>
      <dd>URIs from clients can't be mapped, such as with the <directive>
      ProxyPass</directive> used with FastCGI responders.</dd>

    </dl>

</section>

<section id="logging"><title>Logging</title>

    <ol>
        <li>Processing errors are logged at log level <code>error</code>
        and higher.</li>
        <li>Messages written by the application are logged at log
        level <code>warn</code>.</li>
        <li>General messages for debugging are logged at log level
        <code>debug</code>.</li>
        <li>Environment variables passed to the application are
        logged at log level <code>trace2</code>. The value of the
        <code>REMOTE_PASSWD</code> variable will be obscured,
        but <strong>any other sensitive data will be visible in the
        log</strong>.</li>
        <li>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 <code>trace5</code>.  <strong>All
        sensitive data will be visible in the log.</strong></li>
    </ol>

    <p><directive module="core">LogLevel</directive> can be used
    to configure a log level specific to mod_authnz_fcgi.  For
    example:</p>

<highlight language="config">
LogLevel info authnz_fcgi:trace8
</highlight>

</section>

<directivesynopsis>
<name>AuthnzFcgiDefineProvider</name>
<description>Defines a FastCGI application as a provider for
authentication and/or authorization</description>
<syntax>AuthnzFcgiDefineProvider <em>type</em> <em>provider-name</em>
<em>backend-address</em></syntax>
<default>none</default>
<contextlist><context>server config</context></contextlist>
<usage>
    <p>This directive is used to define a FastCGI application as
    a provider for a particular phase of authentication or
    authorization.</p>

    <dl>
      <dt><em>type</em></dt>
      <dd>This must be set to <em>authn</em> for authentication,
      <em>authz</em> for authorization, or <em>authnz</em> for
      a generic FastCGI authorizer which performs both checks.</dd>

      <dt><em>provider-name</em></dt>
      <dd>This is used to assign a name to the provider which is
      used in other directives such as
      <directive module="mod_auth_basic">AuthBasicProvider</directive>
      and
      <directive module="mod_authz_core">Require</directive>.</dd>

      <dt><em>backend-address</em></dt>
      <dd>This specifies the address of the application, in the form
      <em>fcgi://hostname:port/</em>.  The application process(es)
      must be managed independently, such as with
      <program>fcgistarter</program>.</dd>
    </dl>
</usage>
</directivesynopsis>

<directivesynopsis>
<name>AuthnzFcgiCheckAuthnProvider</name>
<description>Enables a FastCGI application to handle the check_authn
authentication hook.</description>
<syntax>AuthnzFcgiCheckAuthnProvider <em>provider-name</em>|<code>None</code>
<em>option</em> ...</syntax>
<default>none</default>
<contextlist><context>directory</context></contextlist>
<override>FileInfo</override>
<usage>
    <p>This directive is used to enable a FastCGI authorizer to
    handle a specific processing phase of authentication or
    authorization.</p>

    <p>Some capabilities of FastCGI authorizers require enablement
    using this directive instead of
    <directive>AuthBasicProvider</directive>:</p>

    <ul>
      <li>Non-Basic authentication; generally, determining the user
      id of the client and returning it from the authorizer; see the
      <code>UserExpr</code> option below</li>
      <li>Selecting a custom response code; for a non-200 response
      from the authorizer, the code from the authorizer will be the
      status of the response</li>
      <li>Setting the body of a non-200 response; if the authorizer
      provides a response body with a non-200 response, that body
      will be returned to the client; up to 8192 bytes of text are
      supported</li>
    </ul>

    <dl>
      <dt><em>provider-name</em></dt>
      <dd>This is the name of a provider defined with <directive>
      AuthnzFcgiDefineProvider</directive>.</dd>

      <dt><code>None</code></dt>
      <dd>Specify <code>None</code> to disable a provider enabled
      with this directive in an outer scope, such as in a parent
      directory.</dd>

      <dt><em>option</em></dt>
      <dd>The following options are supported:

      <dl>
         <dt>Authoritative On|Off (default On)</dt>
         <dd>This controls whether or not other modules are allowed
         to run when this module has a FastCGI authorizer configured
         and it fails the request.</dd>

         <dt>DefaultUser <em>userid</em></dt>
         <dd>When the authorizer returns success and <code>UserExpr</code>
         is configured and evaluates to an empty string (e.g., authorizer
         didn't return a variable), this value will be used as the user
         id.  This is typically used when the authorizer has a concept of
         guest, or unauthenticated, users and guest users are mapped to
         some specific user id for logging and other purposes.</dd>

         <dt>RequireBasicAuth On|Off (default Off)</dt>
         <dd>This controls whether or not Basic auth is required
         before passing the request to the authorizer.  If required,
         the authorizer won't be invoked without a user id and
         password; 401 will be returned for a request without that.</dd>

         <dt>UserExpr <em>expr</em> (no default)</dt>
         <dd>When Basic authentication isn't provided by the client
         and the authorizer determines the user, this expression,
         evaluated after calling the authorizer, determines the
         user.  The expression follows <a href="../expr.html">
         ap_expr syntax</a> and must resolve to a string.  A typical
         use is to reference a <code>Variable-<em>XXX</em></code>
         setting returned by the authorizer using an option like
         <code>UserExpr "%{reqenv:<em>XXX</em>}"</code>.  If
         this option is specified and the user id can't be retrieved
         using the expression after a successful authentication, the
         request will be rejected with a 500 error.</dd>

       </dl>
      </dd>
     </dl>
</usage>
</directivesynopsis>

</modulesynopsis>