@serve.zone/interfaces 32.121.1 → 32.123.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +12 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/data/corestoredata.d.ts +87 -0
- package/dist_ts/data/corestoredata.js +164 -0
- package/dist_ts/data/delegatedadmintoken.d.ts +10 -1
- package/dist_ts/data/delegatedadmintoken.js +22 -3
- package/dist_ts/data/index.d.ts +3 -0
- package/dist_ts/data/index.js +4 -1
- package/dist_ts/data/palletworkspace.d.ts +59 -0
- package/dist_ts/data/palletworkspace.js +39 -0
- package/dist_ts/data/serviceadmintoken.d.ts +101 -0
- package/dist_ts/data/serviceadmintoken.js +150 -0
- package/dist_ts/data/settings.d.ts +2 -0
- package/dist_ts/data/settings.js +3 -1
- package/dist_ts/requests/admin.d.ts +39 -0
- package/dist_ts/requests/corestore.d.ts +75 -0
- package/dist_ts/requests/corestore.js +1 -1
- package/dist_ts/requests/runtimesession.d.ts +38 -0
- package/dist_ts/runtime.d.ts +1 -0
- package/dist_ts/runtime.js +2 -1
- package/dist_ts/runtime.serviceadmintoken.d.ts +66 -0
- package/dist_ts/runtime.serviceadmintoken.js +293 -0
- package/package.json +8 -7
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/data/corestoredata.ts +255 -0
- package/ts/data/delegatedadmintoken.ts +23 -2
- package/ts/data/index.ts +3 -0
- package/ts/data/palletworkspace.ts +90 -0
- package/ts/data/serviceadmintoken.ts +263 -0
- package/ts/data/settings.ts +2 -0
- package/ts/requests/admin.ts +42 -0
- package/ts/requests/corestore.ts +100 -0
- package/ts/requests/runtimesession.ts +53 -0
- package/ts/runtime.serviceadmintoken.ts +395 -0
- package/ts/runtime.ts +1 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read-only, bounded inspection contracts for Corestore-managed service databases
|
|
3
|
+
* and object storage buckets routed through Cloudly and the cluster relay.
|
|
4
|
+
*
|
|
5
|
+
* Credentials never leave Corestore; every query is strictly read-only and bounded
|
|
6
|
+
* in execution time, row count, and serialized byte size.
|
|
7
|
+
*/
|
|
8
|
+
export const corestoreDataInspectionContract = Object.freeze({
|
|
9
|
+
databaseInspectPath: '/control/data/database/inspect',
|
|
10
|
+
objectStorageInspectPath: '/control/data/objectstorage/inspect',
|
|
11
|
+
maxCollections: 500,
|
|
12
|
+
defaultQueryLimit: 25,
|
|
13
|
+
maxQueryLimit: 100,
|
|
14
|
+
maxSkip: 10_000,
|
|
15
|
+
defaultObjectLimit: 50,
|
|
16
|
+
maxObjectLimit: 100,
|
|
17
|
+
maxPayloadBytes: 512 * 1024,
|
|
18
|
+
queryTimeoutMs: 5_000,
|
|
19
|
+
maxFilterDepth: 12,
|
|
20
|
+
maxCollectionNameLength: 200,
|
|
21
|
+
maxPrefixLength: 1_024,
|
|
22
|
+
} as const);
|
|
23
|
+
|
|
24
|
+
export type TCorestoreDatabaseInspectOperation = 'collections' | 'find' | 'count';
|
|
25
|
+
|
|
26
|
+
export interface ICorestoreDatabaseCollectionSummary {
|
|
27
|
+
name: string;
|
|
28
|
+
estimatedCount: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ICorestoreDatabaseInspectRequest {
|
|
32
|
+
serviceId: string;
|
|
33
|
+
operation: TCorestoreDatabaseInspectOperation;
|
|
34
|
+
collection?: string;
|
|
35
|
+
filter?: Record<string, unknown>;
|
|
36
|
+
projection?: Record<string, 0 | 1>;
|
|
37
|
+
sort?: Record<string, 1 | -1>;
|
|
38
|
+
limit?: number;
|
|
39
|
+
skip?: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type TCorestoreDatabaseInspectResult =
|
|
43
|
+
| {
|
|
44
|
+
operation: 'collections';
|
|
45
|
+
serviceId: string;
|
|
46
|
+
databaseName: string;
|
|
47
|
+
collections: ICorestoreDatabaseCollectionSummary[];
|
|
48
|
+
}
|
|
49
|
+
| {
|
|
50
|
+
operation: 'find';
|
|
51
|
+
serviceId: string;
|
|
52
|
+
databaseName: string;
|
|
53
|
+
collection: string;
|
|
54
|
+
documents: Record<string, unknown>[];
|
|
55
|
+
returnedCount: number;
|
|
56
|
+
totalMatchedCount: number;
|
|
57
|
+
hasMore: boolean;
|
|
58
|
+
truncated: boolean;
|
|
59
|
+
}
|
|
60
|
+
| {
|
|
61
|
+
operation: 'count';
|
|
62
|
+
serviceId: string;
|
|
63
|
+
databaseName: string;
|
|
64
|
+
collection: string;
|
|
65
|
+
count: number;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export interface ICorestoreObjectStorageEntry {
|
|
69
|
+
key: string;
|
|
70
|
+
size: number;
|
|
71
|
+
etag: string;
|
|
72
|
+
lastModified?: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface ICorestoreObjectStorageInspectRequest {
|
|
76
|
+
serviceId: string;
|
|
77
|
+
prefix?: string;
|
|
78
|
+
startAfter?: string;
|
|
79
|
+
limit?: number;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface ICorestoreObjectStorageInspectResult {
|
|
83
|
+
serviceId: string;
|
|
84
|
+
bucketName: string;
|
|
85
|
+
prefix: string;
|
|
86
|
+
entries: ICorestoreObjectStorageEntry[];
|
|
87
|
+
hasMore: boolean;
|
|
88
|
+
nextStartAfter?: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const serviceIdPattern = /^[A-Za-z0-9][A-Za-z0-9:._-]{0,199}$/;
|
|
92
|
+
const forbiddenFilterOperators = new Set(['$where', '$function', '$accumulator']);
|
|
93
|
+
|
|
94
|
+
const isPlainRecord = (valueArg: unknown): valueArg is Record<string, unknown> => (
|
|
95
|
+
Boolean(valueArg)
|
|
96
|
+
&& typeof valueArg === 'object'
|
|
97
|
+
&& !Array.isArray(valueArg)
|
|
98
|
+
&& (Object.getPrototypeOf(valueArg) === Object.prototype
|
|
99
|
+
|| Object.getPrototypeOf(valueArg) === null)
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Validates that a MongoDB/NoSQLDB read filter contains no server-side JavaScript
|
|
104
|
+
* execution operators (`$where`, `$function`, `$accumulator`) and stays within
|
|
105
|
+
* bounded nesting depth.
|
|
106
|
+
*/
|
|
107
|
+
export const validateCorestoreQueryFilter = (
|
|
108
|
+
valueArg: unknown,
|
|
109
|
+
pathArg = 'filter',
|
|
110
|
+
depthArg = 0,
|
|
111
|
+
): string[] => {
|
|
112
|
+
if (depthArg > corestoreDataInspectionContract.maxFilterDepth) {
|
|
113
|
+
return [`${pathArg} exceeds maximum nesting depth of ${corestoreDataInspectionContract.maxFilterDepth}`];
|
|
114
|
+
}
|
|
115
|
+
if (Array.isArray(valueArg)) {
|
|
116
|
+
const errors: string[] = [];
|
|
117
|
+
for (const [index, entry] of valueArg.entries()) {
|
|
118
|
+
errors.push(...validateCorestoreQueryFilter(entry, `${pathArg}[${index}]`, depthArg + 1));
|
|
119
|
+
}
|
|
120
|
+
return errors;
|
|
121
|
+
}
|
|
122
|
+
if (!isPlainRecord(valueArg)) {
|
|
123
|
+
if (depthArg === 0) {
|
|
124
|
+
return [`${pathArg} must be a JSON object`];
|
|
125
|
+
}
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
const errors: string[] = [];
|
|
129
|
+
for (const [key, nested] of Object.entries(valueArg)) {
|
|
130
|
+
if (forbiddenFilterOperators.has(key)) {
|
|
131
|
+
errors.push(`${pathArg}.${key} is not permitted in read-only inspection queries`);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (key.includes('\0')) {
|
|
135
|
+
errors.push(`${pathArg} contains an invalid null byte in key`);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
errors.push(...validateCorestoreQueryFilter(nested, `${pathArg}.${key}`, depthArg + 1));
|
|
139
|
+
}
|
|
140
|
+
return errors;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export const validateCorestoreDatabaseInspectRequest = (
|
|
144
|
+
valueArg: unknown,
|
|
145
|
+
): string[] => {
|
|
146
|
+
if (!isPlainRecord(valueArg)) {
|
|
147
|
+
return ['database inspect request must be an object'];
|
|
148
|
+
}
|
|
149
|
+
const errors: string[] = [];
|
|
150
|
+
if (typeof valueArg.serviceId !== 'string' || !serviceIdPattern.test(valueArg.serviceId)) {
|
|
151
|
+
errors.push('serviceId must be a valid bounded identifier');
|
|
152
|
+
}
|
|
153
|
+
const op = valueArg.operation;
|
|
154
|
+
if (op !== 'collections' && op !== 'find' && op !== 'count') {
|
|
155
|
+
errors.push('operation must be collections, find, or count');
|
|
156
|
+
return errors;
|
|
157
|
+
}
|
|
158
|
+
if (op === 'find' || op === 'count') {
|
|
159
|
+
if (
|
|
160
|
+
typeof valueArg.collection !== 'string'
|
|
161
|
+
|| valueArg.collection.trim().length === 0
|
|
162
|
+
|| valueArg.collection.length > corestoreDataInspectionContract.maxCollectionNameLength
|
|
163
|
+
|| valueArg.collection.includes('\0')
|
|
164
|
+
|| valueArg.collection.includes('$')
|
|
165
|
+
) {
|
|
166
|
+
errors.push('collection must be a valid non-empty collection name');
|
|
167
|
+
}
|
|
168
|
+
if (valueArg.filter !== undefined) {
|
|
169
|
+
errors.push(...validateCorestoreQueryFilter(valueArg.filter, 'filter'));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (op === 'find') {
|
|
173
|
+
if (valueArg.projection !== undefined) {
|
|
174
|
+
if (!isPlainRecord(valueArg.projection)) {
|
|
175
|
+
errors.push('projection must be an object');
|
|
176
|
+
} else {
|
|
177
|
+
for (const [field, flag] of Object.entries(valueArg.projection)) {
|
|
178
|
+
if (!field || field.includes('\0') || (flag !== 0 && flag !== 1)) {
|
|
179
|
+
errors.push(`projection.${field} must be 0 or 1`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (valueArg.sort !== undefined) {
|
|
185
|
+
if (!isPlainRecord(valueArg.sort)) {
|
|
186
|
+
errors.push('sort must be an object');
|
|
187
|
+
} else {
|
|
188
|
+
for (const [field, dir] of Object.entries(valueArg.sort)) {
|
|
189
|
+
if (!field || field.includes('\0') || (dir !== 1 && dir !== -1)) {
|
|
190
|
+
errors.push(`sort.${field} must be 1 or -1`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (valueArg.limit !== undefined) {
|
|
196
|
+
if (
|
|
197
|
+
!Number.isSafeInteger(valueArg.limit)
|
|
198
|
+
|| (valueArg.limit as number) < 1
|
|
199
|
+
|| (valueArg.limit as number) > corestoreDataInspectionContract.maxQueryLimit
|
|
200
|
+
) {
|
|
201
|
+
errors.push(`limit must be an integer between 1 and ${corestoreDataInspectionContract.maxQueryLimit}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (valueArg.skip !== undefined) {
|
|
205
|
+
if (
|
|
206
|
+
!Number.isSafeInteger(valueArg.skip)
|
|
207
|
+
|| (valueArg.skip as number) < 0
|
|
208
|
+
|| (valueArg.skip as number) > corestoreDataInspectionContract.maxSkip
|
|
209
|
+
) {
|
|
210
|
+
errors.push(`skip must be an integer between 0 and ${corestoreDataInspectionContract.maxSkip}`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return errors;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
export const validateCorestoreObjectStorageInspectRequest = (
|
|
218
|
+
valueArg: unknown,
|
|
219
|
+
): string[] => {
|
|
220
|
+
if (!isPlainRecord(valueArg)) {
|
|
221
|
+
return ['object storage inspect request must be an object'];
|
|
222
|
+
}
|
|
223
|
+
const errors: string[] = [];
|
|
224
|
+
if (typeof valueArg.serviceId !== 'string' || !serviceIdPattern.test(valueArg.serviceId)) {
|
|
225
|
+
errors.push('serviceId must be a valid bounded identifier');
|
|
226
|
+
}
|
|
227
|
+
if (valueArg.prefix !== undefined) {
|
|
228
|
+
if (
|
|
229
|
+
typeof valueArg.prefix !== 'string'
|
|
230
|
+
|| valueArg.prefix.length > corestoreDataInspectionContract.maxPrefixLength
|
|
231
|
+
|| valueArg.prefix.includes('\0')
|
|
232
|
+
) {
|
|
233
|
+
errors.push('prefix must be a bounded UTF-8 string without null bytes');
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (valueArg.startAfter !== undefined) {
|
|
237
|
+
if (
|
|
238
|
+
typeof valueArg.startAfter !== 'string'
|
|
239
|
+
|| valueArg.startAfter.length > corestoreDataInspectionContract.maxPrefixLength
|
|
240
|
+
|| valueArg.startAfter.includes('\0')
|
|
241
|
+
) {
|
|
242
|
+
errors.push('startAfter must be a bounded UTF-8 string without null bytes');
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (valueArg.limit !== undefined) {
|
|
246
|
+
if (
|
|
247
|
+
!Number.isSafeInteger(valueArg.limit)
|
|
248
|
+
|| (valueArg.limit as number) < 1
|
|
249
|
+
|| (valueArg.limit as number) > corestoreDataInspectionContract.maxObjectLimit
|
|
250
|
+
) {
|
|
251
|
+
errors.push(`limit must be an integer between 1 and ${corestoreDataInspectionContract.maxObjectLimit}`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return errors;
|
|
255
|
+
};
|
|
@@ -46,9 +46,17 @@ export const delegatedAdminTokenContract = Object.freeze({
|
|
|
46
46
|
* creates, rotates, retires and revokes nothing.
|
|
47
47
|
* - `serviceCredentials`: a service's platform credential (`SERVEZONE_PLATFORM_AUTHORIZATION`):
|
|
48
48
|
* inspect, ensure, rotate and revoke it.
|
|
49
|
+
* - `serviceAdminTokens`: mint short-lived, scope-limited Ed25519 Service Admin Tokens for hosted
|
|
50
|
+
* services (`getServiceAdminAuthorityStatus`, `mintServiceAdminToken`).
|
|
51
|
+
* - `databaseRead`: bounded read-only inspection of Corestore-managed service databases and object
|
|
52
|
+
* storage buckets (`getCorestoreInventory`, `inspectServiceDatabase`, `inspectServiceObjectStorage`).
|
|
53
|
+
* - `workspace`: run commands, read/write files, and open interactive shells inside running
|
|
54
|
+
* deployment containers (`deploymentWorkspace*`, `deploymentShell*`).
|
|
49
55
|
* - `monitor`: read clusters, nodes, services, deployments, runtime log attempts and assignment logs.
|
|
50
56
|
*/
|
|
51
|
-
export const delegatedAdminTokenScopes = [
|
|
57
|
+
export const delegatedAdminTokenScopes = [
|
|
58
|
+
'secrets', 'serviceCredentials', 'serviceAdminTokens', 'databaseRead', 'workspace', 'monitor',
|
|
59
|
+
] as const;
|
|
52
60
|
|
|
53
61
|
export type TDelegatedAdminTokenScope = typeof delegatedAdminTokenScopes[number];
|
|
54
62
|
|
|
@@ -59,6 +67,16 @@ export const delegatedAdminTokenScopeRequests = Object.freeze({
|
|
|
59
67
|
'changeSecretLifecycle',
|
|
60
68
|
] as const),
|
|
61
69
|
serviceCredentials: Object.freeze(['getServiceMachineCredential', 'mutateServiceMachineCredential'] as const),
|
|
70
|
+
serviceAdminTokens: Object.freeze(['getServiceAdminAuthorityStatus', 'mintServiceAdminToken'] as const),
|
|
71
|
+
databaseRead: Object.freeze([
|
|
72
|
+
'getCorestoreInventory', 'inspectServiceDatabase', 'inspectServiceObjectStorage',
|
|
73
|
+
] as const),
|
|
74
|
+
workspace: Object.freeze([
|
|
75
|
+
'deploymentWorkspaceReadFile', 'deploymentWorkspaceWriteFile', 'deploymentWorkspaceReadDir',
|
|
76
|
+
'deploymentWorkspaceMkdir', 'deploymentWorkspaceRm', 'deploymentWorkspaceExists',
|
|
77
|
+
'deploymentWorkspaceExec', 'deploymentShellGetCommand', 'deploymentShellStart',
|
|
78
|
+
'deploymentShellInput', 'deploymentShellKill',
|
|
79
|
+
] as const),
|
|
62
80
|
monitor: Object.freeze([
|
|
63
81
|
'getClusters', 'getNodes', 'getServices', 'getDeployments', 'getServiceRuntimeLogAttempts',
|
|
64
82
|
'getRuntimeAssignmentLogs',
|
|
@@ -248,7 +266,10 @@ export const snapshotDelegatedAdminTokenMint = (value: unknown): IDelegatedAdmin
|
|
|
248
266
|
if (namesPrefixes) {
|
|
249
267
|
const prefixes = secretKeyPrefixes(mint.secretKeyPrefixes, false);
|
|
250
268
|
// Preserve the empty-list input accepted by existing serviceCredentials-only mints.
|
|
251
|
-
requireValue(
|
|
269
|
+
requireValue(
|
|
270
|
+
copy.scopes.includes('secrets')
|
|
271
|
+
|| (prefixes.length === 0 && !copy.scopes.includes('monitor') && !copy.scopes.includes('serviceAdminTokens')),
|
|
272
|
+
);
|
|
252
273
|
copy.secretKeyPrefixes = prefixes;
|
|
253
274
|
}
|
|
254
275
|
return copy;
|
package/ts/data/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ export * from './controller.js';
|
|
|
12
12
|
export * from './controlledtakeover.js';
|
|
13
13
|
export * from './corestore.js';
|
|
14
14
|
export * from './corestorecontroltoken.js';
|
|
15
|
+
export * from './corestoredata.js';
|
|
15
16
|
export * from './corestorelegacyadoption.js';
|
|
16
17
|
export * from './corestorereplication.js';
|
|
17
18
|
export * from './delegatedadmintoken.js';
|
|
@@ -72,6 +73,7 @@ export { runtimeNetworkProjectionRetirementContract, snapshotRuntimeNetworkProje
|
|
|
72
73
|
export * from './networkprotection.js';
|
|
73
74
|
export * from './networksigning.js';
|
|
74
75
|
export * from './privatenetwork.js';
|
|
76
|
+
export * from './palletworkspace.js';
|
|
75
77
|
export * from './preparedimages.js';
|
|
76
78
|
export * from './registry.js';
|
|
77
79
|
export * from './releaseversion.js';
|
|
@@ -100,6 +102,7 @@ export * from './sparknodereport.js';
|
|
|
100
102
|
export * from './nodeaction.js';
|
|
101
103
|
export * from './sparkfleettarget.js';
|
|
102
104
|
export * from './service.js';
|
|
105
|
+
export * from './serviceadmintoken.js';
|
|
103
106
|
export * from './servicecredential.js';
|
|
104
107
|
export * from './serviceplatformownership.js';
|
|
105
108
|
export * from './serviceports.js';
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { IRuntimeSessionBinding } from './runtimesession.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Bounded command execution and interactive shell contracts between a Cloudly
|
|
5
|
+
* controller and an authenticated Pallet node session.
|
|
6
|
+
*/
|
|
7
|
+
export const palletWorkspaceContract = Object.freeze({
|
|
8
|
+
maxCommandArguments: 256,
|
|
9
|
+
maxCommandBytes: 65_536,
|
|
10
|
+
defaultTimeoutMs: 30_000,
|
|
11
|
+
maxTimeoutMs: 120_000,
|
|
12
|
+
maxOutputBytes: 512 * 1024,
|
|
13
|
+
maxStdinBytes: 2 * 1024 * 1024,
|
|
14
|
+
maxShellSessions: 8,
|
|
15
|
+
shellIdleTimeoutMs: 15 * 60 * 1000,
|
|
16
|
+
maxTerminalDimension: 65_535,
|
|
17
|
+
} as const);
|
|
18
|
+
|
|
19
|
+
export interface IRunRuntimeAssignmentExecRequest {
|
|
20
|
+
session: IRuntimeSessionBinding;
|
|
21
|
+
assignmentId: string;
|
|
22
|
+
command: string[];
|
|
23
|
+
stdinBase64?: string;
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface IRunRuntimeAssignmentExecResponse {
|
|
28
|
+
stdoutBase64: string;
|
|
29
|
+
stderrBase64: string;
|
|
30
|
+
exitCode: number;
|
|
31
|
+
timedOut?: boolean;
|
|
32
|
+
truncated?: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface IStartRuntimeAssignmentShellRequest {
|
|
36
|
+
session: IRuntimeSessionBinding;
|
|
37
|
+
assignmentId: string;
|
|
38
|
+
processId: string;
|
|
39
|
+
command: string[];
|
|
40
|
+
columns?: number;
|
|
41
|
+
rows?: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface IStartRuntimeAssignmentShellResponse {
|
|
45
|
+
processId: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface IWriteRuntimeAssignmentShellRequest {
|
|
49
|
+
session: IRuntimeSessionBinding;
|
|
50
|
+
processId: string;
|
|
51
|
+
inputBase64: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface IKillRuntimeAssignmentShellRequest {
|
|
55
|
+
session: IRuntimeSessionBinding;
|
|
56
|
+
processId: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface IPushRuntimeAssignmentShellOutputRequest {
|
|
60
|
+
session: IRuntimeSessionBinding;
|
|
61
|
+
processId: string;
|
|
62
|
+
output?: string;
|
|
63
|
+
error?: string;
|
|
64
|
+
done: boolean;
|
|
65
|
+
exitCode?: number;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const validatePalletWorkspaceCommand = (commandArg: unknown): string[] => {
|
|
69
|
+
if (!Array.isArray(commandArg) || commandArg.length === 0) {
|
|
70
|
+
return ['command must be a non-empty array of strings'];
|
|
71
|
+
}
|
|
72
|
+
if (commandArg.length > palletWorkspaceContract.maxCommandArguments) {
|
|
73
|
+
return [`command exceeds maximum of ${palletWorkspaceContract.maxCommandArguments} arguments`];
|
|
74
|
+
}
|
|
75
|
+
const encoder = new TextEncoder();
|
|
76
|
+
let totalBytes = 0;
|
|
77
|
+
for (const [index, part] of commandArg.entries()) {
|
|
78
|
+
if (typeof part !== 'string' || part.includes('\0')) {
|
|
79
|
+
return [`command[${index}] must be a string without null bytes`];
|
|
80
|
+
}
|
|
81
|
+
if (index === 0 && part.length === 0) {
|
|
82
|
+
return ['command[0] must be non-empty'];
|
|
83
|
+
}
|
|
84
|
+
totalBytes += encoder.encode(part).byteLength;
|
|
85
|
+
if (totalBytes > palletWorkspaceContract.maxCommandBytes) {
|
|
86
|
+
return [`command exceeds maximum byte length of ${palletWorkspaceContract.maxCommandBytes}`];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return [];
|
|
90
|
+
};
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { readDataElements, readDataProperty, readExactDataRecord } from '../private/dataproperties.js';
|
|
2
|
+
import { workloadReplicaIdentityEnvironmentNames } from './workloadreplicaidentity.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Environment variables injected into workloads (non-secret public key + issuer + service id)
|
|
6
|
+
* so services can verify short-lived Cloudly-brokered Service Admin Tokens completely offline.
|
|
7
|
+
*/
|
|
8
|
+
export const serviceAdminTokenEnvironmentNames = Object.freeze({
|
|
9
|
+
jwks: 'SERVEZONE_SERVICE_ADMIN_JWKS',
|
|
10
|
+
issuer: 'SERVEZONE_SERVICE_ADMIN_ISSUER',
|
|
11
|
+
serviceId: workloadReplicaIdentityEnvironmentNames.serviceId,
|
|
12
|
+
} as const);
|
|
13
|
+
|
|
14
|
+
export const serviceAdminTokenContract = Object.freeze({
|
|
15
|
+
defaultLifetimeMs: 15 * 60 * 1000,
|
|
16
|
+
minimumLifetimeMs: 60 * 1000,
|
|
17
|
+
maximumLifetimeMs: 60 * 60 * 1000,
|
|
18
|
+
maximumScopes: 32,
|
|
19
|
+
maximumReasonLength: 200,
|
|
20
|
+
maximumJwksKeys: 4,
|
|
21
|
+
clockSkewToleranceSeconds: 30,
|
|
22
|
+
audiencePrefix: 'service:',
|
|
23
|
+
jtiPrefix: 'sat_',
|
|
24
|
+
kidPrefix: 'sat-',
|
|
25
|
+
jwtType: 'at+jwt',
|
|
26
|
+
algorithm: 'EdDSA',
|
|
27
|
+
} as const);
|
|
28
|
+
|
|
29
|
+
/** A single public Ed25519 JWK published by Cloudly's Service Admin Token Authority. */
|
|
30
|
+
export interface IServiceAdminAuthorityJwk {
|
|
31
|
+
kty: 'OKP';
|
|
32
|
+
crv: 'Ed25519';
|
|
33
|
+
alg: 'EdDSA';
|
|
34
|
+
use: 'sig';
|
|
35
|
+
kid: string;
|
|
36
|
+
/** 32-byte raw Ed25519 public key, canonical unpadded base64url (43 chars). */
|
|
37
|
+
x: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Canonical JWKS payload injected into `SERVEZONE_SERVICE_ADMIN_JWKS`. */
|
|
41
|
+
export interface IServiceAdminAuthorityJwks {
|
|
42
|
+
keys: IServiceAdminAuthorityJwk[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Value-free status of Cloudly's Service Admin Token signing authority. */
|
|
46
|
+
export interface IServiceAdminAuthorityStatus {
|
|
47
|
+
activeKeyId: string;
|
|
48
|
+
issuer: string;
|
|
49
|
+
jwks: IServiceAdminAuthorityJwks;
|
|
50
|
+
keyCount: number;
|
|
51
|
+
updatedAt: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Verified JWT payload of a Cloudly-brokered Service Admin Token. */
|
|
55
|
+
export interface IServiceAdminTokenClaims {
|
|
56
|
+
iss: string;
|
|
57
|
+
aud: string;
|
|
58
|
+
sub: string;
|
|
59
|
+
serviceId: string;
|
|
60
|
+
scopes: string[];
|
|
61
|
+
jti: string;
|
|
62
|
+
iat: number;
|
|
63
|
+
exp: number;
|
|
64
|
+
reason?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Request payload to mint a short-lived Service Admin Token (excluding caller identity). */
|
|
68
|
+
export interface IServiceAdminTokenMintRequest {
|
|
69
|
+
serviceId: string;
|
|
70
|
+
scopes: string[];
|
|
71
|
+
lifetimeMs?: number;
|
|
72
|
+
reason?: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Returned once on mint; Cloudly stores only immutable audit metadata (never the token). */
|
|
76
|
+
export interface IServiceAdminTokenMintResult {
|
|
77
|
+
token: string;
|
|
78
|
+
jti: string;
|
|
79
|
+
serviceId: string;
|
|
80
|
+
issuer: string;
|
|
81
|
+
subject: string;
|
|
82
|
+
scopes: string[];
|
|
83
|
+
issuedAt: number;
|
|
84
|
+
expiresAt: number;
|
|
85
|
+
keyId: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export const serviceAdminTokenRefusals = [
|
|
89
|
+
'ADMIN_AUTHORIZATION_REQUIRED',
|
|
90
|
+
'SERVICE_ADMIN_TOKEN_REQUEST_INVALID',
|
|
91
|
+
'SERVICE_ADMIN_TOKEN_SERVICE_NOT_FOUND',
|
|
92
|
+
'SERVICE_ADMIN_AUTHORITY_UNAVAILABLE',
|
|
93
|
+
] as const;
|
|
94
|
+
|
|
95
|
+
export type TServiceAdminTokenRefusal = typeof serviceAdminTokenRefusals[number];
|
|
96
|
+
|
|
97
|
+
export interface IServiceAdminTokenErrorData {
|
|
98
|
+
code: TServiceAdminTokenRefusal;
|
|
99
|
+
retryable: false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const serviceIdPattern = /^[A-Za-z0-9][A-Za-z0-9:._-]{0,199}$/;
|
|
103
|
+
const scopePattern = /^[a-z][a-z0-9._-]{0,31}:(?:[a-z][a-z0-9._-]{0,31}|\*)$/;
|
|
104
|
+
const kidPattern = /^sat-[a-f0-9]{16}$/;
|
|
105
|
+
const ed25519XPattern = /^[A-Za-z0-9_-]{43}$/;
|
|
106
|
+
const jtiPattern = /^sat_[a-f0-9]{32,64}$/;
|
|
107
|
+
|
|
108
|
+
const fail = (): never => {
|
|
109
|
+
throw new Error('Service admin token contract rejected.');
|
|
110
|
+
};
|
|
111
|
+
function requireValue(valueArg: unknown): asserts valueArg {
|
|
112
|
+
if (!valueArg) fail();
|
|
113
|
+
}
|
|
114
|
+
const safe = <T>(operationArg: () => T): T => {
|
|
115
|
+
try {
|
|
116
|
+
return operationArg();
|
|
117
|
+
} catch {
|
|
118
|
+
return fail();
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export const buildServiceAdminAudience = (serviceIdArg: string): string => (
|
|
123
|
+
`${serviceAdminTokenContract.audiencePrefix}${serviceIdArg}`
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
export const isServiceAdminTokenServiceId = (valueArg: unknown): valueArg is string => (
|
|
127
|
+
typeof valueArg === 'string' && serviceIdPattern.test(valueArg)
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
export const isServiceAdminTokenScope = (valueArg: unknown): valueArg is string => (
|
|
131
|
+
typeof valueArg === 'string' && scopePattern.test(valueArg)
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
export const isServiceAdminTokenJti = (valueArg: unknown): valueArg is string => (
|
|
135
|
+
typeof valueArg === 'string' && jtiPattern.test(valueArg)
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
export const isServiceAdminAuthorityKeyId = (valueArg: unknown): valueArg is string => (
|
|
139
|
+
typeof valueArg === 'string' && kidPattern.test(valueArg)
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
export const isServiceAdminTokenLifetime = (valueArg: unknown): valueArg is number => (
|
|
143
|
+
typeof valueArg === 'number'
|
|
144
|
+
&& Number.isSafeInteger(valueArg)
|
|
145
|
+
&& valueArg >= serviceAdminTokenContract.minimumLifetimeMs
|
|
146
|
+
&& valueArg <= serviceAdminTokenContract.maximumLifetimeMs
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Checks whether a single granted scope satisfies a required scope.
|
|
151
|
+
* - `admin:*` matches any valid scope.
|
|
152
|
+
* - `<namespace>:*` matches any scope in `<namespace>:...`.
|
|
153
|
+
* - Otherwise requires exact match.
|
|
154
|
+
*/
|
|
155
|
+
export const serviceAdminTokenScopeMatches = (
|
|
156
|
+
grantedScopeArg: string,
|
|
157
|
+
requiredScopeArg: string,
|
|
158
|
+
): boolean => {
|
|
159
|
+
if (!isServiceAdminTokenScope(grantedScopeArg) || !isServiceAdminTokenScope(requiredScopeArg)) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
if (grantedScopeArg === 'admin:*' || grantedScopeArg === requiredScopeArg) {
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
if (grantedScopeArg.endsWith(':*')) {
|
|
166
|
+
const prefix = grantedScopeArg.slice(0, -1); // includes trailing ':'
|
|
167
|
+
return requiredScopeArg.startsWith(prefix);
|
|
168
|
+
}
|
|
169
|
+
return false;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
/** Returns true when every required scope is satisfied by at least one granted scope. */
|
|
173
|
+
export const serviceAdminTokenScopesSatisfy = (
|
|
174
|
+
grantedScopesArg: readonly string[],
|
|
175
|
+
requiredScopesArg: readonly string[],
|
|
176
|
+
): boolean => (
|
|
177
|
+
requiredScopesArg.every((requiredArg) => (
|
|
178
|
+
grantedScopesArg.some((grantedArg) => serviceAdminTokenScopeMatches(grantedArg, requiredArg))
|
|
179
|
+
))
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
/** Structural copy & validation of a mint request (scopes normalized sorted & distinct). */
|
|
183
|
+
export const snapshotServiceAdminTokenMintRequest = (
|
|
184
|
+
valueArg: unknown,
|
|
185
|
+
): IServiceAdminTokenMintRequest => safe(() => {
|
|
186
|
+
const namesLifetime = readDataProperty(valueArg, 'lifetimeMs') !== null;
|
|
187
|
+
const namesReason = readDataProperty(valueArg, 'reason') !== null;
|
|
188
|
+
const allowedKeys = [
|
|
189
|
+
'serviceId',
|
|
190
|
+
'scopes',
|
|
191
|
+
...(namesLifetime ? ['lifetimeMs'] : []),
|
|
192
|
+
...(namesReason ? ['reason'] : []),
|
|
193
|
+
];
|
|
194
|
+
const record = readExactDataRecord(valueArg, allowedKeys);
|
|
195
|
+
requireValue(record !== null);
|
|
196
|
+
requireValue(isServiceAdminTokenServiceId(record.serviceId));
|
|
197
|
+
|
|
198
|
+
const rawScopes = readDataElements(record.scopes, serviceAdminTokenContract.maximumScopes);
|
|
199
|
+
requireValue(
|
|
200
|
+
rawScopes !== null
|
|
201
|
+
&& rawScopes.length > 0
|
|
202
|
+
&& new Set(rawScopes).size === rawScopes.length
|
|
203
|
+
&& rawScopes.every((entryArg) => isServiceAdminTokenScope(entryArg)),
|
|
204
|
+
);
|
|
205
|
+
const scopes = (rawScopes as string[]).slice().sort();
|
|
206
|
+
|
|
207
|
+
const copy: IServiceAdminTokenMintRequest = {
|
|
208
|
+
serviceId: record.serviceId,
|
|
209
|
+
scopes,
|
|
210
|
+
};
|
|
211
|
+
if (namesLifetime) {
|
|
212
|
+
requireValue(isServiceAdminTokenLifetime(record.lifetimeMs));
|
|
213
|
+
copy.lifetimeMs = record.lifetimeMs;
|
|
214
|
+
}
|
|
215
|
+
if (namesReason) {
|
|
216
|
+
requireValue(
|
|
217
|
+
typeof record.reason === 'string'
|
|
218
|
+
&& record.reason.length > 0
|
|
219
|
+
&& record.reason.length <= serviceAdminTokenContract.maximumReasonLength
|
|
220
|
+
&& record.reason === record.reason.trim()
|
|
221
|
+
&& !/[\u0000-\u001f\u007f]/.test(record.reason),
|
|
222
|
+
);
|
|
223
|
+
copy.reason = record.reason;
|
|
224
|
+
}
|
|
225
|
+
return copy;
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
/** Structural copy & validation of a public Ed25519 JWKS payload. */
|
|
229
|
+
export const snapshotServiceAdminAuthorityJwks = (
|
|
230
|
+
valueArg: unknown,
|
|
231
|
+
): IServiceAdminAuthorityJwks => safe(() => {
|
|
232
|
+
const record = readExactDataRecord(valueArg, ['keys']);
|
|
233
|
+
requireValue(record !== null);
|
|
234
|
+
const rawKeys = readDataElements(record.keys, serviceAdminTokenContract.maximumJwksKeys);
|
|
235
|
+
requireValue(rawKeys !== null && rawKeys.length > 0);
|
|
236
|
+
|
|
237
|
+
const seenKids = new Set<string>();
|
|
238
|
+
const keys: IServiceAdminAuthorityJwk[] = [];
|
|
239
|
+
for (const entry of rawKeys) {
|
|
240
|
+
const jwk = readExactDataRecord(entry, ['kty', 'crv', 'alg', 'use', 'kid', 'x']);
|
|
241
|
+
requireValue(jwk !== null);
|
|
242
|
+
requireValue(
|
|
243
|
+
jwk.kty === 'OKP'
|
|
244
|
+
&& jwk.crv === 'Ed25519'
|
|
245
|
+
&& jwk.alg === 'EdDSA'
|
|
246
|
+
&& jwk.use === 'sig'
|
|
247
|
+
&& isServiceAdminAuthorityKeyId(jwk.kid)
|
|
248
|
+
&& typeof jwk.x === 'string'
|
|
249
|
+
&& ed25519XPattern.test(jwk.x)
|
|
250
|
+
&& !seenKids.has(jwk.kid),
|
|
251
|
+
);
|
|
252
|
+
seenKids.add(jwk.kid as string);
|
|
253
|
+
keys.push({
|
|
254
|
+
kty: 'OKP',
|
|
255
|
+
crv: 'Ed25519',
|
|
256
|
+
alg: 'EdDSA',
|
|
257
|
+
use: 'sig',
|
|
258
|
+
kid: jwk.kid as string,
|
|
259
|
+
x: jwk.x as string,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
return { keys };
|
|
263
|
+
});
|
package/ts/data/settings.ts
CHANGED
|
@@ -175,6 +175,8 @@ export const cloudlySystemSecretKeys = Object.freeze({
|
|
|
175
175
|
platformIdentityRecipientPrivateKeyPem: 'PLATFORM_IDENTITY_RECIPIENT_PRIVATE_KEY_PEM',
|
|
176
176
|
/** Cloudly's single platform registration credential for upstream idp.global OIDC client management. */
|
|
177
177
|
platformIdentityRegistrationCredential: 'PLATFORM_IDENTITY_REGISTRATION_CREDENTIAL',
|
|
178
|
+
/** Cloudly's Ed25519 private key PEM for signing short-lived Service Admin Tokens. */
|
|
179
|
+
serviceAdminAuthorityPrivateKeyPem: 'SERVICE_ADMIN_AUTHORITY_PRIVATE_KEY_PEM',
|
|
178
180
|
} as const);
|
|
179
181
|
|
|
180
182
|
/**
|