Debian Codegraph @

doc/sources/admin/ssoaas.rst

raw
1 SSO as a Service (SSOaaS)
2 =========================
3
4 Our concept of SSOaaS
5 ---------------------
6
7 Access management provides 3 services:
8
9 - Global Authentication: Single Sign-On
10 - Authorization: Grant authentication is not enough. User rights
11 must be checked
12 - Accounting: SSO logs (access) + application logs *(transactions and
13 results)*
14
15 LL::NG affords all these services (except application logs of course,
16 but headers are provided to allow this).
17
18 Headers setting is an another LL::NG service. LL::NG can provide any
19 user attributes to an application
20 (see :doc:`Rules and headers<writingrulesand_headers>`)
21
22 ``*aaS`` means that application can drive underlying layer (IaaS for
23 infrastructure, PaaS for platform,…). So for us, ``SSOaaS`` must provide
24 the ability for an application to manage authorizations and choose user
25 attributes to receive. Authentication can not be really ``*aaS``: application
26 can just use it but not manage it.
27
28 LL::NG affords some features that can be used for providing SSO as a
29 service. So a web application can manage its rules and headers.
30 Docker or VM images (Nginx only) includes LL::NG Nginx configuration that
31 aims to a
32 :ref:`Central LL::NG authorization server<platformsoverview-external-servers-for-nginx>`.
33 By default, all authenticated users can access and just one header is set:
34 ``Auth-User``. If application defines a ``RULES_URL`` parameter that refers to
35 a JSON file, authorization server will read it, apply specified rules
36 and set required headers (see :doc:`DevOps Handler<devopshandler>`).
37
38 Two different kinds of architecture are existing to do this:
39
40 - Using a :doc:`Central FastCGI (or uWSGI) server<psgi>`
41 - Using front Reverse-Proxies *(some cloud or HA installations use
42 reverse-proxies in front-end)*
43
44
45 .. note::
46
47 Some requests can be dropped by the central FastCGI/uWSGI server.
48
49 Example below with an uWSGI server to prevent Load Balancer health check requests
50 being forwarded to the central DevOps Handler ::
51
52 route-remote-addr = ^127\.0\.0\.25[34]$ break: 403 Forbidden for IP ${REMOTE_ADDR}
53
54
55 Example of a Central FastCGI architecture:
56
57 |image0|
58
59 In both case, Handler type must be set to :doc:`DevOps<devopshandler>`.
60
61 Examples of webserver configuration for Docker/VM images
62 --------------------------------------------------------
63
64 Using a Central FastCGI (or uWSGI) Server
65 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
66
67 Nginx
68 ^^^^^
69
70 Examples below are customized web server templates for
71 requesting authorization from a Central FastCGI server.
72 You can replace 'fastcgi_*' directives by 'uwsgi_*' for
73 requesting a Central uWSGI server (Nginx only):
74
75
76 .. code-block:: nginx
77
78 server {
79 listen <port>;
80 server_name myapp.domain.com;
81 root /var/www/myapp;
82 index index.php;
83
84 location = /lmauth {
85 internal;
86 include /etc/nginx/fastcgi_params;
87
88 # Handler directive to declare this VHost as DevOps and
89 # Pass authorization requests to central FastCGI server
90 fastcgi_param VHOSTTYPE DevOps;
91 # or to declare DevOpsST handler
92 # fastcgi_param VHOSTTYPE DevOpsST;
93 fastcgi_pass 10.1.2.3:9090;
94
95 # Drop post data
96 fastcgi_pass_request_body off;
97 fastcgi_param CONTENT_LENGTH "";
98
99 # Keep original request (LL::NG server will receive /lmauth)
100 fastcgi_param X_ORIGINAL_URI $original_uri;
101
102 # Prevent attacks on older Nginx versions (<1.29.5)
103 fastcgi_param HTTP_HOST $host;
104
105 # Set redirection parameters
106 fastcgi_param HTTPS_REDIRECT "$https";
107 fastcgi_param PORT_REDIRECT $server_port;
108
109 # This URL will be fetched by the Central FastCGI server every 10 mn and
110 # then used for compliling access rules and headers relative to this VirtualHost
111 # CHECK THAT IT CAN BE REACHED BY THE CENTRAL FASTCGI SERVER
112 fastcgi_param RULES_URL http://myapp.domain.com/rules.json;
113 # or to use an external rules server
114 # fastcgi_param RULES_URL http://rulesserver/my.json;
115
116 }
117
118 location /rules.json {
119 auth_request off;
120 allow 10.1.2.3;
121 deny all;
122 }
123
124 # Example with php-fpm:
125 location ~ ^(.*\.php)$ {
126 auth_request /lmauth;
127 set $original_uri $uri$is_args$args;
128 auth_request_set $lmremote_user $upstream_http_lm_remote_user;
129 auth_request_set $lmlocation $upstream_http_location;
130 error_page 401 $lmlocation;
131 include /etc/nginx/nginx-lua-headers.conf;
132 # ...
133 # Example with php-fpm
134 include snippets/fastcgi-php.conf;
135 fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
136 }
137
138 # Example as Reverse-Proxy:
139 location /api/ {
140 auth_request /lmauth;
141 set $original_uri $uri$is_args$args;
142 auth_request_set $lmremote_user $upstream_http_lm_remote_user;
143 auth_request_set $lmlocation $upstream_http_location;
144 error_page 401 $lmlocation;
145 include /etc/nginx/nginx-lua-headers.conf;
146 # ...
147 proxy_pass http://myapp.dev.com:8081/;
148 }
149
150 location / {
151 try_files $uri $uri/ =404;
152 }
153 }
154
155
156 Apache
157 ^^^^^^
158
159 LemonLDAP::NG provides a dedicated FastCGI client (Lemonldap::NG::SSOaaS::Apache::Client) which is an alternative to
160 L<Lemonldap::NG::Handler::ApacheMP2> that replaces main handler.
161 It calls a remote LemonLDAP::NG FastCGI server to get authentication, authorization and headers.
162 You have to install `Lemonldap::NG::SSOaaS::Apache::Client` (LemonLDAP::NG FastCGI client),
163 `FCGI::Client` (Perl FastCGI dependency) and `Mod_Perl2` (Apache module used for parsing HTTP headers).
164 Then, add this in your apache2.conf web applications or Reverse-Proxies.
165
166
167 .. code-block:: apache
168
169 <VirtualHost port>
170 ServerName myapp.domain.com
171 DocumentRoot "/var/www/myapp"
172 ErrorLog /var/log/apache2/localsite_error.log
173 CustomLog /var/log/apache2/localsite_access.log combine
174
175 <Location /rules.json>
176 Order deny,allow
177 Deny from all
178 Allow from 10.1.2.3
179 </Location>
180
181 <LocationMatch "^/(?!rules.json)">
182 PerlHeaderParserHandler Lemonldap::NG::SSOaaS::Apache::Client
183
184 # Handler directive to declare this VHost as DevOps and
185 # Pass authorization requests to Central FastCGI server
186 PerlSetVar VHOSTTYPE DevOps
187 # or to declare DevOpsST handler
188 # PerlSetVar VHOSTTYPE DevOpsST
189 PerlSetVar LLNG_SERVER 10.1.2.3:9090
190
191 # Keep original hostname
192 PerlSetVar HOST HTTP_HOST
193
194 # Set redirection parameters
195 PerlSetVar HTTPS_REDIRECT HTTPS
196 PerlSetVar PORT_REDIRECT SERVER_PORT
197
198 # This URL will be fetched by the Central FastCGI server every 10mn and
199 # then used for compliling access rules and headers relative to this VirtualHost
200 # CHECK THAT IT CAN BE REACHED BY THE CENTRAL FASTCGI SERVER
201 PerlSetVar RULES_URL http://myapp.domain.com/rules.json
202 # or to use an external rules server
203 # PerlSetVar RULES_URL http://rulesserver/my.json;
204 </LocationMatch>
205 </VirtualHost>
206
207
208 Node.js
209 ^^^^^^^
210
211 Using `express <https://github.com/expressjs/express#readme>`__ and
212 `fastcgi-authz-client <https://github.com/LemonLDAPNG/node-fastcgi-authz-client>`__,
213 you can also protect an Express server. Example:
214
215 .. code-block:: javascript
216
217 var express = require('express');
218 var app = express();
219 var FcgiAuthz = require('fastcgi-authz-client');
220 var handler = FcgiAuthz({
221 host: '127.0.0.1',
222 port: 9090,
223 PARAMS: {
224 RULES_URL: 'http://my-server/rules.json'
225 HTTPS_REDIRECT: 'ON',
226 PORT_REDIRECT: '443'
227 }
228 });
229
230 app.use(handler);
231
232 // Simple express application
233 app.get('/', function(req, res) {
234 return res.send('Hello ' + req.upstreamHeaders['auth-user'] + ' !');
235 });
236
237 // Launch server
238 app.listen(3000, function() {
239 return console.log('Example app listening on port 3000!');
240 });
241
242
243 Plack application
244 ^^^^^^^^^^^^^^^^^
245
246 You just have to enable
247 `Plack::Middleware::Auth::FCGI <https://metacpan.org/pod/Plack::Middleware::Auth::FCGI>`__.
248 Simple example:
249
250 .. code-block:: perl
251
252 use Plack::Builder;
253
254 my $app = sub {
255 my $env = shift;
256 my $user = $env->{fcgiauth-auth-user};
257 return [ 200, [ 'Content-Type' => 'text/plain' ], [ "Hello $user" ] ];
258 };
259
260 # Optionally ($fcgiResponse is the PSGI response of remote FCGI auth server)
261 #sub on_reject {
262 # my($self, $env, $fcgiResponse) = @_;
263 # my $statusCode = $fcgiResponse->{status};
264 # ...
265 #}
266
267 builder
268 {
269 enable "Auth::FCGI",
270 host => '127.0.0.1',
271 port => '9090',
272 fcgi_auth_params => {
273 RULES_URL => 'https://my-server/rules.json',
274 HTTPS_REDIRECT => 'ON',
275 PORT_REDIRECT => 443
276 },
277 # Optional rejection subroutine
278 #on_reject => \&on_reject;
279 ;
280 $app;
281 };
282
283 Using front Reverse-Proxies
284 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
285
286 This is a simple Nginx configuration file. It looks like a standard
287 LL::NG Nginx configuration file except for:
288
289 - VHOSTTYPE parameter forced to use DevOps handler
290 - /rules.json do not have to be protected by LL::NG
291 but by the web server itself.
292
293 This configuration handles ``*.dev.sso.my.domain`` URL and forwards
294 authenticated requests to ``<vhost>.internal.domain``. Rules can be
295 defined in ``/rules.json`` which is located at the website root
296 directory.
297
298 .. code-block:: nginx
299
300 server {
301 listen <port>;
302 server_name "~^(?<vhost>.+?)\.dev\.sso\.my\.domain$";
303 location = /lmauth {
304 internal;
305 include /etc/nginx/fastcgi_params;
306 fastcgi_pass unix:/var/run/llng-fastcgi-server/llng-fastcgi.sock;
307
308 # Force handler type:
309 fastcgi_param VHOSTTYPE DevOps;
310
311 # Drop post data
312 fastcgi_pass_request_body off;
313 fastcgi_param CONTENT_LENGTH "";
314
315 # Prevent attacks on older Nginx versions (<1.29.5)
316 fastcgi_param HTTP_HOST $host;
317
318 # Keep original request (LL::NG server will received /lmauth)
319 fastcgi_param X_ORIGINAL_URI $original_uri;
320
321 # Set redirection params
322 fastcgi_param HTTPS_REDIRECT "$https";
323 fastcgi_param PORT_REDIRECT $server_port;
324 }
325
326 location /rules.json {
327 auth_request off;
328 allow 127.0.0.0/8;
329 deny all;
330 }
331
332 location / {
333 auth_request /lmauth;
334 set $original_uri $uri$is_args$args;
335 auth_request_set $lmremote_user $upstream_http_lm_remote_user;
336 auth_request_set $lmlocation $upstream_http_location;
337 error_page 401 $lmlocation;
338
339 include /etc/nginx/nginx-lua-headers.conf;
340
341 proxy_pass https://$vhost.internal.domain;
342 }
343 }
344
345 .. |image0| image:: /documentation/devops.png