@leitwerk-dev/server 0.4.2 → 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-CtlotzYm.d.ts → app-DZUsf76a.d.ts} +30 -1
- 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 -3
- package/dist/auth/api-token-service.d.ts.map +1 -1
- package/dist/auth/auth-client.d.ts +17 -12
- package/dist/auth/auth-client.d.ts.map +1 -1
- package/dist/auth/auth-config.d.ts +2 -1
- package/dist/auth/auth-config.d.ts.map +1 -1
- package/dist/auth/auth-service.d.ts +10 -10
- package/dist/auth/auth-service.d.ts.map +1 -1
- package/dist/auth/auth-test-helpers.d.ts +24 -0
- 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 -14
- package/dist/auth/oidc-client.d.ts.map +1 -1
- package/dist/auth/oidc-evidence.d.ts +22 -0
- package/dist/auth/oidc-evidence.d.ts.map +1 -0
- package/dist/auth/routes.d.ts.map +1 -1
- package/dist/{chunk-YLWY4UTT.js → chunk-6EEU4QOU.js} +162 -5
- package/dist/chunk-6EEU4QOU.js.map +1 -0
- package/dist/{chunk-OUA5EZS2.js → chunk-AJ2DQWI3.js} +225 -189
- package/dist/chunk-AJ2DQWI3.js.map +1 -0
- package/dist/config/config-loader.d.ts.map +1 -1
- package/dist/config/config-types.d.ts +17 -0
- package/dist/config/config-types.d.ts.map +1 -1
- package/dist/db/api-token-repo.d.ts +3 -0
- package/dist/db/api-token-repo.d.ts.map +1 -1
- package/dist/db/auth-repo.d.ts +5 -0
- package/dist/db/auth-repo.d.ts.map +1 -1
- package/dist/db/database.d.ts.map +1 -1
- package/dist/db/schema.d.ts +32 -0
- package/dist/db/schema.d.ts.map +1 -1
- 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 -18
- package/src/auth/api-token-service.ts +9 -10
- package/src/auth/auth-client.ts +18 -18
- package/src/auth/auth-config.ts +18 -19
- package/src/auth/auth-service.ts +54 -72
- package/src/auth/auth-test-helpers.ts +101 -0
- package/src/auth/github-oauth-client.ts +8 -22
- package/src/auth/oidc-client.ts +34 -28
- package/src/auth/oidc-evidence.ts +168 -0
- package/src/auth/routes.ts +22 -6
- package/src/config/config-loader.ts +34 -0
- package/src/config/config-types.ts +18 -0
- package/src/db/api-token-repo.ts +6 -1
- package/src/db/auth-repo.ts +7 -0
- package/src/db/database.ts +14 -0
- package/src/db/schema.ts +2 -0
- 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-KR3N2JAE.js +0 -8
- package/dist/chunk-OUA5EZS2.js.map +0 -1
- package/dist/chunk-YLWY4UTT.js.map +0 -1
- /package/dist/{app-KR3N2JAE.js.map → app-2TCRADVA.js.map} +0 -0
|
@@ -54,6 +54,104 @@ function tokenExpiry(policy, expiresAt, now2) {
|
|
|
54
54
|
return new Date(ms).toISOString();
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
// src/auth/oidc-evidence.ts
|
|
58
|
+
function safeClaims(claims) {
|
|
59
|
+
return JSON.parse(
|
|
60
|
+
JSON.stringify(
|
|
61
|
+
claims,
|
|
62
|
+
(key, value) => /^(access_token|refresh_token|id_token|client_secret|authorization)$/i.test(key) ? void 0 : value
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
function actorFromClaims(provider, claims) {
|
|
67
|
+
const rawIdentity = claims[provider.identity_claim];
|
|
68
|
+
const identity = typeof rawIdentity === "string" ? rawIdentity.trim() : "";
|
|
69
|
+
if (!identity) {
|
|
70
|
+
throw new Error(`Authentication identity claim ${provider.identity_claim} was not present`);
|
|
71
|
+
}
|
|
72
|
+
const displayName = [claims.name, claims.preferred_username, claims.email].find(
|
|
73
|
+
(value) => typeof value === "string" && value.trim() !== ""
|
|
74
|
+
) ?? identity;
|
|
75
|
+
return {
|
|
76
|
+
id: `${provider.id}:${identity}`,
|
|
77
|
+
kind: "user",
|
|
78
|
+
provider: provider.id,
|
|
79
|
+
displayName
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function interpretOidcLogin(provider, exchange) {
|
|
83
|
+
const idTokenClaims = safeClaims(exchange.idTokenClaims);
|
|
84
|
+
const userInfoClaims = exchange.userInfoClaims ? safeClaims(exchange.userInfoClaims) : null;
|
|
85
|
+
if (typeof idTokenClaims.sub !== "string" || !idTokenClaims.sub.trim() || userInfoClaims && userInfoClaims.sub !== idTokenClaims.sub)
|
|
86
|
+
throw new Error("Invalid OIDC subject evidence");
|
|
87
|
+
const claims = { ...idTokenClaims, ...userInfoClaims };
|
|
88
|
+
const actor = actorFromClaims(provider, claims);
|
|
89
|
+
const groups = claims[provider.access?.groups_claim ?? "groups"];
|
|
90
|
+
return {
|
|
91
|
+
actor,
|
|
92
|
+
oidcEvidence: {
|
|
93
|
+
providerId: provider.id,
|
|
94
|
+
issuer: provider.issuer,
|
|
95
|
+
identityClaim: provider.identity_claim,
|
|
96
|
+
subject: idTokenClaims.sub,
|
|
97
|
+
loginAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
98
|
+
idTokenClaims,
|
|
99
|
+
userInfoClaims,
|
|
100
|
+
facts: {
|
|
101
|
+
identity: actor.id.slice(provider.id.length + 1),
|
|
102
|
+
email: typeof claims.email === "string" ? claims.email : null,
|
|
103
|
+
emailVerified: claims.email_verified === true,
|
|
104
|
+
groups: Array.isArray(groups) && groups.every((group) => typeof group === "string") ? groups : []
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function validDomain(domain) {
|
|
110
|
+
return domain.length <= 253 && domain.split(".").every((label) => /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i.test(label));
|
|
111
|
+
}
|
|
112
|
+
function policyErrors(policy, legacy) {
|
|
113
|
+
const errors = [];
|
|
114
|
+
if (legacy) errors.push("cannot combine access with deprecated auth.allowlist");
|
|
115
|
+
const lists = [policy.users, policy.groups, policy.email_domains];
|
|
116
|
+
if (policy.mode === "all" && (lists.some((list) => list !== void 0) || policy.match !== void 0 || policy.groups_claim !== void 0))
|
|
117
|
+
errors.push("access mode all cannot include restrictions, match, or groups_claim");
|
|
118
|
+
if (policy.mode === "restricted" && !lists.some((list) => list && list.length > 0))
|
|
119
|
+
errors.push("restricted access requires at least one non-empty criterion");
|
|
120
|
+
if (lists.some(
|
|
121
|
+
(list) => list !== void 0 && (list.length === 0 || list.some((item) => !item.trim()))
|
|
122
|
+
))
|
|
123
|
+
errors.push("access criteria must be non-empty lists of non-empty strings");
|
|
124
|
+
if (policy.email_domains?.some((domain) => !validDomain(domain)))
|
|
125
|
+
errors.push("access email_domains must contain exact domain names");
|
|
126
|
+
return errors;
|
|
127
|
+
}
|
|
128
|
+
function evidenceAllows(actor, provider, evidence, allowlist) {
|
|
129
|
+
if (!evidence || evidence.providerId !== provider.id || evidence.issuer !== provider.issuer || evidence.identityClaim !== provider.identity_claim || typeof evidence.subject !== "string" || !evidence.subject.trim() || evidence.idTokenClaims.sub !== evidence.subject || evidence.userInfoClaims !== null && evidence.userInfoClaims.sub !== evidence.subject)
|
|
130
|
+
return false;
|
|
131
|
+
const claims = { ...evidence.idTokenClaims, ...evidence.userInfoClaims };
|
|
132
|
+
const identity = typeof claims[provider.identity_claim] === "string" ? claims[provider.identity_claim].trim() : "";
|
|
133
|
+
if (!identity || actor.id !== `${provider.id}:${identity}`) return false;
|
|
134
|
+
const policy = provider.access;
|
|
135
|
+
if (!policy) return allowlist.has(identity);
|
|
136
|
+
if (policy.mode === "all") return true;
|
|
137
|
+
const matches = [];
|
|
138
|
+
if (policy.users) matches.push(policy.users.includes(identity));
|
|
139
|
+
if (policy.groups) {
|
|
140
|
+
const groups = claims[policy.groups_claim ?? "groups"];
|
|
141
|
+
matches.push(
|
|
142
|
+
Array.isArray(groups) && groups.every((group) => typeof group === "string") && policy.groups.some((group) => groups.includes(group))
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
if (policy.email_domains) {
|
|
146
|
+
const email = claims.email;
|
|
147
|
+
const domain = typeof email === "string" && /^[^\s@]+@[^\s@]+$/.test(email) ? email.split("@")[1]?.toLowerCase() : void 0;
|
|
148
|
+
matches.push(
|
|
149
|
+
claims.email_verified === true && domain !== void 0 && validDomain(domain) && policy.email_domains.some((allowed) => allowed.toLowerCase() === domain)
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
return matches.length > 0 && (policy.match === "any" ? matches.some(Boolean) : matches.every(Boolean));
|
|
153
|
+
}
|
|
154
|
+
|
|
57
155
|
// src/commit-message-policy.ts
|
|
58
156
|
import {
|
|
59
157
|
BUILT_IN_COMMIT_MESSAGE_RULES
|
|
@@ -235,6 +333,20 @@ Expected object at <root>, got ${describeType(parsed)}`
|
|
|
235
333
|
};
|
|
236
334
|
}
|
|
237
335
|
const config = applyConfigDefaults(parsedRecord.output);
|
|
336
|
+
for (const [index2, provider] of (config.auth?.providers ?? []).entries()) {
|
|
337
|
+
if (provider.kind !== "oidc" || typeof provider.client_secret !== "string") continue;
|
|
338
|
+
provider.client_secret = provider.client_secret.replace(
|
|
339
|
+
/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,
|
|
340
|
+
(_placeholder, variable) => {
|
|
341
|
+
const value = process.env[variable];
|
|
342
|
+
if (!value)
|
|
343
|
+
throw new Error(
|
|
344
|
+
`auth.providers[${index2}].client_secret: environment variable ${variable} is missing or empty`
|
|
345
|
+
);
|
|
346
|
+
return value;
|
|
347
|
+
}
|
|
348
|
+
);
|
|
349
|
+
}
|
|
238
350
|
const errors = validateResolvedConfig(config);
|
|
239
351
|
if (errors.length > 0) {
|
|
240
352
|
return { ok: false, error: `Config validation errors:
|
|
@@ -271,7 +383,17 @@ var authOidcProviderSchema = v.looseObject({
|
|
|
271
383
|
client_secret: authNonEmptyString,
|
|
272
384
|
redirect_uri: v.optional(authNonEmptyString),
|
|
273
385
|
scopes: v.optional(v.pipe(stringArraySchema, v.nonEmpty())),
|
|
274
|
-
identity_claim: v.optional(authNonEmptyString)
|
|
386
|
+
identity_claim: v.optional(authNonEmptyString),
|
|
387
|
+
access: v.optional(
|
|
388
|
+
v.strictObject({
|
|
389
|
+
mode: v.picklist(["all", "restricted"]),
|
|
390
|
+
match: v.optional(v.picklist(["all", "any"])),
|
|
391
|
+
users: v.optional(v.array(authNonEmptyString)),
|
|
392
|
+
groups: v.optional(v.array(authNonEmptyString)),
|
|
393
|
+
groups_claim: v.optional(authNonEmptyString),
|
|
394
|
+
email_domains: v.optional(v.array(authNonEmptyString))
|
|
395
|
+
})
|
|
396
|
+
)
|
|
275
397
|
});
|
|
276
398
|
var authGithubProviderSchema = v.looseObject({
|
|
277
399
|
id: v.literal("github"),
|
|
@@ -874,6 +996,15 @@ function collectAuthConfigErrors(config) {
|
|
|
874
996
|
} catch (error) {
|
|
875
997
|
errors.push(error instanceof Error ? error.message : "Invalid auth.api_tokens configuration");
|
|
876
998
|
}
|
|
999
|
+
for (const [index2, provider] of (auth?.providers ?? []).entries()) {
|
|
1000
|
+
if (provider.kind === "oidc" && provider.access) {
|
|
1001
|
+
errors.push(
|
|
1002
|
+
...policyErrors(provider.access, auth?.allowlist !== void 0).map(
|
|
1003
|
+
(message) => `auth.providers[${index2}].access: ${message}`
|
|
1004
|
+
)
|
|
1005
|
+
);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
877
1008
|
if (!auth || auth.enabled !== true) {
|
|
878
1009
|
return errors;
|
|
879
1010
|
}
|
|
@@ -1669,7 +1800,8 @@ var authSessions = sqliteTable(
|
|
|
1669
1800
|
actorProvider: text("actor_provider"),
|
|
1670
1801
|
displayName: text("display_name"),
|
|
1671
1802
|
createdAt: text("created_at").notNull(),
|
|
1672
|
-
expiresAt: text("expires_at").notNull()
|
|
1803
|
+
expiresAt: text("expires_at").notNull(),
|
|
1804
|
+
oidcEvidenceJson: text("oidc_evidence_json")
|
|
1673
1805
|
},
|
|
1674
1806
|
(t) => [
|
|
1675
1807
|
index("idx_auth_sessions_expires").on(t.expiresAt),
|
|
@@ -1998,7 +2130,8 @@ var apiTokens = sqliteTable(
|
|
|
1998
2130
|
createdAt: text("created_at").notNull(),
|
|
1999
2131
|
expiresAt: text("expires_at"),
|
|
2000
2132
|
revokedAt: text("revoked_at"),
|
|
2001
|
-
lastUsedAt: text("last_used_at")
|
|
2133
|
+
lastUsedAt: text("last_used_at"),
|
|
2134
|
+
oidcEvidenceJson: text("oidc_evidence_json")
|
|
2002
2135
|
},
|
|
2003
2136
|
(t) => [
|
|
2004
2137
|
uniqueIndex("idx_api_tokens_secret_hash").on(t.secretHash),
|
|
@@ -2496,6 +2629,17 @@ var KNOWN_MIGRATIONS = [
|
|
|
2496
2629
|
[apiTokens],
|
|
2497
2630
|
(sqlite) => existingTableSql(sqlite, "auth_sessions") !== null && existingTableSql(sqlite, "api_tokens") === null
|
|
2498
2631
|
),
|
|
2632
|
+
{
|
|
2633
|
+
id: "20260909_add_oidc_evidence",
|
|
2634
|
+
tableNames: ["auth_sessions", "api_tokens"],
|
|
2635
|
+
matches: (sqlite) => existingTableSql(sqlite, "auth_sessions") !== null && (!tableHasColumn(sqlite, "auth_sessions", "oidc_evidence_json") || !tableHasColumn(sqlite, "api_tokens", "oidc_evidence_json")),
|
|
2636
|
+
apply(sqlite) {
|
|
2637
|
+
for (const table of ["auth_sessions", "api_tokens"]) {
|
|
2638
|
+
if (!tableHasColumn(sqlite, table, "oidc_evidence_json"))
|
|
2639
|
+
sqlite.exec(`ALTER TABLE ${table} ADD COLUMN oidc_evidence_json text`);
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
},
|
|
2499
2643
|
{
|
|
2500
2644
|
id: "20260901_add_session_transfers",
|
|
2501
2645
|
tableNames: ["session_transfer_grants", "session_transfer_attempts"],
|
|
@@ -3061,10 +3205,11 @@ import { createTopicWikiRepo } from "@leitwerk-dev/wiki/server";
|
|
|
3061
3205
|
// src/db/api-token-repo.ts
|
|
3062
3206
|
import { and, desc, eq, isNull } from "drizzle-orm";
|
|
3063
3207
|
function record2(row) {
|
|
3064
|
-
const { ownerKind, ownerId, actorJson, providerBindingJson, ...fields } = row;
|
|
3208
|
+
const { ownerKind, ownerId, actorJson, providerBindingJson, oidcEvidenceJson, ...fields } = row;
|
|
3065
3209
|
return {
|
|
3066
3210
|
...fields,
|
|
3067
3211
|
owner: {
|
|
3212
|
+
oidcEvidence: oidcEvidenceJson ? JSON.parse(oidcEvidenceJson) : null,
|
|
3068
3213
|
kind: ownerKind,
|
|
3069
3214
|
id: ownerId,
|
|
3070
3215
|
actor: JSON.parse(actorJson),
|
|
@@ -3084,6 +3229,7 @@ function createApiTokenRepo(db) {
|
|
|
3084
3229
|
ownerKind: owner.kind,
|
|
3085
3230
|
ownerId: owner.id,
|
|
3086
3231
|
actorJson: JSON.stringify(owner.actor),
|
|
3232
|
+
oidcEvidenceJson: owner.oidcEvidence ? JSON.stringify(owner.oidcEvidence) : null,
|
|
3087
3233
|
providerBindingJson: owner.providerBinding ? JSON.stringify(owner.providerBinding) : null
|
|
3088
3234
|
}).run();
|
|
3089
3235
|
},
|
|
@@ -3546,6 +3692,7 @@ import { and as and5, eq as eq7, gt, lt } from "drizzle-orm";
|
|
|
3546
3692
|
function sessionRowToRecord(row) {
|
|
3547
3693
|
return {
|
|
3548
3694
|
idHash: row.idHash,
|
|
3695
|
+
oidcEvidence: row.oidcEvidenceJson ? JSON.parse(row.oidcEvidenceJson) : null,
|
|
3549
3696
|
actor: {
|
|
3550
3697
|
id: row.actorId,
|
|
3551
3698
|
kind: "user",
|
|
@@ -3564,6 +3711,7 @@ function createAuthSessionRepo(db) {
|
|
|
3564
3711
|
const values = {
|
|
3565
3712
|
idHash: input.idHash,
|
|
3566
3713
|
actorId: input.actor.id,
|
|
3714
|
+
oidcEvidenceJson: input.oidcEvidence ? JSON.stringify(input.oidcEvidence) : null,
|
|
3567
3715
|
actorProvider: input.actor.provider,
|
|
3568
3716
|
displayName: input.actor.displayName ?? null,
|
|
3569
3717
|
createdAt: ts,
|
|
@@ -8025,6 +8173,11 @@ function createLaunchPipeline(deps) {
|
|
|
8025
8173
|
mutate(launchRunId, (run) => transitionLaunchStep(run, id, "completed"));
|
|
8026
8174
|
} catch (error) {
|
|
8027
8175
|
controller.abort();
|
|
8176
|
+
if (!(error instanceof SafeLaunchPreparationError)) {
|
|
8177
|
+
logger.warn(
|
|
8178
|
+
`Launch preparation failed; correlationId=${launchRunId}; check=${check4.id}`
|
|
8179
|
+
);
|
|
8180
|
+
}
|
|
8028
8181
|
const safeSummary = error instanceof SafeLaunchPreparationError ? error.safeSummary : "The preparation check did not complete. Verify access and try again.";
|
|
8029
8182
|
return fail(launchRunId, id, {
|
|
8030
8183
|
safeSummary,
|
|
@@ -8063,6 +8216,7 @@ function createLaunchPipeline(deps) {
|
|
|
8063
8216
|
reused: committed.kind === "committed" ? committed.reused : false
|
|
8064
8217
|
};
|
|
8065
8218
|
} catch (error) {
|
|
8219
|
+
logger.warn(`Unexpected launch failure; correlationId=${launchRunId}`);
|
|
8066
8220
|
const run = deps.launchRuns.getById(launchRunId);
|
|
8067
8221
|
const failure = adapter.unexpectedFailure?.(error) ?? {
|
|
8068
8222
|
safeSummary: "The launch could not be completed. Try again.",
|
|
@@ -13028,6 +13182,9 @@ export {
|
|
|
13028
13182
|
resolveApiTokenPolicy,
|
|
13029
13183
|
ApiTokenValidationError,
|
|
13030
13184
|
tokenExpiry,
|
|
13185
|
+
actorFromClaims,
|
|
13186
|
+
interpretOidcLogin,
|
|
13187
|
+
evidenceAllows,
|
|
13031
13188
|
generateOpaqueToken,
|
|
13032
13189
|
createOpaqueToken,
|
|
13033
13190
|
hashOpaqueToken,
|
|
@@ -13162,4 +13319,4 @@ export {
|
|
|
13162
13319
|
createProjectedSessionSnapshotStore,
|
|
13163
13320
|
createBroadcaster
|
|
13164
13321
|
};
|
|
13165
|
-
//# sourceMappingURL=chunk-
|
|
13322
|
+
//# sourceMappingURL=chunk-6EEU4QOU.js.map
|