@serve.zone/interfaces 32.121.0 → 32.122.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.
@@ -46,9 +46,11 @@ 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`).
49
51
  * - `monitor`: read clusters, nodes, services, deployments, runtime log attempts and assignment logs.
50
52
  */
51
- export const delegatedAdminTokenScopes = ['secrets', 'serviceCredentials', 'monitor'] as const;
53
+ export const delegatedAdminTokenScopes = ['secrets', 'serviceCredentials', 'serviceAdminTokens', 'monitor'] as const;
52
54
 
53
55
  export type TDelegatedAdminTokenScope = typeof delegatedAdminTokenScopes[number];
54
56
 
@@ -59,6 +61,7 @@ export const delegatedAdminTokenScopeRequests = Object.freeze({
59
61
  'changeSecretLifecycle',
60
62
  ] as const),
61
63
  serviceCredentials: Object.freeze(['getServiceMachineCredential', 'mutateServiceMachineCredential'] as const),
64
+ serviceAdminTokens: Object.freeze(['getServiceAdminAuthorityStatus', 'mintServiceAdminToken'] as const),
62
65
  monitor: Object.freeze([
63
66
  'getClusters', 'getNodes', 'getServices', 'getDeployments', 'getServiceRuntimeLogAttempts',
64
67
  'getRuntimeAssignmentLogs',
@@ -248,7 +251,10 @@ export const snapshotDelegatedAdminTokenMint = (value: unknown): IDelegatedAdmin
248
251
  if (namesPrefixes) {
249
252
  const prefixes = secretKeyPrefixes(mint.secretKeyPrefixes, false);
250
253
  // Preserve the empty-list input accepted by existing serviceCredentials-only mints.
251
- requireValue(copy.scopes.includes('secrets') || (prefixes.length === 0 && !copy.scopes.includes('monitor')));
254
+ requireValue(
255
+ copy.scopes.includes('secrets')
256
+ || (prefixes.length === 0 && !copy.scopes.includes('monitor') && !copy.scopes.includes('serviceAdminTokens')),
257
+ );
252
258
  copy.secretKeyPrefixes = prefixes;
253
259
  }
254
260
  return copy;
package/ts/data/index.ts CHANGED
@@ -100,6 +100,7 @@ export * from './sparknodereport.js';
100
100
  export * from './nodeaction.js';
101
101
  export * from './sparkfleettarget.js';
102
102
  export * from './service.js';
103
+ export * from './serviceadmintoken.js';
103
104
  export * from './servicecredential.js';
104
105
  export * from './serviceplatformownership.js';
105
106
  export * from './serviceports.js';
@@ -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
+ });
@@ -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
  /**
@@ -50,6 +50,7 @@ export interface IPlatformIdentityBindingState {
50
50
  redirectUris: string[];
51
51
  postLogoutRedirectUris: string[];
52
52
  scopes: string[];
53
+ grantTypes?: string[];
53
54
  sessionSecretVariable: string;
54
55
  appId?: string;
55
56
  clientId?: string;
@@ -11,6 +11,11 @@ import type {
11
11
  import type {
12
12
  IDelegatedAdminTokenMetadata, IDelegatedAdminTokenMint, IDelegatedAdminTokenMintResult,
13
13
  } from '../data/delegatedadmintoken.js';
14
+ import type {
15
+ IServiceAdminAuthorityStatus,
16
+ IServiceAdminTokenMintRequest,
17
+ IServiceAdminTokenMintResult,
18
+ } from '../data/serviceadmintoken.js';
14
19
 
15
20
  export interface IReq_Admin_GetServiceMachineCredential extends plugins.typedrequestInterfaces.implementsTR<
16
21
  plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_GetServiceMachineCredential
@@ -249,3 +254,40 @@ export interface IReq_Admin_RevokeDelegatedAdminToken extends plugins.typedreque
249
254
  request: { identity: IIdentityCredential; tokenId: string };
250
255
  response: { metadata: IDelegatedAdminTokenMetadata };
251
256
  }
257
+
258
+ /**
259
+ * Value-free status of Cloudly's Ed25519 Service Admin Token Authority (active `kid`, `issuer`,
260
+ * and public JWKS). Admits administrators or delegated tokens with `serviceAdminTokens`.
261
+ */
262
+ export interface IReq_Admin_GetServiceAdminAuthorityStatus extends plugins.typedrequestInterfaces.implementsTR<
263
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_GetServiceAdminAuthorityStatus
264
+ > {
265
+ method: 'getServiceAdminAuthorityStatus';
266
+ request: { identity: IIdentityCredential };
267
+ response: { authority: IServiceAdminAuthorityStatus };
268
+ }
269
+
270
+ /**
271
+ * Rotates Cloudly's Ed25519 Service Admin Token Authority signing key while retaining the previous
272
+ * public key in JWKS during the token-lifetime overlap window. Requires a fresh human administrator.
273
+ */
274
+ export interface IReq_Admin_RotateServiceAdminAuthorityKey extends plugins.typedrequestInterfaces.implementsTR<
275
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_RotateServiceAdminAuthorityKey
276
+ > {
277
+ method: 'rotateServiceAdminAuthorityKey';
278
+ request: { identity: IIdentityCredential };
279
+ response: { authority: IServiceAdminAuthorityStatus };
280
+ }
281
+
282
+ /**
283
+ * Mints a short-lived, scope-limited, service-pinned Ed25519 Service Admin Token (`at+jwt`)
284
+ * accepted offline by hosted services that trust `SERVEZONE_SERVICE_ADMIN_JWKS`.
285
+ * Admits a fresh human administrator or a delegated temp token with the `serviceAdminTokens` scope.
286
+ */
287
+ export interface IReq_Admin_MintServiceAdminToken extends plugins.typedrequestInterfaces.implementsTR<
288
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_MintServiceAdminToken
289
+ > {
290
+ method: 'mintServiceAdminToken';
291
+ request: { identity: IIdentityCredential } & IServiceAdminTokenMintRequest;
292
+ response: IServiceAdminTokenMintResult;
293
+ }