@geek-fun/serverlessinsight 0.8.6 → 0.8.7
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/.serverlessinsight/state-cdn-flow-app-cdn-flow-service.json.backup +1 -1
- package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +2 -2
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +19 -19
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +1 -1
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +11 -11
- package/AGENTS.md +29 -0
- package/dist/package.json +1 -1
- package/dist/src/common/aliyunClient/ramOperations.js +104 -15
- package/dist/src/common/iacHelper.js +3 -1
- package/dist/src/common/iamStatements.js +21 -1
- package/dist/src/common/nameBuilder.js +12 -1
- package/dist/src/common/tencentClient/camOperations.js +24 -12
- package/dist/src/common/volcengineClient/iamOperations.js +15 -11
- package/dist/src/lang/en.js +7 -0
- package/dist/src/lang/zh-CN.js +6 -0
- package/dist/src/stack/aliyunStack/apigwExecutor.js +5 -5
- package/dist/src/stack/aliyunStack/apigwResource.js +10 -8
- package/dist/src/stack/aliyunStack/apigwTypes.js +20 -5
- package/dist/src/stack/aliyunStack/deployer.js +33 -3
- package/dist/src/stack/aliyunStack/fc3Resource.js +172 -18
- package/dist/src/stack/aliyunStack/sharedLogProject.js +22 -5
- package/dist/src/stack/scfStack/scfPlanner.js +1 -1
- package/dist/src/stack/scfStack/scfResource.js +72 -10
- package/dist/src/stack/scfStack/sharedLogset.js +9 -1
- package/dist/src/stack/volcengineStack/apigwPlanner.js +5 -1
- package/dist/src/stack/volcengineStack/apigwResource.js +52 -30
- package/dist/src/stack/volcengineStack/apigwTypes.js +18 -7
- package/dist/src/stack/volcengineStack/sharedLogProject.js +9 -3
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +5 -4
- package/dist/src/stack/volcengineStack/vefaasResource.js +74 -10
- package/dist/src/stack/volcengineStack/vefaasTypes.js +61 -7
- package/dist/src/validator/semanticValidation.js +41 -0
- package/package.json +1 -1
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"id": "iam-test-app-dev-sls"
|
|
23
23
|
}
|
|
24
24
|
],
|
|
25
|
-
"lastUpdated": "2026-08-
|
|
25
|
+
"lastUpdated": "2026-08-30T13:25:42.949Z"
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
|
-
"lineage": "
|
|
30
|
+
"lineage": "bec4a8ca-11b2-46eb-92e1-362da042e3b6",
|
|
31
31
|
"serial": 3
|
|
32
32
|
}
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"nasConfig": null,
|
|
28
28
|
"logConfig": {
|
|
29
29
|
"project": "insight-poc-deploy-app-dev-sls",
|
|
30
|
-
"logstore": "insight-poc-deploy-dev-fn-logs",
|
|
30
|
+
"logstore": "insight-poc-deploy-dev-insight-poc-fn-fn-logs",
|
|
31
31
|
"enableRequestMetrics": true,
|
|
32
32
|
"enableInstanceMetrics": true
|
|
33
33
|
},
|
|
@@ -68,30 +68,30 @@
|
|
|
68
68
|
"lastUpdateStatusReasonCode": null
|
|
69
69
|
},
|
|
70
70
|
{
|
|
71
|
-
"sid": "si:aliyun:sls_logstore:dev:insight-poc-deploy-app-dev-sls/insight-poc-deploy-dev-fn-logs",
|
|
72
|
-
"id": "insight-poc-deploy-app-dev-sls/insight-poc-deploy-dev-fn-logs",
|
|
71
|
+
"sid": "si:aliyun:sls_logstore:dev:insight-poc-deploy-app-dev-sls/insight-poc-deploy-dev-insight-poc-fn-fn-logs",
|
|
72
|
+
"id": "insight-poc-deploy-app-dev-sls/insight-poc-deploy-dev-insight-poc-fn-fn-logs",
|
|
73
73
|
"type": "ALIYUN_SLS_LOGSTORE",
|
|
74
|
-
"logstoreName": "insight-poc-deploy-dev-fn-logs"
|
|
74
|
+
"logstoreName": "insight-poc-deploy-dev-insight-poc-fn-fn-logs"
|
|
75
75
|
},
|
|
76
76
|
{
|
|
77
|
-
"sid": "si:aliyun:sls_index:dev:insight-poc-deploy-app-dev-sls/insight-poc-deploy-dev-fn-logs/index",
|
|
78
|
-
"id": "insight-poc-deploy-app-dev-sls/insight-poc-deploy-dev-fn-logs/index",
|
|
77
|
+
"sid": "si:aliyun:sls_index:dev:insight-poc-deploy-app-dev-sls/insight-poc-deploy-dev-insight-poc-fn-fn-logs/index",
|
|
78
|
+
"id": "insight-poc-deploy-app-dev-sls/insight-poc-deploy-dev-insight-poc-fn-fn-logs/index",
|
|
79
79
|
"type": "ALIYUN_SLS_INDEX",
|
|
80
80
|
"projectName": "insight-poc-deploy-app-dev-sls",
|
|
81
|
-
"logstoreName": "insight-poc-deploy-dev-fn-logs"
|
|
81
|
+
"logstoreName": "insight-poc-deploy-dev-insight-poc-fn-fn-logs"
|
|
82
82
|
},
|
|
83
83
|
{
|
|
84
|
-
"sid": "si:aliyun:ram_role:dev:insight-poc-deploy-app-insight-poc-deploy-dev-
|
|
85
|
-
"id": "insight-poc-deploy-app-insight-poc-deploy-dev-
|
|
84
|
+
"sid": "si:aliyun:ram_role:dev:insight-poc-deploy-app-insight-poc-deploy-dev-insig-role-160n4hk",
|
|
85
|
+
"id": "insight-poc-deploy-app-insight-poc-deploy-dev-insig-role-160n4hk",
|
|
86
86
|
"type": "ALIYUN_RAM_ROLE",
|
|
87
|
-
"
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
"roleArn": "acs:ram::123456789012:role/test-role",
|
|
88
|
+
"roleName": "test-role",
|
|
89
|
+
"roleId": "role-123",
|
|
90
|
+
"arn": "acs:ram::123456789012:role/test-role",
|
|
91
|
+
"policyName": "test-role-policy"
|
|
92
92
|
}
|
|
93
93
|
],
|
|
94
|
-
"lastUpdated": "2026-08-
|
|
94
|
+
"lastUpdated": "2026-08-30T13:26:27.547Z",
|
|
95
95
|
"status": "ready"
|
|
96
96
|
},
|
|
97
97
|
"events.gateway_event": {
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
{
|
|
106
106
|
"method": "GET",
|
|
107
107
|
"path": "/api/hello",
|
|
108
|
-
"backend": "
|
|
108
|
+
"backend": "insight-poc-fn"
|
|
109
109
|
}
|
|
110
110
|
],
|
|
111
111
|
"domain": null
|
|
@@ -166,7 +166,7 @@
|
|
|
166
166
|
"stageName": "RELEASE"
|
|
167
167
|
}
|
|
168
168
|
],
|
|
169
|
-
"lastUpdated": "2026-08-
|
|
169
|
+
"lastUpdated": "2026-08-30T13:26:27.549Z"
|
|
170
170
|
}
|
|
171
171
|
},
|
|
172
172
|
"shared": {
|
|
@@ -185,11 +185,11 @@
|
|
|
185
185
|
"id": "insight-poc-deploy-app-dev-sls"
|
|
186
186
|
}
|
|
187
187
|
],
|
|
188
|
-
"lastUpdated": "2026-08-
|
|
188
|
+
"lastUpdated": "2026-08-30T13:26:22.545Z"
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
},
|
|
193
|
-
"lineage": "
|
|
193
|
+
"lineage": "be6eecfe-dc78-4bfe-9e47-f152e78b5cc8",
|
|
194
194
|
"serial": 2
|
|
195
195
|
}
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"role": "trn:iam::123456789012:role/test-role",
|
|
23
23
|
"logConfig": {
|
|
24
24
|
"project": "insight-volc-app-dev-tls",
|
|
25
|
-
"topic": "insight-volc-dev-fn-logs"
|
|
25
|
+
"topic": "insight-volc-dev-insight_poc_fn-fn-logs"
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"instances": [
|
|
@@ -42,20 +42,20 @@
|
|
|
42
42
|
"lastUpdateTime": null
|
|
43
43
|
},
|
|
44
44
|
{
|
|
45
|
-
"sid": "si:volcengine:tls_topic:dev:insight-volc-app-dev-tls/insight-volc-dev-fn-logs",
|
|
46
|
-
"id": "insight-volc-app-dev-tls/insight-volc-dev-fn-logs",
|
|
45
|
+
"sid": "si:volcengine:tls_topic:dev:insight-volc-app-dev-tls/insight-volc-dev-insight_poc_fn-fn-logs",
|
|
46
|
+
"id": "insight-volc-app-dev-tls/insight-volc-dev-insight_poc_fn-fn-logs",
|
|
47
47
|
"type": "VOLCENGINE_TLS_TOPIC",
|
|
48
|
-
"topicName": "insight-volc-dev-fn-logs",
|
|
48
|
+
"topicName": "insight-volc-dev-insight_poc_fn-fn-logs",
|
|
49
49
|
"topicId": "topic-123"
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
|
-
"sid": "si:volcengine:tls_index:dev:insight-volc-app-dev-tls/insight-volc-dev-fn-logs/index",
|
|
53
|
-
"id": "insight-volc-app-dev-tls/insight-volc-dev-fn-logs/index",
|
|
52
|
+
"sid": "si:volcengine:tls_index:dev:insight-volc-app-dev-tls/insight-volc-dev-insight_poc_fn-fn-logs/index",
|
|
53
|
+
"id": "insight-volc-app-dev-tls/insight-volc-dev-insight_poc_fn-fn-logs/index",
|
|
54
54
|
"type": "VOLCENGINE_TLS_INDEX"
|
|
55
55
|
},
|
|
56
56
|
{
|
|
57
|
-
"sid": "si:volcengine:iam_role:dev:insight-volc-app-insight-volc-dev-role",
|
|
58
|
-
"id": "insight-volc-app-insight-volc-dev-role",
|
|
57
|
+
"sid": "si:volcengine:iam_role:dev:insight-volc-app-insight-volc-dev-insight-poc-fn-role",
|
|
58
|
+
"id": "insight-volc-app-insight-volc-dev-insight-poc-fn-role",
|
|
59
59
|
"type": "VOLCENGINE_IAM_ROLE",
|
|
60
60
|
"trn": "trn:iam::123456789012:role/test-role",
|
|
61
61
|
"roleName": "test-role",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
}
|
|
64
64
|
],
|
|
65
65
|
"status": "ready",
|
|
66
|
-
"lastUpdated": "2026-08-
|
|
66
|
+
"lastUpdated": "2026-08-30T13:25:57.473Z"
|
|
67
67
|
}
|
|
68
68
|
},
|
|
69
69
|
"shared": {
|
|
@@ -83,11 +83,11 @@
|
|
|
83
83
|
"projectId": "proj-123"
|
|
84
84
|
}
|
|
85
85
|
],
|
|
86
|
-
"lastUpdated": "2026-08-
|
|
86
|
+
"lastUpdated": "2026-08-30T13:25:54.472Z"
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
},
|
|
91
|
-
"lineage": "
|
|
91
|
+
"lineage": "79ee1cef-4d59-408b-b683-490f7282db5d",
|
|
92
92
|
"serial": 1
|
|
93
93
|
}
|
package/AGENTS.md
CHANGED
|
@@ -171,6 +171,35 @@ import { createRamOperations } from '../../common/aliyunClient/ramOperations';
|
|
|
171
171
|
- Keep abstractions provider-agnostic
|
|
172
172
|
- Clean separation of concerns between providers
|
|
173
173
|
|
|
174
|
+
## Resource Naming (Cross-Platform) - MANDATORY
|
|
175
|
+
|
|
176
|
+
All si-generated cloud resource names MUST come from shared builders — never inline name templates. One name template appearing in more than one place (planner / executor / validator) is a defect: duplicated templates drift.
|
|
177
|
+
|
|
178
|
+
### Canonical Builders
|
|
179
|
+
|
|
180
|
+
| Resource | Builder (single source of truth) | Shape |
|
|
181
|
+
|---|---|---|
|
|
182
|
+
| Function execution role | `buildFunctionRoleName` (`src/common/nameBuilder.ts`) | `${app}-${service}-${stage}-${fn.key}-role` — identical on every provider |
|
|
183
|
+
| Role execution policy | `buildRolePolicyName` (`src/common/nameBuilder.ts`) | `${roleName}-policy` |
|
|
184
|
+
| Function log topic/logstore | per-provider shared-log module (`buildFunctionLogTopicName` / `buildFunctionLogstoreName`) | `${service}-${stage}-${fn.key}-fn-logs` |
|
|
185
|
+
| Shared log project/logset | `buildSharedProjectName` / `buildSharedLogsetName` | `${app}-${stage}-sls` / `-tls` / `-cls` |
|
|
186
|
+
| Length-limited names | `buildConstrainedName` with the provider's cloud limit | truncate + hash deterministically |
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
// GOOD
|
|
190
|
+
const policyName = buildRolePolicyName(roleName);
|
|
191
|
+
|
|
192
|
+
// AVOID - duplicated template, drifts from the other call sites
|
|
193
|
+
const policyName = `${roleName}-policy`;
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Rules
|
|
197
|
+
|
|
198
|
+
1. **Per-owner teardown**: a log container owned by a function/event includes that owner's key in its name (issue #214), so removing one owner never deletes a container another owner still uses. Provider-level singletons (e.g. the aliyun gateway log config, instance id `${region}:PROVIDER`) are the exception: service-scoped, with deletion guarded by active-reference checks.
|
|
199
|
+
2. **Stored-first on rename**: when a name derivation changes, executors and planners MUST read the recorded name from state instances first and apply the new derivation only to fresh creates (see `resolveTlsTopicNameFromInstances` in volcengine `apigwResource.ts`). Otherwise existing deployments phantom-drift and orphan containers.
|
|
200
|
+
3. **In-place migration**: reuse branches key on instance type — existing deployments keep their recorded role/container and get trust/policy updated in place; new names apply only to newly created resources. Never recreate a role or container just to change its name.
|
|
201
|
+
4. **SIDs are per-provider**: `si:<provider>:<service>:<stage>:<id>` — intentionally NOT unified cross-provider; a SID's lifecycle is bound to its physical resource.
|
|
202
|
+
|
|
174
203
|
## Code Style
|
|
175
204
|
|
|
176
205
|
### TypeScript
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geek-fun/serverlessinsight",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.7",
|
|
4
4
|
"description": "Full life cycle cross providers serverless application management for your fast-growing business.",
|
|
5
5
|
"homepage": "https://serverlessinsight.com",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -33,11 +33,12 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.createRamOperations = void 0;
|
|
36
|
+
exports.createRamOperations = exports.buildFc3ExecutionPolicyDocument = void 0;
|
|
37
37
|
const ram = __importStar(require("@alicloud/ram20150501"));
|
|
38
38
|
const lang_1 = require("../../lang");
|
|
39
39
|
const logger_1 = require("../logger");
|
|
40
40
|
const iamStatements_1 = require("../iamStatements");
|
|
41
|
+
const nameBuilder_1 = require("../nameBuilder");
|
|
41
42
|
const buildAssumeRolePolicy = (trustedServices) => JSON.stringify({
|
|
42
43
|
Version: '1',
|
|
43
44
|
Statement: [
|
|
@@ -109,18 +110,24 @@ const mapToAliyunStatement = (stmt) => {
|
|
|
109
110
|
}
|
|
110
111
|
return result;
|
|
111
112
|
};
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
/** @public Exec policy document from a derived baseline; falls back to the static FC_EXECUTION_STATEMENTS when omitted. */
|
|
114
|
+
const buildFc3ExecutionPolicyDocument = (executionStatements, customStatements) => {
|
|
115
|
+
const nativeBaseline = executionStatements
|
|
116
|
+
? executionStatements.map(mapToAliyunStatement)
|
|
117
|
+
: FC_EXECUTION_STATEMENTS;
|
|
118
|
+
const merged = (0, iamStatements_1.mergePolicyStatements)(nativeBaseline, customStatements, mapToAliyunStatement);
|
|
114
119
|
return (0, iamStatements_1.buildPolicyDocument)(merged, { version: '1' });
|
|
115
120
|
};
|
|
121
|
+
exports.buildFc3ExecutionPolicyDocument = buildFc3ExecutionPolicyDocument;
|
|
122
|
+
const buildExecutionPolicy = (executionStatements, customStatements) => (0, exports.buildFc3ExecutionPolicyDocument)(executionStatements, customStatements);
|
|
116
123
|
/* istanbul ignore next */ const createRamOperations = (ramClient) => {
|
|
117
|
-
const attachRolePolicyForFc = async (roleName, customStatements) => {
|
|
118
|
-
const policyName =
|
|
124
|
+
const attachRolePolicyForFc = async (roleName, customStatements, executionStatements) => {
|
|
125
|
+
const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
|
|
119
126
|
// Create policy
|
|
120
127
|
try {
|
|
121
128
|
const createPolicyRequest = new ram.CreatePolicyRequest({
|
|
122
129
|
policyName,
|
|
123
|
-
policyDocument: buildExecutionPolicy(customStatements),
|
|
130
|
+
policyDocument: buildExecutionPolicy(executionStatements, customStatements),
|
|
124
131
|
description: `FC execution policy for ${roleName}`,
|
|
125
132
|
});
|
|
126
133
|
await ramClient.createPolicy(createPolicyRequest);
|
|
@@ -215,8 +222,88 @@ const buildExecutionPolicy = (customStatements) => {
|
|
|
215
222
|
return [];
|
|
216
223
|
}
|
|
217
224
|
};
|
|
225
|
+
const updateExecutionPolicyDocumentFn = async (roleName, policyDocument) => {
|
|
226
|
+
const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
|
|
227
|
+
const ensureAttached = async () => {
|
|
228
|
+
try {
|
|
229
|
+
await ramClient.attachPolicyToRole(new ram.AttachPolicyToRoleRequest({ policyType: 'Custom', policyName, roleName }));
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
if (!(error &&
|
|
233
|
+
typeof error === 'object' &&
|
|
234
|
+
'code' in error &&
|
|
235
|
+
error.code === 'EntityAlreadyExists.Role.Policy')) {
|
|
236
|
+
throw error;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
let currentDocument;
|
|
241
|
+
try {
|
|
242
|
+
const getPolicyResponse = await ramClient.getPolicy(new ram.GetPolicyRequest({ policyName, policyType: 'Custom' }));
|
|
243
|
+
const defaultVersionId = getPolicyResponse.body?.policy?.defaultVersion;
|
|
244
|
+
if (defaultVersionId) {
|
|
245
|
+
const versionResponse = await ramClient.getPolicyVersion(new ram.GetPolicyVersionRequest({
|
|
246
|
+
policyName,
|
|
247
|
+
policyType: 'Custom',
|
|
248
|
+
versionId: defaultVersionId,
|
|
249
|
+
}));
|
|
250
|
+
currentDocument = versionResponse.body?.policyVersion?.policyDocument;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
if (!(error &&
|
|
255
|
+
typeof error === 'object' &&
|
|
256
|
+
'code' in error &&
|
|
257
|
+
error.code === 'EntityNotExist.Policy')) {
|
|
258
|
+
throw error;
|
|
259
|
+
}
|
|
260
|
+
try {
|
|
261
|
+
await ramClient.createPolicy(new ram.CreatePolicyRequest({
|
|
262
|
+
policyName,
|
|
263
|
+
policyDocument,
|
|
264
|
+
description: `FC execution policy for ${roleName}`,
|
|
265
|
+
}));
|
|
266
|
+
}
|
|
267
|
+
catch (error2) {
|
|
268
|
+
if (!(error2 &&
|
|
269
|
+
typeof error2 === 'object' &&
|
|
270
|
+
'code' in error2 &&
|
|
271
|
+
error2.code === 'EntityAlreadyExists.Policy')) {
|
|
272
|
+
throw error2;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
await ensureAttached();
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (currentDocument === policyDocument) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
try {
|
|
282
|
+
const listResponse = await ramClient.listPolicyVersions(new ram.ListPolicyVersionsRequest({ policyName, policyType: 'Custom' }));
|
|
283
|
+
const versions = listResponse.body?.policyVersions?.policyVersion ?? [];
|
|
284
|
+
const keepBeforeCreate = 4;
|
|
285
|
+
const toDelete = versions
|
|
286
|
+
.filter((v) => !v.isDefaultVersion)
|
|
287
|
+
.sort((a, b) => (a.createDate ?? '').localeCompare(b.createDate ?? ''))
|
|
288
|
+
.slice(0, Math.max(0, versions.length - keepBeforeCreate));
|
|
289
|
+
for (const version of toDelete) {
|
|
290
|
+
if (version.versionId) {
|
|
291
|
+
await ramClient.deletePolicyVersion(new ram.DeletePolicyVersionRequest({ policyName, versionId: version.versionId }));
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
logger_1.logger.warn(lang_1.lang.__('RAM_POLICY_VERSION_PRUNE_FAILED', { policyName, error: String(error) }));
|
|
297
|
+
}
|
|
298
|
+
await ramClient.createPolicyVersion(new ram.CreatePolicyVersionRequest({
|
|
299
|
+
policyName,
|
|
300
|
+
policyDocument,
|
|
301
|
+
setAsDefault: true,
|
|
302
|
+
}));
|
|
303
|
+
await ensureAttached();
|
|
304
|
+
};
|
|
218
305
|
return {
|
|
219
|
-
createRole: async (roleName, trustedServices, description, customStatements, managedPolicies) => {
|
|
306
|
+
createRole: async (roleName, trustedServices, description, customStatements, managedPolicies, executionStatements) => {
|
|
220
307
|
const assumeRolePolicy = buildAssumeRolePolicy(trustedServices);
|
|
221
308
|
try {
|
|
222
309
|
const request = new ram.CreateRoleRequest({
|
|
@@ -235,7 +322,7 @@ const buildExecutionPolicy = (customStatements) => {
|
|
|
235
322
|
maxSessionDuration: response.body?.role?.maxSessionDuration,
|
|
236
323
|
assumeRolePolicyDocument: assumeRolePolicy,
|
|
237
324
|
};
|
|
238
|
-
const policyName = await attachRolePolicyForFc(roleName, customStatements);
|
|
325
|
+
const policyName = await attachRolePolicyForFc(roleName, customStatements, executionStatements);
|
|
239
326
|
if (managedPolicies && managedPolicies.length > 0) {
|
|
240
327
|
await attachManagedPoliciesFn(roleName, managedPolicies);
|
|
241
328
|
}
|
|
@@ -255,7 +342,8 @@ const buildExecutionPolicy = (customStatements) => {
|
|
|
255
342
|
newAssumeRolePolicyDocument: assumeRolePolicy,
|
|
256
343
|
});
|
|
257
344
|
await ramClient.updateRole(updateRequest);
|
|
258
|
-
const policyName =
|
|
345
|
+
const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
|
|
346
|
+
await updateExecutionPolicyDocumentFn(roleName, (0, exports.buildFc3ExecutionPolicyDocument)(executionStatements, customStatements));
|
|
259
347
|
if (managedPolicies && managedPolicies.length > 0) {
|
|
260
348
|
await attachManagedPoliciesFn(roleName, managedPolicies);
|
|
261
349
|
}
|
|
@@ -297,7 +385,7 @@ const buildExecutionPolicy = (customStatements) => {
|
|
|
297
385
|
updateDate: getResponse.body?.role?.updateDate,
|
|
298
386
|
maxSessionDuration: getResponse.body?.role?.maxSessionDuration,
|
|
299
387
|
assumeRolePolicyDocument: assumeRolePolicy,
|
|
300
|
-
policyName:
|
|
388
|
+
policyName: (0, nameBuilder_1.buildRolePolicyName)(roleName),
|
|
301
389
|
};
|
|
302
390
|
const updateRequest = new ram.UpdateRoleRequest({
|
|
303
391
|
roleName,
|
|
@@ -317,8 +405,8 @@ const buildExecutionPolicy = (customStatements) => {
|
|
|
317
405
|
throw error;
|
|
318
406
|
}
|
|
319
407
|
},
|
|
320
|
-
updateRolePolicy: async (roleName, customStatements) => {
|
|
321
|
-
const policyName =
|
|
408
|
+
updateRolePolicy: async (roleName, customStatements, executionStatements) => {
|
|
409
|
+
const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
|
|
322
410
|
try {
|
|
323
411
|
await ramClient.detachPolicyFromRole(new ram.DetachPolicyFromRoleRequest({ policyType: 'Custom', policyName, roleName }));
|
|
324
412
|
}
|
|
@@ -334,7 +422,7 @@ const buildExecutionPolicy = (customStatements) => {
|
|
|
334
422
|
try {
|
|
335
423
|
await ramClient.createPolicy(new ram.CreatePolicyRequest({
|
|
336
424
|
policyName,
|
|
337
|
-
policyDocument: buildExecutionPolicy(customStatements),
|
|
425
|
+
policyDocument: buildExecutionPolicy(executionStatements, customStatements),
|
|
338
426
|
description: `FC execution policy for ${roleName}`,
|
|
339
427
|
}));
|
|
340
428
|
}
|
|
@@ -362,6 +450,7 @@ const buildExecutionPolicy = (customStatements) => {
|
|
|
362
450
|
throw error;
|
|
363
451
|
}
|
|
364
452
|
},
|
|
453
|
+
updateExecutionPolicyDocument: updateExecutionPolicyDocumentFn,
|
|
365
454
|
getRole: async (roleName) => {
|
|
366
455
|
try {
|
|
367
456
|
const request = new ram.GetRoleRequest({
|
|
@@ -380,7 +469,7 @@ const buildExecutionPolicy = (customStatements) => {
|
|
|
380
469
|
updateDate: response.body.role.updateDate,
|
|
381
470
|
maxSessionDuration: response.body.role.maxSessionDuration,
|
|
382
471
|
assumeRolePolicyDocument: response.body.role.assumeRolePolicyDocument,
|
|
383
|
-
policyName:
|
|
472
|
+
policyName: (0, nameBuilder_1.buildRolePolicyName)(roleName),
|
|
384
473
|
};
|
|
385
474
|
}
|
|
386
475
|
catch (error) {
|
|
@@ -394,7 +483,7 @@ const buildExecutionPolicy = (customStatements) => {
|
|
|
394
483
|
}
|
|
395
484
|
},
|
|
396
485
|
deleteRole: async (roleName, managedPolicies) => {
|
|
397
|
-
const policyName =
|
|
486
|
+
const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
|
|
398
487
|
if (managedPolicies && managedPolicies.length > 0) {
|
|
399
488
|
await detachManagedPoliciesFn(roleName, managedPolicies);
|
|
400
489
|
}
|
|
@@ -98,7 +98,9 @@ const getIacDefinition = (iac, rawValue) => {
|
|
|
98
98
|
if (matchFn?.length) {
|
|
99
99
|
return iac.functions?.find((fc) => fc.key === matchFn[1]);
|
|
100
100
|
}
|
|
101
|
-
|
|
101
|
+
// Bare values are the function's deployed NAME, never its key — resolving by
|
|
102
|
+
// key here would reintroduce the issue #227 trust-policy incident.
|
|
103
|
+
return iac.functions?.find((fc) => fc.name === rawValue);
|
|
102
104
|
};
|
|
103
105
|
exports.getIacDefinition = getIacDefinition;
|
|
104
106
|
/* istanbul ignore next */
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// These functions operate on raw statement arrays and never import
|
|
4
4
|
// provider-specific modules — consumers supply their own map functions.
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.buildPolicyDocument = exports.parseBuiltInStatements = exports.mergePolicyStatements = void 0;
|
|
6
|
+
exports.buildPolicyDocument = exports.parseBuiltInStatements = exports.unionPolicyStatements = exports.mergePolicyStatements = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* Merge built-in native statements with optional custom user statements.
|
|
9
9
|
* Returns a NEW array — the input arrays are never mutated.
|
|
@@ -21,6 +21,26 @@ const mergePolicyStatements = (nativeBuiltIn, custom, mapFn) => {
|
|
|
21
21
|
return [...nativeBuiltIn, ...mappedCustom];
|
|
22
22
|
};
|
|
23
23
|
exports.mergePolicyStatements = mergePolicyStatements;
|
|
24
|
+
/**
|
|
25
|
+
* Union statement lists (e.g. the derived baselines of several functions
|
|
26
|
+
* sharing one legacy role), deduplicating identical statements. Returns a NEW
|
|
27
|
+
* array — the inputs are never mutated.
|
|
28
|
+
*/
|
|
29
|
+
const unionPolicyStatements = (statementLists) => {
|
|
30
|
+
const seen = new Set();
|
|
31
|
+
const merged = [];
|
|
32
|
+
for (const list of statementLists) {
|
|
33
|
+
for (const statement of list) {
|
|
34
|
+
const fingerprint = JSON.stringify(statement);
|
|
35
|
+
if (seen.has(fingerprint))
|
|
36
|
+
continue;
|
|
37
|
+
seen.add(fingerprint);
|
|
38
|
+
merged.push(statement);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return merged;
|
|
42
|
+
};
|
|
43
|
+
exports.unionPolicyStatements = unionPolicyStatements;
|
|
24
44
|
/**
|
|
25
45
|
* Parse a provider's built-in policy JSON string into its raw Statement array.
|
|
26
46
|
* Returns an empty array when the JSON is invalid or has no Statement field.
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* deploy set are additionally rejected up-front by semantic validation.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.CONSTRAINT_NAME_LIMITS = exports.buildConstrainedName = exports.stableHash = exports.DEFAULT_HASH_LENGTH = void 0;
|
|
19
|
+
exports.buildRolePolicyName = exports.buildFunctionRoleName = exports.CONSTRAINT_NAME_LIMITS = exports.buildConstrainedName = exports.stableHash = exports.DEFAULT_HASH_LENGTH = void 0;
|
|
20
20
|
const FNV_OFFSET_BASIS = 0x811c9dc5;
|
|
21
21
|
const FNV_PRIME = 0x01000193;
|
|
22
22
|
const SANITISERS = {
|
|
@@ -77,4 +77,15 @@ exports.CONSTRAINT_NAME_LIMITS = {
|
|
|
77
77
|
ALIYUN_CREATE_API_NAME: 50,
|
|
78
78
|
ALIYUN_API_GROUP_NAME: 50,
|
|
79
79
|
VOLCENGINE_ROUTE_NAME: 63,
|
|
80
|
+
FUNCTION_ROLE_NAME: 64,
|
|
80
81
|
};
|
|
82
|
+
/** Single source of truth for per-function execution role names across all providers. */
|
|
83
|
+
const buildFunctionRoleName = (serviceName, stage, fnKey) => (0, exports.buildConstrainedName)({
|
|
84
|
+
parts: [serviceName, stage, fnKey, 'role'],
|
|
85
|
+
maxLength: exports.CONSTRAINT_NAME_LIMITS.FUNCTION_ROLE_NAME,
|
|
86
|
+
charset: 'hyphen',
|
|
87
|
+
});
|
|
88
|
+
exports.buildFunctionRoleName = buildFunctionRoleName;
|
|
89
|
+
/** Single source of truth for the execution policy name attached to a role. */
|
|
90
|
+
const buildRolePolicyName = (roleName) => `${roleName}-policy`;
|
|
91
|
+
exports.buildRolePolicyName = buildRolePolicyName;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createCamOperations = void 0;
|
|
4
4
|
const iamStatements_1 = require("../iamStatements");
|
|
5
|
+
const nameBuilder_1 = require("../nameBuilder");
|
|
5
6
|
const logger_1 = require("../logger");
|
|
6
7
|
const lang_1 = require("../../lang");
|
|
7
8
|
// SCF built-in execution policy (same idea as Aliyun's FC_EXECUTION_POLICY)
|
|
@@ -37,8 +38,9 @@ const mapToCamStatement = (stmt) => {
|
|
|
37
38
|
}
|
|
38
39
|
return result;
|
|
39
40
|
};
|
|
40
|
-
const buildExecutionPolicy = (customStatements) => {
|
|
41
|
-
const
|
|
41
|
+
const buildExecutionPolicy = (customStatements, executionStatements) => {
|
|
42
|
+
const baseline = executionStatements?.map(mapToCamStatement) ?? SCF_EXECUTION_STATEMENTS;
|
|
43
|
+
const merged = (0, iamStatements_1.mergePolicyStatements)(baseline, customStatements, mapToCamStatement);
|
|
42
44
|
return (0, iamStatements_1.buildPolicyDocument)(merged, { version: '2.0' });
|
|
43
45
|
};
|
|
44
46
|
const buildAssumeRolePolicy = (trustedServices) => JSON.stringify({
|
|
@@ -104,7 +106,17 @@ const createCamOperations = (camClient) => {
|
|
|
104
106
|
}
|
|
105
107
|
};
|
|
106
108
|
return {
|
|
107
|
-
|
|
109
|
+
getOwnerUin: async () => {
|
|
110
|
+
try {
|
|
111
|
+
const response = await camClient.GetUserAppId(undefined);
|
|
112
|
+
return response.OwnerUin ?? response.Uin ?? undefined;
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
logger_1.logger.warn(lang_1.lang.__('TENCENT_UIN_FETCH_FAILED', { error: String(error) }));
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
createRole: async (roleName, trustedServices, description, customStatements, managedPolicies, executionStatements) => {
|
|
108
120
|
const assumeRolePolicy = buildAssumeRolePolicy(trustedServices);
|
|
109
121
|
try {
|
|
110
122
|
const response = await camClient.CreateRole({
|
|
@@ -129,11 +141,11 @@ const createCamOperations = (camClient) => {
|
|
|
129
141
|
roleArn,
|
|
130
142
|
};
|
|
131
143
|
// Attach inline policy with built-in + custom statements
|
|
132
|
-
const policyName =
|
|
144
|
+
const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
|
|
133
145
|
try {
|
|
134
146
|
await camClient.CreatePolicy({
|
|
135
147
|
PolicyName: policyName,
|
|
136
|
-
PolicyDocument: buildExecutionPolicy(customStatements),
|
|
148
|
+
PolicyDocument: buildExecutionPolicy(customStatements, executionStatements),
|
|
137
149
|
Description: `SCF execution policy for ${roleName}`,
|
|
138
150
|
});
|
|
139
151
|
await attachPolicy(roleName, policyName);
|
|
@@ -170,12 +182,12 @@ const createCamOperations = (camClient) => {
|
|
|
170
182
|
try {
|
|
171
183
|
const getResponse = await camClient.GetRole({ RoleName: roleName });
|
|
172
184
|
const roleData = getResponse.RoleInfo;
|
|
173
|
-
const policyName =
|
|
185
|
+
const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
|
|
174
186
|
// Re-attach built-in policy (idempotent)
|
|
175
187
|
try {
|
|
176
188
|
await camClient.CreatePolicy({
|
|
177
189
|
PolicyName: policyName,
|
|
178
|
-
PolicyDocument: buildExecutionPolicy(customStatements),
|
|
190
|
+
PolicyDocument: buildExecutionPolicy(customStatements, executionStatements),
|
|
179
191
|
Description: `SCF execution policy for ${roleName}`,
|
|
180
192
|
});
|
|
181
193
|
await attachPolicy(roleName, policyName);
|
|
@@ -219,7 +231,7 @@ const createCamOperations = (camClient) => {
|
|
|
219
231
|
roleId: roleData.RoleId,
|
|
220
232
|
roleArn: roleData.RoleArn,
|
|
221
233
|
description: roleData.Description,
|
|
222
|
-
policyName:
|
|
234
|
+
policyName: (0, nameBuilder_1.buildRolePolicyName)(roleName),
|
|
223
235
|
};
|
|
224
236
|
}
|
|
225
237
|
catch (error) {
|
|
@@ -232,7 +244,7 @@ const createCamOperations = (camClient) => {
|
|
|
232
244
|
}
|
|
233
245
|
},
|
|
234
246
|
deleteRole: async (roleName, managedPolicies) => {
|
|
235
|
-
const policyName =
|
|
247
|
+
const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
|
|
236
248
|
// Detach managed policies first (don't delete them)
|
|
237
249
|
if (managedPolicies && managedPolicies.length > 0) {
|
|
238
250
|
for (const policyArn of managedPolicies) {
|
|
@@ -256,8 +268,8 @@ const createCamOperations = (camClient) => {
|
|
|
256
268
|
throw error;
|
|
257
269
|
}
|
|
258
270
|
},
|
|
259
|
-
updateRolePolicy: async (roleName, customStatements) => {
|
|
260
|
-
const policyName =
|
|
271
|
+
updateRolePolicy: async (roleName, customStatements, executionStatements) => {
|
|
272
|
+
const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
|
|
261
273
|
// Detach + delete old
|
|
262
274
|
await detachPolicy(roleName, policyName);
|
|
263
275
|
await deletePolicyByName(camClient, policyName);
|
|
@@ -265,7 +277,7 @@ const createCamOperations = (camClient) => {
|
|
|
265
277
|
try {
|
|
266
278
|
await camClient.CreatePolicy({
|
|
267
279
|
PolicyName: policyName,
|
|
268
|
-
PolicyDocument: buildExecutionPolicy(customStatements),
|
|
280
|
+
PolicyDocument: buildExecutionPolicy(customStatements, executionStatements),
|
|
269
281
|
Description: `SCF execution policy for ${roleName}`,
|
|
270
282
|
});
|
|
271
283
|
}
|