@revoengine/cli 1.0.19 → 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.
- package/README.md +27 -1
- package/dist/src/client.d.ts +6 -2
- package/dist/src/client.js +1 -1
- package/dist/src/component-lock.d.ts +3 -0
- package/dist/src/component-lock.js +7 -5
- package/dist/src/metadata-backfill.js +9 -0
- package/dist/src/migration.js +1 -0
- 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/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/types.d.ts +10 -0
- package/dist/src/workspace-prune.js +6 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @revoengine/cli
|
|
2
2
|
|
|
3
|
+
Development and GitLab CI use Node.js 24.21.0. Run `nvm use` in this repository to select the checked-in `.nvmrc`.
|
|
4
|
+
|
|
3
5
|
Official command-line interface for moving RevoEngine configuration between an instance, a Git repository, and another instance.
|
|
4
6
|
|
|
5
7
|
The CLI has three main capabilities:
|
|
@@ -562,8 +564,9 @@ The same family is included in `revo pull --all`, repository `diff`/`plan`/`depl
|
|
|
562
564
|
Select it alone with `--resources service-account`. Named profiles (`--project`/`--env`), URL/token environment variables,
|
|
563
565
|
and the ordinary authenticated runtime work through the existing config resolution. `--force` retains the existing drift policy.
|
|
564
566
|
|
|
565
|
-
The portable manifest contains the Stable Key, name, and a single Group
|
|
567
|
+
The portable manifest contains the Stable Key, name, and a single Group, Service Account or built-in System management principal. The manifest field `owner` remains the portable dependency policy; Platform 1.6.4 writes it as a restricted management `access` ACL, with target UUIDs and no legacy `ownerId`/`ownerType` fields.
|
|
566
568
|
Group USER owners and Job Template `triggerUser` references to Service Accounts are resolved to target `userId` at write time.
|
|
569
|
+
Use `owner: { "type": "system" }` for a Group or Service Account managed by the physical built-in System account. The CLI reads the target account with UUID `00000000-0000-0000-0000-000000000000` and verifies `serviceAccount: true` and active state before any dependent write; an unmigrated instance is blocked. System itself is never exported as a managed account, assigned a Stable Key, updated or pruned. An ordinary account named System remains managed through its own Stable Key.
|
|
567
570
|
Human principals are reported for manual configuration; an account with a human owner needs a target account with the exact Stable Key before it can be adopted.
|
|
568
571
|
A missing or circular owner dependency blocks writes. Groups and accounts are created in dependency order before their consumers.
|
|
569
572
|
|
|
@@ -571,3 +574,26 @@ API keys and secrets cannot be exported. Every newly created Service Account is
|
|
|
571
574
|
The push result contains `credentials: { stableKey, environment, policy: "target-local", status: "configure-manually" }`.
|
|
572
575
|
Existing target secrets remain local and are never compared, copied, rotated, or exposed in manifests, plans, lock files, or HTTP trace.
|
|
573
576
|
Execution memberships, unrestricted or multiple-principal management ACLs, other account metadata, and `metadataAdvanced` remain target-local. Existing self access is preserved when a portable management principal changes; name/metadata updates omit the ACL. Complex target ACLs cannot be replaced through the single-principal manifest, including with `--force`.
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
## Runtime execution policies
|
|
580
|
+
|
|
581
|
+
Endpoint `execution` still identifies its Component. The separate optional `executionPolicy` selects runtime authority and, for Endpoints, the account exposed through `api.currentUser`:
|
|
582
|
+
|
|
583
|
+
```json
|
|
584
|
+
{
|
|
585
|
+
"executionPolicy": {
|
|
586
|
+
"mode": "SERVICE_ACCOUNT",
|
|
587
|
+
"serviceAccount": { "kind": "system" },
|
|
588
|
+
"currentUser": "CALLER"
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
A normal Service Account uses `serviceAccount: { "kind": "service-account", "stableKey": "Ops/Robot#abc12345" }`. The target account must be active and have platform access. Plans include accounts created earlier in a multi-resource migration; writes resolve fresh target IDs and account state. The manifest and lock contain portable references, never source account UUIDs.
|
|
594
|
+
|
|
595
|
+
Both Endpoints and Job Templates accept `mode: "INHERIT"`, `"CALLER"` or `"SERVICE_ACCOUNT"`. Non-Service Account modes omit `serviceAccount`. Endpoint `currentUser` independently accepts `"INHERIT"`, `"CALLER"` or `"EXECUTION_ACCOUNT"`. Job Templates expose the executor through `api.currentUser` and record the initiator separately; unattended jobs require a Service Account. Set instance defaults in **Settings > Endpoints**. Instance settings are target-local and are not copied by resource migration.
|
|
596
|
+
|
|
597
|
+
Job Template manifests retain the legacy `executionPrincipal` reference for existing definitions, including `{ "kind": "system" }`. Use either this field or `executionPolicy`, never both. Writing an explicit policy clears the legacy `triggerUser` alias. Definitions without either field retain target-local execution configuration. An explicit policy pointing to a human or an unkeyed ordinary account cannot be exported as a portable definition.
|
|
598
|
+
|
|
599
|
+
Selecting System or another instance administrator execution account approves the current instance Component and library code. Later source changes require administrator approval; ordinary editors cannot replace approved code silently. Authority selection preserves the caller in the audit trail.
|
package/dist/src/client.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RuntimeExecutionPolicy } from './types.ts';
|
|
1
2
|
import { RequestQueue } from './request-queue.ts';
|
|
2
3
|
import type { ComponentRecord, DatabaseSchemaRecord, DatabaseViewRecord, EndpointRecord, EventRecord, GroupRecord, JobTemplateRecord, RoleGroupRecord, ServiceAccountRecord, ScheduleRecord } from './types.ts';
|
|
3
4
|
import type { TrackableResourceType } from './tracked-resources.ts';
|
|
@@ -123,6 +124,7 @@ export type DatabaseViewUpdatePayload = {
|
|
|
123
124
|
});
|
|
124
125
|
export type EndpointListRequest = ComponentListRequest;
|
|
125
126
|
export type EndpointWritePayload = {
|
|
127
|
+
executionPolicy?: RuntimeExecutionPolicy;
|
|
126
128
|
version: number;
|
|
127
129
|
metadata: Record<string, unknown>;
|
|
128
130
|
name?: string;
|
|
@@ -241,7 +243,8 @@ export type ScheduleCreatePayload = {
|
|
|
241
243
|
targetConfig?: Record<string, unknown> | null;
|
|
242
244
|
};
|
|
243
245
|
export type JobTemplateUpdatePayload = {
|
|
244
|
-
|
|
246
|
+
executionPolicy?: RuntimeExecutionPolicy;
|
|
247
|
+
triggerUser?: string | null;
|
|
245
248
|
version: number;
|
|
246
249
|
name?: string;
|
|
247
250
|
category?: string | null;
|
|
@@ -253,7 +256,8 @@ export type JobTemplateUpdatePayload = {
|
|
|
253
256
|
inputs?: unknown;
|
|
254
257
|
};
|
|
255
258
|
export type JobTemplateCreatePayload = {
|
|
256
|
-
|
|
259
|
+
executionPolicy?: RuntimeExecutionPolicy;
|
|
260
|
+
triggerUser?: string | null;
|
|
257
261
|
name: string;
|
|
258
262
|
category?: string | null;
|
|
259
263
|
desc?: string;
|
package/dist/src/client.js
CHANGED
|
@@ -1208,7 +1208,7 @@ export class RevoClient {
|
|
|
1208
1208
|
throw new Error('Invalid account response.');
|
|
1209
1209
|
}
|
|
1210
1210
|
const record = {};
|
|
1211
|
-
for (const field of ['userId', 'name', 'serviceAccount', 'ownerId', 'ownerType', 'access', 'memberships', 'version', 'deletedAt']) {
|
|
1211
|
+
for (const field of ['userId', 'name', 'serviceAccount', 'ownerId', 'ownerType', 'access', 'memberships', 'version', 'deletedAt', 'deletedBy', 'status', 'platformAccess']) {
|
|
1212
1212
|
if (wrapper[field] !== undefined) {
|
|
1213
1213
|
Object.assign(record, { [field]: wrapper[field] });
|
|
1214
1214
|
}
|
|
@@ -215,11 +215,13 @@ export function readComponentLock(projectRoot) {
|
|
|
215
215
|
sourceHash: String(entry.sourceHash),
|
|
216
216
|
...((isRecord(entry.owner) && (entry.owner.type === 'group' || entry.owner.type === 'service-account') && typeof entry.owner.stableKey === 'string')
|
|
217
217
|
? { owner: { type: entry.owner.type, stableKey: entry.owner.stableKey } }
|
|
218
|
-
: (isRecord(entry.owner) && entry.owner.type === '
|
|
219
|
-
? { owner: { type: '
|
|
220
|
-
: (isRecord(entry.owner) && entry.owner.type === '
|
|
221
|
-
? { owner: { type: '
|
|
222
|
-
:
|
|
218
|
+
: (isRecord(entry.owner) && entry.owner.type === 'system')
|
|
219
|
+
? { owner: { type: 'system' } }
|
|
220
|
+
: (isRecord(entry.owner) && entry.owner.type === 'manual-user')
|
|
221
|
+
? { owner: { type: 'manual-user' } }
|
|
222
|
+
: (isRecord(entry.owner) && entry.owner.type === 'unresolved' && typeof entry.owner.reason === 'string')
|
|
223
|
+
? { owner: { type: 'unresolved', reason: entry.owner.reason } }
|
|
224
|
+
: {}),
|
|
223
225
|
environments: Object.fromEntries(Object.entries(entry.environments)
|
|
224
226
|
.filter(([, baseline]) => typeof baseline.remoteHash === 'string' && typeof baseline.syncedAt === 'string')
|
|
225
227
|
.map(([envName, baseline]) => [envName, {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto';
|
|
2
2
|
import { readResourceInventory, resourceIdOf, unwrapResource, } from "./resource-inventory.js";
|
|
3
3
|
import { isDatabaseBackupArtifact } from "./database-table-artifacts.js";
|
|
4
|
+
import { isBuiltinSystemAccount } from "./resource-syncs/account-principal.js";
|
|
4
5
|
import { buildStableKey, buildResourceIdentityStableKeyValue, normalizeStableKeyValue, readConfiguredResourceMetadataStableKey, sanitizeUserMetadata, } from "./resource-metadata.js";
|
|
5
6
|
import { shouldTrackResource } from "./tracked-resources.js";
|
|
6
7
|
function isRecord(value) {
|
|
@@ -160,6 +161,8 @@ function endpointExclusionReason(endpoint) {
|
|
|
160
161
|
return endpoint.deletedAt || endpoint.deletedBy ? 'deleted endpoint is excluded' : null;
|
|
161
162
|
}
|
|
162
163
|
function buildMetadataUpdatePayload(resource, stableKeyName, stableKey, resourceType) {
|
|
164
|
+
if (isBuiltinSystemAccount(resource))
|
|
165
|
+
throw new Error('The built-in System account cannot be managed by metadata backfill.');
|
|
163
166
|
if (!Number.isInteger(resource.version)) {
|
|
164
167
|
throw new Error(`${resourceType} version is required to update metadata`);
|
|
165
168
|
}
|
|
@@ -487,6 +490,10 @@ export async function buildMetadataBackfillPlan(input) {
|
|
|
487
490
|
}
|
|
488
491
|
if (shouldTrackResource(trackedResources, 'service-account') && typeof client.listAllServiceAccounts === 'function') {
|
|
489
492
|
for await (const { listedId, resource: account } of readResourceInventory(client, 'service-account')) {
|
|
493
|
+
if (isBuiltinSystemAccount(account)) {
|
|
494
|
+
items.push({ resourceType: 'service-account', resourceId: resourceIdOf(account) || listedId, name: String(account.name || 'System'), category: null, action: 'skip', metadataField: 'metadata', stableKeyName, reason: 'built-in System account is managed by the platform' });
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
490
497
|
if (!listedId) {
|
|
491
498
|
continue;
|
|
492
499
|
}
|
|
@@ -982,6 +989,8 @@ export async function applyMetadataBackfillPlan(input) {
|
|
|
982
989
|
}
|
|
983
990
|
if (item.resourceType === 'service-account') {
|
|
984
991
|
const account = await client.getServiceAccount(item.resourceId);
|
|
992
|
+
if (isBuiltinSystemAccount(account))
|
|
993
|
+
throw new Error('The built-in System account cannot be managed by metadata backfill.');
|
|
985
994
|
const current = readConfiguredResourceMetadataStableKey(account, plan.stableKeyName);
|
|
986
995
|
if (current && !plan.force) {
|
|
987
996
|
results.push({ resourceType: item.resourceType, resourceId: item.resourceId, stableKey: current, action: 'skip' });
|
package/dist/src/migration.js
CHANGED
|
@@ -1065,6 +1065,7 @@ async function planWorkspace(input) {
|
|
|
1065
1065
|
envName: environmentKey,
|
|
1066
1066
|
stableKeyName,
|
|
1067
1067
|
includeDependencyBlockers: input.sourceMode === 'workspace',
|
|
1068
|
+
projectedServiceAccounts: identities?.projection.serviceAccounts,
|
|
1068
1069
|
...(input.projectDependencies === true && components
|
|
1069
1070
|
? { projectedComponents: projectedComponentDependencies(components) }
|
|
1070
1071
|
: {}),
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { type RevoClient } from '../client.ts';
|
|
2
2
|
import type { GroupOwnerPolicy } from '../component-lock.ts';
|
|
3
|
-
import type { ServiceAccountRecord } from '../types.ts';
|
|
3
|
+
import type { ServiceAccountRecord, RuntimeExecutionPolicy } from '../types.ts';
|
|
4
4
|
export type ExecutionPrincipal = {
|
|
5
5
|
kind: 'service-account';
|
|
6
6
|
stableKey: string;
|
|
7
|
+
} | {
|
|
8
|
+
kind: 'system';
|
|
9
|
+
stableKey?: never;
|
|
7
10
|
};
|
|
11
|
+
export declare const SYSTEM_ACCOUNT_ID = "00000000-0000-0000-0000-000000000000";
|
|
12
|
+
export declare function isBuiltinSystemAccount(account: ServiceAccountRecord): boolean;
|
|
13
|
+
export declare function resolveSystemAccount(client: RevoClient, requireExecutionAccess?: boolean): Promise<ServiceAccountRecord>;
|
|
14
|
+
export declare function ownerFromPrincipal(principal: ExecutionPrincipal): GroupOwnerPolicy;
|
|
15
|
+
export declare function resolveExecutionPrincipal(client: RevoClient, principal: ExecutionPrincipal, stableKeyName: string): Promise<string>;
|
|
8
16
|
export type IdentityProjection = {
|
|
9
17
|
serviceAccounts?: string[];
|
|
10
18
|
groups?: string[];
|
|
@@ -20,3 +28,13 @@ export declare function resolvePortableOwner(client: RevoClient, owner: GroupOwn
|
|
|
20
28
|
ownerId: string;
|
|
21
29
|
}>;
|
|
22
30
|
export declare function ownerIsAvailable(client: RevoClient, owner: GroupOwnerPolicy, stableKeyName: string, projection?: IdentityProjection): Promise<boolean>;
|
|
31
|
+
export type PortableExecutionPolicy = {
|
|
32
|
+
mode: 'INHERIT' | 'CALLER' | 'SERVICE_ACCOUNT';
|
|
33
|
+
serviceAccount?: ExecutionPrincipal;
|
|
34
|
+
currentUser?: 'INHERIT' | 'CALLER' | 'EXECUTION_ACCOUNT';
|
|
35
|
+
};
|
|
36
|
+
export declare function validExecutionPrincipal(value: unknown): value is ExecutionPrincipal;
|
|
37
|
+
export declare function validPortableExecutionPolicy(value: unknown, allowCurrentUser?: boolean): value is PortableExecutionPolicy;
|
|
38
|
+
export declare function portableExecutionPolicy(client: RevoClient, policy: RuntimeExecutionPolicy | null | undefined, stableKeyName: string): Promise<PortableExecutionPolicy | undefined>;
|
|
39
|
+
export declare function runtimeExecutionPolicyPayload(client: RevoClient, policy: PortableExecutionPolicy | undefined, stableKeyName: string): Promise<RuntimeExecutionPolicy | undefined>;
|
|
40
|
+
export declare function executionPrincipalAvailable(client: RevoClient, principal: ExecutionPrincipal, stableKeyName: string, projected?: string[], requireExecutionAccess?: boolean): Promise<boolean>;
|
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
import { ApiError } from "../client.js";
|
|
2
2
|
import { readConfiguredResourceMetadataStableKey } from "../resource-metadata.js";
|
|
3
3
|
import { unwrapData } from "./util.js";
|
|
4
|
+
export const SYSTEM_ACCOUNT_ID = '00000000-0000-0000-0000-000000000000';
|
|
5
|
+
export function isBuiltinSystemAccount(account) {
|
|
6
|
+
return account.userId === SYSTEM_ACCOUNT_ID && account.serviceAccount === true;
|
|
7
|
+
}
|
|
8
|
+
export async function resolveSystemAccount(client, requireExecutionAccess = false) {
|
|
9
|
+
const account = await client.getAccount(SYSTEM_ACCOUNT_ID);
|
|
10
|
+
if (!isBuiltinSystemAccount(account) || account.deletedAt || account.deletedBy
|
|
11
|
+
|| ![0, 'ACTIVE'].includes(account.status) || (requireExecutionAccess && account.platformAccess !== true)) {
|
|
12
|
+
throw new Error('The target built-in System account is unavailable; migrate the instance before using a System reference.');
|
|
13
|
+
}
|
|
14
|
+
return account;
|
|
15
|
+
}
|
|
16
|
+
export function ownerFromPrincipal(principal) {
|
|
17
|
+
return principal.kind === 'system' ? { type: 'system' } : { type: 'service-account', stableKey: principal.stableKey };
|
|
18
|
+
}
|
|
19
|
+
export async function resolveExecutionPrincipal(client, principal, stableKeyName) {
|
|
20
|
+
if (principal.kind === 'system')
|
|
21
|
+
return String((await resolveSystemAccount(client, true)).userId);
|
|
22
|
+
const matches = await serviceAccountMatches(client, principal.stableKey, stableKeyName);
|
|
23
|
+
if (matches.length !== 1 || !matches[0].userId)
|
|
24
|
+
throw new Error('Execution principal must resolve to exactly one target service account.');
|
|
25
|
+
return matches[0].userId;
|
|
26
|
+
}
|
|
4
27
|
export async function accountPrincipal(client, userId, stableKeyName) {
|
|
5
28
|
let account;
|
|
6
29
|
try {
|
|
@@ -12,16 +35,18 @@ export async function accountPrincipal(client, userId, stableKeyName) {
|
|
|
12
35
|
}
|
|
13
36
|
throw error;
|
|
14
37
|
}
|
|
15
|
-
if (account.serviceAccount !== true || account.deletedAt) {
|
|
38
|
+
if (account.serviceAccount !== true || account.deletedAt || account.deletedBy) {
|
|
16
39
|
return undefined;
|
|
17
40
|
}
|
|
41
|
+
if (isBuiltinSystemAccount(account))
|
|
42
|
+
return { kind: 'system' };
|
|
18
43
|
const stableKey = readConfiguredResourceMetadataStableKey(account, stableKeyName);
|
|
19
44
|
return stableKey ? { kind: 'service-account', stableKey } : undefined;
|
|
20
45
|
}
|
|
21
46
|
export async function readPortableOwner(client, record, stableKeyName) {
|
|
22
47
|
if (record.ownerType === 'USER' && record.ownerId) {
|
|
23
48
|
const principal = await accountPrincipal(client, record.ownerId, stableKeyName);
|
|
24
|
-
return principal ?
|
|
49
|
+
return principal ? ownerFromPrincipal(principal) : { type: 'manual-user' };
|
|
25
50
|
}
|
|
26
51
|
if (record.ownerType === 'GROUP' && record.ownerId) {
|
|
27
52
|
const group = unwrapData(await client.getGroup(record.ownerId));
|
|
@@ -35,13 +60,16 @@ export async function serviceAccountMatches(client, stableKey, stableKeyName) {
|
|
|
35
60
|
const matches = [];
|
|
36
61
|
for (const summary of serviceAccounts) {
|
|
37
62
|
const account = await client.getServiceAccount(String(summary.userId || ''));
|
|
38
|
-
if (readConfiguredResourceMetadataStableKey(account, stableKeyName) === stableKey) {
|
|
63
|
+
if (!isBuiltinSystemAccount(account) && readConfiguredResourceMetadataStableKey(account, stableKeyName) === stableKey) {
|
|
39
64
|
matches.push(account);
|
|
40
65
|
}
|
|
41
66
|
}
|
|
42
67
|
return matches;
|
|
43
68
|
}
|
|
44
69
|
export async function resolvePortableOwner(client, owner, stableKeyName) {
|
|
70
|
+
if (owner.type === 'system') {
|
|
71
|
+
return { ownerType: 'USER', ownerId: String((await resolveSystemAccount(client)).userId) };
|
|
72
|
+
}
|
|
45
73
|
if (owner.type === 'service-account') {
|
|
46
74
|
const matches = await serviceAccountMatches(client, owner.stableKey, stableKeyName);
|
|
47
75
|
if (matches.length !== 1 || !matches[0].userId) {
|
|
@@ -66,7 +94,7 @@ export async function resolvePortableOwner(client, owner, stableKeyName) {
|
|
|
66
94
|
throw new Error('Owner requires manual target configuration.');
|
|
67
95
|
}
|
|
68
96
|
export async function ownerIsAvailable(client, owner, stableKeyName, projection) {
|
|
69
|
-
if (owner.type !== 'group' && owner.type !== 'service-account') {
|
|
97
|
+
if (owner.type !== 'group' && owner.type !== 'service-account' && owner.type !== 'system') {
|
|
70
98
|
return false;
|
|
71
99
|
}
|
|
72
100
|
try {
|
|
@@ -74,6 +102,8 @@ export async function ownerIsAvailable(client, owner, stableKeyName, projection)
|
|
|
74
102
|
return true;
|
|
75
103
|
}
|
|
76
104
|
catch {
|
|
105
|
+
if (owner.type === 'system')
|
|
106
|
+
return false;
|
|
77
107
|
// Projection cannot mask duplicate live identities.
|
|
78
108
|
if (owner.type === 'service-account') {
|
|
79
109
|
const matches = await serviceAccountMatches(client, owner.stableKey, stableKeyName);
|
|
@@ -84,3 +114,63 @@ export async function ownerIsAvailable(client, owner, stableKeyName, projection)
|
|
|
84
114
|
return matches.length === 0 && (projection?.groups || []).includes(owner.stableKey);
|
|
85
115
|
}
|
|
86
116
|
}
|
|
117
|
+
export function validExecutionPrincipal(value) {
|
|
118
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
119
|
+
return false;
|
|
120
|
+
const principal = value;
|
|
121
|
+
return principal.kind === 'system' ? Object.keys(principal).length === 1
|
|
122
|
+
: principal.kind === 'service-account' && typeof principal.stableKey === 'string' && !!principal.stableKey.trim()
|
|
123
|
+
&& Object.keys(principal).every(key => ['kind', 'stableKey'].includes(key));
|
|
124
|
+
}
|
|
125
|
+
export function validPortableExecutionPolicy(value, allowCurrentUser = false) {
|
|
126
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
127
|
+
return false;
|
|
128
|
+
const policy = value;
|
|
129
|
+
return ['INHERIT', 'CALLER', 'SERVICE_ACCOUNT'].includes(String(policy.mode))
|
|
130
|
+
&& Object.keys(policy).every(key => ['mode', 'serviceAccount', ...(allowCurrentUser ? ['currentUser'] : [])].includes(key))
|
|
131
|
+
&& (policy.mode === 'SERVICE_ACCOUNT' ? validExecutionPrincipal(policy.serviceAccount) : policy.serviceAccount === undefined)
|
|
132
|
+
&& (policy.currentUser === undefined || allowCurrentUser && ['INHERIT', 'CALLER', 'EXECUTION_ACCOUNT'].includes(String(policy.currentUser)));
|
|
133
|
+
}
|
|
134
|
+
export async function portableExecutionPolicy(client, policy, stableKeyName) {
|
|
135
|
+
if (!policy)
|
|
136
|
+
return undefined;
|
|
137
|
+
if (!['INHERIT', 'CALLER', 'SERVICE_ACCOUNT'].includes(policy.mode))
|
|
138
|
+
throw new Error('Invalid saved runtime execution policy.');
|
|
139
|
+
const serviceAccount = policy.mode === 'SERVICE_ACCOUNT' && policy.serviceAccountUserId
|
|
140
|
+
? await accountPrincipal(client, policy.serviceAccountUserId, stableKeyName) : undefined;
|
|
141
|
+
if (policy.mode === 'SERVICE_ACCOUNT' && !serviceAccount)
|
|
142
|
+
throw new Error('Execution account is human, unavailable, or missing a portable Stable Key.');
|
|
143
|
+
return { mode: policy.mode, ...(serviceAccount ? { serviceAccount } : {}), ...(policy.currentUser ? { currentUser: policy.currentUser } : {}) };
|
|
144
|
+
}
|
|
145
|
+
export async function runtimeExecutionPolicyPayload(client, policy, stableKeyName) {
|
|
146
|
+
if (!policy)
|
|
147
|
+
return undefined;
|
|
148
|
+
const userId = policy.mode === 'SERVICE_ACCOUNT' ? await resolveExecutionPrincipal(client, policy.serviceAccount, stableKeyName) : undefined;
|
|
149
|
+
if (userId && policy.serviceAccount.kind !== 'system') {
|
|
150
|
+
const target = await client.getAccount(userId);
|
|
151
|
+
if (target.deletedAt || target.deletedBy || ![0, 'ACTIVE'].includes(target.status) || target.platformAccess !== true) {
|
|
152
|
+
throw new Error('Execution service account must be active and have platform access.');
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return { mode: policy.mode, ...(userId ? { serviceAccountUserId: userId } : {}), ...(policy.currentUser ? { currentUser: policy.currentUser } : {}) };
|
|
156
|
+
}
|
|
157
|
+
export async function executionPrincipalAvailable(client, principal, stableKeyName, projected = [], requireExecutionAccess = false) {
|
|
158
|
+
if (principal.kind === 'system') {
|
|
159
|
+
try {
|
|
160
|
+
await resolveSystemAccount(client, true);
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const matches = await serviceAccountMatches(client, principal.stableKey, stableKeyName);
|
|
168
|
+
if (matches.length === 1) {
|
|
169
|
+
if (!requireExecutionAccess)
|
|
170
|
+
return true;
|
|
171
|
+
const target = await client.getAccount(String(matches[0].userId));
|
|
172
|
+
return target.serviceAccount === true && !target.deletedAt && !target.deletedBy
|
|
173
|
+
&& [0, 'ACTIVE'].includes(target.status) && target.platformAccess === true;
|
|
174
|
+
}
|
|
175
|
+
return matches.length === 0 && projected.includes(principal.stableKey);
|
|
176
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type PortableExecutionPolicy } from './account-principal.ts';
|
|
1
2
|
import { type FieldChange } from '../diff-details.ts';
|
|
2
3
|
import type { RevoClient } from '../client.ts';
|
|
3
4
|
export declare const ENDPOINTS_DIRECTORY = "Endpoints";
|
|
@@ -25,6 +26,7 @@ export type EndpointManifest = {
|
|
|
25
26
|
};
|
|
26
27
|
options?: Record<string, unknown>;
|
|
27
28
|
execution?: EndpointComponentBinding;
|
|
29
|
+
executionPolicy?: PortableExecutionPolicy;
|
|
28
30
|
schema?: EndpointSchemaBinding;
|
|
29
31
|
};
|
|
30
32
|
export type EndpointPullResult = {
|
|
@@ -110,6 +112,7 @@ export declare function buildEndpointsPlan(input: {
|
|
|
110
112
|
envName: string;
|
|
111
113
|
stableKeyName: string;
|
|
112
114
|
projectedComponents?: ProjectedEndpointComponentDependency[];
|
|
115
|
+
projectedServiceAccounts?: string[];
|
|
113
116
|
includeDependencyBlockers?: boolean;
|
|
114
117
|
}): Promise<EndpointPlan>;
|
|
115
118
|
export declare function pushEndpoints(input: {
|
|
@@ -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
|
}
|
|
@@ -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;
|
|
@@ -43,21 +46,21 @@ async function readManagementPrincipal(client, record, stableKeyName) {
|
|
|
43
46
|
}
|
|
44
47
|
export function hashPortableServiceAccount(manifest) {
|
|
45
48
|
return hashStable({ kind: manifest.kind, stableKey: manifest.stableKey, name: manifest.name, metadata: manifest.metadata,
|
|
46
|
-
...(['group', 'service-account'].includes(manifest.owner.type) ? { owner: manifest.owner } : {}) });
|
|
49
|
+
...(['group', 'service-account', 'system'].includes(manifest.owner.type) ? { owner: manifest.owner } : {}) });
|
|
47
50
|
}
|
|
48
51
|
function serviceAccountHint(value) {
|
|
49
52
|
return String(value.name || '').trim().toLowerCase();
|
|
50
53
|
}
|
|
51
54
|
function diffServiceAccounts(desired, target) {
|
|
52
55
|
return { changedFields: ['name', 'metadata', 'owner'].filter((field) => {
|
|
53
|
-
if (field === 'owner' && !['group', 'service-account'].includes(desired.owner.type)) {
|
|
56
|
+
if (field === 'owner' && !['group', 'service-account', 'system'].includes(desired.owner.type)) {
|
|
54
57
|
return false;
|
|
55
58
|
}
|
|
56
59
|
return hashStable(desired[field]) !== hashStable(target[field]);
|
|
57
60
|
}) };
|
|
58
61
|
}
|
|
59
62
|
function comparableManifest(desired, target) {
|
|
60
|
-
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 };
|
|
61
64
|
}
|
|
62
65
|
export function serviceAccountManifestPath(workspaceRoot, manifest) {
|
|
63
66
|
return path.join(workspaceRoot, SERVICE_ACCOUNTS_DIRECTORY, `${sanitizeSegment(manifest.name)}-${stableKeySuffix(manifest.stableKey)}`, SERVICE_ACCOUNT_MANIFEST_FILE);
|
|
@@ -97,13 +100,15 @@ function validateManifest(manifest, stableKeyName) {
|
|
|
97
100
|
|| !isRecord(manifest.metadata)) {
|
|
98
101
|
errors.push('manifest must contain kind, stableKey, name and metadata');
|
|
99
102
|
}
|
|
100
|
-
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))) {
|
|
101
104
|
errors.push('owner must contain a portable owner policy');
|
|
102
105
|
}
|
|
103
106
|
else if (['group', 'service-account'].includes(String(manifest.owner.type))
|
|
104
107
|
&& (typeof manifest.owner.stableKey !== 'string' || !manifest.owner.stableKey.trim())) {
|
|
105
108
|
errors.push('portable owner requires stableKey');
|
|
106
109
|
}
|
|
110
|
+
if (isRecord(manifest.owner) && manifest.owner.type === 'system' && Object.keys(manifest.owner).length !== 1)
|
|
111
|
+
errors.push('System owner contains unsupported fields');
|
|
107
112
|
if (isRecord(manifest.owner) && Object.keys(manifest.owner).some((key) => !['type', 'stableKey', 'reason'].includes(key))) {
|
|
108
113
|
errors.push('owner contains unsupported fields');
|
|
109
114
|
}
|
|
@@ -194,9 +199,9 @@ export async function buildServiceAccountsPlan(input) {
|
|
|
194
199
|
items.push({ status: 'collision', stableKey: desired.stableKey, name: desired.name, reason: 'duplicate target stableKey', desiredHash });
|
|
195
200
|
continue;
|
|
196
201
|
}
|
|
197
|
-
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') {
|
|
198
203
|
if (!await ownerIsAvailable(input.client, desired.owner, input.stableKeyName, projectedIdentities)) {
|
|
199
|
-
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.`);
|
|
200
205
|
items.push({ status: 'conflict', stableKey: desired.stableKey, name: desired.name, desiredHash, reason: 'owner is missing or ambiguous' });
|
|
201
206
|
continue;
|
|
202
207
|
}
|
|
@@ -273,7 +278,7 @@ export async function buildServiceAccountsPlan(input) {
|
|
|
273
278
|
if (consumedUnmanaged.has(record)) {
|
|
274
279
|
continue;
|
|
275
280
|
}
|
|
276
|
-
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` });
|
|
277
282
|
}
|
|
278
283
|
const rank = {
|
|
279
284
|
create: 0,
|
|
@@ -312,7 +317,7 @@ export async function pullServiceAccountsToWorkspace(input) {
|
|
|
312
317
|
const manifest = await serviceAccountManifestFromRecord(input.client, record, input.stableKeyName);
|
|
313
318
|
if (!manifest) {
|
|
314
319
|
const name = String(record.name || serviceAccountIdOf(record) || 'unknown');
|
|
315
|
-
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` });
|
|
316
321
|
continue;
|
|
317
322
|
}
|
|
318
323
|
const errors = validateManifest(manifest, input.stableKeyName);
|
|
@@ -463,10 +468,12 @@ async function buildCreatePayload(client, manifest, stableKeyName) {
|
|
|
463
468
|
return { name: manifest.name, metadata: manifest.metadata, access: await managementAccessPayload(client, manifest, stableKeyName) };
|
|
464
469
|
}
|
|
465
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.');
|
|
466
473
|
if (!Number.isInteger(target.version)) {
|
|
467
474
|
throw new Error('target service-account version is required');
|
|
468
475
|
}
|
|
469
|
-
const ownerChanged = ['group', 'service-account'].includes(manifest.owner.type)
|
|
476
|
+
const ownerChanged = ['group', 'service-account', 'system'].includes(manifest.owner.type)
|
|
470
477
|
&& hashStable(manifest.owner) !== hashStable(await readManagementPrincipal(client, target, stableKeyName));
|
|
471
478
|
return { name: manifest.name, metadata: { ...sanitizeUserMetadata(target.metadata), ...manifest.metadata }, version: target.version,
|
|
472
479
|
...(ownerChanged
|
package/dist/src/types.d.ts
CHANGED
|
@@ -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;
|
|
@@ -172,6 +178,9 @@ export type ServiceAccountAccessRecord = {
|
|
|
172
178
|
}>;
|
|
173
179
|
};
|
|
174
180
|
export type ServiceAccountRecord = {
|
|
181
|
+
status?: number | string;
|
|
182
|
+
platformAccess?: boolean;
|
|
183
|
+
deletedBy?: string | null;
|
|
175
184
|
category?: string | null;
|
|
176
185
|
userId?: string;
|
|
177
186
|
name?: string;
|
|
@@ -228,6 +237,7 @@ export type GroupRecord = {
|
|
|
228
237
|
[key: string]: unknown;
|
|
229
238
|
};
|
|
230
239
|
export type JobTemplateRecord = {
|
|
240
|
+
executionPolicy?: RuntimeExecutionPolicy | null;
|
|
231
241
|
jobTemplateId?: string;
|
|
232
242
|
id?: string;
|
|
233
243
|
name?: string;
|
|
@@ -4,6 +4,7 @@ import { hashStable, readComponentLock, removeComponentLockBaseline, writeCompon
|
|
|
4
4
|
import { readProjectStableKeyName } from "./project.js";
|
|
5
5
|
import { readResourceInventory, resourceIdOf } from "./resource-inventory.js";
|
|
6
6
|
import { normalizeStableKeyValue, readConfiguredResourceMetadataStableKey } from "./resource-metadata.js";
|
|
7
|
+
import { isBuiltinSystemAccount } from "./resource-syncs/account-principal.js";
|
|
7
8
|
import { findManifestFiles, isRecord, requireProjectLayout } from "./resource-syncs/util.js";
|
|
8
9
|
const manifests = {
|
|
9
10
|
component: ['Components', 'component.json'],
|
|
@@ -91,6 +92,8 @@ function localReferences(resource, manifest) {
|
|
|
91
92
|
}
|
|
92
93
|
if (isRecord(manifest.executionPrincipal))
|
|
93
94
|
add('service-account', manifest.executionPrincipal.stableKey);
|
|
95
|
+
if (isRecord(manifest.executionPolicy) && isRecord(manifest.executionPolicy.serviceAccount) && manifest.executionPolicy.serviceAccount.kind === 'service-account')
|
|
96
|
+
add('service-account', manifest.executionPolicy.serviceAccount.stableKey);
|
|
94
97
|
return refs;
|
|
95
98
|
}
|
|
96
99
|
function remoteReferences(resource, record, tables) {
|
|
@@ -105,6 +108,8 @@ function remoteReferences(resource, record, tables) {
|
|
|
105
108
|
add('component', record.options.componentSchemaId);
|
|
106
109
|
if (resource === 'job-template')
|
|
107
110
|
add('service-account', record.triggerUser);
|
|
111
|
+
if ((resource === 'job-template' || resource === 'endpoint') && isRecord(record.executionPolicy) && record.executionPolicy.mode === 'SERVICE_ACCOUNT')
|
|
112
|
+
add('service-account', record.executionPolicy.serviceAccountUserId);
|
|
108
113
|
if (resource === 'schedule' || resource === 'event') {
|
|
109
114
|
add(record.targetType === 'JOB_TEMPLATE' ? 'job-template' : 'database-view', record.targetId);
|
|
110
115
|
}
|
|
@@ -174,7 +179,7 @@ export function planWorkspacePrune(input) {
|
|
|
174
179
|
throw new Error(`Repeated ${resource} target ID "${id}".`);
|
|
175
180
|
const stableKey = readConfiguredResourceMetadataStableKey(record, input.stableKeyName);
|
|
176
181
|
byId.set(key(resource, id), { resource, record, stableKey });
|
|
177
|
-
if (!stableKey)
|
|
182
|
+
if (!stableKey || isBuiltinSystemAccount(record))
|
|
178
183
|
continue;
|
|
179
184
|
const identity = normalizeStableKeyValue(stableKey);
|
|
180
185
|
if (keys.has(identity))
|