@routr/simpleauth 2.0.5-alpha.14 → 2.0.5-alpha.15
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/dist/runner.js +2 -1
- package/dist/service.js +15 -12
- package/dist/tracer.d.ts +1 -0
- package/dist/tracer.js +49 -0
- package/dist/utils.js +1 -1
- package/package.json +11 -12
package/dist/runner.js
CHANGED
|
@@ -22,6 +22,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
22
22
|
* See the License for the specific language governing permissions and
|
|
23
23
|
* limitations under the License.
|
|
24
24
|
*/
|
|
25
|
+
require("./tracer").init("simpleauth");
|
|
25
26
|
const logger_1 = __importDefault(require("@fonoster/logger"));
|
|
26
27
|
const service_1 = __importDefault(require("./service"));
|
|
27
28
|
if (!process.env.PATH_TO_AUTH) {
|
|
@@ -31,7 +32,7 @@ if (!process.env.PATH_TO_AUTH) {
|
|
|
31
32
|
const whiteList = process.env.WHITELIST ? process.env.WHITELIST.split(',') : [];
|
|
32
33
|
try {
|
|
33
34
|
const users = require(process.env.PATH_TO_AUTH);
|
|
34
|
-
service_1.default({ bindAddr: process.env.BIND_ADDR || "0.0.0.0:51903", users, whiteList });
|
|
35
|
+
(0, service_1.default)({ bindAddr: process.env.BIND_ADDR || "0.0.0.0:51903", users, whiteList });
|
|
35
36
|
}
|
|
36
37
|
catch (e) {
|
|
37
38
|
if (e.code === "MODULE_NOT_FOUND") {
|
package/dist/service.js
CHANGED
|
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
*
|
|
11
11
|
* This file is part of Routr
|
|
12
12
|
*
|
|
13
|
-
* Licensed under the MIT License (the "License")
|
|
13
|
+
* Licensed under the MIT License (the "License")
|
|
14
14
|
* you may not use this file except in compliance with
|
|
15
15
|
* the License. You may obtain a copy of the License at
|
|
16
16
|
*
|
|
@@ -22,11 +22,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
22
22
|
* See the License for the specific language governing permissions and
|
|
23
23
|
* limitations under the License.
|
|
24
24
|
*/
|
|
25
|
-
const common_1 = require("@routr/common");
|
|
26
|
-
const tracer = common_1.Tracer.init("simpleauth");
|
|
27
25
|
const api_1 = __importDefault(require("@opentelemetry/api"));
|
|
28
26
|
const logger_1 = __importDefault(require("@fonoster/logger"));
|
|
29
|
-
const
|
|
27
|
+
const common_1 = require("@routr/common");
|
|
30
28
|
const utils_1 = require("./utils");
|
|
31
29
|
const processor_1 = __importDefault(require("@routr/processor"));
|
|
32
30
|
function SimpleAuthProcessor(config) {
|
|
@@ -35,15 +33,14 @@ function SimpleAuthProcessor(config) {
|
|
|
35
33
|
.listen((req, res) => {
|
|
36
34
|
logger_1.default.verbose(`authenticating ${req.message.from.address.uri.user} endpoint with simpleauth`);
|
|
37
35
|
logger_1.default.silly(JSON.stringify(req, null, ' '));
|
|
36
|
+
const tracer = api_1.default.trace.getTracer("routr-tracer");
|
|
38
37
|
const currentSpan = api_1.default.trace.getSpan(api_1.default.context.active());
|
|
39
38
|
// display traceid in the terminal
|
|
40
39
|
logger_1.default.verbose(`traceid: ${currentSpan.spanContext().traceId}`);
|
|
41
|
-
const span = tracer.startSpan('server.js:sayHello()', {
|
|
42
|
-
kind: 1,
|
|
43
|
-
attributes: { key: 'value' },
|
|
44
|
-
});
|
|
45
|
-
span.addEvent(`invoking sayHello() to...`);
|
|
40
|
+
const span = tracer.startSpan('server.js:sayHello()', { kind: 1 });
|
|
46
41
|
if (whiteList.includes(req.message.from.address.uri.user)) {
|
|
42
|
+
span.addEvent(`authenticated ${req.message.from.address.uri.user} from whitelist`);
|
|
43
|
+
span.end();
|
|
47
44
|
return res.send(req);
|
|
48
45
|
}
|
|
49
46
|
// Calculate and return challenge
|
|
@@ -51,15 +48,21 @@ function SimpleAuthProcessor(config) {
|
|
|
51
48
|
const auth = Object.assign({}, req.message.authorization);
|
|
52
49
|
auth.method = req.method;
|
|
53
50
|
// Calculate response and compare with the one send by the endpoint
|
|
54
|
-
const calcRes =
|
|
51
|
+
const calcRes = (0, common_1.calculateAuthResponse)(auth, (0, utils_1.getCredentials)(auth.username, users));
|
|
55
52
|
if (calcRes !== auth.response) {
|
|
56
|
-
|
|
53
|
+
span.addEvent(`user ${req.message.from.address.uri.user} unauthorized to complete request`);
|
|
54
|
+
span.end();
|
|
55
|
+
return res.send((0, utils_1.createUnauthorizedResponse)(auth.realm));
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
58
|
else {
|
|
60
|
-
|
|
59
|
+
span.addEvent(`authorization header not found for user ${req.message.from.address.uri.user}`);
|
|
60
|
+
span.end();
|
|
61
|
+
return res.send((0, utils_1.createUnauthorizedResponse)(req.message.requestUri.host));
|
|
61
62
|
}
|
|
62
63
|
// Forward request to next middleware
|
|
64
|
+
span.addEvent(`user ${req.message.from.address.uri.user} authorized`);
|
|
65
|
+
span.end();
|
|
63
66
|
res.send(req);
|
|
64
67
|
});
|
|
65
68
|
}
|
package/dist/tracer.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function init(serviceName: string): import("@opentelemetry/api").Tracer;
|
package/dist/tracer.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.init = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
9
|
+
* http://github.com/fonoster/routr
|
|
10
|
+
*
|
|
11
|
+
* This file is part of Routr
|
|
12
|
+
*
|
|
13
|
+
* Licensed under the MIT License (the "License")
|
|
14
|
+
* you may not use this file except in compliance with
|
|
15
|
+
* the License. You may obtain a copy of the License at
|
|
16
|
+
*
|
|
17
|
+
* https://opensource.org/licenses/MIT
|
|
18
|
+
*
|
|
19
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
20
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
21
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
|
+
* See the License for the specific language governing permissions and
|
|
23
|
+
* limitations under the License.
|
|
24
|
+
*/
|
|
25
|
+
const api_1 = __importDefault(require("@opentelemetry/api"));
|
|
26
|
+
const instrumentation_1 = require("@opentelemetry/instrumentation");
|
|
27
|
+
const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
|
|
28
|
+
const resources_1 = require("@opentelemetry/resources");
|
|
29
|
+
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
30
|
+
const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
|
|
31
|
+
const exporter_jaeger_1 = require("@opentelemetry/exporter-jaeger");
|
|
32
|
+
const instrumentation_grpc_1 = require("@opentelemetry/instrumentation-grpc");
|
|
33
|
+
function init(serviceName) {
|
|
34
|
+
const provider = new sdk_trace_node_1.NodeTracerProvider({
|
|
35
|
+
resource: new resources_1.Resource({
|
|
36
|
+
[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: serviceName,
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
39
|
+
const exporter = new exporter_jaeger_1.JaegerExporter();
|
|
40
|
+
provider.addSpanProcessor(new sdk_trace_base_1.SimpleSpanProcessor(exporter));
|
|
41
|
+
provider.register();
|
|
42
|
+
(0, instrumentation_1.registerInstrumentations)({
|
|
43
|
+
instrumentations: [
|
|
44
|
+
new instrumentation_grpc_1.GrpcInstrumentation(),
|
|
45
|
+
],
|
|
46
|
+
});
|
|
47
|
+
return api_1.default.trace.getTracer('routr-tracer');
|
|
48
|
+
}
|
|
49
|
+
exports.init = init;
|
package/dist/utils.js
CHANGED
|
@@ -33,7 +33,7 @@ const createUnauthorizedResponse = (realm, params = { qop: "auth", algorithm: "M
|
|
|
33
33
|
qop: params.qop,
|
|
34
34
|
opaque: '',
|
|
35
35
|
stale: false,
|
|
36
|
-
nonce: common_1.generateNonce(),
|
|
36
|
+
nonce: (0, common_1.generateNonce)(),
|
|
37
37
|
algorithm: params.algorithm
|
|
38
38
|
},
|
|
39
39
|
extensions: [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@routr/simpleauth",
|
|
3
|
-
"version": "2.0.5-alpha.
|
|
3
|
+
"version": "2.0.5-alpha.15",
|
|
4
4
|
"description": "This middleware delegates authentication to an external service",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/routr#readme",
|
|
@@ -20,18 +20,17 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@fonoster/logger": "^0.3.3",
|
|
23
|
-
"@grpc/grpc-js": "^1.
|
|
24
|
-
"@opentelemetry/api": "^1.0.
|
|
25
|
-
"@opentelemetry/exporter-jaeger": "^1.0.
|
|
26
|
-
"@opentelemetry/exporter-zipkin": "^1.0.1",
|
|
23
|
+
"@grpc/grpc-js": "^1.5.9",
|
|
24
|
+
"@opentelemetry/api": "^1.0.4",
|
|
25
|
+
"@opentelemetry/exporter-jaeger": "^1.0.4",
|
|
27
26
|
"@opentelemetry/instrumentation": "^0.27.0",
|
|
28
27
|
"@opentelemetry/instrumentation-grpc": "^0.27.0",
|
|
29
|
-
"@opentelemetry/resources": "^1.0.
|
|
30
|
-
"@opentelemetry/sdk-trace-base": "^1.0.
|
|
31
|
-
"@opentelemetry/sdk-trace-node": "^1.0.
|
|
32
|
-
"@opentelemetry/semantic-conventions": "^1.0.
|
|
33
|
-
"@routr/common": "^2.0.5-alpha.
|
|
34
|
-
"@routr/processor": "^2.0.5-alpha.
|
|
28
|
+
"@opentelemetry/resources": "^1.0.4",
|
|
29
|
+
"@opentelemetry/sdk-trace-base": "^1.0.4",
|
|
30
|
+
"@opentelemetry/sdk-trace-node": "^1.0.4",
|
|
31
|
+
"@opentelemetry/semantic-conventions": "^1.0.4",
|
|
32
|
+
"@routr/common": "^2.0.5-alpha.15",
|
|
33
|
+
"@routr/processor": "^2.0.5-alpha.15",
|
|
35
34
|
"google-protobuf": "^3.9.2"
|
|
36
35
|
},
|
|
37
36
|
"files": [
|
|
@@ -47,5 +46,5 @@
|
|
|
47
46
|
"bugs": {
|
|
48
47
|
"url": "https://github.com/fonoster/routr/issues"
|
|
49
48
|
},
|
|
50
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "3e08aa86f1596252546134bff677d17d7dd54ced"
|
|
51
50
|
}
|