@leitwerk-dev/server 0.4.3 → 0.4.4
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/dist/app-2TCRADVA.js +8 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/auth/api-token-routes.d.ts.map +1 -1
- package/dist/auth/api-token-service.d.ts +4 -4
- package/dist/auth/api-token-service.d.ts.map +1 -1
- package/dist/auth/auth-client.d.ts +18 -11
- package/dist/auth/auth-client.d.ts.map +1 -1
- package/dist/auth/auth-service.d.ts +8 -10
- package/dist/auth/auth-service.d.ts.map +1 -1
- package/dist/auth/auth-test-helpers.d.ts +12 -5
- package/dist/auth/auth-test-helpers.d.ts.map +1 -1
- package/dist/auth/github-oauth-client.d.ts +3 -13
- package/dist/auth/github-oauth-client.d.ts.map +1 -1
- package/dist/auth/oidc-client.d.ts +6 -16
- package/dist/auth/oidc-client.d.ts.map +1 -1
- package/dist/auth/oidc-evidence.d.ts +8 -4
- package/dist/auth/oidc-evidence.d.ts.map +1 -1
- package/dist/{chunk-2OC3SK6F.js → chunk-6EEU4QOU.js} +52 -5
- package/dist/chunk-6EEU4QOU.js.map +1 -0
- package/dist/{chunk-SKQGTUDA.js → chunk-AJ2DQWI3.js} +162 -173
- package/dist/chunk-AJ2DQWI3.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/launch-pipeline.d.ts.map +1 -1
- package/dist/main.js +3 -3
- package/dist/process-launcher-registry.d.ts +3 -0
- package/dist/process-launcher-registry.d.ts.map +1 -1
- package/dist/routes/launchers.d.ts.map +1 -1
- package/dist/testing.js +1 -1
- package/package.json +12 -12
- package/src/app.ts +1 -0
- package/src/auth/api-token-routes.ts +17 -21
- package/src/auth/api-token-service.ts +4 -17
- package/src/auth/auth-client.ts +19 -19
- package/src/auth/auth-service.ts +34 -86
- package/src/auth/auth-test-helpers.ts +40 -10
- package/src/auth/github-oauth-client.ts +8 -22
- package/src/auth/oidc-client.ts +7 -19
- package/src/auth/oidc-evidence.ts +61 -6
- package/src/launch-pipeline.ts +6 -0
- package/src/process-launcher-registry.ts +56 -6
- package/src/routes/launchers.ts +35 -20
- package/dist/app-MELYT4QS.js +0 -8
- package/dist/chunk-2OC3SK6F.js.map +0 -1
- package/dist/chunk-SKQGTUDA.js.map +0 -1
- /package/dist/{app-MELYT4QS.js.map → app-2TCRADVA.js.map} +0 -0
package/src/auth/oidc-client.ts
CHANGED
|
@@ -12,29 +12,18 @@ import {
|
|
|
12
12
|
randomState,
|
|
13
13
|
} from "openid-client";
|
|
14
14
|
import { isLoopbackHttpUrl } from "../config/url-policy.js";
|
|
15
|
+
import type { AuthAuthorizationRequest, AuthCallbackRequest } from "./auth-client.js";
|
|
15
16
|
import type { ResolvedOidcProvider } from "./auth-config.js";
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
provider: ResolvedOidcProvider;
|
|
19
|
-
state: string;
|
|
20
|
-
pkceVerifier: string;
|
|
21
|
-
redirectUrl: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
18
|
+
/** @internal */
|
|
24
19
|
export interface OidcTokensAndClaims {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
userInfoClaims?: Record<string, unknown> | null;
|
|
20
|
+
idTokenClaims: Record<string, unknown>;
|
|
21
|
+
userInfoClaims: Record<string, unknown> | null;
|
|
28
22
|
}
|
|
29
23
|
|
|
30
24
|
export interface OidcClient {
|
|
31
|
-
createAuthorizationRequest(provider: ResolvedOidcProvider): Promise<
|
|
32
|
-
exchangeCallback(input:
|
|
33
|
-
provider: ResolvedOidcProvider;
|
|
34
|
-
callbackUrl: URL;
|
|
35
|
-
state: string;
|
|
36
|
-
pkceVerifier: string;
|
|
37
|
-
}): Promise<OidcTokensAndClaims>;
|
|
25
|
+
createAuthorizationRequest(provider: ResolvedOidcProvider): Promise<AuthAuthorizationRequest>;
|
|
26
|
+
exchangeCallback(input: AuthCallbackRequest<ResolvedOidcProvider>): Promise<OidcTokensAndClaims>;
|
|
38
27
|
}
|
|
39
28
|
|
|
40
29
|
export function createOpenIdClient(): OidcClient {
|
|
@@ -72,7 +61,7 @@ export function createOpenIdClient(): OidcClient {
|
|
|
72
61
|
code_challenge: codeChallenge,
|
|
73
62
|
code_challenge_method: "S256",
|
|
74
63
|
}).toString();
|
|
75
|
-
return {
|
|
64
|
+
return { state, pkceVerifier, redirectUrl };
|
|
76
65
|
},
|
|
77
66
|
|
|
78
67
|
async exchangeCallback(input) {
|
|
@@ -114,7 +103,6 @@ export function createOpenIdClient(): OidcClient {
|
|
|
114
103
|
throw new Error("OIDC UserInfo subject mismatch");
|
|
115
104
|
}
|
|
116
105
|
return {
|
|
117
|
-
claims: userInfo ? { ...idClaims, ...userInfo } : idClaims,
|
|
118
106
|
idTokenClaims: idClaims,
|
|
119
107
|
userInfoClaims: userInfo,
|
|
120
108
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Actor } from "@leitwerk-dev/domain";
|
|
2
2
|
import type { UserInformationResponseBody } from "@leitwerk-dev/protocol/http-contracts";
|
|
3
3
|
import type { OidcAccessPolicy } from "../config/config-types.js";
|
|
4
|
-
import type { ResolvedOidcProvider } from "./auth-config.js";
|
|
4
|
+
import type { ResolvedAuthProvider, ResolvedOidcProvider } from "./auth-config.js";
|
|
5
|
+
import type { OidcTokensAndClaims } from "./oidc-client.js";
|
|
5
6
|
|
|
6
7
|
/** Session/token evidence, never attached to an Actor. @internal */
|
|
7
8
|
export interface OidcEvidence extends UserInformationResponseBody {
|
|
@@ -9,8 +10,8 @@ export interface OidcEvidence extends UserInformationResponseBody {
|
|
|
9
10
|
identityClaim: string;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
/** Exclude credential-shaped claims even when returned by a custom provider.
|
|
13
|
-
|
|
13
|
+
/** Exclude credential-shaped claims even when returned by a custom provider. */
|
|
14
|
+
function safeClaims(claims: Record<string, unknown>): Record<string, unknown> {
|
|
14
15
|
return JSON.parse(
|
|
15
16
|
JSON.stringify(claims, (key, value) =>
|
|
16
17
|
/^(access_token|refresh_token|id_token|client_secret|authorization)$/i.test(key)
|
|
@@ -21,8 +22,62 @@ export function safeClaims(claims: Record<string, unknown>): Record<string, unkn
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
/** @internal */
|
|
24
|
-
export function
|
|
25
|
-
|
|
25
|
+
export function actorFromClaims(
|
|
26
|
+
provider: ResolvedAuthProvider,
|
|
27
|
+
claims: Record<string, unknown>,
|
|
28
|
+
): Actor {
|
|
29
|
+
const rawIdentity = claims[provider.identity_claim];
|
|
30
|
+
const identity = typeof rawIdentity === "string" ? rawIdentity.trim() : "";
|
|
31
|
+
if (!identity) {
|
|
32
|
+
throw new Error(`Authentication identity claim ${provider.identity_claim} was not present`);
|
|
33
|
+
}
|
|
34
|
+
const displayName =
|
|
35
|
+
[claims.name, claims.preferred_username, claims.email].find(
|
|
36
|
+
(value): value is string => typeof value === "string" && value.trim() !== "",
|
|
37
|
+
) ?? identity;
|
|
38
|
+
return {
|
|
39
|
+
id: `${provider.id}:${identity}`,
|
|
40
|
+
kind: "user",
|
|
41
|
+
provider: provider.id,
|
|
42
|
+
displayName,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** @internal */
|
|
47
|
+
export function interpretOidcLogin(
|
|
48
|
+
provider: ResolvedOidcProvider,
|
|
49
|
+
exchange: OidcTokensAndClaims,
|
|
50
|
+
): { actor: Actor; oidcEvidence: OidcEvidence } {
|
|
51
|
+
const idTokenClaims = safeClaims(exchange.idTokenClaims);
|
|
52
|
+
const userInfoClaims = exchange.userInfoClaims ? safeClaims(exchange.userInfoClaims) : null;
|
|
53
|
+
if (
|
|
54
|
+
typeof idTokenClaims.sub !== "string" ||
|
|
55
|
+
!idTokenClaims.sub.trim() ||
|
|
56
|
+
(userInfoClaims && userInfoClaims.sub !== idTokenClaims.sub)
|
|
57
|
+
)
|
|
58
|
+
throw new Error("Invalid OIDC subject evidence");
|
|
59
|
+
const claims = { ...idTokenClaims, ...userInfoClaims };
|
|
60
|
+
const actor = actorFromClaims(provider, claims);
|
|
61
|
+
const groups = claims[provider.access?.groups_claim ?? "groups"];
|
|
62
|
+
return {
|
|
63
|
+
actor,
|
|
64
|
+
oidcEvidence: {
|
|
65
|
+
providerId: provider.id,
|
|
66
|
+
issuer: provider.issuer,
|
|
67
|
+
identityClaim: provider.identity_claim,
|
|
68
|
+
subject: idTokenClaims.sub,
|
|
69
|
+
loginAt: new Date().toISOString(),
|
|
70
|
+
idTokenClaims,
|
|
71
|
+
userInfoClaims,
|
|
72
|
+
facts: {
|
|
73
|
+
identity: actor.id.slice(provider.id.length + 1),
|
|
74
|
+
email: typeof claims.email === "string" ? claims.email : null,
|
|
75
|
+
emailVerified: claims.email_verified === true,
|
|
76
|
+
groups:
|
|
77
|
+
Array.isArray(groups) && groups.every((group) => typeof group === "string") ? groups : [],
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
};
|
|
26
81
|
}
|
|
27
82
|
|
|
28
83
|
function validDomain(domain: string): boolean {
|
|
@@ -75,7 +130,7 @@ export function evidenceAllows(
|
|
|
75
130
|
(evidence.userInfoClaims !== null && evidence.userInfoClaims.sub !== evidence.subject)
|
|
76
131
|
)
|
|
77
132
|
return false;
|
|
78
|
-
const claims =
|
|
133
|
+
const claims = { ...evidence.idTokenClaims, ...evidence.userInfoClaims };
|
|
79
134
|
const identity =
|
|
80
135
|
typeof claims[provider.identity_claim] === "string"
|
|
81
136
|
? (claims[provider.identity_claim] as string).trim()
|
package/src/launch-pipeline.ts
CHANGED
|
@@ -400,6 +400,11 @@ export function createLaunchPipeline(deps: {
|
|
|
400
400
|
mutate(launchRunId, (run) => transitionLaunchStep(run, id, "completed"));
|
|
401
401
|
} catch (error) {
|
|
402
402
|
controller.abort();
|
|
403
|
+
if (!(error instanceof SafeLaunchPreparationError)) {
|
|
404
|
+
logger.warn(
|
|
405
|
+
`Launch preparation failed; correlationId=${launchRunId}; check=${check.id}`,
|
|
406
|
+
);
|
|
407
|
+
}
|
|
403
408
|
const safeSummary =
|
|
404
409
|
error instanceof SafeLaunchPreparationError
|
|
405
410
|
? error.safeSummary
|
|
@@ -442,6 +447,7 @@ export function createLaunchPipeline(deps: {
|
|
|
442
447
|
reused: committed.kind === "committed" ? committed.reused : false,
|
|
443
448
|
};
|
|
444
449
|
} catch (error) {
|
|
450
|
+
logger.warn(`Unexpected launch failure; correlationId=${launchRunId}`);
|
|
445
451
|
const run = deps.launchRuns.getById(launchRunId);
|
|
446
452
|
const failure = adapter.unexpectedFailure?.(error) ?? {
|
|
447
453
|
safeSummary: "The launch could not be completed. Try again.",
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
1
2
|
import type { ExtensionCatalog } from "@leitwerk-dev/extension-runtime";
|
|
2
3
|
import type {
|
|
3
4
|
ExtensionProcessDefinition,
|
|
4
5
|
LauncherContext,
|
|
5
6
|
LauncherModelProfileSummary,
|
|
7
|
+
LauncherReadiness,
|
|
6
8
|
ProcessLaunchConfig,
|
|
7
9
|
ProcessLauncherDefinition,
|
|
8
10
|
ProcessLauncherService,
|
|
9
11
|
ResolvedProcessLauncher,
|
|
10
12
|
UiLauncherSummary,
|
|
11
13
|
} from "@leitwerk-dev/process-sdk";
|
|
12
|
-
import { buildProcessLaunchers } from "@leitwerk-dev/process-sdk";
|
|
14
|
+
import { buildProcessLaunchers, SafeLaunchPreparationError } from "@leitwerk-dev/process-sdk";
|
|
13
15
|
import type { CommitMessageConfig } from "./config/config-types.js";
|
|
14
16
|
import { buildProcessLaunchPlan, validateLaunchPreparationChecks } from "./process-launch-plan.js";
|
|
15
17
|
|
|
@@ -24,6 +26,7 @@ interface ProcessLauncherRegistryOptions {
|
|
|
24
26
|
modelProfiles?: readonly LauncherModelProfileSummary[];
|
|
25
27
|
getModelProfilesForProcess?: (processId: string) => readonly LauncherModelProfileSummary[];
|
|
26
28
|
commitMessages?: CommitMessageConfig;
|
|
29
|
+
logger?: { warn(message: string): void };
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
function buildResolvedProcessLauncher(
|
|
@@ -112,6 +115,30 @@ export function buildProcessLauncherRegistry(
|
|
|
112
115
|
};
|
|
113
116
|
}
|
|
114
117
|
|
|
118
|
+
function resolveUiReadiness(
|
|
119
|
+
launcherId: string,
|
|
120
|
+
input: Record<string, unknown>,
|
|
121
|
+
): LauncherReadiness {
|
|
122
|
+
const { ui } = requireUiLauncher(launcherId);
|
|
123
|
+
try {
|
|
124
|
+
return ui.readiness?.(input) ?? { status: "ready", issues: [] };
|
|
125
|
+
} catch {
|
|
126
|
+
const correlationId = randomUUID();
|
|
127
|
+
// Do not log exception messages: integration errors may contain credentials.
|
|
128
|
+
options.logger?.warn(`Launcher readiness failed; correlationId=${correlationId}`);
|
|
129
|
+
return {
|
|
130
|
+
status: "blocked",
|
|
131
|
+
issues: [
|
|
132
|
+
{
|
|
133
|
+
code: "launcher_readiness_failed",
|
|
134
|
+
summary: "Configuration readiness could not be checked.",
|
|
135
|
+
remediation: `Ask an operator to inspect the server logs. Reference: ${correlationId}`,
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
115
142
|
const uiLaunchers = [...launchers.values()]
|
|
116
143
|
.filter((launcher) => launcher.definition.ui)
|
|
117
144
|
.map(
|
|
@@ -133,9 +160,16 @@ export function buildProcessLauncherRegistry(
|
|
|
133
160
|
|
|
134
161
|
return {
|
|
135
162
|
listUiLaunchers() {
|
|
136
|
-
return uiLaunchers
|
|
163
|
+
return uiLaunchers.map((launcher) => ({
|
|
164
|
+
...launcher,
|
|
165
|
+
...(requireUiLauncher(launcher.id).ui.readiness
|
|
166
|
+
? { readiness: resolveUiReadiness(launcher.id, {}) }
|
|
167
|
+
: {}),
|
|
168
|
+
}));
|
|
137
169
|
},
|
|
138
170
|
|
|
171
|
+
resolveUiReadiness,
|
|
172
|
+
|
|
139
173
|
async resolveUiDefaults(launcherId, ctx = {}) {
|
|
140
174
|
const { launcher, ui } = requireUiLauncher(launcherId);
|
|
141
175
|
return (await ui.resolveDefaults?.(createLauncherContext(launcher.processId, ctx))) ?? {};
|
|
@@ -159,10 +193,26 @@ export function buildProcessLauncherRegistry(
|
|
|
159
193
|
|
|
160
194
|
resolvePreparationChecks(launcherId, input, launchConfig) {
|
|
161
195
|
const { ui } = requireUiLauncher(launcherId);
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
196
|
+
const checks = [...(ui.preparationChecks?.(input, launchConfig) ?? [])];
|
|
197
|
+
if (ui.readiness) {
|
|
198
|
+
checks.unshift({
|
|
199
|
+
id: "launcher-readiness",
|
|
200
|
+
label: "Check launcher configuration",
|
|
201
|
+
async run() {
|
|
202
|
+
const readiness = resolveUiReadiness(launcherId, input);
|
|
203
|
+
if (readiness.status !== "ready") {
|
|
204
|
+
const summary = readiness.issues
|
|
205
|
+
.map((issue) => `${issue.summary} ${issue.remediation}`)
|
|
206
|
+
.join(" ");
|
|
207
|
+
throw new SafeLaunchPreparationError(
|
|
208
|
+
"Launcher configuration is incomplete",
|
|
209
|
+
summary || "Complete launcher configuration before launching.",
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
return validateLaunchPreparationChecks(checks, `Launcher '${launcherId}'`);
|
|
166
216
|
},
|
|
167
217
|
|
|
168
218
|
async resolveUiLauncher(launcherId, input, ctx = {}) {
|
package/src/routes/launchers.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type {
|
|
|
3
3
|
LauncherDefaultsResponseBody,
|
|
4
4
|
LauncherModelConfigPreviewResponseBody,
|
|
5
5
|
LauncherOptionsResponseBody,
|
|
6
|
+
LauncherReadinessResponseBody,
|
|
6
7
|
LauncherRecentValuesResponseBody,
|
|
7
8
|
LaunchersResponseBody,
|
|
8
9
|
LauncherValidationResponseBody,
|
|
@@ -195,27 +196,41 @@ export function registerLauncherRoutes(
|
|
|
195
196
|
},
|
|
196
197
|
);
|
|
197
198
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
normalized.request.launcherInput
|
|
209
|
-
)
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
} catch (error) {
|
|
213
|
-
if (sendLauncherLookupFailure(reply, error)) {
|
|
214
|
-
return;
|
|
199
|
+
function postLauncherInput(
|
|
200
|
+
path: string,
|
|
201
|
+
resolve: (launcherId: string, input: Record<string, unknown>) => unknown,
|
|
202
|
+
) {
|
|
203
|
+
app.post<{ Params: { launcherId: string }; Body: unknown }>(
|
|
204
|
+
`/api/launchers/:launcherId/${path}`,
|
|
205
|
+
async (req, reply) => {
|
|
206
|
+
const normalized = normalizeLauncherRequest(req.body);
|
|
207
|
+
if (!normalized.ok) return sendLauncherRequestNormalizationError(reply, normalized.error);
|
|
208
|
+
try {
|
|
209
|
+
return await resolve(req.params.launcherId, normalized.request.launcherInput);
|
|
210
|
+
} catch (error) {
|
|
211
|
+
if (sendLauncherLookupFailure(reply, error)) return;
|
|
212
|
+
throw error;
|
|
215
213
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
214
|
+
},
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
postLauncherInput(
|
|
219
|
+
"readiness",
|
|
220
|
+
(launcherId, input) =>
|
|
221
|
+
({
|
|
222
|
+
readiness: deps.launcherService.resolveUiReadiness?.(launcherId, input) ?? {
|
|
223
|
+
status: "ready",
|
|
224
|
+
issues: [],
|
|
225
|
+
},
|
|
226
|
+
}) satisfies LauncherReadinessResponseBody,
|
|
227
|
+
);
|
|
228
|
+
postLauncherInput(
|
|
229
|
+
"options",
|
|
230
|
+
async (launcherId, input) =>
|
|
231
|
+
({
|
|
232
|
+
options: await deps.launcherService.resolveUiOptions(launcherId, input),
|
|
233
|
+
}) satisfies LauncherOptionsResponseBody,
|
|
219
234
|
);
|
|
220
235
|
|
|
221
236
|
app.post<{ Params: { launcherId: string }; Body: unknown }>(
|