@serve.zone/interfaces 32.119.0 → 32.121.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/deploymentoperation.js +29 -4
- package/dist_ts/data/deploymentpreflight.d.ts +5 -2
- package/dist_ts/data/deploymentpreflight.js +1 -1
- package/dist_ts/data/nodeaction.js +2 -2
- package/dist_ts/data/secret.d.ts +2 -2
- package/dist_ts/data/secret.js +4 -4
- package/dist_ts/data/serviceruntime.d.ts +1 -1
- package/dist_ts/data/serviceruntime.js +2 -1
- package/dist_ts/data/settings.d.ts +4 -0
- package/dist_ts/data/settings.js +5 -1
- package/dist_ts/platform/identity.d.ts +99 -0
- package/dist_ts/platform/identity.js +185 -0
- package/dist_ts/platform/identityenvironment.d.ts +40 -0
- package/dist_ts/platform/identityenvironment.js +101 -0
- package/dist_ts/platform/index.d.ts +5 -1
- package/dist_ts/platform/index.js +6 -2
- package/dist_ts/platform/types.d.ts +4 -1
- package/dist_ts/platform/types.js +1 -1
- package/dist_ts/requests/identity.d.ts +87 -0
- package/dist_ts/requests/identity.js +1 -1
- package/dist_ts/runtime.workloadinit.d.ts +11 -5
- package/dist_ts/runtime.workloadinit.js +29 -8
- package/package.json +4 -4
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/data/deploymentoperation.ts +24 -2
- package/ts/data/deploymentpreflight.ts +5 -2
- package/ts/data/nodeaction.ts +1 -1
- package/ts/data/secret.ts +5 -3
- package/ts/data/serviceruntime.ts +1 -0
- package/ts/data/settings.ts +4 -0
- package/ts/platform/identity.ts +304 -0
- package/ts/platform/identityenvironment.ts +151 -0
- package/ts/platform/index.ts +6 -0
- package/ts/platform/types.ts +4 -0
- package/ts/requests/identity.ts +127 -1
- package/ts/runtime.workloadinit.ts +41 -12
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { isReservedSecretKey } from '../data/secret.js';
|
|
2
|
+
import { hasExactKeys, isPlainRecord } from '../private/dataproperties.js';
|
|
3
|
+
|
|
4
|
+
/** Plain environment variable names owned by a platform identity binding. */
|
|
5
|
+
export const identityPlainEnvironmentKeys = Object.freeze([
|
|
6
|
+
'IDP_ISSUER',
|
|
7
|
+
'IDP_CLIENT_ID',
|
|
8
|
+
'PUBLIC_ORIGIN',
|
|
9
|
+
] as const);
|
|
10
|
+
|
|
11
|
+
export type TIdentityPlainEnvironmentKey = typeof identityPlainEnvironmentKeys[number];
|
|
12
|
+
|
|
13
|
+
/** Managed launcher-environment secret key owned by a platform identity binding for the OIDC client secret. */
|
|
14
|
+
export const identityClientSecretKey = 'IDP_CLIENT_SECRET' as const;
|
|
15
|
+
|
|
16
|
+
export const identityDeclarationLimits = Object.freeze({
|
|
17
|
+
maxRedirectPaths: 16,
|
|
18
|
+
maxPostLogoutRedirectPaths: 16,
|
|
19
|
+
maxScopes: 32,
|
|
20
|
+
maxSessionSecretVariableLength: 128,
|
|
21
|
+
} as const);
|
|
22
|
+
|
|
23
|
+
export const identitySessionSecretVariableRegex = /^[A-Z][A-Z0-9_]*_SESSION_SECRET$/;
|
|
24
|
+
export const identityRedirectPathRegex = /^\/(?!\/)[A-Za-z0-9._~!$&'()*+,;=:@%\/-]{0,1023}$/;
|
|
25
|
+
export const identityScopeRegex = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Secret-free identity capability declaration carried inside a deployment's proposed configuration.
|
|
29
|
+
* Required exactly when `'identity'` is listed in `requiredCapabilities`.
|
|
30
|
+
*/
|
|
31
|
+
export interface IDeploymentIdentityDeclaration {
|
|
32
|
+
redirectPaths: string[];
|
|
33
|
+
postLogoutRedirectPaths: string[];
|
|
34
|
+
scopes: string[];
|
|
35
|
+
sessionSecretVariable: string;
|
|
36
|
+
/** Required when `publicDomains` has more than one entry; must be an exact entry of `publicDomains`. */
|
|
37
|
+
originDomain?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Value-free persisted state of one service's platform identity binding.
|
|
42
|
+
* Never carries `IDP_CLIENT_SECRET` or the session secret; those live only in Cloudly's secret store.
|
|
43
|
+
*/
|
|
44
|
+
export interface IPlatformIdentityBindingState {
|
|
45
|
+
issuer?: string;
|
|
46
|
+
origin: string;
|
|
47
|
+
originDomain: string;
|
|
48
|
+
redirectPaths: string[];
|
|
49
|
+
postLogoutRedirectPaths: string[];
|
|
50
|
+
redirectUris: string[];
|
|
51
|
+
postLogoutRedirectUris: string[];
|
|
52
|
+
scopes: string[];
|
|
53
|
+
sessionSecretVariable: string;
|
|
54
|
+
appId?: string;
|
|
55
|
+
clientId?: string;
|
|
56
|
+
generation: number;
|
|
57
|
+
pendingOperationId?: string;
|
|
58
|
+
clientSecretRotatedAt?: number;
|
|
59
|
+
lastError?: string;
|
|
60
|
+
updatedAt: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Value-free administrative status of Cloudly's platform identity registration provider. */
|
|
64
|
+
export interface IPlatformIdentityProviderStatus {
|
|
65
|
+
/** Canonical DER SPKI standard base64 RSA-OAEP-256 public key for sealing credentials to Cloudly. */
|
|
66
|
+
recipientPublicKeySpkiBase64: string;
|
|
67
|
+
/** Lowercase hex SHA-256 of the DER SPKI public key bytes. */
|
|
68
|
+
recipientPublicKeySha256: string;
|
|
69
|
+
issuer?: string;
|
|
70
|
+
configured: boolean;
|
|
71
|
+
principalId?: string;
|
|
72
|
+
principalLabel?: string;
|
|
73
|
+
installedAt?: number;
|
|
74
|
+
lastRotatedAt?: number;
|
|
75
|
+
lastError?: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Value-free administrative view of one service's platform identity binding. */
|
|
79
|
+
export interface IPlatformIdentityServiceBindingView {
|
|
80
|
+
serviceId: string;
|
|
81
|
+
bindingId: string;
|
|
82
|
+
desiredState: 'enabled' | 'disabled';
|
|
83
|
+
status: 'requested' | 'provisioning' | 'ready' | 'degraded' | 'failed' | 'disabled';
|
|
84
|
+
state: IPlatformIdentityBindingState | null;
|
|
85
|
+
managedSecretKeys: string[];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Sealed RSA-OAEP-256 credential envelope handed to Cloudly at one-time bootstrap. */
|
|
89
|
+
export interface ISealedPlatformIdentityCredentialEnvelope {
|
|
90
|
+
algorithm: 'rsa-oaep-256';
|
|
91
|
+
ciphertextBase64: string;
|
|
92
|
+
publicKeySha256?: string;
|
|
93
|
+
ciphertextSha256?: string;
|
|
94
|
+
operationId?: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** All five environment variable names owned by a platform identity binding. */
|
|
98
|
+
export const getIdentityOwnedEnvironmentNames = (
|
|
99
|
+
sessionSecretVariableArg: string,
|
|
100
|
+
): readonly string[] => [
|
|
101
|
+
...identityPlainEnvironmentKeys,
|
|
102
|
+
identityClientSecretKey,
|
|
103
|
+
sessionSecretVariableArg,
|
|
104
|
+
];
|
|
105
|
+
|
|
106
|
+
/** Whether a hostname is an exact (non-wildcard) canonical hostname. */
|
|
107
|
+
export const isExactIdentityHostname = (hostnameArg: unknown): hostnameArg is string => (
|
|
108
|
+
typeof hostnameArg === 'string'
|
|
109
|
+
&& hostnameArg.length > 0
|
|
110
|
+
&& hostnameArg.length <= 253
|
|
111
|
+
&& !hostnameArg.startsWith('*.')
|
|
112
|
+
&& !hostnameArg.includes('*')
|
|
113
|
+
&& hostnameArg === hostnameArg.toLowerCase()
|
|
114
|
+
&& /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/.test(hostnameArg)
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
/** Resolves the exact origin domain for an identity declaration against granted publicDomains, or null. */
|
|
118
|
+
export const resolveIdentityOriginDomain = (
|
|
119
|
+
declarationArg: Pick<IDeploymentIdentityDeclaration, 'originDomain'>,
|
|
120
|
+
publicDomainsArg: readonly string[],
|
|
121
|
+
): string | null => {
|
|
122
|
+
if (declarationArg.originDomain !== undefined) {
|
|
123
|
+
if (!isExactIdentityHostname(declarationArg.originDomain)) return null;
|
|
124
|
+
return publicDomainsArg.includes(declarationArg.originDomain)
|
|
125
|
+
? declarationArg.originDomain
|
|
126
|
+
: null;
|
|
127
|
+
}
|
|
128
|
+
if (publicDomainsArg.length !== 1) return null;
|
|
129
|
+
return isExactIdentityHostname(publicDomainsArg[0]) ? publicDomainsArg[0] : null;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/** Builds canonical HTTPS URIs on an exact origin domain from canonical absolute paths. */
|
|
133
|
+
export const buildIdentityRedirectUris = (
|
|
134
|
+
originDomainArg: string,
|
|
135
|
+
pathsArg: readonly string[],
|
|
136
|
+
): string[] => pathsArg.map((pathArg) => `https://${originDomainArg}${pathArg}`);
|
|
137
|
+
|
|
138
|
+
const isCanonicalHttpsOrigin = (valueArg: unknown): valueArg is string => {
|
|
139
|
+
if (typeof valueArg !== 'string' || valueArg.length === 0 || valueArg.length > 253) return false;
|
|
140
|
+
try {
|
|
141
|
+
const parsed = new URL(valueArg);
|
|
142
|
+
return parsed.protocol === 'https:'
|
|
143
|
+
&& parsed.origin === valueArg
|
|
144
|
+
&& !parsed.username
|
|
145
|
+
&& !parsed.password;
|
|
146
|
+
} catch {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/** Validates a canonical HTTPS issuer origin URL (e.g. `https://idp.global`). */
|
|
152
|
+
export const validatePlatformIdentityIssuer = (
|
|
153
|
+
issuerArg: unknown,
|
|
154
|
+
pathArg = 'issuer',
|
|
155
|
+
): string[] => (
|
|
156
|
+
isCanonicalHttpsOrigin(issuerArg)
|
|
157
|
+
? []
|
|
158
|
+
: [`${pathArg} must be a canonical https origin URL`]
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const validatePathList = (
|
|
162
|
+
valueArg: unknown,
|
|
163
|
+
optionsArg: { minLength: number; maxLength: number; label: string },
|
|
164
|
+
): string[] => {
|
|
165
|
+
if (!Array.isArray(valueArg)
|
|
166
|
+
|| valueArg.length < optionsArg.minLength
|
|
167
|
+
|| valueArg.length > optionsArg.maxLength) {
|
|
168
|
+
return [`${optionsArg.label} must contain between ${optionsArg.minLength} and ${optionsArg.maxLength} entries`];
|
|
169
|
+
}
|
|
170
|
+
const errors: string[] = [];
|
|
171
|
+
for (const [index, entry] of valueArg.entries()) {
|
|
172
|
+
if (typeof entry !== 'string' || !identityRedirectPathRegex.test(entry)) {
|
|
173
|
+
errors.push(`${optionsArg.label}[${index}] must be a canonical absolute path`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (new Set(valueArg).size !== valueArg.length) {
|
|
177
|
+
errors.push(`${optionsArg.label} must not contain duplicates`);
|
|
178
|
+
}
|
|
179
|
+
return errors;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Validates the `identity` block of a deployment's proposed configuration against its declared
|
|
184
|
+
* `publicDomains` and `environmentVariableNames`.
|
|
185
|
+
*/
|
|
186
|
+
export const validateDeploymentIdentityDeclaration = (
|
|
187
|
+
declarationArg: unknown,
|
|
188
|
+
contextArg: {
|
|
189
|
+
publicDomains: readonly string[];
|
|
190
|
+
environmentVariableNames: readonly string[];
|
|
191
|
+
},
|
|
192
|
+
pathArg = 'identity',
|
|
193
|
+
): string[] => {
|
|
194
|
+
if (!isPlainRecord(declarationArg)) {
|
|
195
|
+
return [`${pathArg} must be an object`];
|
|
196
|
+
}
|
|
197
|
+
const errors: string[] = [];
|
|
198
|
+
if (!hasExactKeys(
|
|
199
|
+
declarationArg,
|
|
200
|
+
['redirectPaths', 'postLogoutRedirectPaths', 'scopes', 'sessionSecretVariable'],
|
|
201
|
+
['originDomain'],
|
|
202
|
+
)) {
|
|
203
|
+
errors.push(`${pathArg} must use its exact schema`);
|
|
204
|
+
}
|
|
205
|
+
errors.push(...validatePathList(declarationArg.redirectPaths, {
|
|
206
|
+
minLength: 1,
|
|
207
|
+
maxLength: identityDeclarationLimits.maxRedirectPaths,
|
|
208
|
+
label: `${pathArg}.redirectPaths`,
|
|
209
|
+
}));
|
|
210
|
+
errors.push(...validatePathList(declarationArg.postLogoutRedirectPaths, {
|
|
211
|
+
minLength: 0,
|
|
212
|
+
maxLength: identityDeclarationLimits.maxPostLogoutRedirectPaths,
|
|
213
|
+
label: `${pathArg}.postLogoutRedirectPaths`,
|
|
214
|
+
}));
|
|
215
|
+
if (!Array.isArray(declarationArg.scopes)
|
|
216
|
+
|| declarationArg.scopes.length < 1
|
|
217
|
+
|| declarationArg.scopes.length > identityDeclarationLimits.maxScopes
|
|
218
|
+
|| declarationArg.scopes.some((scopeArg) => (
|
|
219
|
+
typeof scopeArg !== 'string' || !identityScopeRegex.test(scopeArg)
|
|
220
|
+
))
|
|
221
|
+
|| new Set(declarationArg.scopes).size !== declarationArg.scopes.length) {
|
|
222
|
+
errors.push(`${pathArg}.scopes must be a unique non-empty bounded scope list`);
|
|
223
|
+
} else if (!declarationArg.scopes.includes('openid')) {
|
|
224
|
+
errors.push(`${pathArg}.scopes must include openid`);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const sessionSecretVariable = declarationArg.sessionSecretVariable;
|
|
228
|
+
const validSessionSecretVariable = typeof sessionSecretVariable === 'string'
|
|
229
|
+
&& sessionSecretVariable.length <= identityDeclarationLimits.maxSessionSecretVariableLength
|
|
230
|
+
&& identitySessionSecretVariableRegex.test(sessionSecretVariable)
|
|
231
|
+
&& !isReservedSecretKey(sessionSecretVariable)
|
|
232
|
+
&& !(identityPlainEnvironmentKeys as readonly string[]).includes(sessionSecretVariable)
|
|
233
|
+
&& sessionSecretVariable !== identityClientSecretKey;
|
|
234
|
+
if (!validSessionSecretVariable) {
|
|
235
|
+
errors.push(
|
|
236
|
+
`${pathArg}.sessionSecretVariable must match *_SESSION_SECRET and not be a reserved or fixed identity key`,
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const publicDomains = contextArg.publicDomains;
|
|
241
|
+
if (declarationArg.originDomain !== undefined) {
|
|
242
|
+
if (!isExactIdentityHostname(declarationArg.originDomain)) {
|
|
243
|
+
errors.push(`${pathArg}.originDomain must be an exact non-wildcard canonical hostname`);
|
|
244
|
+
} else if (!publicDomains.includes(declarationArg.originDomain)) {
|
|
245
|
+
errors.push(`${pathArg}.originDomain must be present in publicDomains`);
|
|
246
|
+
}
|
|
247
|
+
} else if (publicDomains.length === 0) {
|
|
248
|
+
errors.push(`${pathArg} requires at least one exact non-wildcard publicDomain`);
|
|
249
|
+
} else if (publicDomains.length > 1) {
|
|
250
|
+
errors.push(`${pathArg}.originDomain is required when publicDomains contains more than one domain`);
|
|
251
|
+
} else if (!isExactIdentityHostname(publicDomains[0])) {
|
|
252
|
+
errors.push(`${pathArg} cannot use a wildcard publicDomain as origin`);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (validSessionSecretVariable) {
|
|
256
|
+
const envNames = new Set(contextArg.environmentVariableNames);
|
|
257
|
+
const missing = getIdentityOwnedEnvironmentNames(sessionSecretVariable)
|
|
258
|
+
.filter((nameArg) => !envNames.has(nameArg));
|
|
259
|
+
if (missing.length > 0) {
|
|
260
|
+
errors.push(
|
|
261
|
+
`${pathArg} requires environmentVariableNames to declare ${missing.join(', ')}`,
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return errors;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
/** Validates a sealed RSA-OAEP-256 credential envelope submitted for platform identity bootstrap. */
|
|
269
|
+
export const validateSealedPlatformIdentityCredentialEnvelope = (
|
|
270
|
+
envelopeArg: unknown,
|
|
271
|
+
pathArg = 'sealedCredential',
|
|
272
|
+
): string[] => {
|
|
273
|
+
if (!isPlainRecord(envelopeArg)) return [`${pathArg} must be an object`];
|
|
274
|
+
const errors: string[] = [];
|
|
275
|
+
if (!hasExactKeys(
|
|
276
|
+
envelopeArg,
|
|
277
|
+
['algorithm', 'ciphertextBase64'],
|
|
278
|
+
['publicKeySha256', 'ciphertextSha256', 'operationId'],
|
|
279
|
+
)) {
|
|
280
|
+
errors.push(`${pathArg} must use its exact schema`);
|
|
281
|
+
}
|
|
282
|
+
if (envelopeArg.algorithm !== 'rsa-oaep-256') {
|
|
283
|
+
errors.push(`${pathArg}.algorithm must be rsa-oaep-256`);
|
|
284
|
+
}
|
|
285
|
+
if (typeof envelopeArg.ciphertextBase64 !== 'string'
|
|
286
|
+
|| envelopeArg.ciphertextBase64.length === 0
|
|
287
|
+
|| envelopeArg.ciphertextBase64.length > 8192
|
|
288
|
+
|| !/^[A-Za-z0-9+/]+={0,2}$/.test(envelopeArg.ciphertextBase64)
|
|
289
|
+
|| envelopeArg.ciphertextBase64.length % 4 !== 0) {
|
|
290
|
+
errors.push(`${pathArg}.ciphertextBase64 must be canonical base64`);
|
|
291
|
+
}
|
|
292
|
+
for (const hashField of ['publicKeySha256', 'ciphertextSha256'] as const) {
|
|
293
|
+
const value = envelopeArg[hashField];
|
|
294
|
+
if (value !== undefined && (typeof value !== 'string' || !/^[a-f0-9]{64}$/.test(value))) {
|
|
295
|
+
errors.push(`${pathArg}.${hashField} must be a 64-character lowercase hex SHA-256`);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
if (envelopeArg.operationId !== undefined
|
|
299
|
+
&& (typeof envelopeArg.operationId !== 'string'
|
|
300
|
+
|| !/^[A-Za-z0-9][A-Za-z0-9:._-]{0,199}$/.test(envelopeArg.operationId))) {
|
|
301
|
+
errors.push(`${pathArg}.operationId must be a canonical identifier`);
|
|
302
|
+
}
|
|
303
|
+
return errors;
|
|
304
|
+
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { IPlatformBinding } from './types.js';
|
|
2
|
+
import type { TServiceRuntimeRefusal, TServiceRuntimeWaitingReason } from '../data/serviceruntime.js';
|
|
3
|
+
import {
|
|
4
|
+
identityClientSecretKey,
|
|
5
|
+
identityPlainEnvironmentKeys,
|
|
6
|
+
identitySessionSecretVariableRegex,
|
|
7
|
+
validatePlatformIdentityIssuer,
|
|
8
|
+
type TIdentityPlainEnvironmentKey,
|
|
9
|
+
} from './identity.js';
|
|
10
|
+
import { readDataProperties } from '../private/dataproperties.js';
|
|
11
|
+
|
|
12
|
+
/** The three non-secret environment variable names injected by a platform identity binding. */
|
|
13
|
+
export const identityBindingEnvironmentKeys = identityPlainEnvironmentKeys;
|
|
14
|
+
|
|
15
|
+
export type TIdentityBindingEnvironment = Record<TIdentityPlainEnvironmentKey, string>;
|
|
16
|
+
|
|
17
|
+
export type TIdentityEnvironmentRefusal = Extract<
|
|
18
|
+
TServiceRuntimeRefusal,
|
|
19
|
+
'identity-environment-conflict'
|
|
20
|
+
>;
|
|
21
|
+
|
|
22
|
+
export type TIdentityEnvironmentWaitingReason = Extract<
|
|
23
|
+
TServiceRuntimeWaitingReason,
|
|
24
|
+
'bindings-pending'
|
|
25
|
+
>;
|
|
26
|
+
|
|
27
|
+
export type TIdentityServiceEnvironmentComposition =
|
|
28
|
+
| { status: 'composed'; environment: Record<string, string> }
|
|
29
|
+
| {
|
|
30
|
+
status: 'waiting';
|
|
31
|
+
reason: TIdentityEnvironmentWaitingReason;
|
|
32
|
+
bindingId: string;
|
|
33
|
+
message: string;
|
|
34
|
+
}
|
|
35
|
+
| {
|
|
36
|
+
status: 'refused';
|
|
37
|
+
reason: TIdentityEnvironmentRefusal;
|
|
38
|
+
bindingId: string;
|
|
39
|
+
message: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const isCanonicalHttpsOrigin = (valueArg: unknown): valueArg is string => (
|
|
43
|
+
validatePlatformIdentityIssuer(valueArg).length === 0
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Composes a service's plain environment with its enabled platform identity binding, or reports
|
|
48
|
+
* the one refusal or wait reason why it cannot be composed.
|
|
49
|
+
*
|
|
50
|
+
* Refusal rules (`identity-environment-conflict`, checked even while the binding is still pending):
|
|
51
|
+
* - A service may hold at most one enabled `identity` binding.
|
|
52
|
+
* - The service's own plain `environment` must not define any of the five identity-owned names
|
|
53
|
+
* (`IDP_ISSUER`, `IDP_CLIENT_ID`, `PUBLIC_ORIGIN`, `IDP_CLIENT_SECRET`, `<sessionSecretVariable>`).
|
|
54
|
+
* - The service's launcher-environment secrets (`secretEnvironmentNamesArg`) must not deliver any
|
|
55
|
+
* of the three plain identity names (`IDP_ISSUER`, `IDP_CLIENT_ID`, `PUBLIC_ORIGIN`), which would
|
|
56
|
+
* silently shadow Cloudly's plain values. (The binding's two managed secrets, `IDP_CLIENT_SECRET`
|
|
57
|
+
* and `<sessionSecretVariable>`, are delivered as launcher secrets by the binding itself.)
|
|
58
|
+
*
|
|
59
|
+
* Wait rule (`bindings-pending`):
|
|
60
|
+
* - While the binding is not yet `'ready'` or does not yet carry a registered `issuer`, `clientId`
|
|
61
|
+
* and `origin`, the workload waits as `bindings-pending`.
|
|
62
|
+
*/
|
|
63
|
+
export const composeIdentityServiceEnvironment = (
|
|
64
|
+
serviceEnvironmentArg: Readonly<Record<string, string>>,
|
|
65
|
+
bindingsArg: readonly IPlatformBinding[],
|
|
66
|
+
secretEnvironmentNamesArg: readonly string[] = [],
|
|
67
|
+
): TIdentityServiceEnvironmentComposition => {
|
|
68
|
+
const bindings = [...bindingsArg]
|
|
69
|
+
.filter((bindingArg) => bindingArg.capability === 'identity' && bindingArg.desiredState === 'enabled')
|
|
70
|
+
.sort((leftArg, rightArg) => (
|
|
71
|
+
leftArg.id < rightArg.id ? -1 : leftArg.id > rightArg.id ? 1 : 0
|
|
72
|
+
));
|
|
73
|
+
if (bindings.length === 0) {
|
|
74
|
+
return { status: 'composed', environment: { ...serviceEnvironmentArg } };
|
|
75
|
+
}
|
|
76
|
+
if (bindings.length > 1) {
|
|
77
|
+
return {
|
|
78
|
+
status: 'refused',
|
|
79
|
+
reason: 'identity-environment-conflict',
|
|
80
|
+
bindingId: bindings[0].id,
|
|
81
|
+
message: `service has multiple enabled identity bindings (${bindings.map((b) => b.id).join(', ')})`,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const binding = bindings[0];
|
|
85
|
+
const state = binding.identity ? readDataProperties(binding.identity) : null;
|
|
86
|
+
const sessionSecretVariable = typeof state?.sessionSecretVariable === 'string'
|
|
87
|
+
&& identitySessionSecretVariableRegex.test(state.sessionSecretVariable)
|
|
88
|
+
? state.sessionSecretVariable
|
|
89
|
+
: undefined;
|
|
90
|
+
|
|
91
|
+
const plainKeysOwned = new Set<string>([
|
|
92
|
+
...identityPlainEnvironmentKeys,
|
|
93
|
+
identityClientSecretKey,
|
|
94
|
+
...(sessionSecretVariable ? [sessionSecretVariable] : []),
|
|
95
|
+
]);
|
|
96
|
+
const servicePlainCollisions = Object.keys(serviceEnvironmentArg)
|
|
97
|
+
.filter((keyArg) => plainKeysOwned.has(keyArg))
|
|
98
|
+
.sort();
|
|
99
|
+
const secretNames = new Set(secretEnvironmentNamesArg);
|
|
100
|
+
const launcherPlainCollisions = (identityPlainEnvironmentKeys as readonly string[])
|
|
101
|
+
.filter((keyArg) => secretNames.has(keyArg))
|
|
102
|
+
.sort();
|
|
103
|
+
|
|
104
|
+
const allCollisions = [...new Set([...servicePlainCollisions, ...launcherPlainCollisions])].sort();
|
|
105
|
+
if (allCollisions.length > 0) {
|
|
106
|
+
return {
|
|
107
|
+
status: 'refused',
|
|
108
|
+
reason: 'identity-environment-conflict',
|
|
109
|
+
bindingId: binding.id,
|
|
110
|
+
message: `identity binding environment collides with ${allCollisions.join(', ')} already set on the workload`
|
|
111
|
+
+ (launcherPlainCollisions.length > 0
|
|
112
|
+
? `; ${launcherPlainCollisions.join(', ')} reaches it as a launcher-environment secret, which would replace the binding's plain value`
|
|
113
|
+
: ''),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (binding.status !== 'ready' || !state) {
|
|
118
|
+
return {
|
|
119
|
+
status: 'waiting',
|
|
120
|
+
reason: 'bindings-pending',
|
|
121
|
+
bindingId: binding.id,
|
|
122
|
+
message: `identity binding ${binding.id} is ${binding.status}; waiting until it is ready`,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const issuer = state.issuer;
|
|
127
|
+
const clientId = state.clientId;
|
|
128
|
+
const origin = state.origin;
|
|
129
|
+
if (!isCanonicalHttpsOrigin(issuer)
|
|
130
|
+
|| !isCanonicalHttpsOrigin(origin)
|
|
131
|
+
|| typeof clientId !== 'string'
|
|
132
|
+
|| clientId.trim().length === 0
|
|
133
|
+
|| clientId.trim() !== clientId) {
|
|
134
|
+
return {
|
|
135
|
+
status: 'waiting',
|
|
136
|
+
reason: 'bindings-pending',
|
|
137
|
+
bindingId: binding.id,
|
|
138
|
+
message: `identity binding ${binding.id} has incomplete non-secret identity metadata`,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
status: 'composed',
|
|
144
|
+
environment: {
|
|
145
|
+
...serviceEnvironmentArg,
|
|
146
|
+
IDP_ISSUER: issuer,
|
|
147
|
+
IDP_CLIENT_ID: clientId,
|
|
148
|
+
PUBLIC_ORIGIN: origin,
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
};
|
package/ts/platform/index.ts
CHANGED
|
@@ -3,6 +3,8 @@ import * as backup from './backup.js';
|
|
|
3
3
|
import * as corestoreendpointselection from './corestoreendpointselection.js';
|
|
4
4
|
import * as database from './database.js';
|
|
5
5
|
import * as email from './email.js';
|
|
6
|
+
import * as identity from './identity.js';
|
|
7
|
+
import * as identityenvironment from './identityenvironment.js';
|
|
6
8
|
import * as letter from './letter.js';
|
|
7
9
|
import * as logging from './logging.js';
|
|
8
10
|
import * as objectstorage from './objectstorage.js';
|
|
@@ -21,6 +23,8 @@ export {
|
|
|
21
23
|
corestoreendpointselection,
|
|
22
24
|
database,
|
|
23
25
|
email,
|
|
26
|
+
identity,
|
|
27
|
+
identityenvironment,
|
|
24
28
|
letter,
|
|
25
29
|
logging,
|
|
26
30
|
objectstorage,
|
|
@@ -36,6 +40,8 @@ export {
|
|
|
36
40
|
|
|
37
41
|
export * from './corestoreendpointselection.js';
|
|
38
42
|
export * from './database.js';
|
|
43
|
+
export * from './identity.js';
|
|
44
|
+
export * from './identityenvironment.js';
|
|
39
45
|
export * from './storage.js';
|
|
40
46
|
export * from './objectstorage.js';
|
|
41
47
|
export * from './objectstorageenvironment.js';
|
package/ts/platform/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TSecretManagementScope } from '../data/secret.js';
|
|
2
|
+
import type { IPlatformIdentityBindingState } from './identity.js';
|
|
2
3
|
import type { IObjectStorageRetentionBinding } from './objectstorageretention.js';
|
|
3
4
|
|
|
4
5
|
export type TPlatformCapability =
|
|
@@ -9,6 +10,7 @@ export type TPlatformCapability =
|
|
|
9
10
|
| 'ai'
|
|
10
11
|
| 'database'
|
|
11
12
|
| 'objectstorage'
|
|
13
|
+
| 'identity'
|
|
12
14
|
| 'logging'
|
|
13
15
|
| 'backup'
|
|
14
16
|
| 'sip';
|
|
@@ -144,6 +146,8 @@ export interface IPlatformBinding {
|
|
|
144
146
|
objectstorageBucketName?: string;
|
|
145
147
|
/** Capability-specific value-free immutable-retention intent and evidence. */
|
|
146
148
|
objectstorageRetention?: IObjectStorageRetentionBinding;
|
|
149
|
+
/** Capability-specific value-free platform identity binding metadata (never secrets). */
|
|
150
|
+
identity?: IPlatformIdentityBindingState;
|
|
147
151
|
/** Server-managed: the legacy Corestore resource this binding adopts. */
|
|
148
152
|
corestoreLegacyAdoption?: IPlatformBindingCorestoreLegacyAdoption;
|
|
149
153
|
/** Why the binding holds its status, as the responsible cluster reported it. */
|
package/ts/requests/identity.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import * as plugins from '../plugins.js';
|
|
2
|
-
import * as userInterfaces from '../data/user.js'
|
|
2
|
+
import * as userInterfaces from '../data/user.js';
|
|
3
|
+
import type {
|
|
4
|
+
IPlatformIdentityProviderStatus,
|
|
5
|
+
IPlatformIdentityServiceBindingView,
|
|
6
|
+
ISealedPlatformIdentityCredentialEnvelope,
|
|
7
|
+
} from '../platform/identity.js';
|
|
3
8
|
|
|
4
9
|
// ========
|
|
5
10
|
// IDENTITY
|
|
@@ -25,3 +30,124 @@ extends plugins.typedrequestInterfaces.implementsTR<
|
|
|
25
30
|
identity: userInterfaces.IIdentity;
|
|
26
31
|
};
|
|
27
32
|
}
|
|
33
|
+
|
|
34
|
+
/** Read Cloudly's platform identity provider status and RSA-OAEP-256 recipient public key. */
|
|
35
|
+
export interface IReq_Admin_GetPlatformIdentityProviderStatus
|
|
36
|
+
extends plugins.typedrequestInterfaces.implementsTR<
|
|
37
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
38
|
+
IReq_Admin_GetPlatformIdentityProviderStatus
|
|
39
|
+
> {
|
|
40
|
+
method: 'getPlatformIdentityProviderStatus';
|
|
41
|
+
request: {
|
|
42
|
+
identity: userInterfaces.IIdentityCredential;
|
|
43
|
+
};
|
|
44
|
+
response: {
|
|
45
|
+
status: IPlatformIdentityProviderStatus;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Install or replace Cloudly's sealed platform registration credential (admin-only, fresh sign-in).
|
|
51
|
+
* The credential arrives sealed RSA-OAEP-256 to Cloudly's recipient public key and is stored only
|
|
52
|
+
* in Cloudly's system secret store.
|
|
53
|
+
*/
|
|
54
|
+
export interface IReq_Admin_InstallPlatformIdentityCredential
|
|
55
|
+
extends plugins.typedrequestInterfaces.implementsTR<
|
|
56
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
57
|
+
IReq_Admin_InstallPlatformIdentityCredential
|
|
58
|
+
> {
|
|
59
|
+
method: 'installPlatformIdentityCredential';
|
|
60
|
+
request: {
|
|
61
|
+
identity: userInterfaces.IIdentityCredential;
|
|
62
|
+
issuer: string;
|
|
63
|
+
principalId?: string;
|
|
64
|
+
principalLabel?: string;
|
|
65
|
+
sealedCredential: ISealedPlatformIdentityCredentialEnvelope;
|
|
66
|
+
};
|
|
67
|
+
response: {
|
|
68
|
+
status: IPlatformIdentityProviderStatus;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Self-rotate Cloudly's platform registration credential upstream on idp.global (admin-only, fresh sign-in). */
|
|
73
|
+
export interface IReq_Admin_RotatePlatformIdentityCredential
|
|
74
|
+
extends plugins.typedrequestInterfaces.implementsTR<
|
|
75
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
76
|
+
IReq_Admin_RotatePlatformIdentityCredential
|
|
77
|
+
> {
|
|
78
|
+
method: 'rotatePlatformIdentityCredential';
|
|
79
|
+
request: {
|
|
80
|
+
identity: userInterfaces.IIdentityCredential;
|
|
81
|
+
};
|
|
82
|
+
response: {
|
|
83
|
+
status: IPlatformIdentityProviderStatus;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Revoke and remove Cloudly's stored platform registration credential (admin-only, fresh sign-in). */
|
|
88
|
+
export interface IReq_Admin_RevokePlatformIdentityCredential
|
|
89
|
+
extends plugins.typedrequestInterfaces.implementsTR<
|
|
90
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
91
|
+
IReq_Admin_RevokePlatformIdentityCredential
|
|
92
|
+
> {
|
|
93
|
+
method: 'revokePlatformIdentityCredential';
|
|
94
|
+
request: {
|
|
95
|
+
identity: userInterfaces.IIdentityCredential;
|
|
96
|
+
};
|
|
97
|
+
response: {
|
|
98
|
+
status: IPlatformIdentityProviderStatus;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Inspect one service's platform identity binding state and managed secret keys (value-free). */
|
|
103
|
+
export interface IReq_Admin_GetServiceIdentityBinding
|
|
104
|
+
extends plugins.typedrequestInterfaces.implementsTR<
|
|
105
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
106
|
+
IReq_Admin_GetServiceIdentityBinding
|
|
107
|
+
> {
|
|
108
|
+
method: 'getServiceIdentityBinding';
|
|
109
|
+
request: {
|
|
110
|
+
identity: userInterfaces.IIdentityCredential;
|
|
111
|
+
serviceId: string;
|
|
112
|
+
};
|
|
113
|
+
response: {
|
|
114
|
+
binding: IPlatformIdentityServiceBindingView | null;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Trigger reconciliation of one service's platform identity binding (admin-only). */
|
|
119
|
+
export interface IReq_Admin_ReconcileServiceIdentityBinding
|
|
120
|
+
extends plugins.typedrequestInterfaces.implementsTR<
|
|
121
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
122
|
+
IReq_Admin_ReconcileServiceIdentityBinding
|
|
123
|
+
> {
|
|
124
|
+
method: 'reconcileServiceIdentityBinding';
|
|
125
|
+
request: {
|
|
126
|
+
identity: userInterfaces.IIdentityCredential;
|
|
127
|
+
serviceId: string;
|
|
128
|
+
};
|
|
129
|
+
response: {
|
|
130
|
+
binding: IPlatformIdentityServiceBindingView | null;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Explicitly rotate one service's OIDC client secret upstream on idp.global and write the new
|
|
136
|
+
* secret into Cloudly's managed secret store (admin-only, fresh sign-in, fenced by generation).
|
|
137
|
+
*/
|
|
138
|
+
export interface IReq_Admin_RotateServiceIdentityClientSecret
|
|
139
|
+
extends plugins.typedrequestInterfaces.implementsTR<
|
|
140
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
141
|
+
IReq_Admin_RotateServiceIdentityClientSecret
|
|
142
|
+
> {
|
|
143
|
+
method: 'rotateServiceIdentityClientSecret';
|
|
144
|
+
request: {
|
|
145
|
+
identity: userInterfaces.IIdentityCredential;
|
|
146
|
+
serviceId: string;
|
|
147
|
+
expectedGeneration: number;
|
|
148
|
+
gracePeriodSeconds?: number;
|
|
149
|
+
};
|
|
150
|
+
response: {
|
|
151
|
+
binding: IPlatformIdentityServiceBindingView;
|
|
152
|
+
};
|
|
153
|
+
}
|