@revoengine/cli 1.0.18 → 1.0.20

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.
@@ -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 !== 'service-account'
134
- || typeof manifest.owner.stableKey !== 'string'
135
- || !manifest.owner.stableKey.trim())) {
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 ? { type: 'service-account', stableKey: principal.stableKey } : { type: 'manual-user' };
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 = { type: 'service-account', stableKey: principal.stableKey };
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 = { type: 'service-account', stableKey: principal.stableKey };
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 = { type: 'service-account', stableKey: principal.stableKey };
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 = { type: 'service-account', stableKey: principal.stableKey };
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 { IdentityProjection } from './account-principal.ts';
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 === 'group' || owner?.type === 'service-account') {
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, serviceAccountMatches } from "./account-principal.js";
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 && (!isRecord(manifest.executionPrincipal)
157
- || !hasOnlyKeys(manifest.executionPrincipal, new Set(['kind', 'stableKey']))
158
- || manifest.executionPrincipal.kind !== 'service-account' || !isNonEmptyString(manifest.executionPrincipal.stableKey))) {
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 || !record.triggerUser) {
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 (!manifest.executionPrincipal) {
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
- const matches = await serviceAccountMatches(client, manifest.executionPrincipal.stableKey, stableKeyName);
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
- if (desired.executionPrincipal) {
464
- const key = desired.executionPrincipal.stableKey;
465
- const liveMatches = await serviceAccountMatches(input.client, key, input.stableKeyName);
466
- if (liveMatches.length > 1 || (liveMatches.length === 0 && !(input.projectedServiceAccounts || []).includes(key))) {
467
- blockers.push(`Job template "${desired.stableKey}" execution principal "${key}" is missing or ambiguous.`);
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
  }
@@ -1,5 +1,6 @@
1
1
  import path from 'node:path';
2
2
  import { readPortableOwner, resolvePortableOwner, ownerIsAvailable } from "./account-principal.js";
3
+ import { isBuiltinSystemAccount } from "./account-principal.js";
3
4
  import { describeFieldChanges } from "../diff-details.js";
4
5
  import { hashStable, readComponentLock, writeComponentLock, } from "../component-lock.js";
5
6
  import { readConfiguredResourceMetadataStableKey, sanitizeUserMetadata, } from "../resource-metadata.js";
@@ -12,6 +13,8 @@ function serviceAccountIdOf(record) {
12
13
  return String(record.userId || '');
13
14
  }
14
15
  export async function serviceAccountManifestFromRecord(client, record, stableKeyName) {
16
+ if (isBuiltinSystemAccount(record))
17
+ return null;
15
18
  const stableKey = readConfiguredResourceMetadataStableKey(record, stableKeyName);
16
19
  if (!stableKey) {
17
20
  return null;
@@ -21,26 +24,43 @@ export async function serviceAccountManifestFromRecord(client, record, stableKey
21
24
  stableKey,
22
25
  name: String(record.name || ''),
23
26
  metadata: { [stableKeyName]: stableKey },
24
- owner: await readPortableOwner(client, record, stableKeyName),
27
+ owner: await readManagementPrincipal(client, record, stableKeyName),
25
28
  };
26
29
  }
30
+ async function readManagementPrincipal(client, record, stableKeyName) {
31
+ // The manifest's portable owner now represents one management ACL principal.
32
+ // Self access is target-local and never creates a dependency on the account itself.
33
+ if (!record.access)
34
+ return readPortableOwner(client, record, stableKeyName);
35
+ const { restricted, users, groups } = record.access;
36
+ if (typeof restricted !== 'boolean' || !Array.isArray(users) || !Array.isArray(groups)) {
37
+ throw new Error('Invalid service-account management access response.');
38
+ }
39
+ const managers = users.filter(user => user.userId !== record.userId);
40
+ if (!restricted || managers.length + groups.length !== 1) {
41
+ return { type: 'unresolved', reason: 'unrestricted or multiple management principals require target-local configuration' };
42
+ }
43
+ return readPortableOwner(client, groups.length
44
+ ? { ownerType: 'GROUP', ownerId: groups[0].groupId }
45
+ : { ownerType: 'USER', ownerId: managers[0].userId }, stableKeyName);
46
+ }
27
47
  export function hashPortableServiceAccount(manifest) {
28
48
  return hashStable({ kind: manifest.kind, stableKey: manifest.stableKey, name: manifest.name, metadata: manifest.metadata,
29
- ...(['group', 'service-account'].includes(manifest.owner.type) ? { owner: manifest.owner } : {}) });
49
+ ...(['group', 'service-account', 'system'].includes(manifest.owner.type) ? { owner: manifest.owner } : {}) });
30
50
  }
31
51
  function serviceAccountHint(value) {
32
52
  return String(value.name || '').trim().toLowerCase();
33
53
  }
34
54
  function diffServiceAccounts(desired, target) {
35
55
  return { changedFields: ['name', 'metadata', 'owner'].filter((field) => {
36
- if (field === 'owner' && !['group', 'service-account'].includes(desired.owner.type)) {
56
+ if (field === 'owner' && !['group', 'service-account', 'system'].includes(desired.owner.type)) {
37
57
  return false;
38
58
  }
39
59
  return hashStable(desired[field]) !== hashStable(target[field]);
40
60
  }) };
41
61
  }
42
62
  function comparableManifest(desired, target) {
43
- return ['group', 'service-account'].includes(desired.owner.type) ? target : { ...target, owner: desired.owner };
63
+ return ['group', 'service-account', 'system'].includes(desired.owner.type) ? target : { ...target, owner: desired.owner };
44
64
  }
45
65
  export function serviceAccountManifestPath(workspaceRoot, manifest) {
46
66
  return path.join(workspaceRoot, SERVICE_ACCOUNTS_DIRECTORY, `${sanitizeSegment(manifest.name)}-${stableKeySuffix(manifest.stableKey)}`, SERVICE_ACCOUNT_MANIFEST_FILE);
@@ -80,13 +100,15 @@ function validateManifest(manifest, stableKeyName) {
80
100
  || !isRecord(manifest.metadata)) {
81
101
  errors.push('manifest must contain kind, stableKey, name and metadata');
82
102
  }
83
- if (!isRecord(manifest.owner) || !['group', 'service-account', 'manual-user', 'unresolved'].includes(String(manifest.owner.type))) {
103
+ if (!isRecord(manifest.owner) || !['group', 'service-account', 'system', 'manual-user', 'unresolved'].includes(String(manifest.owner.type))) {
84
104
  errors.push('owner must contain a portable owner policy');
85
105
  }
86
106
  else if (['group', 'service-account'].includes(String(manifest.owner.type))
87
107
  && (typeof manifest.owner.stableKey !== 'string' || !manifest.owner.stableKey.trim())) {
88
108
  errors.push('portable owner requires stableKey');
89
109
  }
110
+ if (isRecord(manifest.owner) && manifest.owner.type === 'system' && Object.keys(manifest.owner).length !== 1)
111
+ errors.push('System owner contains unsupported fields');
90
112
  if (isRecord(manifest.owner) && Object.keys(manifest.owner).some((key) => !['type', 'stableKey', 'reason'].includes(key))) {
91
113
  errors.push('owner contains unsupported fields');
92
114
  }
@@ -177,9 +199,9 @@ export async function buildServiceAccountsPlan(input) {
177
199
  items.push({ status: 'collision', stableKey: desired.stableKey, name: desired.name, reason: 'duplicate target stableKey', desiredHash });
178
200
  continue;
179
201
  }
180
- if (desired.owner.type === 'group' || desired.owner.type === 'service-account') {
202
+ if (desired.owner.type === 'group' || desired.owner.type === 'service-account' || desired.owner.type === 'system') {
181
203
  if (!await ownerIsAvailable(input.client, desired.owner, input.stableKeyName, projectedIdentities)) {
182
- blockers.push(`Service account "${desired.stableKey}" owner "${desired.owner.stableKey}" is missing or ambiguous.`);
204
+ blockers.push(`Service account "${desired.stableKey}" owner "${desired.owner.type === 'system' ? 'System' : desired.owner.stableKey}" is missing or ambiguous.`);
183
205
  items.push({ status: 'conflict', stableKey: desired.stableKey, name: desired.name, desiredHash, reason: 'owner is missing or ambiguous' });
184
206
  continue;
185
207
  }
@@ -256,7 +278,7 @@ export async function buildServiceAccountsPlan(input) {
256
278
  if (consumedUnmanaged.has(record)) {
257
279
  continue;
258
280
  }
259
- items.push({ status: 'skipped', name: String(record.name || 'unknown'), reason: `missing ${input.stableKeyName}; unmanaged` });
281
+ items.push({ status: 'skipped', name: String(record.name || 'unknown'), reason: isBuiltinSystemAccount(record) ? 'built-in System account is managed by the platform' : `missing ${input.stableKeyName}; unmanaged` });
260
282
  }
261
283
  const rank = {
262
284
  create: 0,
@@ -295,7 +317,7 @@ export async function pullServiceAccountsToWorkspace(input) {
295
317
  const manifest = await serviceAccountManifestFromRecord(input.client, record, input.stableKeyName);
296
318
  if (!manifest) {
297
319
  const name = String(record.name || serviceAccountIdOf(record) || 'unknown');
298
- skipped.push({ name, targetPath: name, reason: `missing ${input.stableKeyName}; unmanaged` });
320
+ skipped.push({ name, targetPath: name, reason: isBuiltinSystemAccount(record) ? 'built-in System account is managed by the platform' : `missing ${input.stableKeyName}; unmanaged` });
299
321
  continue;
300
322
  }
301
323
  const errors = validateManifest(manifest, input.stableKeyName);
@@ -427,15 +449,35 @@ export async function pullServiceAccountsToWorkspace(input) {
427
449
  skipped,
428
450
  };
429
451
  }
452
+ async function managementAccessPayload(client, manifest, stableKeyName, target) {
453
+ if (target?.access) {
454
+ const managers = target.access.users.filter(user => user.userId !== target.userId);
455
+ if (!target.access.restricted || managers.length + target.access.groups.length !== 1) {
456
+ throw new Error('Target management ACL requires target-local configuration; portable owner cannot replace unrestricted or multiple principals.');
457
+ }
458
+ }
459
+ const principal = await resolvePortableOwner(client, manifest.owner, stableKeyName);
460
+ // Preserve an existing self grant without transferring its source UUID.
461
+ const users = target?.userId && target.access?.users.some(user => user.userId === target.userId)
462
+ ? [{ id: target.userId }] : [];
463
+ const groups = [];
464
+ (principal.ownerType === 'USER' ? users : groups).push({ id: principal.ownerId });
465
+ return { restricted: true, users, groups };
466
+ }
430
467
  async function buildCreatePayload(client, manifest, stableKeyName) {
431
- return { name: manifest.name, metadata: manifest.metadata, ...await resolvePortableOwner(client, manifest.owner, stableKeyName) };
468
+ return { name: manifest.name, metadata: manifest.metadata, access: await managementAccessPayload(client, manifest, stableKeyName) };
432
469
  }
433
470
  async function buildBaseUpdatePayload(client, manifest, target, stableKeyName) {
471
+ if (isBuiltinSystemAccount(target))
472
+ throw new Error('The built-in System account cannot be updated by workspace synchronization.');
434
473
  if (!Number.isInteger(target.version)) {
435
474
  throw new Error('target service-account version is required');
436
475
  }
476
+ const ownerChanged = ['group', 'service-account', 'system'].includes(manifest.owner.type)
477
+ && hashStable(manifest.owner) !== hashStable(await readManagementPrincipal(client, target, stableKeyName));
437
478
  return { name: manifest.name, metadata: { ...sanitizeUserMetadata(target.metadata), ...manifest.metadata }, version: target.version,
438
- ...(['group', 'service-account'].includes(manifest.owner.type) ? await resolvePortableOwner(client, manifest.owner, stableKeyName) : {}) };
479
+ ...(ownerChanged
480
+ ? { access: await managementAccessPayload(client, manifest, stableKeyName, target) } : {}) };
439
481
  }
440
482
  function updateEnvironmentBaseline(input) {
441
483
  const { projectRoot } = requireProjectLayout(input.cwd, 'Service-account');
@@ -110,6 +110,11 @@ export type DatabaseViewRecord = {
110
110
  deletedBy?: string | null;
111
111
  [key: string]: unknown;
112
112
  };
113
+ export type RuntimeExecutionPolicy = {
114
+ mode: 'INHERIT' | 'CALLER' | 'SERVICE_ACCOUNT';
115
+ serviceAccountUserId?: string;
116
+ currentUser?: 'INHERIT' | 'CALLER' | 'EXECUTION_ACCOUNT';
117
+ };
113
118
  export type EndpointOptions = {
114
119
  input?: Record<string, unknown>;
115
120
  guard?: Record<string, unknown>;
@@ -133,6 +138,7 @@ export type EndpointOptions = {
133
138
  [key: string]: unknown;
134
139
  };
135
140
  export type EndpointRecord = {
141
+ executionPolicy?: RuntimeExecutionPolicy | null;
136
142
  endpointId?: string;
137
143
  id?: string;
138
144
  name?: string;
@@ -159,11 +165,31 @@ export type EndpointRecord = {
159
165
  deletedBy?: string | null;
160
166
  [key: string]: unknown;
161
167
  };
168
+ export type ServiceAccountAccessRecord = {
169
+ restricted: boolean;
170
+ users: Array<{
171
+ userId: string;
172
+ mail?: string;
173
+ name?: string;
174
+ }>;
175
+ groups: Array<{
176
+ groupId: string;
177
+ name?: string;
178
+ }>;
179
+ };
162
180
  export type ServiceAccountRecord = {
181
+ status?: number | string;
182
+ platformAccess?: boolean;
183
+ deletedBy?: string | null;
163
184
  category?: string | null;
164
185
  userId?: string;
165
186
  name?: string;
166
187
  serviceAccount?: boolean;
188
+ access?: ServiceAccountAccessRecord;
189
+ memberships?: {
190
+ groups: string[];
191
+ roleGroups: string[];
192
+ };
167
193
  ownerId?: string;
168
194
  ownerType?: string;
169
195
  version?: number;
@@ -211,6 +237,7 @@ export type GroupRecord = {
211
237
  [key: string]: unknown;
212
238
  };
213
239
  export type JobTemplateRecord = {
240
+ executionPolicy?: RuntimeExecutionPolicy | null;
214
241
  jobTemplateId?: string;
215
242
  id?: string;
216
243
  name?: string;
package/dist/src/ui.js CHANGED
@@ -130,7 +130,7 @@ function renderCommandCatalog() {
130
130
  commandRow('revo component pull --all [--project <name>] [--yes] [--force]', 'Pull every available component safely'),
131
131
  commandRow('revo component push <identity...> [--project <name>]', 'Push by configured stable key or component ID'),
132
132
  commandRow('revo component push --all [--project <name>] [--yes] [--force] [--prune] [--changed --base <ref>]', 'Push local components with lock checks'),
133
- commandRow('revo component debug <componentId> [BODY] [--stream] [--raw-debug]', 'Debug one local component against sandbox'),
133
+ commandRow('revo component debug <componentId> [BODY] [--read-only=true|false] [--stream]', 'Run one local component in sandbox'),
134
134
  '',
135
135
  paintHeader('Databases'),
136
136
  commandRow('revo database-tables pull --all [--project <name>] [--force] [--strict]', 'Pull portable Database Tables and partitions'),