@cloudbase/manager-node 5.10.2 → 5.10.4
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/CHANGELOG.md +8 -0
- package/changelog_content_en.md +2 -2
- package/lib/database/index.js +7 -7
- package/lib/deploy/FunctionDeployer.js +4 -1
- package/lib/env/index.js +3 -3
- package/lib/env/postgresql.js +14 -0
- package/lib/permission/index.js +84 -36
- package/package.json +1 -1
- package/types/database/index.d.ts +3 -5
- package/types/database/type.d.ts +1 -1
- package/types/deploy/FunctionDeployer.d.ts +4 -1
- package/types/env/postgresql.d.ts +9 -0
- package/types/permission/index.d.ts +47 -20
- package/types/permission/types.d.ts +25 -0
package/CHANGELOG.md
CHANGED
package/changelog_content_en.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
## [5.10.
|
|
1
|
+
## [5.10.3] 2026-11-09
|
|
2
2
|
|
|
3
|
-
-
|
|
3
|
+
- [Added] [TODO: translate] database: enablePGRealtime 改为复用 ModifyPGRealtimeSettings 完成开通
|
package/lib/database/index.js
CHANGED
|
@@ -327,7 +327,6 @@ class DatabaseService {
|
|
|
327
327
|
}
|
|
328
328
|
/**
|
|
329
329
|
* 开通 PG 数据库 Realtime 能力
|
|
330
|
-
* 用于服务首次开通;已开通时重复调用仍返回 Enabled: true(幂等)
|
|
331
330
|
*
|
|
332
331
|
* @param options 开通参数
|
|
333
332
|
* @param options.EnvId 环境 ID(可选,不传则自动使用当前环境 ID)
|
|
@@ -335,17 +334,18 @@ class DatabaseService {
|
|
|
335
334
|
*
|
|
336
335
|
* @example
|
|
337
336
|
* // 使用当前环境 ID 开通
|
|
338
|
-
*
|
|
339
|
-
* console.log(res.Enabled) // true
|
|
337
|
+
* await database.enablePGRealtime()
|
|
340
338
|
*
|
|
341
339
|
* @example
|
|
342
340
|
* // 指定环境 ID 开通
|
|
343
|
-
*
|
|
341
|
+
* await database.enablePGRealtime({ EnvId: 'pg-shared-d4gq5c0ne1a30f155' })
|
|
344
342
|
*/
|
|
345
343
|
async enablePGRealtime(options = {}) {
|
|
346
|
-
|
|
347
|
-
EnvId: options.EnvId
|
|
344
|
+
const { RequestId } = await this.modifyPGRealtimeSettings({
|
|
345
|
+
EnvId: options.EnvId,
|
|
346
|
+
Suspend: false
|
|
348
347
|
});
|
|
348
|
+
return { Enabled: true, RequestId };
|
|
349
349
|
}
|
|
350
350
|
/**
|
|
351
351
|
* 查询 PG Realtime 设置
|
|
@@ -376,7 +376,7 @@ class DatabaseService {
|
|
|
376
376
|
* @returns RequestId
|
|
377
377
|
*
|
|
378
378
|
* @example
|
|
379
|
-
* //
|
|
379
|
+
* // 开通/启用 Realtime
|
|
380
380
|
* await database.modifyPGRealtimeSettings({ Suspend: false })
|
|
381
381
|
*
|
|
382
382
|
* @example
|
|
@@ -83,7 +83,10 @@ class FunctionDeployer {
|
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
85
|
* 配置 HTTP 函数匿名访问(public=true)
|
|
86
|
-
*
|
|
86
|
+
*
|
|
87
|
+
* 读改写 authz.user.rego 后整体覆盖写回,追加放通规则并保留已有规则内容。
|
|
88
|
+
* 规则仅在 authz_engine=opa 的环境生效,authpolicy 环境仍以网关策略条目为准。
|
|
89
|
+
* ⚠️ 整体覆盖写该 key,与并发部署或手工改策略同时发生会丢写。
|
|
87
90
|
*/
|
|
88
91
|
async ensurePublicAccess(functionName) {
|
|
89
92
|
const permissionService = this.environment.getPermissionService();
|
package/lib/env/index.js
CHANGED
|
@@ -20,6 +20,7 @@ const constant_1 = require("../constant");
|
|
|
20
20
|
const storage_config_1 = require("../utils/storage-config");
|
|
21
21
|
const billing_1 = require("../billing");
|
|
22
22
|
const uuid_1 = require("uuid");
|
|
23
|
+
const postgresql_1 = require("./postgresql");
|
|
23
24
|
class EnvService {
|
|
24
25
|
constructor(environment) {
|
|
25
26
|
this.environment = environment;
|
|
@@ -212,10 +213,9 @@ class EnvService {
|
|
|
212
213
|
* @returns 是否为 PG 环境
|
|
213
214
|
*/
|
|
214
215
|
async isPostgresqlEnv() {
|
|
215
|
-
var _a
|
|
216
|
+
var _a;
|
|
216
217
|
const response = await this.describeEnvInfo({ EnvId: this.envId });
|
|
217
|
-
|
|
218
|
-
return Array.isArray(postgresql) && postgresql.length > 0;
|
|
218
|
+
return (0, postgresql_1.isPostgresqlBaseInfo)((_a = response === null || response === void 0 ? void 0 : response.EnvInfo) === null || _a === void 0 ? void 0 : _a.EnvBaseInfo);
|
|
219
219
|
}
|
|
220
220
|
/**
|
|
221
221
|
* 修改环境名称
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPostgresqlBaseInfo = isPostgresqlBaseInfo;
|
|
4
|
+
/**
|
|
5
|
+
* 判断环境基础信息是否属于 PostgreSQL 环境
|
|
6
|
+
* PostgreSQL 字段为数组且长度 > 0 时视为 PG 环境。
|
|
7
|
+
*
|
|
8
|
+
* 抽成纯函数供 EnvService 与 PermissionService 共用,避免两处各写一份判断而漂移。
|
|
9
|
+
* 放在独立叶子模块中(只依赖类型),避免 permission 反向 import 整个 env 造成循环依赖。
|
|
10
|
+
*/
|
|
11
|
+
function isPostgresqlBaseInfo(baseInfo) {
|
|
12
|
+
const postgresql = baseInfo === null || baseInfo === void 0 ? void 0 : baseInfo.PostgreSQL;
|
|
13
|
+
return Array.isArray(postgresql) && postgresql.length > 0;
|
|
14
|
+
}
|
package/lib/permission/index.js
CHANGED
|
@@ -7,6 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.PermissionService = void 0;
|
|
10
|
+
const postgresql_1 = require("../env/postgresql");
|
|
10
11
|
const utils_1 = require("../utils");
|
|
11
12
|
const error_1 = require("../error");
|
|
12
13
|
const PERMISSION_BY_RESOURCE = {
|
|
@@ -22,7 +23,8 @@ class PermissionService {
|
|
|
22
23
|
this.lowcodeService = new utils_1.CloudService(environment.cloudBaseContext, 'lowcode', '2021-01-08');
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
|
-
* @deprecated
|
|
26
|
+
* @deprecated 已废弃:authz_engine=opa 的环境改由 rego 策略鉴权,网关策略条目不参与决策;
|
|
27
|
+
* 该环境请用 modifyEnvAuthzConfig,authpolicy 环境仍以网关策略为准
|
|
26
28
|
*/
|
|
27
29
|
async modifyResourcePermission(options) {
|
|
28
30
|
const { EnvId } = this.environment.lazyEnvironmentConfig;
|
|
@@ -57,7 +59,8 @@ class PermissionService {
|
|
|
57
59
|
return this.tcbService.request('ModifyResourcePermission', reqData);
|
|
58
60
|
}
|
|
59
61
|
/**
|
|
60
|
-
* @deprecated
|
|
62
|
+
* @deprecated 已废弃:authz_engine=opa 的环境改由 rego 策略鉴权,网关策略条目不参与决策;
|
|
63
|
+
* 查询存量网关策略用 describeResourcePolicyList,查询实际生效的 rego 策略用 describeEnvAuthzConfig
|
|
61
64
|
*/
|
|
62
65
|
async describeResourcePermission(options) {
|
|
63
66
|
const { EnvId } = this.environment.lazyEnvironmentConfig;
|
|
@@ -302,30 +305,56 @@ class PermissionService {
|
|
|
302
305
|
RoleIds: roleIds
|
|
303
306
|
});
|
|
304
307
|
}
|
|
308
|
+
/**
|
|
309
|
+
* 查询环境实际生效的鉴权引擎
|
|
310
|
+
*
|
|
311
|
+
* 只发一次 DescribeEnvInfo,同时产出 PostgreSQL 与 Meta.authz_engine 两个结论,
|
|
312
|
+
* 调用方无需自行解析环境 Meta。
|
|
313
|
+
*
|
|
314
|
+
* 注意:不做缓存 —— 引擎由环境 Meta 的 authz_engine 决定,可能在运行期被切换,
|
|
315
|
+
* 缓存会让切换后的查询拿到过期结论。
|
|
316
|
+
*/
|
|
317
|
+
async describeAuthzProfile() {
|
|
318
|
+
var _a;
|
|
319
|
+
const baseInfo = await this.getEnvBaseInfo();
|
|
320
|
+
const isPostgresql = (0, postgresql_1.isPostgresqlBaseInfo)(baseInfo);
|
|
321
|
+
const authzEngineMeta = Array.isArray(baseInfo === null || baseInfo === void 0 ? void 0 : baseInfo.Meta)
|
|
322
|
+
? (_a = baseInfo.Meta.find(tag => tag.Key === 'authz_engine')) === null || _a === void 0 ? void 0 : _a.Value
|
|
323
|
+
: undefined;
|
|
324
|
+
return {
|
|
325
|
+
// PG 环境不存在旧网关策略,统一视为 opa,避免与短路行为自相矛盾
|
|
326
|
+
engine: isPostgresql || authzEngineMeta === 'opa' ? 'opa' : 'authpolicy',
|
|
327
|
+
isPostgresql,
|
|
328
|
+
authzEngineMeta
|
|
329
|
+
};
|
|
330
|
+
}
|
|
305
331
|
/**
|
|
306
332
|
* 拉取环境下的所有用户自定义的网关鉴权策略列表
|
|
307
|
-
*
|
|
308
|
-
*
|
|
333
|
+
*
|
|
334
|
+
* 以下两种环境不会发起请求,直接按空列表处理,并在返回值顶层给出 SkippedReason:
|
|
335
|
+
* - PG 环境:无存量网关策略(postgresql_env)
|
|
336
|
+
* - authz_engine 为 opa:网关策略不生效(opa_authz_engine)
|
|
337
|
+
*
|
|
338
|
+
* ⚠️ SkippedReason 非空时,空列表**不代表「确实没有策略」**:
|
|
339
|
+
* 实际生效的策略请用 describeEnvAuthzConfig({ key: 'authz.user.rego' }) 查询。
|
|
309
340
|
*/
|
|
310
341
|
async describeResourcePolicyList(options = {}) {
|
|
311
342
|
const { resourceType } = options;
|
|
312
343
|
if (resourceType !== undefined && (typeof resourceType !== 'string' || resourceType.trim().length === 0)) {
|
|
313
344
|
(0, error_1.throwInvalidParam)('Invalid resourceType');
|
|
314
345
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
// authz_engine 为 opa 时网关策略不生效,无需调用,直接返回空策略列表
|
|
324
|
-
if (await this.isOpaAuthzEngine()) {
|
|
346
|
+
const profile = await this.describeAuthzProfile();
|
|
347
|
+
const skippedReason = profile.isPostgresql
|
|
348
|
+
? 'postgresql_env'
|
|
349
|
+
: profile.engine === 'opa'
|
|
350
|
+
? 'opa_authz_engine'
|
|
351
|
+
: undefined;
|
|
352
|
+
if (skippedReason) {
|
|
325
353
|
const emptyData = { PolicyList: [], Total: '0' };
|
|
326
354
|
return {
|
|
327
355
|
Data: emptyData,
|
|
328
|
-
RequestId: ''
|
|
356
|
+
RequestId: '',
|
|
357
|
+
SkippedReason: skippedReason
|
|
329
358
|
};
|
|
330
359
|
}
|
|
331
360
|
const { EnvId } = this.environment.lazyEnvironmentConfig;
|
|
@@ -339,20 +368,30 @@ class PermissionService {
|
|
|
339
368
|
* 拉取环境下的鉴权策略配置
|
|
340
369
|
* key: authz.platform.extension.rego - 单独为该环境配置的策略
|
|
341
370
|
* key: authz.user.rego - 用户配置的策略
|
|
371
|
+
*
|
|
372
|
+
* 未配置时云端不返回 Item(或返回空对象),此处统一归一化为 Key/Value 均为空串,
|
|
373
|
+
* 调用方无需再判空。
|
|
342
374
|
*/
|
|
343
375
|
async describeEnvAuthzConfig(options) {
|
|
376
|
+
var _a, _b;
|
|
344
377
|
const { key } = options;
|
|
345
378
|
if (!key || (key !== 'authz.platform.extension.rego' && key !== 'authz.user.rego')) {
|
|
346
379
|
(0, error_1.throwInvalidParam)('key must be "authz.platform.extension.rego" or "authz.user.rego"');
|
|
347
380
|
}
|
|
348
381
|
const { EnvId } = this.environment.lazyEnvironmentConfig;
|
|
349
|
-
|
|
382
|
+
const res = await this.tcbService.request('DescribeEnvConfig', {
|
|
350
383
|
EnvId,
|
|
351
384
|
Key: key
|
|
352
385
|
});
|
|
386
|
+
return Object.assign(Object.assign({}, res), { Item: {
|
|
387
|
+
Key: ((_a = res === null || res === void 0 ? void 0 : res.Item) === null || _a === void 0 ? void 0 : _a.Key) || '',
|
|
388
|
+
Value: ((_b = res === null || res === void 0 ? void 0 : res.Item) === null || _b === void 0 ? void 0 : _b.Value) || ''
|
|
389
|
+
} });
|
|
353
390
|
}
|
|
354
391
|
/**
|
|
355
|
-
* 保存用户编写的 rego
|
|
392
|
+
* 保存用户编写的 rego 策略(authz.user.rego)
|
|
393
|
+
*
|
|
394
|
+
* 仅在 authz_engine=opa 的环境参与鉴权;authpolicy 环境仍以网关策略条目为准。
|
|
356
395
|
*/
|
|
357
396
|
async modifyEnvAuthzConfig(options) {
|
|
358
397
|
const { EnvId } = this.environment.lazyEnvironmentConfig;
|
|
@@ -369,6 +408,28 @@ class PermissionService {
|
|
|
369
408
|
Value: value
|
|
370
409
|
});
|
|
371
410
|
}
|
|
411
|
+
/**
|
|
412
|
+
* 清空用户配置的 rego 策略(恢复「跟随平台默认」)
|
|
413
|
+
*
|
|
414
|
+
* 服务端语义:ModifyEnvConfig 的 Value 传空串 = 删除该 key。
|
|
415
|
+
* 单独提供本方法而不放宽 modifyEnvAuthzConfig 的空值校验 —— 后者会让
|
|
416
|
+
* 「变量未定义传了空串」静默清空生产策略,属高危误用。
|
|
417
|
+
*
|
|
418
|
+
* 注意:清空只删掉该 key,不会回退鉴权引擎 —— 环境 Meta 的 authz_engine
|
|
419
|
+
* 仍为 opa(已实测),旧网关鉴权策略不会因此复活。
|
|
420
|
+
*/
|
|
421
|
+
async clearEnvAuthzConfig(options) {
|
|
422
|
+
const { EnvId } = this.environment.lazyEnvironmentConfig;
|
|
423
|
+
const { key } = options;
|
|
424
|
+
if (key !== 'authz.user.rego') {
|
|
425
|
+
(0, error_1.throwInvalidParam)('key must be "authz.user.rego"');
|
|
426
|
+
}
|
|
427
|
+
return this.tcbService.request('ModifyEnvConfig', {
|
|
428
|
+
EnvId,
|
|
429
|
+
Key: key,
|
|
430
|
+
Value: ''
|
|
431
|
+
});
|
|
432
|
+
}
|
|
372
433
|
/**
|
|
373
434
|
* 获取完整的环境基础信息(含 PostgreSQL、Meta 等字段)
|
|
374
435
|
*/
|
|
@@ -379,25 +440,6 @@ class PermissionService {
|
|
|
379
440
|
const res = await this.environment.getEnvService().describeEnvInfo(params);
|
|
380
441
|
return ((_a = res === null || res === void 0 ? void 0 : res.EnvInfo) === null || _a === void 0 ? void 0 : _a.EnvBaseInfo) || {};
|
|
381
442
|
}
|
|
382
|
-
/**
|
|
383
|
-
* 判断当前环境是否为 PostgreSQL 环境
|
|
384
|
-
*/
|
|
385
|
-
async isPostgresqlEnv() {
|
|
386
|
-
return this.environment.getEnvService().isPostgresqlEnv();
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* 判断当前环境的 authz_engine 是否为 opa
|
|
390
|
-
* 从环境 Meta 中查找 Key 为 authz_engine 的标签,Value 为 opa 表示已切到 OPA
|
|
391
|
-
*/
|
|
392
|
-
async isOpaAuthzEngine() {
|
|
393
|
-
const envBaseInfo = await this.getEnvBaseInfo();
|
|
394
|
-
const meta = envBaseInfo === null || envBaseInfo === void 0 ? void 0 : envBaseInfo.Meta;
|
|
395
|
-
if (!Array.isArray(meta)) {
|
|
396
|
-
return false;
|
|
397
|
-
}
|
|
398
|
-
const authzEngineTag = meta.find(tag => tag.Key === 'authz_engine');
|
|
399
|
-
return (authzEngineTag === null || authzEngineTag === void 0 ? void 0 : authzEngineTag.Value) === 'opa';
|
|
400
|
-
}
|
|
401
443
|
}
|
|
402
444
|
exports.PermissionService = PermissionService;
|
|
403
445
|
__decorate([
|
|
@@ -418,6 +460,9 @@ __decorate([
|
|
|
418
460
|
__decorate([
|
|
419
461
|
(0, utils_1.preLazy)()
|
|
420
462
|
], PermissionService.prototype, "deleteRoles", null);
|
|
463
|
+
__decorate([
|
|
464
|
+
(0, utils_1.preLazy)()
|
|
465
|
+
], PermissionService.prototype, "describeAuthzProfile", null);
|
|
421
466
|
__decorate([
|
|
422
467
|
(0, utils_1.preLazy)()
|
|
423
468
|
], PermissionService.prototype, "describeResourcePolicyList", null);
|
|
@@ -427,3 +472,6 @@ __decorate([
|
|
|
427
472
|
__decorate([
|
|
428
473
|
(0, utils_1.preLazy)()
|
|
429
474
|
], PermissionService.prototype, "modifyEnvAuthzConfig", null);
|
|
475
|
+
__decorate([
|
|
476
|
+
(0, utils_1.preLazy)()
|
|
477
|
+
], PermissionService.prototype, "clearEnvAuthzConfig", null);
|
package/package.json
CHANGED
|
@@ -229,7 +229,6 @@ export declare class DatabaseService {
|
|
|
229
229
|
executePGSql(options: IExecutePGSqlOptions): Promise<IExecutePGSqlResult>;
|
|
230
230
|
/**
|
|
231
231
|
* 开通 PG 数据库 Realtime 能力
|
|
232
|
-
* 用于服务首次开通;已开通时重复调用仍返回 Enabled: true(幂等)
|
|
233
232
|
*
|
|
234
233
|
* @param options 开通参数
|
|
235
234
|
* @param options.EnvId 环境 ID(可选,不传则自动使用当前环境 ID)
|
|
@@ -237,12 +236,11 @@ export declare class DatabaseService {
|
|
|
237
236
|
*
|
|
238
237
|
* @example
|
|
239
238
|
* // 使用当前环境 ID 开通
|
|
240
|
-
*
|
|
241
|
-
* console.log(res.Enabled) // true
|
|
239
|
+
* await database.enablePGRealtime()
|
|
242
240
|
*
|
|
243
241
|
* @example
|
|
244
242
|
* // 指定环境 ID 开通
|
|
245
|
-
*
|
|
243
|
+
* await database.enablePGRealtime({ EnvId: 'pg-shared-d4gq5c0ne1a30f155' })
|
|
246
244
|
*/
|
|
247
245
|
enablePGRealtime(options?: IEnablePGRealtimeOptions): Promise<IEnablePGRealtimeResult>;
|
|
248
246
|
/**
|
|
@@ -270,7 +268,7 @@ export declare class DatabaseService {
|
|
|
270
268
|
* @returns RequestId
|
|
271
269
|
*
|
|
272
270
|
* @example
|
|
273
|
-
* //
|
|
271
|
+
* // 开通/启用 Realtime
|
|
274
272
|
* await database.modifyPGRealtimeSettings({ Suspend: false })
|
|
275
273
|
*
|
|
276
274
|
* @example
|
package/types/database/type.d.ts
CHANGED
|
@@ -268,7 +268,7 @@ export interface IModifyPGRealtimeSettingsOptions {
|
|
|
268
268
|
/**
|
|
269
269
|
* 挂起租户,全局生效(所有节点)
|
|
270
270
|
* true:立即断开该租户全部在线 WebSocket 连接,拒绝新连接(HTTP 403),并禁用服务端广播 API
|
|
271
|
-
* false
|
|
271
|
+
* false:恢复;未开通时传 false 可直接完成开通
|
|
272
272
|
* 注意:suspend 值的变化都会触发一次断连,客户端需重连
|
|
273
273
|
*/
|
|
274
274
|
Suspend?: boolean;
|
|
@@ -59,7 +59,10 @@ export declare class FunctionDeployer {
|
|
|
59
59
|
resolveStrategy(config: IFunctionDeployConfig): IFunctionDeployPlan['buildStrategy'];
|
|
60
60
|
/**
|
|
61
61
|
* 配置 HTTP 函数匿名访问(public=true)
|
|
62
|
-
*
|
|
62
|
+
*
|
|
63
|
+
* 读改写 authz.user.rego 后整体覆盖写回,追加放通规则并保留已有规则内容。
|
|
64
|
+
* 规则仅在 authz_engine=opa 的环境生效,authpolicy 环境仍以网关策略条目为准。
|
|
65
|
+
* ⚠️ 整体覆盖写该 key,与并发部署或手工改策略同时发生会丢写。
|
|
63
66
|
*/
|
|
64
67
|
ensurePublicAccess(functionName: string): Promise<void>;
|
|
65
68
|
/**
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EnvBaseInfo } from '../interfaces/tcb.interface';
|
|
2
|
+
/**
|
|
3
|
+
* 判断环境基础信息是否属于 PostgreSQL 环境
|
|
4
|
+
* PostgreSQL 字段为数组且长度 > 0 时视为 PG 环境。
|
|
5
|
+
*
|
|
6
|
+
* 抽成纯函数供 EnvService 与 PermissionService 共用,避免两处各写一份判断而漂移。
|
|
7
|
+
* 放在独立叶子模块中(只依赖类型),避免 permission 反向 import 整个 env 造成循环依赖。
|
|
8
|
+
*/
|
|
9
|
+
export declare function isPostgresqlBaseInfo(baseInfo?: EnvBaseInfo): boolean;
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { Environment } from '../environment';
|
|
2
|
-
import { ModifyResourcePermissionOptions, ModifyResourcePermissionResp, DescribeResourcePermissionOptions, DescribeResourcePermissionResp, CreateRoleOptions, CreateRoleResp, DescribeRoleListOptions, DescribeRoleListResp, ModifyRoleOptions, ModifyRoleResp, DeleteRolesOptions, DeleteRolesResp, DescribeResourcePolicyListOptions,
|
|
2
|
+
import { ModifyResourcePermissionOptions, ModifyResourcePermissionResp, DescribeResourcePermissionOptions, DescribeResourcePermissionResp, CreateRoleOptions, CreateRoleResp, DescribeRoleListOptions, DescribeRoleListResp, ModifyRoleOptions, ModifyRoleResp, DeleteRolesOptions, DeleteRolesResp, DescribeResourcePolicyListOptions, DescribeResourcePolicyListResult, DescribeEnvAuthzConfigOptions, ModifyEnvAuthzConfigOptions, ClearEnvAuthzConfigOptions, AuthzProfile } from './types';
|
|
3
3
|
export declare class PermissionService {
|
|
4
4
|
private environment;
|
|
5
5
|
private tcbService;
|
|
6
6
|
private lowcodeService;
|
|
7
7
|
constructor(environment: Environment);
|
|
8
8
|
/**
|
|
9
|
-
* @deprecated
|
|
9
|
+
* @deprecated 已废弃:authz_engine=opa 的环境改由 rego 策略鉴权,网关策略条目不参与决策;
|
|
10
|
+
* 该环境请用 modifyEnvAuthzConfig,authpolicy 环境仍以网关策略为准
|
|
10
11
|
*/
|
|
11
12
|
modifyResourcePermission(options: ModifyResourcePermissionOptions): Promise<{
|
|
12
13
|
Data: ModifyResourcePermissionResp;
|
|
13
14
|
RequestId: string;
|
|
14
15
|
}>;
|
|
15
16
|
/**
|
|
16
|
-
* @deprecated
|
|
17
|
+
* @deprecated 已废弃:authz_engine=opa 的环境改由 rego 策略鉴权,网关策略条目不参与决策;
|
|
18
|
+
* 查询存量网关策略用 describeResourcePolicyList,查询实际生效的 rego 策略用 describeEnvAuthzConfig
|
|
17
19
|
*/
|
|
18
20
|
describeResourcePermission(options: DescribeResourcePermissionOptions): Promise<{
|
|
19
21
|
Data: DescribeResourcePermissionResp;
|
|
@@ -35,42 +37,67 @@ export declare class PermissionService {
|
|
|
35
37
|
Data: DeleteRolesResp;
|
|
36
38
|
RequestId: string;
|
|
37
39
|
}>;
|
|
40
|
+
/**
|
|
41
|
+
* 查询环境实际生效的鉴权引擎
|
|
42
|
+
*
|
|
43
|
+
* 只发一次 DescribeEnvInfo,同时产出 PostgreSQL 与 Meta.authz_engine 两个结论,
|
|
44
|
+
* 调用方无需自行解析环境 Meta。
|
|
45
|
+
*
|
|
46
|
+
* 注意:不做缓存 —— 引擎由环境 Meta 的 authz_engine 决定,可能在运行期被切换,
|
|
47
|
+
* 缓存会让切换后的查询拿到过期结论。
|
|
48
|
+
*/
|
|
49
|
+
describeAuthzProfile(): Promise<AuthzProfile>;
|
|
38
50
|
/**
|
|
39
51
|
* 拉取环境下的所有用户自定义的网关鉴权策略列表
|
|
40
|
-
*
|
|
41
|
-
*
|
|
52
|
+
*
|
|
53
|
+
* 以下两种环境不会发起请求,直接按空列表处理,并在返回值顶层给出 SkippedReason:
|
|
54
|
+
* - PG 环境:无存量网关策略(postgresql_env)
|
|
55
|
+
* - authz_engine 为 opa:网关策略不生效(opa_authz_engine)
|
|
56
|
+
*
|
|
57
|
+
* ⚠️ SkippedReason 非空时,空列表**不代表「确实没有策略」**:
|
|
58
|
+
* 实际生效的策略请用 describeEnvAuthzConfig({ key: 'authz.user.rego' }) 查询。
|
|
42
59
|
*/
|
|
43
|
-
describeResourcePolicyList(options?: DescribeResourcePolicyListOptions): Promise<
|
|
44
|
-
Data: DescribeResourcePolicyListResp;
|
|
45
|
-
RequestId: string;
|
|
46
|
-
}>;
|
|
60
|
+
describeResourcePolicyList(options?: DescribeResourcePolicyListOptions): Promise<DescribeResourcePolicyListResult>;
|
|
47
61
|
/**
|
|
48
62
|
* 拉取环境下的鉴权策略配置
|
|
49
63
|
* key: authz.platform.extension.rego - 单独为该环境配置的策略
|
|
50
64
|
* key: authz.user.rego - 用户配置的策略
|
|
65
|
+
*
|
|
66
|
+
* 未配置时云端不返回 Item(或返回空对象),此处统一归一化为 Key/Value 均为空串,
|
|
67
|
+
* 调用方无需再判空。
|
|
51
68
|
*/
|
|
52
69
|
describeEnvAuthzConfig(options: DescribeEnvAuthzConfigOptions): Promise<{
|
|
53
|
-
Item:
|
|
70
|
+
Item: {
|
|
71
|
+
Key: string;
|
|
72
|
+
Value: string;
|
|
73
|
+
};
|
|
54
74
|
RequestId: string;
|
|
55
75
|
}>;
|
|
56
76
|
/**
|
|
57
|
-
* 保存用户编写的 rego
|
|
77
|
+
* 保存用户编写的 rego 策略(authz.user.rego)
|
|
78
|
+
*
|
|
79
|
+
* 仅在 authz_engine=opa 的环境参与鉴权;authpolicy 环境仍以网关策略条目为准。
|
|
58
80
|
*/
|
|
59
81
|
modifyEnvAuthzConfig(options: ModifyEnvAuthzConfigOptions): Promise<{
|
|
60
82
|
AffectedRows: number;
|
|
61
83
|
RequestId: string;
|
|
62
84
|
}>;
|
|
63
85
|
/**
|
|
64
|
-
*
|
|
86
|
+
* 清空用户配置的 rego 策略(恢复「跟随平台默认」)
|
|
87
|
+
*
|
|
88
|
+
* 服务端语义:ModifyEnvConfig 的 Value 传空串 = 删除该 key。
|
|
89
|
+
* 单独提供本方法而不放宽 modifyEnvAuthzConfig 的空值校验 —— 后者会让
|
|
90
|
+
* 「变量未定义传了空串」静默清空生产策略,属高危误用。
|
|
91
|
+
*
|
|
92
|
+
* 注意:清空只删掉该 key,不会回退鉴权引擎 —— 环境 Meta 的 authz_engine
|
|
93
|
+
* 仍为 opa(已实测),旧网关鉴权策略不会因此复活。
|
|
65
94
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
private isPostgresqlEnv;
|
|
95
|
+
clearEnvAuthzConfig(options: ClearEnvAuthzConfigOptions): Promise<{
|
|
96
|
+
AffectedRows: number;
|
|
97
|
+
RequestId: string;
|
|
98
|
+
}>;
|
|
71
99
|
/**
|
|
72
|
-
*
|
|
73
|
-
* 从环境 Meta 中查找 Key 为 authz_engine 的标签,Value 为 opa 表示已切到 OPA
|
|
100
|
+
* 获取完整的环境基础信息(含 PostgreSQL、Meta 等字段)
|
|
74
101
|
*/
|
|
75
|
-
private
|
|
102
|
+
private getEnvBaseInfo;
|
|
76
103
|
}
|
|
@@ -145,6 +145,18 @@ export interface DescribeResourcePolicyListResp {
|
|
|
145
145
|
PolicyList: ResourcePolicyItem[];
|
|
146
146
|
Total: string;
|
|
147
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* describeResourcePolicyList 未发起请求的原因
|
|
150
|
+
* - postgresql_env:PG 环境无存量网关策略
|
|
151
|
+
* - opa_authz_engine:环境已切到 OPA 引擎,旧网关策略不参与鉴权
|
|
152
|
+
*/
|
|
153
|
+
export type ResourcePolicyListSkippedReason = 'postgresql_env' | 'opa_authz_engine';
|
|
154
|
+
export interface DescribeResourcePolicyListResult {
|
|
155
|
+
Data: DescribeResourcePolicyListResp;
|
|
156
|
+
RequestId: string;
|
|
157
|
+
/** 本次未发起请求的原因;缺省表示真实查询结果 */
|
|
158
|
+
SkippedReason?: ResourcePolicyListSkippedReason;
|
|
159
|
+
}
|
|
148
160
|
export interface DescribeEnvAuthzConfigOptions {
|
|
149
161
|
key: 'authz.platform.extension.rego' | 'authz.user.rego';
|
|
150
162
|
}
|
|
@@ -159,3 +171,16 @@ export interface ModifyEnvAuthzConfigOptions {
|
|
|
159
171
|
export interface ModifyEnvAuthzConfigResp {
|
|
160
172
|
AffectedRows: number;
|
|
161
173
|
}
|
|
174
|
+
export interface ClearEnvAuthzConfigOptions {
|
|
175
|
+
key: 'authz.user.rego';
|
|
176
|
+
}
|
|
177
|
+
/** 网关鉴权引擎 */
|
|
178
|
+
export type AuthzEngine = 'authpolicy' | 'opa';
|
|
179
|
+
export interface AuthzProfile {
|
|
180
|
+
/** 实际生效的鉴权引擎(PG 环境一律视为 opa) */
|
|
181
|
+
engine: AuthzEngine;
|
|
182
|
+
/** 是否为 PostgreSQL 环境 */
|
|
183
|
+
isPostgresql: boolean;
|
|
184
|
+
/** Meta 中 authz_engine 的原始取值,便于排查 */
|
|
185
|
+
authzEngineMeta?: string;
|
|
186
|
+
}
|