@mondaydotcomorg/monday-authorization 1.1.9-featurebelkaauthz-sdk-improved-error-handling.2402 → 1.1.9-featurefilipmcipher-core-flags-client.2760
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/package.json +5 -5
- package/dist/index.d.ts +0 -13
- package/dist/index.js +0 -50
- package/dist/lib/attributions-service.d.ts +0 -3
- package/dist/lib/attributions-service.js +0 -54
- package/dist/lib/authorization-attributes-service.d.ts +0 -23
- package/dist/lib/authorization-attributes-service.js +0 -68
- package/dist/lib/authorization-internal-service.d.ts +0 -15
- package/dist/lib/authorization-internal-service.js +0 -78
- package/dist/lib/authorization-middleware.d.ts +0 -6
- package/dist/lib/authorization-middleware.js +0 -57
- package/dist/lib/authorization-service.d.ts +0 -29
- package/dist/lib/authorization-service.js +0 -185
- package/dist/lib/prometheus-service.d.ts +0 -10
- package/dist/lib/prometheus-service.js +0 -50
- package/dist/lib/testKit/index.d.ts +0 -11
- package/dist/lib/testKit/index.js +0 -58
- package/dist/lib/types/authorization-attributes-contracts.d.ts +0 -10
- package/dist/lib/types/authorization-attributes-contracts.js +0 -2
- package/dist/lib/types/express.d.ts +0 -10
- package/dist/lib/types/express.js +0 -1
- package/dist/lib/types/general.d.ts +0 -30
- package/dist/lib/types/general.js +0 -2
- package/dist/lib/types/scoped-actions-contracts.d.ts +0 -38
- package/dist/lib/types/scoped-actions-contracts.js +0 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mondaydotcomorg/monday-authorization",
|
|
3
|
-
"version": "1.1.9-
|
|
3
|
+
"version": "1.1.9-featurefilipmcipher-core-flags-client.2760+996328beb",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@mondaydotcomorg/monday-fetch": "^0.0.7",
|
|
13
|
-
"@mondaydotcomorg/monday-jwt": "^3.0.
|
|
14
|
-
"@mondaydotcomorg/monday-logger": "^
|
|
15
|
-
"@mondaydotcomorg/trident-backend-api": "^0.
|
|
13
|
+
"@mondaydotcomorg/monday-jwt": "^3.0.14",
|
|
14
|
+
"@mondaydotcomorg/monday-logger": "^4.0.11",
|
|
15
|
+
"@mondaydotcomorg/trident-backend-api": "^0.23.10",
|
|
16
16
|
"node-fetch": "^2.6.7",
|
|
17
17
|
"on-headers": "^1.0.2",
|
|
18
18
|
"ts-node": "^10.0.0"
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"files": [
|
|
34
34
|
"dist/"
|
|
35
35
|
],
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "996328beba873d81b9dd60aa3273d807a0a57244"
|
|
37
37
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { MondayFetchOptions } from '@mondaydotcomorg/monday-fetch';
|
|
2
|
-
import * as TestKit from './lib/testKit';
|
|
3
|
-
export interface InitOptions {
|
|
4
|
-
prometheus?: any;
|
|
5
|
-
mondayFetchOptions?: MondayFetchOptions;
|
|
6
|
-
redisClient?: any;
|
|
7
|
-
grantedFeatureRedisExpirationInSeconds?: number;
|
|
8
|
-
}
|
|
9
|
-
export declare function init(options?: InitOptions): void;
|
|
10
|
-
export { authorizationCheckMiddleware, getAuthorizationMiddleware, skipAuthorizationMiddleware, } from './lib/authorization-middleware';
|
|
11
|
-
export { AuthorizationService } from './lib/authorization-service';
|
|
12
|
-
export { AuthorizationAttributesService } from './lib/authorization-attributes-service';
|
|
13
|
-
export { TestKit };
|
package/dist/index.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.TestKit = exports.AuthorizationAttributesService = exports.AuthorizationService = exports.skipAuthorizationMiddleware = exports.getAuthorizationMiddleware = exports.authorizationCheckMiddleware = exports.init = void 0;
|
|
27
|
-
const prometheus_service_1 = require("./lib/prometheus-service");
|
|
28
|
-
const authorization_service_1 = require("./lib/authorization-service");
|
|
29
|
-
const TestKit = __importStar(require("./lib/testKit"));
|
|
30
|
-
exports.TestKit = TestKit;
|
|
31
|
-
function init(options = {}) {
|
|
32
|
-
if (options.prometheus) {
|
|
33
|
-
(0, prometheus_service_1.setPrometheus)(options.prometheus);
|
|
34
|
-
}
|
|
35
|
-
if (options.mondayFetchOptions) {
|
|
36
|
-
(0, authorization_service_1.setRequestFetchOptions)(options.mondayFetchOptions);
|
|
37
|
-
}
|
|
38
|
-
if (options.redisClient) {
|
|
39
|
-
(0, authorization_service_1.setRedisClient)(options.redisClient, options.grantedFeatureRedisExpirationInSeconds);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.init = init;
|
|
43
|
-
var authorization_middleware_1 = require("./lib/authorization-middleware");
|
|
44
|
-
Object.defineProperty(exports, "authorizationCheckMiddleware", { enumerable: true, get: function () { return authorization_middleware_1.authorizationCheckMiddleware; } });
|
|
45
|
-
Object.defineProperty(exports, "getAuthorizationMiddleware", { enumerable: true, get: function () { return authorization_middleware_1.getAuthorizationMiddleware; } });
|
|
46
|
-
Object.defineProperty(exports, "skipAuthorizationMiddleware", { enumerable: true, get: function () { return authorization_middleware_1.skipAuthorizationMiddleware; } });
|
|
47
|
-
var authorization_service_2 = require("./lib/authorization-service");
|
|
48
|
-
Object.defineProperty(exports, "AuthorizationService", { enumerable: true, get: function () { return authorization_service_2.AuthorizationService; } });
|
|
49
|
-
var authorization_attributes_service_1 = require("./lib/authorization-attributes-service");
|
|
50
|
-
Object.defineProperty(exports, "AuthorizationAttributesService", { enumerable: true, get: function () { return authorization_attributes_service_1.AuthorizationAttributesService; } });
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAttributionsFromApi = void 0;
|
|
4
|
-
const trident_backend_api_1 = require("@mondaydotcomorg/trident-backend-api");
|
|
5
|
-
const authorization_internal_service_1 = require("./authorization-internal-service");
|
|
6
|
-
const APP_NAME_VARIABLE_KEY = 'APP_NAME';
|
|
7
|
-
const APP_NAME_HEADER_NAME = 'x-caller-app-name-from-sdk';
|
|
8
|
-
const FROM_SDK_HEADER_SUFFIX = `-from-sdk`;
|
|
9
|
-
let didSendFailureLogOnce = false;
|
|
10
|
-
function getAttributionsFromApi() {
|
|
11
|
-
let callerAppNameFromSdk = {
|
|
12
|
-
[APP_NAME_HEADER_NAME]: tryJsonParse(getEnvVariable(APP_NAME_VARIABLE_KEY)),
|
|
13
|
-
};
|
|
14
|
-
try {
|
|
15
|
-
const tridentContext = trident_backend_api_1.Api.getPart('context');
|
|
16
|
-
if (!tridentContext) {
|
|
17
|
-
return callerAppNameFromSdk;
|
|
18
|
-
}
|
|
19
|
-
const { runtimeAttributions } = tridentContext;
|
|
20
|
-
let runtimeAttributionsOutgoingHeaders = runtimeAttributions === null || runtimeAttributions === void 0 ? void 0 : runtimeAttributions.buildOutgoingHeaders('HTTP_INTERNAL');
|
|
21
|
-
if (!runtimeAttributionsOutgoingHeaders) {
|
|
22
|
-
return callerAppNameFromSdk;
|
|
23
|
-
}
|
|
24
|
-
const attributionsHeaders = Object.fromEntries(runtimeAttributionsOutgoingHeaders);
|
|
25
|
-
const attributionHeadersFromSdk = {};
|
|
26
|
-
Object.keys(attributionsHeaders).forEach(function (key) {
|
|
27
|
-
attributionHeadersFromSdk[`${key}${FROM_SDK_HEADER_SUFFIX}`] = attributionsHeaders[key];
|
|
28
|
-
});
|
|
29
|
-
return attributionHeadersFromSdk;
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
if (!didSendFailureLogOnce) {
|
|
33
|
-
authorization_internal_service_1.logger.warn({ tag: 'authorization-service', error }, 'Failed to generate attributions headers from the API. Unexpected error while extracting headers. It may be caused by out of date Trident version.');
|
|
34
|
-
didSendFailureLogOnce = true;
|
|
35
|
-
}
|
|
36
|
-
return callerAppNameFromSdk;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.getAttributionsFromApi = getAttributionsFromApi;
|
|
40
|
-
function getEnvVariable(key) {
|
|
41
|
-
const envVar = process.env[key] || process.env[key.toUpperCase()] || process.env[key.toLowerCase()];
|
|
42
|
-
return envVar;
|
|
43
|
-
}
|
|
44
|
-
function tryJsonParse(value) {
|
|
45
|
-
if (!value) {
|
|
46
|
-
return value;
|
|
47
|
-
}
|
|
48
|
-
try {
|
|
49
|
-
return JSON.parse(value);
|
|
50
|
-
}
|
|
51
|
-
catch (_err) {
|
|
52
|
-
return value;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { ResourceAttributeAssignment, ResourceAttributeResponse } from './types/authorization-attributes-contracts';
|
|
2
|
-
import { Resource } from './types/general';
|
|
3
|
-
export declare class AuthorizationAttributesService {
|
|
4
|
-
/**
|
|
5
|
-
* Upsert resource attributes synchronously, performing http call to the authorization MS to assign the given attributes to the given resource.
|
|
6
|
-
* @param accountId
|
|
7
|
-
* @param userId
|
|
8
|
-
* @param resourceAttributeAssignments - Array of resource (resourceType, resourceId) and attribute (key, value) pairs to upsert in the authorization MS.
|
|
9
|
-
* e.g. [{ resourceType: 'board', resourceId: 123, key: 'board_kind', value: 'private' }]
|
|
10
|
-
* @returns ResourceAttributeResponse - The affected (created and updated_ resource attributes assignments in the `attributes` field.
|
|
11
|
-
*/
|
|
12
|
-
static upsertResourceAttributes(accountId: number, userId: number, resourceAttributeAssignments: ResourceAttributeAssignment[]): Promise<ResourceAttributeResponse>;
|
|
13
|
-
/**
|
|
14
|
-
* Delete resource attributes assignments synchronously, performing http call to the authorization MS to delete the given attributes from the given singular resource.
|
|
15
|
-
* @param accountId
|
|
16
|
-
* @param userId
|
|
17
|
-
* @param resource - The resource (resourceType, resourceId) to delete the attributes for.
|
|
18
|
-
* @param attributeKeys - Array of attribute keys to delete for the resource.
|
|
19
|
-
* @returns ResourceAttributeResponse - The affected (deleted) resource attributes assignments in the `attributes` field.
|
|
20
|
-
*/
|
|
21
|
-
static deleteResourceAttributes(accountId: number, userId: number, resource: Resource, attributeKeys: string[]): Promise<ResourceAttributeResponse>;
|
|
22
|
-
private static getResourceAttributesUrl;
|
|
23
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.AuthorizationAttributesService = void 0;
|
|
13
|
-
const monday_fetch_1 = require("@mondaydotcomorg/monday-fetch");
|
|
14
|
-
const authorization_internal_service_1 = require("./authorization-internal-service");
|
|
15
|
-
const attributions_service_1 = require("./attributions-service");
|
|
16
|
-
class AuthorizationAttributesService {
|
|
17
|
-
/**
|
|
18
|
-
* Upsert resource attributes synchronously, performing http call to the authorization MS to assign the given attributes to the given resource.
|
|
19
|
-
* @param accountId
|
|
20
|
-
* @param userId
|
|
21
|
-
* @param resourceAttributeAssignments - Array of resource (resourceType, resourceId) and attribute (key, value) pairs to upsert in the authorization MS.
|
|
22
|
-
* e.g. [{ resourceType: 'board', resourceId: 123, key: 'board_kind', value: 'private' }]
|
|
23
|
-
* @returns ResourceAttributeResponse - The affected (created and updated_ resource attributes assignments in the `attributes` field.
|
|
24
|
-
*/
|
|
25
|
-
static upsertResourceAttributes(accountId, userId, resourceAttributeAssignments) {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
const internalAuthToken = authorization_internal_service_1.AuthorizationInternalService.generateInternalAuthToken(accountId, userId);
|
|
28
|
-
const attributionHeaders = (0, attributions_service_1.getAttributionsFromApi)();
|
|
29
|
-
const response = yield (0, monday_fetch_1.fetch)(this.getResourceAttributesUrl(accountId), {
|
|
30
|
-
method: 'POST',
|
|
31
|
-
headers: Object.assign({ Authorization: internalAuthToken, 'Content-Type': 'application/json' }, attributionHeaders),
|
|
32
|
-
timeout: authorization_internal_service_1.AuthorizationInternalService.getRequestTimeout(),
|
|
33
|
-
body: JSON.stringify({ resourceAttributeAssignments }),
|
|
34
|
-
}, authorization_internal_service_1.AuthorizationInternalService.getRequestFetchOptions());
|
|
35
|
-
const responseBody = yield response.json();
|
|
36
|
-
authorization_internal_service_1.AuthorizationInternalService.throwOnHttpErrorIfNeeded(response, 'upsertResourceAttributesSync');
|
|
37
|
-
return { attributes: responseBody['attributes'] };
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Delete resource attributes assignments synchronously, performing http call to the authorization MS to delete the given attributes from the given singular resource.
|
|
42
|
-
* @param accountId
|
|
43
|
-
* @param userId
|
|
44
|
-
* @param resource - The resource (resourceType, resourceId) to delete the attributes for.
|
|
45
|
-
* @param attributeKeys - Array of attribute keys to delete for the resource.
|
|
46
|
-
* @returns ResourceAttributeResponse - The affected (deleted) resource attributes assignments in the `attributes` field.
|
|
47
|
-
*/
|
|
48
|
-
static deleteResourceAttributes(accountId, userId, resource, attributeKeys) {
|
|
49
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
const internalAuthToken = authorization_internal_service_1.AuthorizationInternalService.generateInternalAuthToken(accountId, userId);
|
|
51
|
-
const url = `${this.getResourceAttributesUrl(accountId)}/${resource.type}/${resource.id}`;
|
|
52
|
-
const attributionHeaders = (0, attributions_service_1.getAttributionsFromApi)();
|
|
53
|
-
const response = yield (0, monday_fetch_1.fetch)(url, {
|
|
54
|
-
method: 'DELETE',
|
|
55
|
-
headers: Object.assign({ Authorization: internalAuthToken, 'Content-Type': 'application/json' }, attributionHeaders),
|
|
56
|
-
timeout: authorization_internal_service_1.AuthorizationInternalService.getRequestTimeout(),
|
|
57
|
-
body: JSON.stringify({ keys: attributeKeys }),
|
|
58
|
-
}, authorization_internal_service_1.AuthorizationInternalService.getRequestFetchOptions());
|
|
59
|
-
const responseBody = yield response.json();
|
|
60
|
-
authorization_internal_service_1.AuthorizationInternalService.throwOnHttpErrorIfNeeded(response, 'deleteResourceAttributesSync');
|
|
61
|
-
return { attributes: responseBody['attributes'] };
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
static getResourceAttributesUrl(accountId) {
|
|
65
|
-
return `${process.env.AUTHORIZATION_URL}/attributes/${accountId}/resource`;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
exports.AuthorizationAttributesService = AuthorizationAttributesService;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/// <reference types="bunyan" />
|
|
2
|
-
import { Request } from 'express';
|
|
3
|
-
import { fetch, MondayFetchOptions } from '@mondaydotcomorg/monday-fetch';
|
|
4
|
-
import * as MondayLogger from '@mondaydotcomorg/monday-logger';
|
|
5
|
-
export declare const logger: MondayLogger.Logger;
|
|
6
|
-
export declare class AuthorizationInternalService {
|
|
7
|
-
static skipAuthorization(requset: Request): void;
|
|
8
|
-
static markAuthorized(request: Request): void;
|
|
9
|
-
static failIfNotCoveredByAuthorization(request: Request): void;
|
|
10
|
-
static throwOnHttpErrorIfNeeded(response: Awaited<ReturnType<typeof fetch>>, placement: string): void;
|
|
11
|
-
static generateInternalAuthToken(accountId: number, userId: number): string;
|
|
12
|
-
static setRequestFetchOptions(customMondayFetchOptions: MondayFetchOptions): void;
|
|
13
|
-
static getRequestFetchOptions(): MondayFetchOptions;
|
|
14
|
-
static getRequestTimeout(): 60000 | 2000;
|
|
15
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.AuthorizationInternalService = exports.logger = void 0;
|
|
27
|
-
const monday_jwt_1 = require("@mondaydotcomorg/monday-jwt");
|
|
28
|
-
const MondayLogger = __importStar(require("@mondaydotcomorg/monday-logger"));
|
|
29
|
-
const INTERNAL_APP_NAME = 'internal_ms';
|
|
30
|
-
const defaultMondayFetchOptions = {
|
|
31
|
-
retries: 3,
|
|
32
|
-
callback: logOnFetchFail,
|
|
33
|
-
};
|
|
34
|
-
function logOnFetchFail(retriesLeft, error) {
|
|
35
|
-
if (retriesLeft == 0) {
|
|
36
|
-
exports.logger.error({ retriesLeft, error }, 'Authorization attempt failed due to network issues');
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
exports.logger.info({ retriesLeft, error }, 'Authorization attempt failed due to network issues, trying again');
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
let mondayFetchOptions = defaultMondayFetchOptions;
|
|
43
|
-
exports.logger = MondayLogger.getLogger();
|
|
44
|
-
class AuthorizationInternalService {
|
|
45
|
-
static skipAuthorization(requset) {
|
|
46
|
-
requset.authorizationSkipPerformed = true;
|
|
47
|
-
}
|
|
48
|
-
static markAuthorized(request) {
|
|
49
|
-
request.authorizationCheckPerformed = true;
|
|
50
|
-
}
|
|
51
|
-
static failIfNotCoveredByAuthorization(request) {
|
|
52
|
-
if (!request.authorizationCheckPerformed && !request.authorizationSkipPerformed) {
|
|
53
|
-
throw 'Endpoint is not covered by authorization check';
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
static throwOnHttpErrorIfNeeded(response, placement) {
|
|
57
|
-
if (response.ok) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
const status = response.status;
|
|
61
|
-
exports.logger.error({ tag: 'authorization-service', placement, status }, 'AuthorizationService: authorization request failed');
|
|
62
|
-
throw new Error(`AuthorizationService: [${placement}] authorization request failed with status ${status}`);
|
|
63
|
-
}
|
|
64
|
-
static generateInternalAuthToken(accountId, userId) {
|
|
65
|
-
return (0, monday_jwt_1.signAuthorizationHeader)({ appName: INTERNAL_APP_NAME, accountId, userId });
|
|
66
|
-
}
|
|
67
|
-
static setRequestFetchOptions(customMondayFetchOptions) {
|
|
68
|
-
mondayFetchOptions = Object.assign(Object.assign({}, defaultMondayFetchOptions), customMondayFetchOptions);
|
|
69
|
-
}
|
|
70
|
-
static getRequestFetchOptions() {
|
|
71
|
-
return mondayFetchOptions;
|
|
72
|
-
}
|
|
73
|
-
static getRequestTimeout() {
|
|
74
|
-
const isDevEnv = process.env.NODE_ENV === 'development';
|
|
75
|
-
return isDevEnv ? 60000 : 2000;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.AuthorizationInternalService = AuthorizationInternalService;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { NextFunction } from 'express';
|
|
2
|
-
import { Action, BaseRequest, BaseResponse, Context, ContextGetter, ResourceGetter } from './types/general';
|
|
3
|
-
export declare function getAuthorizationMiddleware(action: Action, resourceGetter: ResourceGetter, contextGetter?: ContextGetter): (request: BaseRequest, response: BaseResponse, next: NextFunction) => Promise<void>;
|
|
4
|
-
export declare function skipAuthorizationMiddleware(request: BaseRequest, response: BaseResponse, next: NextFunction): void;
|
|
5
|
-
export declare function authorizationCheckMiddleware(request: BaseRequest, response: BaseResponse, next: NextFunction): void;
|
|
6
|
-
export declare function defaultContextGetter(request: BaseRequest): Context;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.defaultContextGetter = exports.authorizationCheckMiddleware = exports.skipAuthorizationMiddleware = exports.getAuthorizationMiddleware = void 0;
|
|
16
|
-
const on_headers_1 = __importDefault(require("on-headers"));
|
|
17
|
-
const authorization_internal_service_1 = require("./authorization-internal-service");
|
|
18
|
-
const authorization_service_1 = require("./authorization-service");
|
|
19
|
-
// getAuthorizationMiddleware is duplicated in testKit/index.ts
|
|
20
|
-
// If you are making changes to this function, please make sure to update the other file as well
|
|
21
|
-
function getAuthorizationMiddleware(action, resourceGetter, contextGetter) {
|
|
22
|
-
return function authorizationMiddleware(request, response, next) {
|
|
23
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
contextGetter || (contextGetter = defaultContextGetter);
|
|
25
|
-
const { userId, accountId } = contextGetter(request);
|
|
26
|
-
const resources = resourceGetter(request);
|
|
27
|
-
const { isAuthorized } = yield authorization_service_1.AuthorizationService.isAuthorized(accountId, userId, resources, action);
|
|
28
|
-
authorization_internal_service_1.AuthorizationInternalService.markAuthorized(request);
|
|
29
|
-
if (!isAuthorized) {
|
|
30
|
-
response.status(403).json({ message: 'Access denied' });
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
next();
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
exports.getAuthorizationMiddleware = getAuthorizationMiddleware;
|
|
38
|
-
function skipAuthorizationMiddleware(request, response, next) {
|
|
39
|
-
authorization_internal_service_1.AuthorizationInternalService.skipAuthorization(request);
|
|
40
|
-
next();
|
|
41
|
-
}
|
|
42
|
-
exports.skipAuthorizationMiddleware = skipAuthorizationMiddleware;
|
|
43
|
-
function authorizationCheckMiddleware(request, response, next) {
|
|
44
|
-
if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
|
|
45
|
-
(0, on_headers_1.default)(response, function () {
|
|
46
|
-
if (response.statusCode < 400) {
|
|
47
|
-
authorization_internal_service_1.AuthorizationInternalService.failIfNotCoveredByAuthorization(request);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
next();
|
|
52
|
-
}
|
|
53
|
-
exports.authorizationCheckMiddleware = authorizationCheckMiddleware;
|
|
54
|
-
function defaultContextGetter(request) {
|
|
55
|
-
return request.payload;
|
|
56
|
-
}
|
|
57
|
-
exports.defaultContextGetter = defaultContextGetter;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { MondayFetchOptions } from '@mondaydotcomorg/monday-fetch';
|
|
2
|
-
import { Action, AuthorizationObject, Resource } from './types/general';
|
|
3
|
-
import { ScopedAction, ScopedActionPermit, ScopedActionResponseObject, ScopeOptions } from './types/scoped-actions-contracts';
|
|
4
|
-
export interface AuthorizeResponse {
|
|
5
|
-
isAuthorized: boolean;
|
|
6
|
-
unauthorizedIds?: number[];
|
|
7
|
-
unauthorizedObjects?: AuthorizationObject[];
|
|
8
|
-
}
|
|
9
|
-
export declare function setRequestFetchOptions(customMondayFetchOptions: MondayFetchOptions): void;
|
|
10
|
-
export declare function setRedisClient(client: any, grantedFeatureRedisExpirationInSeconds?: number): void;
|
|
11
|
-
export declare class AuthorizationService {
|
|
12
|
-
static redisClient?: any;
|
|
13
|
-
static grantedFeatureRedisExpirationInSeconds?: number;
|
|
14
|
-
/**
|
|
15
|
-
* @deprecated use the second form with authorizationRequestObjects instead,
|
|
16
|
-
* support of this function will be dropped gradually
|
|
17
|
-
*/
|
|
18
|
-
static isAuthorized(accountId: number, userId: number, resources: Resource[], action: Action): Promise<AuthorizeResponse>;
|
|
19
|
-
static isAuthorized(accountId: number, userId: number, authorizationRequestObjects: AuthorizationObject[]): Promise<AuthorizeResponse>;
|
|
20
|
-
static isUserGrantedWithFeature(accountId: number, userId: number, featureName: string, options?: {
|
|
21
|
-
shouldSkipCache?: boolean;
|
|
22
|
-
}): Promise<boolean>;
|
|
23
|
-
private static fetchIsUserGrantedWithFeature;
|
|
24
|
-
private static getCachedKeyName;
|
|
25
|
-
static canActionInScope(accountId: number, userId: number, action: string, scope: ScopeOptions): Promise<ScopedActionPermit>;
|
|
26
|
-
static canActionInScopeMultiple(accountId: number, userId: number, scopedActions: ScopedAction[]): Promise<ScopedActionResponseObject[]>;
|
|
27
|
-
private static isAuthorizedSingular;
|
|
28
|
-
private static isAuthorizedMultiple;
|
|
29
|
-
}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.AuthorizationService = exports.setRedisClient = exports.setRequestFetchOptions = void 0;
|
|
13
|
-
const lodash_1 = require("lodash");
|
|
14
|
-
const perf_hooks_1 = require("perf_hooks");
|
|
15
|
-
const monday_fetch_1 = require("@mondaydotcomorg/monday-fetch");
|
|
16
|
-
const prometheus_service_1 = require("./prometheus-service");
|
|
17
|
-
const authorization_internal_service_1 = require("./authorization-internal-service");
|
|
18
|
-
const attributions_service_1 = require("./attributions-service");
|
|
19
|
-
const GRANTED_FEATURE_CACHE_EXPIRATION_SECONDS = 5 * 60;
|
|
20
|
-
function setRequestFetchOptions(customMondayFetchOptions) {
|
|
21
|
-
authorization_internal_service_1.AuthorizationInternalService.setRequestFetchOptions(customMondayFetchOptions);
|
|
22
|
-
}
|
|
23
|
-
exports.setRequestFetchOptions = setRequestFetchOptions;
|
|
24
|
-
function setRedisClient(client, grantedFeatureRedisExpirationInSeconds = GRANTED_FEATURE_CACHE_EXPIRATION_SECONDS) {
|
|
25
|
-
AuthorizationService.redisClient = client;
|
|
26
|
-
if (grantedFeatureRedisExpirationInSeconds && grantedFeatureRedisExpirationInSeconds > 0) {
|
|
27
|
-
AuthorizationService.grantedFeatureRedisExpirationInSeconds = grantedFeatureRedisExpirationInSeconds;
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
authorization_internal_service_1.logger.warn({ grantedFeatureRedisExpirationInSeconds }, 'Invalid input for grantedFeatureRedisExpirationInSeconds, must be positive number. using default ttl.');
|
|
31
|
-
AuthorizationService.grantedFeatureRedisExpirationInSeconds = GRANTED_FEATURE_CACHE_EXPIRATION_SECONDS;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.setRedisClient = setRedisClient;
|
|
35
|
-
class AuthorizationService {
|
|
36
|
-
static isAuthorized(...args) {
|
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
if (args.length === 3) {
|
|
39
|
-
return this.isAuthorizedMultiple(args[0], args[1], args[2]);
|
|
40
|
-
}
|
|
41
|
-
else if (args.length == 4) {
|
|
42
|
-
return this.isAuthorizedSingular(args[0], args[1], args[2], args[3]);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
throw new Error('isAuthorized accepts either 3 or 4 arguments');
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
static isUserGrantedWithFeature(accountId, userId, featureName, options = {}) {
|
|
50
|
-
var _a;
|
|
51
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
let cachedKey = this.getCachedKeyName(userId, featureName);
|
|
53
|
-
const shouldSkipCache = (_a = options.shouldSkipCache) !== null && _a !== void 0 ? _a : false;
|
|
54
|
-
if (this.redisClient && !shouldSkipCache) {
|
|
55
|
-
let grantedFeatureValue = yield this.redisClient.get(cachedKey);
|
|
56
|
-
if (!(grantedFeatureValue === undefined || grantedFeatureValue === null)) {
|
|
57
|
-
// redis returns the value as string
|
|
58
|
-
return grantedFeatureValue === 'true';
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
let grantedFeatureValue = yield this.fetchIsUserGrantedWithFeature(featureName, accountId, userId);
|
|
62
|
-
if (this.redisClient) {
|
|
63
|
-
yield this.redisClient.set(cachedKey, grantedFeatureValue, 'EX', this.grantedFeatureRedisExpirationInSeconds);
|
|
64
|
-
}
|
|
65
|
-
return grantedFeatureValue;
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
static fetchIsUserGrantedWithFeature(featureName, accountId, userId) {
|
|
69
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
let authorizationObject = {
|
|
71
|
-
action: featureName,
|
|
72
|
-
resource_type: 'feature',
|
|
73
|
-
};
|
|
74
|
-
let authorizeResponsePromise = yield this.isAuthorized(accountId, userId, [authorizationObject]);
|
|
75
|
-
return authorizeResponsePromise.isAuthorized;
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
static getCachedKeyName(userId, featureName) {
|
|
79
|
-
return `granted-feature-${featureName}-${userId}`;
|
|
80
|
-
}
|
|
81
|
-
static canActionInScope(accountId, userId, action, scope) {
|
|
82
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
const scopedActions = [{ action, scope }];
|
|
84
|
-
const scopedActionResponseObjects = yield this.canActionInScopeMultiple(accountId, userId, scopedActions);
|
|
85
|
-
return scopedActionResponseObjects[0].permit;
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
static canActionInScopeMultiple(accountId, userId, scopedActions) {
|
|
89
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
const internalAuthToken = authorization_internal_service_1.AuthorizationInternalService.generateInternalAuthToken(accountId, userId);
|
|
91
|
-
const scopedActionsPayload = scopedActions.map(scopedAction => {
|
|
92
|
-
return Object.assign(Object.assign({}, scopedAction), { scope: (0, lodash_1.mapKeys)(scopedAction.scope, (_, key) => (0, lodash_1.snakeCase)(key)) }); // for example: { workspaceId: 1 } => { workspace_id: 1 }
|
|
93
|
-
});
|
|
94
|
-
const attributionHeaders = (0, attributions_service_1.getAttributionsFromApi)();
|
|
95
|
-
const response = yield (0, monday_fetch_1.fetch)(getCanActionsInScopesUrl(), {
|
|
96
|
-
method: 'POST',
|
|
97
|
-
headers: Object.assign({ Authorization: internalAuthToken, 'Content-Type': 'application/json' }, attributionHeaders),
|
|
98
|
-
timeout: authorization_internal_service_1.AuthorizationInternalService.getRequestTimeout(),
|
|
99
|
-
body: JSON.stringify({
|
|
100
|
-
user_id: userId,
|
|
101
|
-
scoped_actions: scopedActionsPayload,
|
|
102
|
-
}),
|
|
103
|
-
}, authorization_internal_service_1.AuthorizationInternalService.getRequestFetchOptions());
|
|
104
|
-
authorization_internal_service_1.AuthorizationInternalService.throwOnHttpErrorIfNeeded(response, 'canActionInScopeMultiple');
|
|
105
|
-
const responseBody = yield response.json();
|
|
106
|
-
const camelCaseKeys = obj => Object.fromEntries(Object.entries(obj).map(([key, value]) => [(0, lodash_1.camelCase)(key), value]));
|
|
107
|
-
const scopedActionsResponseObjects = responseBody.result.map(responseObject => {
|
|
108
|
-
const { scopedAction, permit } = responseObject;
|
|
109
|
-
const { scope } = scopedAction;
|
|
110
|
-
const transformKeys = obj => camelCaseKeys(obj);
|
|
111
|
-
return Object.assign(Object.assign({}, responseObject), { scopedAction: Object.assign(Object.assign({}, scopedAction), { scope: transformKeys(scope) }), permit: transformKeys(permit) });
|
|
112
|
-
});
|
|
113
|
-
return scopedActionsResponseObjects;
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
static isAuthorizedSingular(accountId, userId, resources, action) {
|
|
117
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
-
const { authorizationObjects } = createAuthorizationParams(resources, action);
|
|
119
|
-
return this.isAuthorizedMultiple(accountId, userId, authorizationObjects);
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
static isAuthorizedMultiple(accountId, userId, authorizationRequestObjects) {
|
|
123
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
-
const internalAuthToken = authorization_internal_service_1.AuthorizationInternalService.generateInternalAuthToken(accountId, userId);
|
|
125
|
-
const startTime = perf_hooks_1.performance.now();
|
|
126
|
-
const attributionHeaders = (0, attributions_service_1.getAttributionsFromApi)();
|
|
127
|
-
const response = yield (0, monday_fetch_1.fetch)(getAuthorizeUrl(), {
|
|
128
|
-
method: 'POST',
|
|
129
|
-
headers: Object.assign({ Authorization: internalAuthToken, 'Content-Type': 'application/json' }, attributionHeaders),
|
|
130
|
-
timeout: authorization_internal_service_1.AuthorizationInternalService.getRequestTimeout(),
|
|
131
|
-
body: JSON.stringify({
|
|
132
|
-
user_id: userId,
|
|
133
|
-
authorize_request_objects: authorizationRequestObjects,
|
|
134
|
-
}),
|
|
135
|
-
}, authorization_internal_service_1.AuthorizationInternalService.getRequestFetchOptions());
|
|
136
|
-
const endTime = perf_hooks_1.performance.now();
|
|
137
|
-
const time = endTime - startTime;
|
|
138
|
-
const responseStatus = response.status;
|
|
139
|
-
(0, prometheus_service_1.sendAuthorizationChecksPerRequestMetric)(responseStatus, authorizationRequestObjects.length);
|
|
140
|
-
authorization_internal_service_1.AuthorizationInternalService.throwOnHttpErrorIfNeeded(response, 'isAuthorizedMultiple');
|
|
141
|
-
const responseBody = yield response.json();
|
|
142
|
-
const unauthorizedObjects = [];
|
|
143
|
-
responseBody.result.forEach(function (isAuthorized, index) {
|
|
144
|
-
const authorizationObject = authorizationRequestObjects[index];
|
|
145
|
-
if (!isAuthorized) {
|
|
146
|
-
unauthorizedObjects.push(authorizationObject);
|
|
147
|
-
}
|
|
148
|
-
(0, prometheus_service_1.sendAuthorizationCheckResponseTimeMetric)(authorizationObject.resource_type, authorizationObject.action, isAuthorized, responseStatus, time);
|
|
149
|
-
});
|
|
150
|
-
if (unauthorizedObjects.length > 0) {
|
|
151
|
-
authorization_internal_service_1.logger.info({
|
|
152
|
-
resources: JSON.stringify(unauthorizedObjects),
|
|
153
|
-
}, 'AuthorizationService: resource is unauthorized');
|
|
154
|
-
const unauthorizedIds = unauthorizedObjects
|
|
155
|
-
.filter(obj => !!obj.resource_id)
|
|
156
|
-
.map(obj => obj.resource_id);
|
|
157
|
-
return { isAuthorized: false, unauthorizedIds, unauthorizedObjects };
|
|
158
|
-
}
|
|
159
|
-
return { isAuthorized: true };
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
exports.AuthorizationService = AuthorizationService;
|
|
164
|
-
function createAuthorizationParams(resources, action) {
|
|
165
|
-
const params = {
|
|
166
|
-
authorizationObjects: resources.map((resource) => {
|
|
167
|
-
const authorizationObject = {
|
|
168
|
-
resource_id: resource.id,
|
|
169
|
-
resource_type: resource.type,
|
|
170
|
-
action,
|
|
171
|
-
};
|
|
172
|
-
if (resource.wrapperData) {
|
|
173
|
-
authorizationObject.wrapper_data = resource.wrapperData;
|
|
174
|
-
}
|
|
175
|
-
return authorizationObject;
|
|
176
|
-
}),
|
|
177
|
-
};
|
|
178
|
-
return params;
|
|
179
|
-
}
|
|
180
|
-
function getAuthorizeUrl() {
|
|
181
|
-
return `${process.env.MONDAY_INTERNAL_URL}/internal_ms/authorization/authorize`;
|
|
182
|
-
}
|
|
183
|
-
function getCanActionsInScopesUrl() {
|
|
184
|
-
return `${process.env.MONDAY_INTERNAL_URL}/internal_ms/authorization/can_actions_in_scopes`;
|
|
185
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Action } from './types/general';
|
|
2
|
-
export declare const METRICS: {
|
|
3
|
-
AUTHORIZATION_CHECK: string;
|
|
4
|
-
AUTHORIZATION_CHECKS_PER_REQUEST: string;
|
|
5
|
-
AUTHORIZATION_CHECK_RESPONSE_TIME: string;
|
|
6
|
-
};
|
|
7
|
-
export declare function setPrometheus(customPrometheus: any): void;
|
|
8
|
-
export declare function getMetricsManager(): any;
|
|
9
|
-
export declare function sendAuthorizationChecksPerRequestMetric(responseStatus: any, amountOfAuthorizationObjects: any): void;
|
|
10
|
-
export declare function sendAuthorizationCheckResponseTimeMetric(resourceType: string, action: Action, isAuthorized: boolean, responseStatus: number, time: number): void;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sendAuthorizationCheckResponseTimeMetric = exports.sendAuthorizationChecksPerRequestMetric = exports.getMetricsManager = exports.setPrometheus = exports.METRICS = void 0;
|
|
4
|
-
let prometheus = null;
|
|
5
|
-
let authorizationChecksPerRequestMetric = null;
|
|
6
|
-
let authorizationCheckResponseTimeMetric = null;
|
|
7
|
-
exports.METRICS = {
|
|
8
|
-
AUTHORIZATION_CHECK: 'authorization_check',
|
|
9
|
-
AUTHORIZATION_CHECKS_PER_REQUEST: 'authorization_checks_per_request',
|
|
10
|
-
AUTHORIZATION_CHECK_RESPONSE_TIME: 'authorization_check_response_time',
|
|
11
|
-
};
|
|
12
|
-
const authorizationChecksPerRequestMetricConfig = {
|
|
13
|
-
name: exports.METRICS.AUTHORIZATION_CHECKS_PER_REQUEST,
|
|
14
|
-
labels: ['responseStatus'],
|
|
15
|
-
description: 'Authorization checks per request summary',
|
|
16
|
-
};
|
|
17
|
-
const authorizationCheckResponseTimeMetricConfig = {
|
|
18
|
-
name: exports.METRICS.AUTHORIZATION_CHECK_RESPONSE_TIME,
|
|
19
|
-
labels: ['resourceType', 'action', 'isAuthorized', 'responseStatus'],
|
|
20
|
-
description: 'Authorization check response time summary',
|
|
21
|
-
};
|
|
22
|
-
function setPrometheus(customPrometheus) {
|
|
23
|
-
prometheus = customPrometheus;
|
|
24
|
-
const { METRICS_TYPES } = prometheus;
|
|
25
|
-
authorizationChecksPerRequestMetric = getMetricsManager().addMetric(METRICS_TYPES.SUMMARY, authorizationChecksPerRequestMetricConfig.name, authorizationChecksPerRequestMetricConfig.labels, authorizationChecksPerRequestMetricConfig.description);
|
|
26
|
-
authorizationCheckResponseTimeMetric = getMetricsManager().addMetric(METRICS_TYPES.SUMMARY, authorizationCheckResponseTimeMetricConfig.name, authorizationCheckResponseTimeMetricConfig.labels, authorizationCheckResponseTimeMetricConfig.description);
|
|
27
|
-
}
|
|
28
|
-
exports.setPrometheus = setPrometheus;
|
|
29
|
-
function getMetricsManager() {
|
|
30
|
-
return prometheus === null || prometheus === void 0 ? void 0 : prometheus.metricsManager;
|
|
31
|
-
}
|
|
32
|
-
exports.getMetricsManager = getMetricsManager;
|
|
33
|
-
function sendAuthorizationChecksPerRequestMetric(responseStatus, amountOfAuthorizationObjects) {
|
|
34
|
-
try {
|
|
35
|
-
if (authorizationChecksPerRequestMetric) {
|
|
36
|
-
authorizationChecksPerRequestMetric.labels(responseStatus).observe(amountOfAuthorizationObjects);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
catch (e) { }
|
|
40
|
-
}
|
|
41
|
-
exports.sendAuthorizationChecksPerRequestMetric = sendAuthorizationChecksPerRequestMetric;
|
|
42
|
-
function sendAuthorizationCheckResponseTimeMetric(resourceType, action, isAuthorized, responseStatus, time) {
|
|
43
|
-
try {
|
|
44
|
-
if (authorizationCheckResponseTimeMetric) {
|
|
45
|
-
authorizationCheckResponseTimeMetric.labels(resourceType, action, isAuthorized, responseStatus).observe(time);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
catch (e) { }
|
|
49
|
-
}
|
|
50
|
-
exports.sendAuthorizationCheckResponseTimeMetric = sendAuthorizationCheckResponseTimeMetric;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { NextFunction } from "express";
|
|
2
|
-
import { Action, BaseRequest, BaseResponse, ContextGetter, Resource, ResourceGetter } from "../types/general";
|
|
3
|
-
export type TestPermittedAction = {
|
|
4
|
-
accountId: number;
|
|
5
|
-
userId: number;
|
|
6
|
-
resources: Resource[];
|
|
7
|
-
action: Action;
|
|
8
|
-
};
|
|
9
|
-
export declare const addTestPermittedAction: (accountId: number, userId: number, resources: Resource[], action: Action) => void;
|
|
10
|
-
export declare const clearTestPermittedActions: () => void;
|
|
11
|
-
export declare const getTestAuthorizationMiddleware: (action: Action, resourceGetter: ResourceGetter, contextGetter?: ContextGetter) => (request: BaseRequest, response: BaseResponse, next: NextFunction) => Promise<void>;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getTestAuthorizationMiddleware = exports.clearTestPermittedActions = exports.addTestPermittedAction = void 0;
|
|
13
|
-
const authorization_middleware_1 = require("../authorization-middleware");
|
|
14
|
-
const authorization_internal_service_1 = require("../authorization-internal-service");
|
|
15
|
-
let testPermittedActions = [];
|
|
16
|
-
const addTestPermittedAction = (accountId, userId, resources, action) => {
|
|
17
|
-
testPermittedActions.push({ accountId, userId, resources, action });
|
|
18
|
-
};
|
|
19
|
-
exports.addTestPermittedAction = addTestPermittedAction;
|
|
20
|
-
const clearTestPermittedActions = () => {
|
|
21
|
-
testPermittedActions = [];
|
|
22
|
-
};
|
|
23
|
-
exports.clearTestPermittedActions = clearTestPermittedActions;
|
|
24
|
-
const isActionAuthorized = (accountId, userId, resources, action) => {
|
|
25
|
-
return {
|
|
26
|
-
isAuthorized: resources.every(resource => {
|
|
27
|
-
return testPermittedActions.some(combination => {
|
|
28
|
-
return combination.accountId === accountId &&
|
|
29
|
-
combination.userId === userId &&
|
|
30
|
-
combination.action === action &&
|
|
31
|
-
combination.resources.some(combinationResource => {
|
|
32
|
-
return resources.some(resource => {
|
|
33
|
-
return combinationResource.id === resource.id &&
|
|
34
|
-
combinationResource.type === resource.type &&
|
|
35
|
-
JSON.stringify(combinationResource.wrapperData) === JSON.stringify(resource.wrapperData);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
})
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
const getTestAuthorizationMiddleware = (action, resourceGetter, contextGetter) => {
|
|
43
|
-
return function authorizationMiddleware(request, response, next) {
|
|
44
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
contextGetter || (contextGetter = authorization_middleware_1.defaultContextGetter);
|
|
46
|
-
const { userId, accountId } = contextGetter(request);
|
|
47
|
-
const resources = resourceGetter(request);
|
|
48
|
-
const { isAuthorized } = isActionAuthorized(accountId, userId, resources, action);
|
|
49
|
-
authorization_internal_service_1.AuthorizationInternalService.markAuthorized(request);
|
|
50
|
-
if (!isAuthorized) {
|
|
51
|
-
response.status(403).json({ message: 'Access denied' });
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
next();
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
exports.getTestAuthorizationMiddleware = getTestAuthorizationMiddleware;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Resource } from './general';
|
|
2
|
-
export interface ResourceAttributeAssignment {
|
|
3
|
-
resourceType: Resource['type'];
|
|
4
|
-
resourceId: Resource['id'];
|
|
5
|
-
key: string;
|
|
6
|
-
value: string;
|
|
7
|
-
}
|
|
8
|
-
export interface ResourceAttributeResponse {
|
|
9
|
-
attributes: ResourceAttributeAssignment[];
|
|
10
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Request, Response } from 'express';
|
|
2
|
-
export interface Resource {
|
|
3
|
-
id?: number;
|
|
4
|
-
type: string;
|
|
5
|
-
wrapperData?: object;
|
|
6
|
-
}
|
|
7
|
-
export type Action = string;
|
|
8
|
-
export type ResourceGetter = (request: BaseRequest) => Resource[];
|
|
9
|
-
export interface Context {
|
|
10
|
-
accountId: number;
|
|
11
|
-
userId: number;
|
|
12
|
-
}
|
|
13
|
-
export type ContextGetter = (request: BaseRequest) => Context;
|
|
14
|
-
export interface AuthorizationObject {
|
|
15
|
-
resource_id?: Resource['id'];
|
|
16
|
-
resource_type: Resource['type'];
|
|
17
|
-
wrapper_data?: Resource['wrapperData'];
|
|
18
|
-
action: Action;
|
|
19
|
-
}
|
|
20
|
-
export interface AuthorizationParams {
|
|
21
|
-
authorizationObjects: AuthorizationObject[];
|
|
22
|
-
}
|
|
23
|
-
type BasicObject = {};
|
|
24
|
-
export type BaseParameters = BasicObject;
|
|
25
|
-
export type BaseResponseBody = BasicObject;
|
|
26
|
-
export type BaseBodyParameters = BasicObject;
|
|
27
|
-
export type BaseQueryParameters = BasicObject;
|
|
28
|
-
export type BaseRequest = Request<BaseParameters, BaseResponseBody, BaseBodyParameters, BaseQueryParameters>;
|
|
29
|
-
export type BaseResponse = Response<BaseResponseBody>;
|
|
30
|
-
export {};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export interface WorkspaceScope {
|
|
2
|
-
workspaceId: number;
|
|
3
|
-
}
|
|
4
|
-
export interface BoardScope {
|
|
5
|
-
boardId: number;
|
|
6
|
-
}
|
|
7
|
-
export interface PulseScope {
|
|
8
|
-
pulseId: number;
|
|
9
|
-
}
|
|
10
|
-
export interface AccountProductScope {
|
|
11
|
-
accountProductId: number;
|
|
12
|
-
}
|
|
13
|
-
export interface AccountScope {
|
|
14
|
-
accountId: number;
|
|
15
|
-
}
|
|
16
|
-
export type ScopeOptions = WorkspaceScope | BoardScope | PulseScope | AccountProductScope | AccountScope;
|
|
17
|
-
export interface Translation {
|
|
18
|
-
key: string;
|
|
19
|
-
[option: string]: string;
|
|
20
|
-
}
|
|
21
|
-
export declare enum PermitTechnicalReason {
|
|
22
|
-
NO_REASON = 0,
|
|
23
|
-
NOT_ELIGIBLE = 1,
|
|
24
|
-
BY_ROLE_IN_SCOPE = 2
|
|
25
|
-
}
|
|
26
|
-
export interface ScopedActionPermit {
|
|
27
|
-
can: boolean;
|
|
28
|
-
reason: Translation;
|
|
29
|
-
technicalReason: PermitTechnicalReason;
|
|
30
|
-
}
|
|
31
|
-
export interface ScopedAction {
|
|
32
|
-
action: string;
|
|
33
|
-
scope: ScopeOptions;
|
|
34
|
-
}
|
|
35
|
-
export interface ScopedActionResponseObject {
|
|
36
|
-
scopedAction: ScopedAction;
|
|
37
|
-
permit: ScopedActionPermit;
|
|
38
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PermitTechnicalReason = void 0;
|
|
4
|
-
var PermitTechnicalReason;
|
|
5
|
-
(function (PermitTechnicalReason) {
|
|
6
|
-
PermitTechnicalReason[PermitTechnicalReason["NO_REASON"] = 0] = "NO_REASON";
|
|
7
|
-
PermitTechnicalReason[PermitTechnicalReason["NOT_ELIGIBLE"] = 1] = "NOT_ELIGIBLE";
|
|
8
|
-
PermitTechnicalReason[PermitTechnicalReason["BY_ROLE_IN_SCOPE"] = 2] = "BY_ROLE_IN_SCOPE";
|
|
9
|
-
})(PermitTechnicalReason || (exports.PermitTechnicalReason = PermitTechnicalReason = {}));
|