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 Require ip 10.1.2.3
177 </Location>
178
179 <LocationMatch "^/(?!rules.json)">
180 PerlHeaderParserHandler Lemonldap::NG::SSOaaS::Apache::Client
181
182 # Handler directive to declare this VHost as DevOps and
183 # Pass authorization requests to Central FastCGI server
184 PerlSetVar VHOSTTYPE DevOps
185 # or to declare DevOpsST handler
186 # PerlSetVar VHOSTTYPE DevOpsST
187 PerlSetVar LLNG_SERVER 10.1.2.3:9090
188
189 # Keep original hostname
190 PerlSetVar HOST HTTP_HOST
191
192 # Set redirection parameters
193 PerlSetVar HTTPS_REDIRECT HTTPS
194 PerlSetVar PORT_REDIRECT SERVER_PORT
195
196 # This URL will be fetched by the Central FastCGI server every 10mn and
197 # then used for compliling access rules and headers relative to this VirtualHost
198 # CHECK THAT IT CAN BE REACHED BY THE CENTRAL FASTCGI SERVER
199 PerlSetVar RULES_URL http://myapp.domain.com/rules.json
200 # or to use an external rules server
201 # PerlSetVar RULES_URL http://rulesserver/my.json;
202 </LocationMatch>
203 </VirtualHost>
204
205
206 Node.js
207 ^^^^^^^
208
209 Using `express <https://github.com/expressjs/express#readme>`__ and
210 `fastcgi-authz-client <https://github.com/LemonLDAPNG/node-fastcgi-authz-client>`__,
211 you can also protect an Express server. Example:
212
213 .. code-block:: javascript
214
215 var express = require('express');
216 var app = express();
217 var FcgiAuthz = require('fastcgi-authz-client');
218 var handler = FcgiAuthz({
219 host: '127.0.0.1',
220 port: 9090,
221 PARAMS: {
222 RULES_URL: 'http://my-server/rules.json'
223 HTTPS_REDIRECT: 'ON',
224 PORT_REDIRECT: '443'
225 }
226 });
227
228 app.use(handler);
229
230 // Simple express application
231 app.get('/', function(req, res) {
232 return res.send('Hello ' + req.upstreamHeaders['auth-user'] + ' !');
233 });
234
235 // Launch server
236 app.listen(3000, function() {
237 return console.log('Example app listening on port 3000!');
238 });
239
240
241 Plack application
242 ^^^^^^^^^^^^^^^^^
243
244 You just have to enable
245 `Plack::Middleware::Auth::FCGI <https://metacpan.org/pod/Plack::Middleware::Auth::FCGI>`__.
246 Simple example:
247
248 .. code-block:: perl
249
250 use Plack::Builder;
251
252 my $app = sub {
253 my $env = shift;
254 my $user = $env->{fcgiauth-auth-user};
255 return [ 200, [ 'Content-Type' => 'text/plain' ], [ "Hello $user" ] ];
256 };
257
258 # Optionally ($fcgiResponse is the PSGI response of remote FCGI auth server)
259 #sub on_reject {
260 # my($self, $env, $fcgiResponse) = @_;
261 # my $statusCode = $fcgiResponse->{status};
262 # ...
263 #}
264
265 builder
266 {
267 enable "Auth::FCGI",
268 host => '127.0.0.1',
269 port => '9090',
270 fcgi_auth_params => {
271 RULES_URL => 'https://my-server/rules.json',
272 HTTPS_REDIRECT => 'ON',
273 PORT_REDIRECT => 443
274 },
275 # Optional rejection subroutine
276 #on_reject => \&on_reject;
277 ;
278 $app;
279 };
280
281 Using front Reverse-Proxies
282 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
283
284 This is a simple Nginx configuration file. It looks like a standard
285 LL::NG Nginx configuration file except for:
286
287 - VHOSTTYPE parameter forced to use DevOps handler
288 - /rules.json do not have to be protected by LL::NG
289 but by the web server itself.
290
291 This configuration handles ``*.dev.sso.my.domain`` URL and forwards
292 authenticated requests to ``<vhost>.internal.domain``. Rules can be
293 defined in ``/rules.json`` which is located at the website root
294 directory.
295
296 .. code-block:: nginx
297
298 server {
299 listen <port>;
300 server_name "~^(?<vhost>.+?)\.dev\.sso\.my\.domain$";
301 location = /lmauth {
302 internal;
303 include /etc/nginx/fastcgi_params;
304 fastcgi_pass unix:/var/run/llng-fastcgi-server/llng-fastcgi.sock;
305
306 # Force handler type:
307 fastcgi_param VHOSTTYPE DevOps;
308
309 # Drop post data
310 fastcgi_pass_request_body off;
311 fastcgi_param CONTENT_LENGTH "";
312
313 # Prevent attacks on older Nginx versions (<1.29.5)
314 fastcgi_param HTTP_HOST $host;
315
316 # Keep original request (LL::NG server will received /lmauth)
317 fastcgi_param X_ORIGINAL_URI $original_uri;
318
319 # Set redirection params
320 fastcgi_param HTTPS_REDIRECT "$https";
321 fastcgi_param PORT_REDIRECT $server_port;
322 }
323
324 location /rules.json {
325 auth_request off;
326 allow 127.0.0.0/8;
327 deny all;
328 }
329
330 location / {
331 auth_request /lmauth;
332 set $original_uri $uri$is_args$args;
333 auth_request_set $lmremote_user $upstream_http_lm_remote_user;
334 auth_request_set $lmlocation $upstream_http_location;
335 error_page 401 $lmlocation;
336
337 include /etc/nginx/nginx-lua-headers.conf;
338
339 proxy_pass https://$vhost.internal.domain;
340 }
341 }
342
343 .. |image0| image:: /documentation/devops.png