lemonldap-ng-handler 0.5.4 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,302 @@
1
+ # Lemonldap::NG handler for Node.js
2
+
3
+ Beta [Lemonldap::NG](https://lemonldap-ng.org) handler for node.js
4
+
5
+ ## SYNOPSIS
6
+
7
+ ### lemonldap-ng.ini
8
+ ```ini
9
+ ...
10
+ [node-handler]
11
+
12
+ nodeVhosts = test.example.com, test2.example.com
13
+ ```
14
+
15
+ ### Express app
16
+ ```javascript
17
+ // Variables
18
+ var express = require('express');
19
+ var app = express();
20
+ var handler = require('lemonldap-ng-handler');
21
+
22
+ // initialize handler (optional args)
23
+ handler.init({
24
+ configStorage: {
25
+ "confFile":"test/lemonldap-ng.ini"
26
+ }
27
+ });
28
+
29
+ // and load it
30
+ app.use(handler.run);
31
+
32
+ // Then simply use your express app
33
+ app.get('/', function(req, res) {
34
+ return res.send('Hello ' + req.headers['Auth-User'] + ' !');
35
+ });
36
+ app.listen(3000, function() {
37
+ return console.log('Example app listening on port 3000!');
38
+ });
39
+ ```
40
+
41
+ ### Nginx authorization server
42
+
43
+ FastCGI server:
44
+ ```javascript
45
+ var handler = require('lemonldap-ng-handler');
46
+
47
+ handler.init({
48
+ configStorage: {
49
+ "confFile": "/path/to/lemonldap-ng.ini"
50
+ }
51
+ });
52
+
53
+ handler.nginxServer({
54
+ "mode": "fcgi", // or "http", default: fcgi
55
+ "port": 9090, // default value
56
+ "ip": 'localhost' // default value
57
+ });
58
+ ```
59
+
60
+ Nginx configuration. For more, see [Nginx configuration on LLNG website](https://lemonldap-ng.org/documentation/latest/configvhost#nginx_configuration)
61
+ ```nginx
62
+ server {
63
+ listen 19876;
64
+ server_name test.example.com;
65
+ root /home/xavier/dev/lemonldap/e2e-tests/conf/site;
66
+
67
+ # Internal authentication request
68
+ location = /lmauth {
69
+ internal;
70
+ include /etc/nginx/fastcgi_params;
71
+ fastcgi_pass localhost:9090;
72
+
73
+ # Drop post datas
74
+ fastcgi_pass_request_body off;
75
+ fastcgi_param CONTENT_LENGTH "";
76
+
77
+ # Keep original hostname
78
+ fastcgi_param HOST $http_host;
79
+
80
+ # Keep original request (LLNG server will received /llauth)
81
+ fastcgi_param X_ORIGINAL_URI $request_uri;
82
+ }
83
+
84
+ # Client requests
85
+ location / {
86
+ auth_request /lmauth;
87
+ auth_request_set $lmremote_user $upstream_http_lm_remote_user;
88
+ auth_request_set $lmlocation $upstream_http_location;
89
+ error_page 401 $lmlocation;
90
+ include conf/nginx-lua-headers.conf;
91
+ }
92
+
93
+ }
94
+ ```
95
+
96
+ ## DESCRIPTION
97
+
98
+ Lemonldap::NG is a complete Web-SSO system that can run with reverse-proxies
99
+ or directly on application webservers. It can be used in conjunction with
100
+ OpenID-Connect, CAS and SAML systems as identity or service provider. It can
101
+ also be used as proxy between those federation systems.
102
+
103
+ It manages both authentication and authorization and provides headers for
104
+ accounting. So you can have a full AAA protection. Authorization are built by
105
+ associating a regular expression and a rule. Regular expression is applied on
106
+ the requested URL and the rule calculates if the user is authorized.
107
+
108
+ LLNG is designed in 3 kinds of elements:
109
+ * a portal
110
+ * a manager
111
+ * some handlers for Apache, [Plack family](https://plackperl.org), Node.js
112
+ * some FastCGI servers to provide Nginx handler or
113
+ [SSOaaS](https://lemonldap-ng.org/documentation/2.0/ssoaas):
114
+ * pure Perl (default)
115
+ * uWSGI _(Perl via uwsgi-psgi plugin)_
116
+ * this Node.js module
117
+
118
+ This module provide the Node.js handler and the FastCGI server.
119
+
120
+ See [Lemonldap::NG website](http://lemonldap-ng.org) for more.
121
+
122
+ ## INSTALLATION
123
+
124
+ Of course, you must have a [LemonLDAP::NG](https://lemonldap-ng.org) system
125
+ installed in your organization. To install node handler, use simply:
126
+ ```shell
127
+ npm install lemonldap-ng-handler
128
+ ```
129
+
130
+ ## CONFIGURATION
131
+
132
+ ### Configuration file *(lemonldap-ng.ini)*
133
+
134
+ Node-lemonldap-ng-handler uses LemonLDAP::NG configuration file, sections
135
+ `[configuration]` and `[node-handler]`.
136
+
137
+ #### Sections `[all]` and `[configuration]`
138
+
139
+ Nothing to change, but lemonldap-ng-handler isn't compatible with all
140
+ LLNG backends. See below.
141
+
142
+ ##### Loggers
143
+
144
+ lemonldap-ng-handler is compatible with the following
145
+ [loggers](https://lemonldap-ng.org/documentation/2.0/logs):
146
+ * Lemonldap::NG::Common::Logger::Std : use console.log
147
+ * Lemonldap::NG::Common::Logger::Syslog : use Syslog _(install modern-syslog
148
+ to use it)_
149
+ * UWSGI : usable only under uwsgi V8 plugin. Override `logger` in section
150
+ `[nginx-handler]` in your `[lemonldap-ng.ini]` file
151
+
152
+ #### New section `[node-handler]`
153
+
154
+ You can overwrite here LemonLDAP::NG configuration keys. You must set the list
155
+ of virtual hosts handled by node.js in key `nodeVhosts`.
156
+
157
+ Example:
158
+ ```ini
159
+ [node-handler]
160
+ nodeVhosts = test1.example.com, test2.example.com
161
+ ```
162
+
163
+ **Rules and headers must be written in Javascript**, not in Perl. Example:
164
+
165
+ default: $uid == 'dwho'
166
+ ^/deny : deny
167
+
168
+ You'll have a warning in the manager when saving this rules since Perl doesn't
169
+ understand Javascript.
170
+
171
+ > Note that `handler` section isn't read by lemonldap-ng-handler.
172
+
173
+ ### Configuration backends
174
+
175
+ Node-lemonldap-ng-handler is compatible with the following Lemonldap::NG
176
+ backends:
177
+ * [File](https://lemonldap-ng.org/documentation/latest/fileconfbackend)
178
+ * [YAMLFile](https://lemonldap-ng.org/documentation/latest/yamlconfbackend)
179
+ * [REST](https://lemonldap-ng.org/documentation/2.0/restconfbackend)
180
+ * [LDAP](https://lemonldap-ng.org/documentation/latest/ldapconfbackend)
181
+ * [MongoDB](https://lemonldap-ng.org/documentation/latest/mongodbconfbackend)
182
+ _(without authentication neither ssl for now)_
183
+ * [CDBI / RDBI](https://lemonldap-ng.org/documentation/latest/sqlconfbackend)
184
+ _(MySQL, PostgreSQL and SQLite3 only)_. **Note that you must install `nodedbi`
185
+ and needed dependencies**. Example with PostgreSQL _(Debian)_:
186
+ ```
187
+ $ sudo apt-get install libdbi-dev libdbd-pgsql
188
+ $ npm install nodedbi
189
+ ```
190
+
191
+ ### Sessions backends
192
+
193
+ Node-lemonldap-ng-handler is compatible with the following Lemonldap::NG
194
+ backends:
195
+ * File:
196
+ * [Apache::Session::File](https://metacpan.org/pod/Apache::Session::File)
197
+ * [Apache::Session::Browseable::File](https://metacpan.org/pod/Apache::Session::Browseable::File)
198
+ * Redis _(install `redis` to use them)_:
199
+ * [Apache::Session::Redis](https://metacpan.org/pod/Apache::Session::Redis)
200
+ * [Apache::Session::Browseable::Redis](https://metacpan.org/pod/Apache::Session::Browseable::Redis)
201
+ * LDAP backends _(install `ldapjs` to use them)_:
202
+ * [Apache::Session::LDAP](https://metacpan.org/pod/Apache::Session::LDAP)
203
+ * [Apache::Session::Browseable::LDAP](https://metacpan.org/pod/Apache::Session::Browseable::LDAP)
204
+ * SQL backends _(install `nodedbi` to use them)_:
205
+ * [Apache::Session::MySQL](https://metacpan.org/pod/Apache::Session::MySQL)
206
+ * [Apache::Session::Browseable::MySQL](https://metacpan.org/pod/Apache::Session::Browseable::MySQL)
207
+ * [Apache::Session::Postgres](https://metacpan.org/pod/Apache::Session::Postgres)
208
+ * [Apache::Session::Browseable::Postgres](https://metacpan.org/pod/Apache::Session::Browseable::Postgres)
209
+ * [Apache::Session::Browseable::PgHstore](https://metacpan.org/pod/Apache::Session::Browseable::PgHstore)
210
+ * [Apache::Session::Browseable::PgJSON](https://metacpan.org/pod/Apache::Session::Browseable::PgJSON)
211
+ * [Apache::Session::SQLite3](https://metacpan.org/pod/Apache::Session::SQLite3)
212
+ * [Apache::Session::Browseable::SQLite](https://metacpan.org/pod/Apache::Session::Browseable::SQLite)
213
+
214
+ **Note that fo SQL backends, you must install nodedbi and needed dependencies**.
215
+ Example with PostgreSQL _(Debian/Ubuntu)_:
216
+ ```
217
+ $ sudo apt-get install libdbi-dev libdbd-pgsql
218
+ $ npm install nodedbi
219
+ ```
220
+
221
+ ### Special handlers
222
+
223
+ Node-lemonldap-ng-handler can be used as
224
+ * [DevOps handler](https://lemonldap-ng.org/documentation/2.0/devopshandler)
225
+ * [ServiceToken handler](https://lemonldap-ng.org/documentation/2.0/servertoserver)
226
+
227
+ You just have to specify `"type":<type>` in `init()` arguments. Example:
228
+ ```javascript
229
+ handler.init({
230
+ "type": "DevOps",
231
+ "configStorage": {
232
+ "confFile": "/path/to/lemonldap-ng.ini"
233
+ }
234
+ });
235
+ ```
236
+
237
+ ## METHODS
238
+
239
+ ### init()
240
+
241
+ Takes an optional object argument with the following optional keys:
242
+ * configStorage: object
243
+ * type: special handler _(see "Special handlers section")_
244
+
245
+ ### run()
246
+
247
+ Used by express to handle requests. Arguments:
248
+ * req: the express request
249
+ * res: the express response
250
+ * next: next function in stack
251
+
252
+ ### nginxServer
253
+
254
+ Launch Nginx compatible authorization server. Takes an optional object as
255
+ argument. Keys:
256
+ * mode: server mode, "fcgi" or "http", defult to "fcgi"
257
+ * port: port to listen to
258
+ * ip: ip address to listen to
259
+
260
+ ## TODO
261
+
262
+ * Custom functions
263
+ * Think to menu problem
264
+ * REST backends
265
+
266
+ ## CHANGELOG
267
+
268
+ See [CHANGELOG](CHANGELOG.md)
269
+
270
+ ## BUG REPORT AND OTHER ISSUES
271
+
272
+ Use OW2 system to report bug or ask for features:
273
+ [LLNG OW2 GitLab](https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/issues)
274
+
275
+ > Note: uWGI isn't supported because V8 plugin for uWSGI [isn't compatible
276
+ with async](http://uwsgi.readthedocs.io/en/latest/V8.html#commonjs)
277
+
278
+ ## DOWNLOAD
279
+
280
+ Lemonldap::NG is available at
281
+ https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/tags
282
+
283
+ This library is available at
284
+ https://github.com/LemonLDAPNG/lemonldap-ng-handler
285
+
286
+ ## COPYRIGHT AND LICENSE
287
+
288
+ Copyright (C) 2016-2019 by [Xavier Guimard](mailto:x.guimard@free.fr)
289
+
290
+ This library is free software; you can redistribute it and/or modify
291
+ it under the terms of the GNU General Public License as published by
292
+ the Free Software Foundation; either version 2, or (at your option)
293
+ any later version.
294
+
295
+ This program is distributed in the hope that it will be useful,
296
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
297
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
298
+ GNU General Public License for more details.
299
+
300
+ You should have received a copy of the GNU General Public License
301
+ along with this program. If not, see http://www.gnu.org/licenses/.
302
+
package/SECURITY.md ADDED
@@ -0,0 +1,11 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ lemonldap-ng-handler is a beta version, only last version is supported for now.
6
+
7
+ ## Reporting a Vulnerability
8
+
9
+ You can create an issue into [this GitHub repository](https://github.com/LemonLDAPNG/node-lemonldap-ng-handler/issues)
10
+ but prefer to use our [main repository](https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/-/issues)
11
+ using **Node Handler** label.
@@ -0,0 +1,22 @@
1
+ /// <reference types="node" />
2
+ import { LLNG_Session } from '@lemonldap-ng/types';
3
+ import { Handler_Args } from './init';
4
+ import LemonldapNGHandler from './handlerMain';
5
+ import express from 'express';
6
+ import http from 'http';
7
+ declare type Vhost_Config = {
8
+ prot: string;
9
+ host: string;
10
+ path: string;
11
+ port: string;
12
+ headers?: {
13
+ [k: string]: string;
14
+ };
15
+ lb?: boolean;
16
+ };
17
+ declare class LemonldapNGHandlerDevOps extends LemonldapNGHandler {
18
+ constructor(args: Handler_Args);
19
+ grant(req: express.Request | http.IncomingMessage, uri: string, session: LLNG_Session): Promise<boolean>;
20
+ loadVhostConfig(req: express.Request | http.IncomingMessage, vhost: string, lvOpts: Vhost_Config): Promise<boolean>;
21
+ }
22
+ export default LemonldapNGHandlerDevOps;
@@ -0,0 +1,10 @@
1
+ /// <reference types="node" />
2
+ import { Request } from 'express';
3
+ import { ParamsDictionary } from 'express-serve-static-core';
4
+ import { IncomingMessage } from 'http';
5
+ import { ParsedQs } from 'qs';
6
+ import LemonldapNGHandlerDevOps from './handlerDevOps';
7
+ declare class LemonldapNGHandlerDevOpsST extends LemonldapNGHandlerDevOps {
8
+ fetchId(req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>> | IncomingMessage): string;
9
+ }
10
+ export default LemonldapNGHandlerDevOpsST;
@@ -0,0 +1,30 @@
1
+ /// <reference types="node" />
2
+ import { LLNG_Session } from '@lemonldap-ng/types';
3
+ import HandlerInit from './init';
4
+ import express from 'express';
5
+ import http from 'http';
6
+ export declare type FastCGI_Opts = {
7
+ mode: string | undefined;
8
+ port: number | undefined;
9
+ ip: string | undefined;
10
+ };
11
+ declare class LemonldapNGHandler extends HandlerInit {
12
+ init(): Promise<boolean>;
13
+ /**
14
+ * run(), the access control function
15
+ */
16
+ run(req: express.Request | http.IncomingMessage, res: http.ServerResponse, next: Function): any;
17
+ selfUri(vhost: string, uri: string): string;
18
+ nginxServer(fcgiOpt: FastCGI_Opts): void;
19
+ setError(res: http.ServerResponse, uri: string, code: number, txt: string): void;
20
+ isUnprotected(req: express.Request | http.IncomingMessage, uri: string): number | false;
21
+ resolveAlias(req: express.Request | http.IncomingMessage): string;
22
+ fetchId(req: express.Request | http.IncomingMessage): string;
23
+ retrieveSession(id: string): Promise<LLNG_Session>;
24
+ grant(req: express.Request | http.IncomingMessage, uri: string, session: LLNG_Session): Promise<boolean>;
25
+ sendHeaders(req: express.Request | http.IncomingMessage, session: LLNG_Session): void;
26
+ hideCookie(req: express.Request | http.IncomingMessage): void;
27
+ forbidden(req: express.Request | http.IncomingMessage, res: http.ServerResponse, session: LLNG_Session): void;
28
+ goToPortal(res: http.ServerResponse, uri: string, args?: string): void;
29
+ }
30
+ export default LemonldapNGHandler;
@@ -0,0 +1,8 @@
1
+ /// <reference types="node" />
2
+ import express from 'express';
3
+ import http from 'http';
4
+ import LemonldapNGHandler from './handlerMain';
5
+ declare class LemonldapNGHandlerServiceToken extends LemonldapNGHandler {
6
+ fetchId(req: express.Request | http.IncomingMessage): string;
7
+ }
8
+ export default LemonldapNGHandlerServiceToken;
package/lib/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import express from 'express';
2
+ import http from 'http';
3
+ import { Handler_Args } from './init';
4
+ import LemonldapNGHandler, { FastCGI_Opts } from './handlerMain';
5
+ import LemonldapNGHandlerDevOps from './handlerDevOps';
6
+ declare let currentClass: typeof LemonldapNGHandler | typeof LemonldapNGHandlerDevOps;
7
+ export declare const init: (args: Handler_Args) => Promise<LemonldapNGHandler>;
8
+ export declare const run: (req: express.Request | http.IncomingMessage, res: http.ServerResponse, next: Function) => any;
9
+ export declare const nginxServer: (args: FastCGI_Opts) => void;
10
+ export { currentClass as class };