@serve.zone/interfaces 32.120.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 +6 -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/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/package.json +1 -1
- 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/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
|
@@ -8,6 +8,7 @@ import type { TServiceDeploymentCapability } from './user.js';
|
|
|
8
8
|
import type { ILegacyImageImportReference } from './deploymentlegacyimport.js';
|
|
9
9
|
import { validateLegacyImageImportReference } from './deploymentlegacyimport.js';
|
|
10
10
|
import { validateProtocolOfferOn, type IProtocolOffer } from '../protocol.js';
|
|
11
|
+
import type { IDeploymentIdentityDeclaration } from '../platform/identity.js';
|
|
11
12
|
import type {
|
|
12
13
|
IDeploymentRouteRequest,
|
|
13
14
|
IServiceDeploymentOperation,
|
|
@@ -166,7 +167,7 @@ export interface IDeploymentPreflightRuntimeTask {
|
|
|
166
167
|
}
|
|
167
168
|
|
|
168
169
|
export interface IDeploymentPreflightPlatformBinding {
|
|
169
|
-
capability: 'database' | 'objectstorage' | 'pushnotification';
|
|
170
|
+
capability: 'database' | 'objectstorage' | 'pushnotification' | 'identity';
|
|
170
171
|
desiredState: 'enabled' | 'disabled';
|
|
171
172
|
status: 'requested' | 'provisioning' | 'ready' | 'degraded' | 'failed' | 'disabled';
|
|
172
173
|
}
|
|
@@ -203,7 +204,9 @@ export interface IDeploymentPreflightProposedConfiguration {
|
|
|
203
204
|
containerArgs?: string[];
|
|
204
205
|
containerPorts: number[];
|
|
205
206
|
volumeMounts: IDeploymentPreflightProposedVolumeMount[];
|
|
206
|
-
requiredCapabilities: Array<'database' | 'objectstorage' | 'pushnotification'>;
|
|
207
|
+
requiredCapabilities: Array<'database' | 'objectstorage' | 'pushnotification' | 'identity'>;
|
|
208
|
+
/** Required exactly when `'identity'` is listed in `requiredCapabilities`. */
|
|
209
|
+
identity?: IDeploymentIdentityDeclaration;
|
|
207
210
|
}
|
|
208
211
|
|
|
209
212
|
export interface IDeploymentReleaseEvidenceReference {
|
package/ts/data/secret.ts
CHANGED
|
@@ -31,6 +31,7 @@ export type TSecretManagementSource =
|
|
|
31
31
|
| 'mail'
|
|
32
32
|
| 'coremail'
|
|
33
33
|
| 'oidc'
|
|
34
|
+
| 'identity'
|
|
34
35
|
| 'webpush'
|
|
35
36
|
| 'platform'
|
|
36
37
|
| 'system';
|
|
@@ -41,6 +42,7 @@ export type TSecretManagementScope =
|
|
|
41
42
|
| `mail:${string}`
|
|
42
43
|
| `coremail:${string}`
|
|
43
44
|
| `oidc:${string}`
|
|
45
|
+
| `identity:${string}`
|
|
44
46
|
| `webpush:${string}`
|
|
45
47
|
| `platform:${string}`
|
|
46
48
|
| `system:${string}`;
|
|
@@ -576,7 +578,7 @@ export const validateSecretVersionMetadata = (
|
|
|
576
578
|
}
|
|
577
579
|
if (!isNonNegativeSafeInteger(versionArg.createdAt)
|
|
578
580
|
|| !isSecretIdentifier(versionArg.createdBy)
|
|
579
|
-
|| !['operator', 'appstore', 'mail', 'coremail', 'oidc', 'webpush', 'platform', 'system']
|
|
581
|
+
|| !['operator', 'appstore', 'mail', 'coremail', 'oidc', 'identity', 'webpush', 'platform', 'system']
|
|
580
582
|
.includes(versionArg.source as string)) {
|
|
581
583
|
errors.push('secret version metadata creation fields must be canonical');
|
|
582
584
|
}
|
|
@@ -766,7 +768,7 @@ export const validateSecretManagementScope = (
|
|
|
766
768
|
const scopeIdentifier = scopeArg.slice(separatorIndex + 1);
|
|
767
769
|
if (
|
|
768
770
|
separatorIndex < 1
|
|
769
|
-
|| !['appstore', 'mail', 'coremail', 'oidc', 'webpush', 'platform', 'system']
|
|
771
|
+
|| !['appstore', 'mail', 'coremail', 'oidc', 'identity', 'webpush', 'platform', 'system']
|
|
770
772
|
.includes(scopeSource)
|
|
771
773
|
|| !isSecretIdentifier(scopeIdentifier)
|
|
772
774
|
) {
|
|
@@ -900,7 +902,7 @@ export const validateSecretMetadata = (secretArg: unknown): string[] => {
|
|
|
900
902
|
errors.push('secret metadata tag keys must be unique');
|
|
901
903
|
}
|
|
902
904
|
}
|
|
903
|
-
if (!['operator', 'appstore', 'mail', 'coremail', 'oidc', 'webpush', 'platform', 'system']
|
|
905
|
+
if (!['operator', 'appstore', 'mail', 'coremail', 'oidc', 'identity', 'webpush', 'platform', 'system']
|
|
904
906
|
.includes(secretArg.managementSource as string)) {
|
|
905
907
|
errors.push('secret metadata managementSource must be canonical');
|
|
906
908
|
} else {
|
|
@@ -92,6 +92,7 @@ const serviceRuntimeRefusals = [
|
|
|
92
92
|
'launcher-secret-ownership-unknown',
|
|
93
93
|
'objectstorage-endpoint-missing', 'objectstorage-binding-invalid', 'objectstorage-environment-conflict',
|
|
94
94
|
'objectstorage-endpoint-unselected', 'database-endpoint-missing', 'database-endpoint-unselected',
|
|
95
|
+
'identity-environment-conflict',
|
|
95
96
|
'published-port-reserved', 'published-port-symmetric-without-egress', 'readiness-network-unsupported',
|
|
96
97
|
'cluster-relay-missing', 'cluster-ingress-environment-conflict', 'workload-identity-environment-conflict',
|
|
97
98
|
] as const;
|
package/ts/data/settings.ts
CHANGED
|
@@ -171,6 +171,10 @@ export const cloudlySystemSecretKeys = Object.freeze({
|
|
|
171
171
|
*/
|
|
172
172
|
coreMailSmtpTlsCertificatePem: 'COREMAIL_SMTP_TLS_CERTIFICATE_PEM',
|
|
173
173
|
coreMailSmtpTlsPrivateKeyPem: 'COREMAIL_SMTP_TLS_PRIVATE_KEY_PEM',
|
|
174
|
+
/** Cloudly's RSA-OAEP-256 recipient private key PEM for platform identity secret delivery. */
|
|
175
|
+
platformIdentityRecipientPrivateKeyPem: 'PLATFORM_IDENTITY_RECIPIENT_PRIVATE_KEY_PEM',
|
|
176
|
+
/** Cloudly's single platform registration credential for upstream idp.global OIDC client management. */
|
|
177
|
+
platformIdentityRegistrationCredential: 'PLATFORM_IDENTITY_REGISTRATION_CREDENTIAL',
|
|
174
178
|
} as const);
|
|
175
179
|
|
|
176
180
|
/**
|
|
@@ -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. */
|