@revoengine/cli 1.0.19 → 1.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -9
- package/dist/src/cli.js +5 -1
- package/dist/src/client.d.ts +20 -3
- package/dist/src/client.js +45 -1
- package/dist/src/commands/agents.d.ts +2 -0
- package/dist/src/commands/agents.js +56 -0
- package/dist/src/commands/component.js +2 -0
- package/dist/src/commands/index.d.ts +1 -0
- package/dist/src/commands/index.js +1 -0
- package/dist/src/commands/migrate.js +14 -2
- package/dist/src/component-lock.d.ts +5 -0
- package/dist/src/component-lock.js +45 -5
- package/dist/src/metadata-backfill.js +48 -1
- package/dist/src/migration.d.ts +9 -2
- package/dist/src/migration.js +60 -0
- package/dist/src/resource-inventory.d.ts +4 -2
- package/dist/src/resource-inventory.js +11 -1
- package/dist/src/resource-syncs/account-principal.d.ts +19 -1
- package/dist/src/resource-syncs/account-principal.js +94 -4
- package/dist/src/resource-syncs/agent-sync.d.ts +98 -0
- package/dist/src/resource-syncs/agent-sync.js +586 -0
- package/dist/src/resource-syncs/endpoint-sync.d.ts +3 -0
- package/dist/src/resource-syncs/endpoint-sync.js +27 -1
- package/dist/src/resource-syncs/group-sync.d.ts +4 -1
- package/dist/src/resource-syncs/group-sync.js +32 -17
- package/dist/src/resource-syncs/identity-migration.d.ts +1 -1
- package/dist/src/resource-syncs/identity-migration.js +20 -1
- package/dist/src/resource-syncs/job-template-sync.d.ts +2 -1
- package/dist/src/resource-syncs/job-template-sync.js +38 -32
- package/dist/src/resource-syncs/service-account-sync.js +16 -9
- package/dist/src/tracked-resources.d.ts +1 -1
- package/dist/src/tracked-resources.js +4 -2
- package/dist/src/types.d.ts +22 -0
- package/dist/src/ui.js +5 -1
- package/dist/src/workspace-diff.js +2 -0
- package/dist/src/workspace-prune.js +44 -3
- package/package.json +2 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { executionPrincipalAvailable, portableExecutionPolicy, runtimeExecutionPolicyPayload, validPortableExecutionPolicy } from "./account-principal.js";
|
|
1
2
|
import path from 'node:path';
|
|
2
3
|
import { describeFieldChanges } from "../diff-details.js";
|
|
3
4
|
import { hashPortableComponentSource, hashStable, readComponentLock, writeComponentLock } from "../component-lock.js";
|
|
@@ -109,7 +110,7 @@ function disambiguateManifestPath(filePath, stableKey) {
|
|
|
109
110
|
}
|
|
110
111
|
const ENDPOINT_MANIFEST_FIELDS = new Set([
|
|
111
112
|
'kind', 'stableKey', 'name', 'category', 'description', 'metadata', 'active', 'timeout',
|
|
112
|
-
'route', 'options', 'execution', 'schema',
|
|
113
|
+
'route', 'options', 'execution', 'executionPolicy', 'schema',
|
|
113
114
|
]);
|
|
114
115
|
const INSTANCE_LOCAL_SCHEMA_OPTION_FIELDS = new Set([
|
|
115
116
|
'componentSchemaId', 'componentSchemaVersion', 'componentSchemaElement',
|
|
@@ -169,6 +170,8 @@ function validateManifest(manifest, stableKeyName) {
|
|
|
169
170
|
&& Object.keys(manifest.options).some((key) => INSTANCE_LOCAL_SCHEMA_OPTION_FIELDS.has(key))) {
|
|
170
171
|
return false;
|
|
171
172
|
}
|
|
173
|
+
if (manifest.executionPolicy !== undefined && !validPortableExecutionPolicy(manifest.executionPolicy, true))
|
|
174
|
+
return false;
|
|
172
175
|
if (manifest.execution !== undefined && !hasValidBinding(manifest.execution)) {
|
|
173
176
|
return false;
|
|
174
177
|
}
|
|
@@ -190,6 +193,7 @@ export function hashPortableEndpoint(manifest) {
|
|
|
190
193
|
route: canonicalValue(manifest.route),
|
|
191
194
|
...(manifest.options === undefined ? {} : { options: canonicalPortableOptions(manifest.options) }),
|
|
192
195
|
...(manifest.execution === undefined ? {} : { execution: canonicalValue(manifest.execution) }),
|
|
196
|
+
...(manifest.executionPolicy === undefined ? {} : { executionPolicy: canonicalValue(manifest.executionPolicy) }),
|
|
193
197
|
...(manifest.schema === undefined ? {} : { schema: canonicalValue(manifest.schema) }),
|
|
194
198
|
});
|
|
195
199
|
}
|
|
@@ -308,6 +312,7 @@ async function manifestFromRecord(input) {
|
|
|
308
312
|
}
|
|
309
313
|
: undefined;
|
|
310
314
|
const options = portableOptions(record);
|
|
315
|
+
const executionPolicy = input.includeExecutionPolicy === false ? undefined : await portableExecutionPolicy(input.client, record.executionPolicy, input.stableKeyName);
|
|
311
316
|
const manifest = {
|
|
312
317
|
kind: 'endpoint',
|
|
313
318
|
stableKey: input.stableKey,
|
|
@@ -320,6 +325,7 @@ async function manifestFromRecord(input) {
|
|
|
320
325
|
route: canonicalRoute(record),
|
|
321
326
|
...(options === undefined ? {} : { options }),
|
|
322
327
|
...(execution ? { execution } : {}),
|
|
328
|
+
...(executionPolicy ? { executionPolicy } : {}),
|
|
323
329
|
...(schema ? { schema } : {}),
|
|
324
330
|
};
|
|
325
331
|
if (!validateManifest(manifest, input.stableKeyName)) {
|
|
@@ -504,6 +510,7 @@ function diffEndpoints(desired, current) {
|
|
|
504
510
|
['route.path', desired.route.path, current.route.path],
|
|
505
511
|
['options', canonicalPortableOptions(desired.options) ?? null, canonicalPortableOptions(current.options) ?? null],
|
|
506
512
|
['execution', canonicalValue(desired.execution ?? null), canonicalValue(current.execution ?? null)],
|
|
513
|
+
...(desired.executionPolicy ? [['executionPolicy', canonicalValue(desired.executionPolicy), canonicalValue(current.executionPolicy ?? null)]] : []),
|
|
507
514
|
['schema', canonicalValue(desired.schema ?? null), canonicalValue(current.schema ?? null)],
|
|
508
515
|
];
|
|
509
516
|
return fields
|
|
@@ -808,6 +815,7 @@ export async function buildEndpointsPlan(input) {
|
|
|
808
815
|
}
|
|
809
816
|
try {
|
|
810
817
|
const manifest = await manifestFromRecord({
|
|
818
|
+
includeExecutionPolicy: (localByStableKey.get(stableKey) || []).some(entry => entry.manifest.executionPolicy !== undefined),
|
|
811
819
|
client: input.client,
|
|
812
820
|
record,
|
|
813
821
|
stableKey,
|
|
@@ -934,6 +942,20 @@ export async function buildEndpointsPlan(input) {
|
|
|
934
942
|
const dependencyBlockers = input.includeDependencyBlockers && dependency.blockers.length > 0
|
|
935
943
|
? { dependencyBlockers: [...dependency.blockers] }
|
|
936
944
|
: {};
|
|
945
|
+
if (desired.executionPolicy) {
|
|
946
|
+
try {
|
|
947
|
+
const principal = desired.executionPolicy.serviceAccount;
|
|
948
|
+
if (principal && !await executionPrincipalAvailable(input.client, principal, input.stableKeyName, input.projectedServiceAccounts, true)) {
|
|
949
|
+
throw new Error('Execution service account is unavailable, inactive, lacks platform access, or is ambiguous.');
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
catch (error) {
|
|
953
|
+
const reason = error instanceof Error ? error.message : 'Execution principal is unavailable.';
|
|
954
|
+
blockers.push(`Endpoint "${desired.stableKey}": ${reason}`);
|
|
955
|
+
items.push({ status: 'conflict', stableKey: desired.stableKey, name: desired.name, reason });
|
|
956
|
+
continue;
|
|
957
|
+
}
|
|
958
|
+
}
|
|
937
959
|
const desiredHash = hashPortableEndpoint(desired);
|
|
938
960
|
if (ambiguousTargetKeys.has(stableKey) || targetIssueKeys.has(stableKey)) {
|
|
939
961
|
continue;
|
|
@@ -1130,7 +1152,9 @@ async function resolveEndpointWritePayload(input) {
|
|
|
1130
1152
|
throw new Error(`execution dependency "${input.manifest.execution?.stableKey}" has no target component id`);
|
|
1131
1153
|
}
|
|
1132
1154
|
const options = endpointWriteOptions(input.manifest, schema);
|
|
1155
|
+
const executionPolicy = await runtimeExecutionPolicyPayload(input.client, input.manifest.executionPolicy, input.stableKeyName);
|
|
1133
1156
|
const common = {
|
|
1157
|
+
...(executionPolicy ? { executionPolicy } : {}),
|
|
1134
1158
|
name: input.manifest.name,
|
|
1135
1159
|
category: input.manifest.category ?? null,
|
|
1136
1160
|
desc: input.manifest.description ?? '',
|
|
@@ -1185,6 +1209,7 @@ async function verifyEndpointWrite(input) {
|
|
|
1185
1209
|
const targetComponents = await loadRemoteComponents(input.client);
|
|
1186
1210
|
const componentsById = new Map(targetComponents.map((component) => [componentIdOf(component), component]));
|
|
1187
1211
|
const verifiedManifest = await manifestFromRecord({
|
|
1212
|
+
includeExecutionPolicy: input.desiredManifest.executionPolicy !== undefined,
|
|
1188
1213
|
client: input.client,
|
|
1189
1214
|
record: verified,
|
|
1190
1215
|
stableKey: verifiedStableKey,
|
|
@@ -1316,6 +1341,7 @@ async function pushEndpointUpdate(input) {
|
|
|
1316
1341
|
}
|
|
1317
1342
|
const targetComponents = await loadRemoteComponents(input.client);
|
|
1318
1343
|
const targetManifest = await manifestFromRecord({
|
|
1344
|
+
includeExecutionPolicy: prepared.manifest.executionPolicy !== undefined,
|
|
1319
1345
|
client: input.client,
|
|
1320
1346
|
record: target,
|
|
1321
1347
|
stableKey: prepared.stableKey,
|
|
@@ -9,6 +9,9 @@ export type GroupManifest = {
|
|
|
9
9
|
owner?: {
|
|
10
10
|
type: 'service-account';
|
|
11
11
|
stableKey: string;
|
|
12
|
+
} | {
|
|
13
|
+
type: 'system';
|
|
14
|
+
stableKey?: never;
|
|
12
15
|
};
|
|
13
16
|
stableKey: string;
|
|
14
17
|
name: string;
|
|
@@ -47,7 +50,7 @@ export type GroupPlanItem = {
|
|
|
47
50
|
currentHash?: string;
|
|
48
51
|
baselineHash?: string;
|
|
49
52
|
ownerStableKey?: string;
|
|
50
|
-
ownerKind?: 'group' | 'service-account';
|
|
53
|
+
ownerKind?: 'group' | 'service-account' | 'system';
|
|
51
54
|
manual?: string[];
|
|
52
55
|
};
|
|
53
56
|
export type GroupsPlan = {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { accountPrincipal, serviceAccountMatches, ownerIsAvailable } from "./account-principal.js";
|
|
3
|
+
import { ownerFromPrincipal, resolveSystemAccount } from "./account-principal.js";
|
|
3
4
|
import { describeFieldChanges, formatDiffValue } from "../diff-details.js";
|
|
4
5
|
import { hashStable, readComponentLock, writeComponentLock, } from "../component-lock.js";
|
|
5
6
|
import { readConfiguredResourceMetadataStableKey, sanitizeUserMetadata, } from "../resource-metadata.js";
|
|
@@ -130,10 +131,9 @@ function validateManifest(manifest, stableKeyName) {
|
|
|
130
131
|
}
|
|
131
132
|
if (manifest.owner !== undefined && (!isRecord(manifest.owner)
|
|
132
133
|
|| Object.keys(manifest.owner).some((key) => key !== 'type' && key !== 'stableKey')
|
|
133
|
-
|| manifest.owner.type
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
errors.push('owner must contain a Service Account stableKey');
|
|
134
|
+
|| !(manifest.owner.type === 'system' && Object.keys(manifest.owner).length === 1
|
|
135
|
+
|| manifest.owner.type === 'service-account' && typeof manifest.owner.stableKey === 'string' && !!manifest.owner.stableKey.trim()))) {
|
|
136
|
+
errors.push('owner must contain a Service Account stableKey or a System reference');
|
|
137
137
|
}
|
|
138
138
|
if (isRecord(manifest.metadata) && Object.keys(manifest.metadata).some((key) => key.startsWith('__'))) {
|
|
139
139
|
errors.push('metadata must not contain backend-reserved keys');
|
|
@@ -168,7 +168,7 @@ async function sourceOwnerPolicy(input) {
|
|
|
168
168
|
const ownerId = typeof input.record.ownerId === 'string' ? input.record.ownerId.trim() : '';
|
|
169
169
|
if (ownerType === 'USER' && ownerId) {
|
|
170
170
|
const principal = await accountPrincipal(input.client, ownerId, input.stableKeyName);
|
|
171
|
-
return principal ?
|
|
171
|
+
return principal ? ownerFromPrincipal(principal) : { type: 'manual-user' };
|
|
172
172
|
}
|
|
173
173
|
if (ownerType === 'GROUP' && ownerId) {
|
|
174
174
|
const owner = input.recordsById.get(ownerId);
|
|
@@ -194,7 +194,7 @@ function resolveCreateDependencies(input) {
|
|
|
194
194
|
.filter((item) => item.status === 'manual-owner' && item.stableKey)
|
|
195
195
|
.map((item) => item.stableKey));
|
|
196
196
|
for (const item of createByKey.values()) {
|
|
197
|
-
if (item.ownerKind === 'service-account') {
|
|
197
|
+
if (item.ownerKind === 'service-account' || item.ownerKind === 'system') {
|
|
198
198
|
continue;
|
|
199
199
|
}
|
|
200
200
|
const ownerStableKey = item.ownerStableKey || '';
|
|
@@ -299,7 +299,7 @@ export async function buildGroupsPlan(input) {
|
|
|
299
299
|
if (record.ownerType === 'USER' && record.ownerId) {
|
|
300
300
|
const principal = await accountPrincipal(input.client, record.ownerId, input.stableKeyName);
|
|
301
301
|
if (principal) {
|
|
302
|
-
manifest.owner =
|
|
302
|
+
manifest.owner = ownerFromPrincipal(principal);
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
}
|
|
@@ -378,7 +378,7 @@ export async function buildGroupsPlan(input) {
|
|
|
378
378
|
});
|
|
379
379
|
}
|
|
380
380
|
else {
|
|
381
|
-
if (owner.type === 'service-account' && !await ownerIsAvailable(input.client, owner, input.stableKeyName, input.projectedIdentities)) {
|
|
381
|
+
if ((owner.type === 'service-account' || owner.type === 'system') && !await ownerIsAvailable(input.client, owner, input.stableKeyName, input.projectedIdentities)) {
|
|
382
382
|
blockers.push(`Group "${desired.stableKey}" service-account owner is missing or ambiguous.`);
|
|
383
383
|
items.push({ status: 'conflict', stableKey: desired.stableKey, name: desired.name, reason: 'service-account owner is missing or ambiguous' });
|
|
384
384
|
continue;
|
|
@@ -415,6 +415,17 @@ export async function buildGroupsPlan(input) {
|
|
|
415
415
|
let ownerChanged = false;
|
|
416
416
|
let ownerStableKey;
|
|
417
417
|
const desiredOwner = desired.owner || lockEntry?.owner;
|
|
418
|
+
if (desiredOwner?.type === 'system') {
|
|
419
|
+
try {
|
|
420
|
+
const system = await resolveSystemAccount(input.client);
|
|
421
|
+
ownerChanged = target.record.ownerType !== 'USER' || target.record.ownerId !== system.userId;
|
|
422
|
+
}
|
|
423
|
+
catch {
|
|
424
|
+
blockers.push(`Group "${desired.stableKey}" System owner is unavailable.`);
|
|
425
|
+
items.push({ status: 'conflict', stableKey: desired.stableKey, name: desired.name, reason: 'System owner is unavailable' });
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
418
429
|
if (desiredOwner?.type === 'service-account') {
|
|
419
430
|
ownerStableKey = desiredOwner.stableKey;
|
|
420
431
|
const matches = await serviceAccountMatches(input.client, ownerStableKey, input.stableKeyName);
|
|
@@ -465,6 +476,7 @@ export async function buildGroupsPlan(input) {
|
|
|
465
476
|
name: desired.name,
|
|
466
477
|
desiredHash,
|
|
467
478
|
currentHash: target.hash,
|
|
479
|
+
...(desiredOwner?.type === 'system' ? { ownerKind: 'system' } : {}),
|
|
468
480
|
...(ownerStableKey ? { ownerStableKey, ownerKind: desiredOwner?.type === 'service-account' ? 'service-account' : 'group' } : {}),
|
|
469
481
|
...(changedFields.length > 0 ? {
|
|
470
482
|
changedFields,
|
|
@@ -600,7 +612,7 @@ export async function pullGroupsToWorkspace(input) {
|
|
|
600
612
|
notices.push({ stableKey: manifest.stableKey, reason: `source members excluded: ${memberCount}` });
|
|
601
613
|
}
|
|
602
614
|
const owner = await sourceOwnerPolicy({ client: input.client, record, recordsById, stableKeyName: input.stableKeyName });
|
|
603
|
-
if (owner.type === 'service-account') {
|
|
615
|
+
if (owner.type === 'service-account' || owner.type === 'system') {
|
|
604
616
|
manifest.owner = owner;
|
|
605
617
|
}
|
|
606
618
|
if (owner.type === 'manual-user') {
|
|
@@ -779,6 +791,9 @@ function localManifestByStableKey(cwd) {
|
|
|
779
791
|
return new Map(readWorkspaceGroups(cwd).map((entry) => [entry.manifest.stableKey, entry]));
|
|
780
792
|
}
|
|
781
793
|
async function liveOwnerMatches(client, stableKeyName, item) {
|
|
794
|
+
if (item.ownerKind === 'system') {
|
|
795
|
+
return [{ groupId: String((await resolveSystemAccount(client)).userId) }];
|
|
796
|
+
}
|
|
782
797
|
if (item.ownerKind === 'service-account') {
|
|
783
798
|
return (await serviceAccountMatches(client, item.ownerStableKey || '', stableKeyName)).map((account) => ({ groupId: account.userId }));
|
|
784
799
|
}
|
|
@@ -873,7 +888,7 @@ export async function pushGroups(input) {
|
|
|
873
888
|
}
|
|
874
889
|
try {
|
|
875
890
|
await assertCreateStillSafe(input.client, input.stableKeyName, local.manifest);
|
|
876
|
-
const created = unwrapData(await input.client.createGroup(buildCreatePayload(local.manifest, ownerId, item.ownerKind === 'service-account' ? 'USER' : 'GROUP')));
|
|
891
|
+
const created = unwrapData(await input.client.createGroup(buildCreatePayload(local.manifest, ownerId, item.ownerKind === 'service-account' || item.ownerKind === 'system' ? 'USER' : 'GROUP')));
|
|
877
892
|
const createdId = groupIdOf(created);
|
|
878
893
|
if (!createdId) {
|
|
879
894
|
throw new Error('create response did not include groupId');
|
|
@@ -883,13 +898,13 @@ export async function pushGroups(input) {
|
|
|
883
898
|
if (verifiedManifest && local.manifest.owner && verified.ownerType === 'USER' && verified.ownerId) {
|
|
884
899
|
const principal = await accountPrincipal(input.client, verified.ownerId, input.stableKeyName);
|
|
885
900
|
if (principal) {
|
|
886
|
-
verifiedManifest.owner =
|
|
901
|
+
verifiedManifest.owner = ownerFromPrincipal(principal);
|
|
887
902
|
}
|
|
888
903
|
}
|
|
889
904
|
if (!verifiedManifest || hashPortableGroup(verifiedManifest) !== liveDesiredHash) {
|
|
890
905
|
throw new Error('created Group did not match desired portable hash');
|
|
891
906
|
}
|
|
892
|
-
if (String(verified.ownerType || '').toUpperCase() !== (item.ownerKind === 'service-account' ? 'USER' : 'GROUP') || verified.ownerId !== ownerId) {
|
|
907
|
+
if (String(verified.ownerType || '').toUpperCase() !== (item.ownerKind === 'service-account' || item.ownerKind === 'system' ? 'USER' : 'GROUP') || verified.ownerId !== ownerId) {
|
|
893
908
|
throw new Error('created Group did not retain the resolved target owner');
|
|
894
909
|
}
|
|
895
910
|
updateEnvironmentBaseline({ cwd: input.cwd, envName: input.envName, stableKey, remoteHash: liveDesiredHash });
|
|
@@ -941,14 +956,14 @@ export async function pushGroups(input) {
|
|
|
941
956
|
if (targetManifest && local.manifest.owner && target.ownerType === 'USER' && target.ownerId) {
|
|
942
957
|
const principal = await accountPrincipal(input.client, target.ownerId, input.stableKeyName);
|
|
943
958
|
if (principal) {
|
|
944
|
-
targetManifest.owner =
|
|
959
|
+
targetManifest.owner = ownerFromPrincipal(principal);
|
|
945
960
|
}
|
|
946
961
|
}
|
|
947
962
|
if (!targetManifest || hashPortableGroup(targetManifest) !== item.currentHash) {
|
|
948
963
|
throw new Error('target changed after planning');
|
|
949
964
|
}
|
|
950
965
|
let desiredOwnerId;
|
|
951
|
-
if (item.ownerStableKey) {
|
|
966
|
+
if (item.ownerStableKey || item.ownerKind === 'system') {
|
|
952
967
|
const ownerMatches = await liveOwnerMatches(input.client, input.stableKeyName, item);
|
|
953
968
|
if (ownerMatches.length !== 1) {
|
|
954
969
|
throw new Error(`expected one live target owner Group, found ${ownerMatches.length}`);
|
|
@@ -958,19 +973,19 @@ export async function pushGroups(input) {
|
|
|
958
973
|
throw new Error('live target owner Group did not include groupId');
|
|
959
974
|
}
|
|
960
975
|
}
|
|
961
|
-
await input.client.updateGroup(targetId, buildUpdatePayload(local.manifest, target, desiredOwnerId, item.ownerKind === 'service-account' ? 'USER' : 'GROUP'));
|
|
976
|
+
await input.client.updateGroup(targetId, buildUpdatePayload(local.manifest, target, desiredOwnerId, item.ownerKind === 'service-account' || item.ownerKind === 'system' ? 'USER' : 'GROUP'));
|
|
962
977
|
const verified = unwrapData(await input.client.getGroup(targetId));
|
|
963
978
|
const verifiedManifest = groupManifestFromRecord(verified, input.stableKeyName);
|
|
964
979
|
if (verifiedManifest && local.manifest.owner && verified.ownerType === 'USER' && verified.ownerId) {
|
|
965
980
|
const principal = await accountPrincipal(input.client, verified.ownerId, input.stableKeyName);
|
|
966
981
|
if (principal) {
|
|
967
|
-
verifiedManifest.owner =
|
|
982
|
+
verifiedManifest.owner = ownerFromPrincipal(principal);
|
|
968
983
|
}
|
|
969
984
|
}
|
|
970
985
|
if (!verifiedManifest || hashPortableGroup(verifiedManifest) !== liveDesiredHash) {
|
|
971
986
|
throw new Error('updated Group did not match desired portable hash');
|
|
972
987
|
}
|
|
973
|
-
if (desiredOwnerId && (String(verified.ownerType || '').toUpperCase() !== (item.ownerKind === 'service-account' ? 'USER' : 'GROUP')
|
|
988
|
+
if (desiredOwnerId && (String(verified.ownerType || '').toUpperCase() !== (item.ownerKind === 'service-account' || item.ownerKind === 'system' ? 'USER' : 'GROUP')
|
|
974
989
|
|| verified.ownerId !== desiredOwnerId)) {
|
|
975
990
|
throw new Error('updated Group did not retain the resolved target owner');
|
|
976
991
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RevoClient } from '../client.ts';
|
|
2
2
|
import { type GroupOwnerPolicy } from '../component-lock.ts';
|
|
3
|
-
import type
|
|
3
|
+
import { type IdentityProjection } from './account-principal.ts';
|
|
4
4
|
type IdentityNode = {
|
|
5
5
|
resource: 'group' | 'service-account';
|
|
6
6
|
stableKey: string;
|
|
@@ -3,6 +3,7 @@ import { readConfiguredResourceMetadataStableKey } from "../resource-metadata.js
|
|
|
3
3
|
import { readWorkspaceGroups } from "./group-sync.js";
|
|
4
4
|
import { readWorkspaceServiceAccounts } from "./service-account-sync.js";
|
|
5
5
|
import { requireProjectLayout, unwrapData } from "./util.js";
|
|
6
|
+
import { isBuiltinSystemAccount, resolveSystemAccount } from "./account-principal.js";
|
|
6
7
|
export async function planIdentityMigration(input) {
|
|
7
8
|
const { projectRoot } = requireProjectLayout(input.cwd, 'Identity migration');
|
|
8
9
|
const lock = readComponentLock(projectRoot);
|
|
@@ -20,6 +21,8 @@ export async function planIdentityMigration(input) {
|
|
|
20
21
|
const { serviceAccounts } = await input.client.listAllServiceAccounts();
|
|
21
22
|
for (const summary of serviceAccounts) {
|
|
22
23
|
const record = await input.client.getServiceAccount(String(summary.userId || ''));
|
|
24
|
+
if (isBuiltinSystemAccount(record))
|
|
25
|
+
continue;
|
|
23
26
|
const key = readConfiguredResourceMetadataStableKey(record, input.stableKeyName);
|
|
24
27
|
if (key) {
|
|
25
28
|
const k = id({ resource: 'service-account', stableKey: key });
|
|
@@ -41,6 +44,16 @@ export async function planIdentityMigration(input) {
|
|
|
41
44
|
}
|
|
42
45
|
}
|
|
43
46
|
const blockers = [];
|
|
47
|
+
let systemAvailable = false;
|
|
48
|
+
if (nodes.some(node => node.owner?.type === 'system')) {
|
|
49
|
+
try {
|
|
50
|
+
await resolveSystemAccount(input.client);
|
|
51
|
+
systemAvailable = true;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
blockers.push('The target built-in System owner is unavailable.');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
44
57
|
const byId = new Map();
|
|
45
58
|
for (const node of nodes) {
|
|
46
59
|
const key = id(node);
|
|
@@ -71,7 +84,13 @@ export async function planIdentityMigration(input) {
|
|
|
71
84
|
}
|
|
72
85
|
state.set(key, 'visiting');
|
|
73
86
|
const owner = node.owner;
|
|
74
|
-
if (owner?.type === '
|
|
87
|
+
if (owner?.type === 'system') {
|
|
88
|
+
if (!systemAvailable) {
|
|
89
|
+
state.set(key, 'blocked');
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else if (owner?.type === 'group' || owner?.type === 'service-account') {
|
|
75
94
|
const dependency = id({ resource: owner.type, stableKey: owner.stableKey });
|
|
76
95
|
const count = liveCounts.get(dependency) || 0;
|
|
77
96
|
if (count > 1) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ExecutionPrincipal } from './account-principal.ts';
|
|
1
|
+
import { type PortableExecutionPolicy, type ExecutionPrincipal } from './account-principal.ts';
|
|
2
2
|
import { type FieldChange } from '../diff-details.ts';
|
|
3
3
|
import type { RevoClient } from '../client.ts';
|
|
4
4
|
export declare const JOB_TEMPLATES_DIRECTORY = "JobTemplates";
|
|
@@ -14,6 +14,7 @@ export type JobTemplateManifest = {
|
|
|
14
14
|
stableKey: string;
|
|
15
15
|
};
|
|
16
16
|
executionPrincipal?: ExecutionPrincipal;
|
|
17
|
+
executionPolicy?: PortableExecutionPolicy;
|
|
17
18
|
timeout?: number;
|
|
18
19
|
options?: unknown;
|
|
19
20
|
inputs?: unknown;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { accountPrincipal,
|
|
2
|
+
import { accountPrincipal, resolveExecutionPrincipal, executionPrincipalAvailable, portableExecutionPolicy, runtimeExecutionPolicyPayload, validExecutionPrincipal, validPortableExecutionPolicy } from "./account-principal.js";
|
|
3
3
|
import { describeFieldChanges } from "../diff-details.js";
|
|
4
4
|
import { hashStable, readComponentLock, writeComponentLock } from "../component-lock.js";
|
|
5
5
|
import { normalizeStableKeyValue, readConfiguredResourceMetadataStableKey, sanitizeUserMetadata } from "../resource-metadata.js";
|
|
@@ -94,7 +94,7 @@ async function loadRemoteComponents(client) {
|
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
const JOB_TEMPLATE_MANIFEST_FIELDS = new Set([
|
|
97
|
-
'executionPrincipal',
|
|
97
|
+
'executionPrincipal', 'executionPolicy',
|
|
98
98
|
'kind', 'stableKey', 'name', 'category', 'description', 'metadata', 'component',
|
|
99
99
|
'timeout', 'options', 'inputs', 'migration',
|
|
100
100
|
]);
|
|
@@ -153,11 +153,12 @@ function validateManifest(manifest, stableKeyName) {
|
|
|
153
153
|
if (!isOptionalRecord(manifest.inputs, { nullable: true })) {
|
|
154
154
|
return false;
|
|
155
155
|
}
|
|
156
|
-
if (manifest.executionPrincipal !== undefined &&
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
if (manifest.executionPrincipal !== undefined && !validExecutionPrincipal(manifest.executionPrincipal))
|
|
157
|
+
return false;
|
|
158
|
+
if (manifest.executionPolicy !== undefined && !validPortableExecutionPolicy(manifest.executionPolicy))
|
|
159
|
+
return false;
|
|
160
|
+
if (manifest.executionPrincipal && manifest.executionPolicy)
|
|
159
161
|
return false;
|
|
160
|
-
}
|
|
161
162
|
if (!hasValidJobTemplateMigration(manifest.migration)) {
|
|
162
163
|
return false;
|
|
163
164
|
}
|
|
@@ -187,22 +188,28 @@ function manifestFromRecord(record, stableKey, componentKey, stableKeyName) {
|
|
|
187
188
|
...(record.inputs === undefined ? {} : { inputs: canonicalValue(record.inputs) }),
|
|
188
189
|
};
|
|
189
190
|
}
|
|
190
|
-
async function withRecordPrincipal(client, record, manifest, stableKeyName, compare) {
|
|
191
|
-
if (!compare
|
|
191
|
+
async function withRecordPrincipal(client, record, manifest, stableKeyName, compare, preferLegacy = false) {
|
|
192
|
+
if (!compare) {
|
|
192
193
|
return manifest;
|
|
193
194
|
}
|
|
195
|
+
const legacyEffective = record.triggerUser && (!record.executionPolicy || record.executionPolicy.mode === 'INHERIT');
|
|
196
|
+
if (record.executionPolicy && !legacyEffective) {
|
|
197
|
+
const policy = await portableExecutionPolicy(client, record.executionPolicy, stableKeyName);
|
|
198
|
+
return preferLegacy ? policy?.serviceAccount ? { ...manifest, executionPrincipal: policy.serviceAccount } : manifest
|
|
199
|
+
: { ...manifest, executionPolicy: policy };
|
|
200
|
+
}
|
|
201
|
+
if (!record.triggerUser)
|
|
202
|
+
return manifest;
|
|
194
203
|
const principal = await accountPrincipal(client, record.triggerUser, stableKeyName);
|
|
195
204
|
return principal ? { ...manifest, executionPrincipal: principal } : manifest;
|
|
196
205
|
}
|
|
197
|
-
async function targetPrincipalId(client, manifest, stableKeyName) {
|
|
198
|
-
if (
|
|
206
|
+
async function targetPrincipalId(client, manifest, stableKeyName, target) {
|
|
207
|
+
if (manifest.executionPolicy)
|
|
208
|
+
return { executionPolicy: await runtimeExecutionPolicyPayload(client, manifest.executionPolicy, stableKeyName), triggerUser: null };
|
|
209
|
+
if (!manifest.executionPrincipal)
|
|
199
210
|
return {};
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
if (matches.length !== 1 || !matches[0].userId) {
|
|
203
|
-
throw new Error('Execution principal must resolve to exactly one target service account.');
|
|
204
|
-
}
|
|
205
|
-
return { triggerUser: matches[0].userId };
|
|
211
|
+
return { triggerUser: await resolveExecutionPrincipal(client, manifest.executionPrincipal, stableKeyName),
|
|
212
|
+
...(target?.executionPolicy && target.executionPolicy.mode !== 'INHERIT' ? { executionPolicy: { mode: 'INHERIT' } } : {}) };
|
|
206
213
|
}
|
|
207
214
|
function buildCreatePayload(manifest, componentId) {
|
|
208
215
|
return {
|
|
@@ -240,6 +247,7 @@ export function hashPortableJobTemplate(manifest) {
|
|
|
240
247
|
metadata: canonicalValue(manifest.metadata),
|
|
241
248
|
component: { stableKey: manifest.component.stableKey },
|
|
242
249
|
...(manifest.executionPrincipal ? { executionPrincipal: manifest.executionPrincipal } : {}),
|
|
250
|
+
...(manifest.executionPolicy ? { executionPolicy: manifest.executionPolicy } : {}),
|
|
243
251
|
...(manifest.timeout === undefined ? {} : { timeout: manifest.timeout }),
|
|
244
252
|
...(options === undefined ? {} : { options }),
|
|
245
253
|
...(manifest.inputs === undefined ? {} : { inputs: canonicalJobTemplateInputs(manifest.inputs) }),
|
|
@@ -253,6 +261,7 @@ function diffJobTemplates(desired, target) {
|
|
|
253
261
|
['metadata', canonicalValue(desired.metadata), canonicalValue(target.metadata)],
|
|
254
262
|
['component.stableKey', desired.component.stableKey, target.component.stableKey],
|
|
255
263
|
...(desired.executionPrincipal ? [['executionPrincipal', desired.executionPrincipal, target.executionPrincipal]] : []),
|
|
264
|
+
...(desired.executionPolicy ? [['executionPolicy', desired.executionPolicy, target.executionPolicy]] : []),
|
|
256
265
|
['timeout', desired.timeout, target.timeout],
|
|
257
266
|
[
|
|
258
267
|
'options',
|
|
@@ -397,7 +406,7 @@ export async function buildJobTemplatesPlan(input) {
|
|
|
397
406
|
items.push({ status: 'conflict', stableKey, name: String(record.name || ''), reason });
|
|
398
407
|
continue;
|
|
399
408
|
}
|
|
400
|
-
const manifest = await withRecordPrincipal(input.client, record, manifestFromRecord(record, stableKey, componentKey, input.stableKeyName), input.stableKeyName, localEntries.some((entry) => entry.manifest.stableKey === stableKey && Boolean(entry.manifest.executionPrincipal)));
|
|
409
|
+
const manifest = await withRecordPrincipal(input.client, record, manifestFromRecord(record, stableKey, componentKey, input.stableKeyName), input.stableKeyName, localEntries.some((entry) => entry.manifest.stableKey === stableKey && Boolean(entry.manifest.executionPrincipal || entry.manifest.executionPolicy)), localEntries.some(entry => entry.manifest.stableKey === stableKey && Boolean(entry.manifest.executionPrincipal)));
|
|
401
410
|
targetByKey.set(stableKeyIdentity, [{
|
|
402
411
|
record,
|
|
403
412
|
manifest,
|
|
@@ -419,7 +428,7 @@ export async function buildJobTemplatesPlan(input) {
|
|
|
419
428
|
continue;
|
|
420
429
|
}
|
|
421
430
|
const lockEntry = lockEntriesByKey.get(stableKeyIdentity);
|
|
422
|
-
if (!desired.executionPrincipal && (desired.migration?.executionPrincipal === 'excluded' || lockEntry?.migration?.executionPrincipal === 'excluded')) {
|
|
431
|
+
if (!desired.executionPrincipal && !desired.executionPolicy && (desired.migration?.executionPrincipal === 'excluded' || lockEntry?.migration?.executionPrincipal === 'excluded')) {
|
|
423
432
|
warnings.push(`Job template "${desired.stableKey}": execution principal excluded; manual target execution principal configuration is required.`);
|
|
424
433
|
}
|
|
425
434
|
if (desired.migration?.componentBinding === 'pinned-unsupported' || lockEntry?.migration?.componentBinding === 'pinned-unsupported') {
|
|
@@ -460,14 +469,11 @@ export async function buildJobTemplatesPlan(input) {
|
|
|
460
469
|
...(projectedDependency ? { componentDesiredHash: projectedDependency.desiredHash } : {}),
|
|
461
470
|
dependencyReadiness,
|
|
462
471
|
};
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
items.push({ status: 'conflict', stableKey: desired.stableKey, name: desired.name, reason: 'execution principal is missing or ambiguous' });
|
|
469
|
-
continue;
|
|
470
|
-
}
|
|
472
|
+
const executor = desired.executionPolicy?.serviceAccount || desired.executionPrincipal;
|
|
473
|
+
if (executor && !await executionPrincipalAvailable(input.client, executor, input.stableKeyName, input.projectedServiceAccounts, Boolean(desired.executionPolicy))) {
|
|
474
|
+
blockers.push(`Job template "${desired.stableKey}" execution principal is unavailable or ambiguous.`);
|
|
475
|
+
items.push({ status: 'conflict', stableKey: desired.stableKey, name: desired.name, reason: 'execution principal is unavailable or ambiguous' });
|
|
476
|
+
continue;
|
|
471
477
|
}
|
|
472
478
|
const desiredHash = hashPortableJobTemplate(desired);
|
|
473
479
|
const matches = targetByKey.get(stableKeyIdentity) || [];
|
|
@@ -530,7 +536,7 @@ export async function buildJobTemplatesPlan(input) {
|
|
|
530
536
|
});
|
|
531
537
|
for (const item of items) {
|
|
532
538
|
const desired = localEntries.find((entry) => entry.manifest.stableKey === item.stableKey)?.manifest;
|
|
533
|
-
if (!desired?.executionPrincipal && (desired?.migration?.executionPrincipal === 'excluded'
|
|
539
|
+
if (!desired?.executionPrincipal && !desired?.executionPolicy && (desired?.migration?.executionPrincipal === 'excluded'
|
|
534
540
|
|| lockEntriesByKey.get(item.stableKey || '')?.migration?.executionPrincipal === 'excluded')) {
|
|
535
541
|
item.manual = ['Configure target-local execution principal manually'];
|
|
536
542
|
}
|
|
@@ -578,7 +584,7 @@ export async function pullJobTemplatesToWorkspace(input) {
|
|
|
578
584
|
}
|
|
579
585
|
const migration = {
|
|
580
586
|
...(typeof record.componentVersion === 'number' ? { componentBinding: 'pinned-unsupported' } : {}),
|
|
581
|
-
...(record.triggerUser && !await accountPrincipal(input.client, record.triggerUser, input.stableKeyName) ? { executionPrincipal: 'excluded' } : {}),
|
|
587
|
+
...(record.triggerUser && (!record.executionPolicy || record.executionPolicy.mode === 'INHERIT') && !await accountPrincipal(input.client, record.triggerUser, input.stableKeyName) ? { executionPrincipal: 'excluded' } : {}),
|
|
582
588
|
};
|
|
583
589
|
manifests.push({
|
|
584
590
|
...await withRecordPrincipal(input.client, record, manifestFromRecord(record, stableKey, dependencyStableKey, input.stableKeyName), input.stableKeyName, true),
|
|
@@ -777,7 +783,7 @@ export async function pushJobTemplates(input) {
|
|
|
777
783
|
const verifiedComponentKey = await componentStableKey({ client: input.client, record: verified, stableKeyName: input.stableKeyName });
|
|
778
784
|
if (!verifiedComponentKey)
|
|
779
785
|
throw new Error(`created job template references a component without ${input.stableKeyName}`);
|
|
780
|
-
const verifiedManifest = await withRecordPrincipal(input.client, verified, manifestFromRecord(verified, verifiedStableKey, verifiedComponentKey, input.stableKeyName), input.stableKeyName, Boolean(prepared.manifest.executionPrincipal));
|
|
786
|
+
const verifiedManifest = await withRecordPrincipal(input.client, verified, manifestFromRecord(verified, verifiedStableKey, verifiedComponentKey, input.stableKeyName), input.stableKeyName, Boolean(prepared.manifest.executionPrincipal || prepared.manifest.executionPolicy), Boolean(prepared.manifest.executionPrincipal));
|
|
781
787
|
if (hashPortableJobTemplate(verifiedManifest) !== prepared.desiredHash) {
|
|
782
788
|
throw new Error('created job template did not match desired portable hash');
|
|
783
789
|
}
|
|
@@ -846,7 +852,7 @@ export async function pushJobTemplates(input) {
|
|
|
846
852
|
const targetComponentKey = await componentStableKey({ client: input.client, record: target, stableKeyName: input.stableKeyName });
|
|
847
853
|
if (!targetComponentKey)
|
|
848
854
|
throw new Error(`target dependency is missing ${input.stableKeyName}`);
|
|
849
|
-
const targetManifest = await withRecordPrincipal(input.client, target, manifestFromRecord(target, targetStableKey, targetComponentKey, input.stableKeyName), input.stableKeyName, Boolean(local.manifest.executionPrincipal));
|
|
855
|
+
const targetManifest = await withRecordPrincipal(input.client, target, manifestFromRecord(target, targetStableKey, targetComponentKey, input.stableKeyName), input.stableKeyName, Boolean(local.manifest.executionPrincipal || local.manifest.executionPolicy), Boolean(local.manifest.executionPrincipal));
|
|
850
856
|
const targetHash = hashPortableJobTemplate(targetManifest);
|
|
851
857
|
if (targetHash !== item.currentHash)
|
|
852
858
|
throw new Error('target changed after planning');
|
|
@@ -876,7 +882,7 @@ export async function pushJobTemplates(input) {
|
|
|
876
882
|
const componentId = componentIdOf(componentMatches[0]);
|
|
877
883
|
if (!componentId)
|
|
878
884
|
throw new Error(`dependency "${local.manifest.component.stableKey}" has no target component id`);
|
|
879
|
-
await input.client.updateJobTemplate(targetId, { ...buildUpdatePayload(local.manifest, componentId, target.version), ...await targetPrincipalId(input.client, local.manifest, input.stableKeyName) });
|
|
885
|
+
await input.client.updateJobTemplate(targetId, { ...buildUpdatePayload(local.manifest, componentId, target.version), ...await targetPrincipalId(input.client, local.manifest, input.stableKeyName, target) });
|
|
880
886
|
const verified = unwrapData(await input.client.getJobTemplate(targetId));
|
|
881
887
|
const verifiedStableKey = readConfiguredResourceMetadataStableKey(verified, input.stableKeyName);
|
|
882
888
|
if (verifiedStableKey !== stableKey)
|
|
@@ -884,7 +890,7 @@ export async function pushJobTemplates(input) {
|
|
|
884
890
|
const verifiedComponentKey = await componentStableKey({ client: input.client, record: verified, stableKeyName: input.stableKeyName });
|
|
885
891
|
if (!verifiedComponentKey)
|
|
886
892
|
throw new Error(`updated target dependency is missing ${input.stableKeyName}`);
|
|
887
|
-
const verifiedManifest = await withRecordPrincipal(input.client, verified, manifestFromRecord(verified, verifiedStableKey, verifiedComponentKey, input.stableKeyName), input.stableKeyName, Boolean(local.manifest.executionPrincipal));
|
|
893
|
+
const verifiedManifest = await withRecordPrincipal(input.client, verified, manifestFromRecord(verified, verifiedStableKey, verifiedComponentKey, input.stableKeyName), input.stableKeyName, Boolean(local.manifest.executionPrincipal || local.manifest.executionPolicy), Boolean(local.manifest.executionPrincipal));
|
|
888
894
|
if (hashPortableJobTemplate(verifiedManifest) !== desiredHash) {
|
|
889
895
|
throw new Error('updated job template did not match desired portable hash');
|
|
890
896
|
}
|