@sanoma-ai/workflows 0.10.3 → 0.10.6
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/CLOUD-IDENTITY.md +128 -17
- package/README.md +15 -4
- package/dist/apply.d.ts +11 -4
- package/dist/apply.js +126 -35
- package/dist/apply.js.map +1 -1
- package/dist/call.js +1 -1
- package/dist/call.js.map +1 -1
- package/dist/cloud-identity.d.ts +5 -1
- package/dist/cloud-identity.js +13 -77
- package/dist/cloud-identity.js.map +1 -1
- package/dist/config.d.ts +3 -0
- package/dist/config.js +3 -2
- package/dist/config.js.map +1 -1
- package/dist/define.d.ts +9 -2
- package/dist/define.js +1 -0
- package/dist/define.js.map +1 -1
- package/dist/dns.d.ts +20 -0
- package/dist/dns.js +26 -0
- package/dist/dns.js.map +1 -0
- package/dist/drift.d.ts +4 -2
- package/dist/drift.js +13 -4
- package/dist/drift.js.map +1 -1
- package/dist/identity-broker.d.ts +14 -0
- package/dist/identity-broker.js +84 -0
- package/dist/identity-broker.js.map +1 -0
- package/dist/identity-provisioning.d.ts +29 -0
- package/dist/identity-provisioning.js +178 -0
- package/dist/identity-provisioning.js.map +1 -0
- package/dist/identity-service.d.ts +25 -0
- package/dist/identity-service.js +148 -0
- package/dist/identity-service.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/op.d.ts +15 -8
- package/dist/op.js.map +1 -1
- package/dist/provisioning-identity.d.ts +27 -0
- package/dist/provisioning-identity.js +81 -0
- package/dist/provisioning-identity.js.map +1 -0
- package/dist/resource.d.ts +67 -6
- package/dist/resource.js +95 -9
- package/dist/resource.js.map +1 -1
- package/dist/resources.d.ts +3 -3
- package/dist/resources.js +6 -5
- package/dist/resources.js.map +1 -1
- package/dist/runtime-ops.d.ts +60 -1
- package/dist/runtime-ops.js +73 -1
- package/dist/runtime-ops.js.map +1 -1
- package/dist/scenario.d.ts +6 -3
- package/dist/scenario.js +13 -1
- package/dist/scenario.js.map +1 -1
- package/oxlint.json +1 -0
- package/package.json +5 -1
- package/src/apply.ts +165 -47
- package/src/call.ts +2 -2
- package/src/cloud-identity.ts +16 -76
- package/src/config.ts +6 -2
- package/src/define.ts +10 -2
- package/src/dns.ts +29 -0
- package/src/drift.ts +13 -4
- package/src/identity-broker.ts +94 -0
- package/src/identity-provisioning.ts +208 -0
- package/src/identity-service.ts +179 -0
- package/src/index.ts +2 -0
- package/src/op.ts +13 -3
- package/src/provisioning-identity.ts +106 -0
- package/src/resource.ts +147 -15
- package/src/resources.ts +6 -5
- package/src/runtime-ops.ts +79 -0
- package/src/scenario.ts +24 -6
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { Pool } from "pg";
|
|
3
|
+
import { NodeRequest, sendNodeResponse } from "srvx/node";
|
|
4
|
+
import { identityBroker, postgresIdentityEnrollments, attachedGoogleTokenIssuer, provisioningIdentityBroker, attachedGoogleIdTokenIssuer, } from "./cloud-identity.js";
|
|
5
|
+
/** Install with administrative authority in the audit database, separately from the serving process. */
|
|
6
|
+
export const CLOUD_IDENTITY_AUDIT_SQL = `
|
|
7
|
+
CREATE SCHEMA IF NOT EXISTS sanoma_identity;
|
|
8
|
+
REVOKE ALL ON SCHEMA sanoma_identity FROM PUBLIC;
|
|
9
|
+
CREATE TABLE IF NOT EXISTS sanoma_identity.audit_events (
|
|
10
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
11
|
+
recorded_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
|
12
|
+
result text NOT NULL CHECK (result IN ('issued', 'denied', 'unavailable')),
|
|
13
|
+
deployment text, company text, environment text, service_account text,
|
|
14
|
+
generation bigint, expires_at timestamptz
|
|
15
|
+
);
|
|
16
|
+
REVOKE ALL ON sanoma_identity.audit_events FROM PUBLIC;
|
|
17
|
+
`;
|
|
18
|
+
const unavailable = () => new Error("Identity service unavailable");
|
|
19
|
+
const poolFor = (connectionString) => {
|
|
20
|
+
if (!connectionString)
|
|
21
|
+
throw unavailable();
|
|
22
|
+
const pool = new Pool({
|
|
23
|
+
connectionString,
|
|
24
|
+
max: 5,
|
|
25
|
+
connectionTimeoutMillis: 10_000,
|
|
26
|
+
query_timeout: 10_000,
|
|
27
|
+
statement_timeout: 10_000,
|
|
28
|
+
});
|
|
29
|
+
// Never forward database diagnostics: they can contain connection information.
|
|
30
|
+
pool.on("error", () => { });
|
|
31
|
+
return pool;
|
|
32
|
+
};
|
|
33
|
+
async function checkRoles(reader, audit) {
|
|
34
|
+
const read = await reader.query(`SELECT
|
|
35
|
+
has_schema_privilege('sanoma_identity', 'USAGE') AND
|
|
36
|
+
NOT has_schema_privilege('sanoma_identity', 'CREATE') AND
|
|
37
|
+
NOT EXISTS (SELECT FROM pg_roles WHERE rolname = current_user AND (rolsuper OR rolcreaterole OR rolcreatedb OR rolbypassrls)) AND
|
|
38
|
+
has_table_privilege('sanoma_identity.deployments', 'SELECT') AND
|
|
39
|
+
has_table_privilege('sanoma_identity.credentials', 'SELECT') AND
|
|
40
|
+
NOT has_table_privilege('sanoma_identity.deployments', 'INSERT,UPDATE,DELETE,TRUNCATE,REFERENCES,TRIGGER') AND
|
|
41
|
+
NOT has_table_privilege('sanoma_identity.credentials', 'INSERT,UPDATE,DELETE,TRUNCATE,REFERENCES,TRIGGER') AS allowed`);
|
|
42
|
+
const write = await audit.query(`SELECT
|
|
43
|
+
has_schema_privilege('sanoma_identity', 'USAGE') AND
|
|
44
|
+
NOT has_schema_privilege('sanoma_identity', 'CREATE') AND
|
|
45
|
+
NOT EXISTS (SELECT FROM pg_roles WHERE rolname = current_user AND (rolsuper OR rolcreaterole OR rolcreatedb OR rolbypassrls)) AND
|
|
46
|
+
has_table_privilege('sanoma_identity.audit_events', 'INSERT') AND
|
|
47
|
+
NOT has_table_privilege('sanoma_identity.audit_events', 'SELECT,UPDATE,DELETE,TRUNCATE,REFERENCES,TRIGGER') AS allowed`);
|
|
48
|
+
if (read.rows[0]?.allowed !== true || write.rows[0]?.allowed !== true)
|
|
49
|
+
throw unavailable();
|
|
50
|
+
}
|
|
51
|
+
/** Starts a standalone broker without loading company code, starting a worker or installing schemas. */
|
|
52
|
+
export async function startIdentityService(options) {
|
|
53
|
+
let reader, audit;
|
|
54
|
+
const server = createServer();
|
|
55
|
+
let closing;
|
|
56
|
+
const close = () => (closing ??= (async () => {
|
|
57
|
+
await new Promise((resolve) => {
|
|
58
|
+
server.close(() => resolve());
|
|
59
|
+
server.closeAllConnections();
|
|
60
|
+
});
|
|
61
|
+
await Promise.all([reader?.end(), audit?.end()]);
|
|
62
|
+
})());
|
|
63
|
+
try {
|
|
64
|
+
const limit = options.maxConcurrentRequests ?? 32;
|
|
65
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 256)
|
|
66
|
+
throw unavailable();
|
|
67
|
+
let active = 0;
|
|
68
|
+
reader = poolFor(options.enrollmentDatabaseUrl);
|
|
69
|
+
audit = poolFor(options.auditDatabaseUrl);
|
|
70
|
+
await checkRoles(reader, audit);
|
|
71
|
+
const record = async (event) => {
|
|
72
|
+
const e = event.enrollment;
|
|
73
|
+
// Fixed columns only: no tokens, hashes, headers or arbitrary caller fields.
|
|
74
|
+
await audit.query(`INSERT INTO sanoma_identity.audit_events
|
|
75
|
+
(result, deployment, company, environment, service_account, generation, expires_at)
|
|
76
|
+
VALUES ($1,$2,$3,$4,$5,$6,$7)`, [
|
|
77
|
+
event.result,
|
|
78
|
+
e?.deployment ?? null,
|
|
79
|
+
e?.company ?? null,
|
|
80
|
+
e?.environment ?? null,
|
|
81
|
+
e?.serviceAccount ?? null,
|
|
82
|
+
e?.generation ?? null,
|
|
83
|
+
event.expiresAt === undefined ? null : new Date(event.expiresAt),
|
|
84
|
+
]);
|
|
85
|
+
};
|
|
86
|
+
const enrollments = postgresIdentityEnrollments(async () => reader);
|
|
87
|
+
const handle = options.mode.type === "runtime"
|
|
88
|
+
? identityBroker({ enrollments, issue: attachedGoogleTokenIssuer(), audit: record })
|
|
89
|
+
: options.mode.type === "provisioning"
|
|
90
|
+
? provisioningIdentityBroker({
|
|
91
|
+
identity: options.mode.identity,
|
|
92
|
+
enrollments,
|
|
93
|
+
issue: attachedGoogleIdTokenIssuer(options.mode.identity),
|
|
94
|
+
audit: record,
|
|
95
|
+
})
|
|
96
|
+
: (() => {
|
|
97
|
+
throw unavailable();
|
|
98
|
+
})();
|
|
99
|
+
server.requestTimeout = 15_000;
|
|
100
|
+
server.headersTimeout = 10_000;
|
|
101
|
+
server.on("request", (req, res) => {
|
|
102
|
+
// Fetch Request adapters may hide a GET body. Refuse it at the HTTP boundary.
|
|
103
|
+
if (req.method === "GET" &&
|
|
104
|
+
(req.headers["transfer-encoding"] || (req.headers["content-length"] ?? "0") !== "0")) {
|
|
105
|
+
res.writeHead(400, { "Content-Type": "application/json", "Cache-Control": "no-store" });
|
|
106
|
+
res.end('{"error":"invalid_request"}');
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (req.url === "/healthz" && (req.method === "GET" || req.method === "HEAD")) {
|
|
110
|
+
res.writeHead(200, { "Content-Type": "text/plain", "Cache-Control": "no-store" });
|
|
111
|
+
res.end("ok\n");
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (active >= limit) {
|
|
115
|
+
res.writeHead(429, { "Content-Type": "application/json", "Cache-Control": "no-store", "Retry-After": "1" });
|
|
116
|
+
res.end('{"error":"busy"}');
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
active++;
|
|
120
|
+
Promise.resolve()
|
|
121
|
+
.then(() => handle(new NodeRequest({ req, res })))
|
|
122
|
+
.then((response) => sendNodeResponse(res, response))
|
|
123
|
+
.catch(() => {
|
|
124
|
+
if (res.headersSent)
|
|
125
|
+
res.destroy();
|
|
126
|
+
else {
|
|
127
|
+
res.writeHead(503, { "Content-Type": "application/json", "Cache-Control": "no-store" });
|
|
128
|
+
res.end('{"error":"unavailable"}');
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
.finally(() => {
|
|
132
|
+
active--;
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
await new Promise((resolve, reject) => {
|
|
136
|
+
server.once("error", reject);
|
|
137
|
+
server.listen(options.port ?? 8080, options.host ?? "127.0.0.1", resolve);
|
|
138
|
+
});
|
|
139
|
+
const { address, family, port } = server.address();
|
|
140
|
+
const hostname = address === "0.0.0.0" || address === "::" ? "localhost" : family === "IPv6" ? `[${address}]` : address;
|
|
141
|
+
return { url: `http://${hostname}:${port}`, stop: close };
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
await close().catch(() => { });
|
|
145
|
+
throw unavailable();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=identity-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity-service.js","sourceRoot":"","sources":["../src/identity-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EACL,cAAc,EACd,2BAA2B,EAC3B,yBAAyB,EACzB,0BAA0B,EAC1B,2BAA2B,GAG5B,MAAM,qBAAqB,CAAC;AAE7B,wGAAwG;AACxG,MAAM,CAAC,MAAM,wBAAwB,GAAG;;;;;;;;;;;CAWvC,CAAC;AAeF,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;AACpE,MAAM,OAAO,GAAG,CAAC,gBAAwB,EAAE,EAAE;IAC3C,IAAI,CAAC,gBAAgB;QAAE,MAAM,WAAW,EAAE,CAAC;IAC3C,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC;QACpB,gBAAgB;QAChB,GAAG,EAAE,CAAC;QACN,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,IAAI,EAAE,GAAG,MAAM,CAAC,OAAO,EAAiB,CAAC;QAClE,MAAM,QAAQ,GACZ,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC;QACzG,OAAO,EAAE,GAAG,EAAE,UAAU,QAAQ,IAAI,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IAC5D,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAC9B,MAAM,WAAW,EAAE,CAAC;IACtB,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export { type CallContext, CLIENT_IP_HEADER, requestOrigin, sameOrigin, type Connector, type ConnectorSetup, type ConnectorVendor, type Driver, type DriverEnv, type DriverFn, defineConnector, DriverError, type Effect, isOp, isSvgElement, INVITE_SECONDS, type LoginContext, type LoginHalf, type LoginIdentity, type LoginMethod, type ModelContext, type Op, type OpSpec, type ResourceGroup, retryableStatus, type SignInMethod, type VendorInfo, withSetup, } from "./op.ts";
|
|
1
|
+
export { type CallContext, CLIENT_IP_HEADER, requestOrigin, sameOrigin, type Connector, type ConnectorSetup, type ConnectorVendor, type Driver, type DriverEnv, type DriverFn, defineConnector, DriverError, type Effect, isOp, isSvgElement, INVITE_SECONDS, type LoginContext, type LoginHalf, type LoginIdentity, type LoginMethod, type ModelContext, type Op, type OpSpec, type ResourceGroup, retryableStatus, type SignInMethod, type SocialClients, type VendorInfo, withSetup, } from "./op.ts";
|
|
2
2
|
export { SanomaPackageField, vendorInfo } from "./vendor-info.ts";
|
|
3
3
|
export { defineWorkflow, Principal, type ApprovalRequest, type ApprovalResult, type ApprovalState, type Approver, type Builtin, type Ctx, type SleepRequest, type StartedBy, type StepOptions, type Trigger, type Use, type WorkflowDefinition, } from "./define.ts";
|
|
4
4
|
export { compareDeclared, type Declared, type Declaring, defineResource, diffDeclared, type FieldReference, type PlanAction, type References, type Resource, type ResourceFields, type ResourceOps, type ResourceSpec, withoutWriteOnly, } from "./resource.ts";
|
|
5
|
+
export { type DnsRecord, dnsRecord } from "./dns.ts";
|
|
5
6
|
export { declaredWakeup, defineConfig, envWakeup, resolveConfig, resolveDatabaseUrl, type ResolvedConfig, type SanomaConfig, } from "./config.ts";
|
|
6
7
|
export { type AppEntry, appSourceOf, readApps } from "./apps.ts";
|
|
7
8
|
export { type AppDefinition, defineApp } from "./definitions.ts";
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export { CLIENT_IP_HEADER, requestOrigin, sameOrigin, defineConnector, DriverErr
|
|
|
2
2
|
export { SanomaPackageField, vendorInfo } from "./vendor-info.js";
|
|
3
3
|
export { defineWorkflow, Principal, } from "./define.js";
|
|
4
4
|
export { compareDeclared, defineResource, diffDeclared, withoutWriteOnly, } from "./resource.js";
|
|
5
|
+
export { dnsRecord } from "./dns.js";
|
|
5
6
|
export { declaredWakeup, defineConfig, envWakeup, resolveConfig, resolveDatabaseUrl, } from "./config.js";
|
|
6
7
|
// An app's `app.ts` (`defineApp`), and where the launcher finds an app's workflows and data file.
|
|
7
8
|
export { appSourceOf, readApps } from "./apps.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,EAChB,aAAa,EACb,UAAU,EAOV,eAAe,EACf,WAAW,EAEX,IAAI,EACJ,YAAY,EACZ,cAAc,EASd,eAAe,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,EAChB,aAAa,EACb,UAAU,EAO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AM,iBAAiB,CAAC"}
|
package/dist/op.d.ts
CHANGED
|
@@ -276,6 +276,13 @@ export interface LoginIdentity {
|
|
|
276
276
|
export type LoginMethod = "code" | "github" | "invite" | "password";
|
|
277
277
|
/** How a person signed in to the staff login, which the ledger records (`signin.recorded`): all but a password. */
|
|
278
278
|
export type SignInMethod = Exclude<LoginMethod, "password">;
|
|
279
|
+
/** The company's own OAuth clients, as a login takes them: GitHub's is its GitHub App's client. */
|
|
280
|
+
export interface SocialClients {
|
|
281
|
+
github?: {
|
|
282
|
+
clientId: string;
|
|
283
|
+
clientSecret: string;
|
|
284
|
+
};
|
|
285
|
+
}
|
|
279
286
|
/**
|
|
280
287
|
* What the app gives a connector's login half (`ConnectorSetup.login`) when it makes it: for a
|
|
281
288
|
* public site, once per site; for the staff login, once, with `staff`.
|
|
@@ -305,17 +312,17 @@ export interface LoginContext {
|
|
|
305
312
|
* sender, and then the login offers no code.
|
|
306
313
|
*/
|
|
307
314
|
sendCode?(email: string, code: string): Promise<void>;
|
|
315
|
+
/**
|
|
316
|
+
* For a public site's login: the company's own OAuth clients (its GitHub App's), each a method
|
|
317
|
+
* when given, by which a visitor signs in or, signed in, links that account (`LoginIdentity.github`).
|
|
318
|
+
*/
|
|
319
|
+
social?: SocialClients;
|
|
308
320
|
/** For the staff login only: who it may let in, the company's social clients, and where it tells of a sign-in. */
|
|
309
321
|
staff?: {
|
|
310
322
|
/** Whether the people files declare the person `identity` names; a login never makes a user for anyone else. */
|
|
311
323
|
admits(identity: LoginIdentity): boolean;
|
|
312
324
|
/** The company's own OAuth clients, each a method when given. */
|
|
313
|
-
social:
|
|
314
|
-
github?: {
|
|
315
|
-
clientId: string;
|
|
316
|
-
clientSecret: string;
|
|
317
|
-
};
|
|
318
|
-
};
|
|
325
|
+
social: SocialClients;
|
|
319
326
|
/** Tells the app of a sign-in by `method` of the person `identity` names, which the ledger records. Must not throw. */
|
|
320
327
|
record(method: SignInMethod, identity: LoginIdentity): Promise<void>;
|
|
321
328
|
};
|
|
@@ -345,8 +352,8 @@ export declare function sameOrigin(request: Request): boolean;
|
|
|
345
352
|
export interface LoginHalf {
|
|
346
353
|
/**
|
|
347
354
|
* Who signed in, as the provider's stable subject, with their email when the provider verified
|
|
348
|
-
* it and their GitHub login when they signed in with GitHub; null for a missing or
|
|
349
|
-
* for which it never throws.
|
|
355
|
+
* it and their GitHub login when they signed in with GitHub or linked it; null for a missing or
|
|
356
|
+
* bad cookie, for which it never throws.
|
|
350
357
|
*/
|
|
351
358
|
verify(request: Request): Promise<{
|
|
352
359
|
subject: string;
|
package/dist/op.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"op.js","sourceRoot":"","sources":["../src/op.ts"],"names":[],"mappings":"AAoEA;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAkB,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;AAkBrE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GAAkB,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAcjE;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAiClC,uFAAuF;AACvF,MAAM,WAAW,GAAG,iCAAiC,CAAC;AAEtD,oFAAoF;AACpF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAY,EAAiB,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE9G,MAAM,eAAe,GAAG,CAAC,KAAc,EAA0B,EAAE,CACjE,CAAC,OAAO,KAAK,KAAK,UAAU,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;IAC1D,KAAK,KAAK,IAAI;IACb,KAAgC,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC;AAEvD;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC7B,MAAS,EACT,KAAQ,EACR,IAAiB;IAEjB,qGAAq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AC;IACD,MAAM,OAAO,GAAG,CAAC,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,MAAM,IAAI,GAAG,EAAE,CAAC,CAAC;IAChH,MAAM,QAAQ,GAAG;QACf,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,yBAAyB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1E,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,iBAAiB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;KACrG,CAAC;IACF,IAAI,QAAQ,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,iBAAiB,MAAM,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1F,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,MAAM;QACN,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC;QACvB,GAAG,CAAC,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;QACxC,GAAG,CAAC,OAAO,CAAC,cAAc,IAAI,EAAE,cAAc,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC;KAC9F,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { IdentityAudit, IdentityEnrollments } from "./cloud-identity.ts";
|
|
2
|
+
/** Fixed by the trusted provisioning issuer deployment, never by a request or company config. */
|
|
3
|
+
export interface ProvisioningIdentity {
|
|
4
|
+
serviceAccount: string;
|
|
5
|
+
/** Google's immutable numeric uniqueId for the source service account. */
|
|
6
|
+
subject: string;
|
|
7
|
+
/** Exact WIF provider audience whose trust condition pins this subject. */
|
|
8
|
+
audience: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ProvisioningIdToken {
|
|
11
|
+
idToken: string;
|
|
12
|
+
expiresAt: number;
|
|
13
|
+
}
|
|
14
|
+
/** Dedicated Cloud Run attached identity with getOpenIdToken on the fixed source account only. */
|
|
15
|
+
export declare function attachedGoogleIdTokenIssuer(configuration: ProvisioningIdentity): () => Promise<ProvisioningIdToken>;
|
|
16
|
+
/**
|
|
17
|
+
* GET /identity for a separate provisioning credential source. Deploy with its own enrollment
|
|
18
|
+
* reader and attached issuer, outside the runtime broker. OIDC tokens last up to one hour:
|
|
19
|
+
* revocation must remove federation/impersonation trust as well as stopping new issuance.
|
|
20
|
+
*/
|
|
21
|
+
export declare function provisioningIdentityBroker(options: {
|
|
22
|
+
identity: ProvisioningIdentity;
|
|
23
|
+
enrollments: IdentityEnrollments;
|
|
24
|
+
/** Trusted Google issuer. The request cannot select subject, audience or token lifetime. */
|
|
25
|
+
issue(): Promise<ProvisioningIdToken>;
|
|
26
|
+
audit(event: IdentityAudit): Promise<void>;
|
|
27
|
+
}): (request: Request) => Promise<Response>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Compute } from "google-auth-library";
|
|
2
|
+
import { enrollmentBroker } from "./identity-broker.js";
|
|
3
|
+
const ACCOUNT = /^[a-z][a-z0-9-]+@[a-z][a-z0-9-]+\.iam\.gserviceaccount\.com$/;
|
|
4
|
+
const AUDIENCE = /^\/\/iam\.googleapis\.com\/projects\/[1-9][0-9]+\/locations\/global\/workloadIdentityPools\/[a-z][a-z0-9-]+\/providers\/[a-z][a-z0-9-]+$/;
|
|
5
|
+
const SCOPE = "https://www.googleapis.com/auth/cloud-platform";
|
|
6
|
+
const fail = () => new Error("Provisioning identity unavailable");
|
|
7
|
+
function identityOf(identity) {
|
|
8
|
+
if (!ACCOUNT.test(identity.serviceAccount) ||
|
|
9
|
+
!/^[1-9][0-9]+$/.test(identity.subject) ||
|
|
10
|
+
!AUDIENCE.test(identity.audience))
|
|
11
|
+
throw fail();
|
|
12
|
+
return { serviceAccount: identity.serviceAccount, subject: identity.subject, audience: identity.audience };
|
|
13
|
+
}
|
|
14
|
+
// The issuer calls Google's authenticated HTTPS endpoint. Check its fixed claims and expiry;
|
|
15
|
+
// signature verification of the returned Google token remains Google's STS responsibility.
|
|
16
|
+
function tokenExpiry(idToken, identity, now) {
|
|
17
|
+
try {
|
|
18
|
+
if (typeof idToken !== "string" || idToken.length > 8192)
|
|
19
|
+
throw fail();
|
|
20
|
+
const parts = idToken.split(".");
|
|
21
|
+
if (parts.length !== 3 || !parts.every((part) => /^[A-Za-z0-9_-]+$/.test(part)))
|
|
22
|
+
throw fail();
|
|
23
|
+
const claims = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
|
|
24
|
+
if (claims.iss !== "https://accounts.google.com" ||
|
|
25
|
+
claims.sub !== identity.subject ||
|
|
26
|
+
claims.aud !== identity.audience ||
|
|
27
|
+
claims.email !== identity.serviceAccount ||
|
|
28
|
+
claims.email_verified !== true ||
|
|
29
|
+
!Number.isSafeInteger(claims.iat) ||
|
|
30
|
+
!Number.isSafeInteger(claims.exp) ||
|
|
31
|
+
claims.iat * 1000 > now + 30_000 ||
|
|
32
|
+
claims.exp <= claims.iat ||
|
|
33
|
+
claims.exp - claims.iat > 3600 ||
|
|
34
|
+
claims.exp * 1000 <= now + 60_000 ||
|
|
35
|
+
claims.exp * 1000 > now + 3_630_000)
|
|
36
|
+
throw fail();
|
|
37
|
+
return claims.exp * 1000;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
throw fail();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** Dedicated Cloud Run attached identity with getOpenIdToken on the fixed source account only. */
|
|
44
|
+
export function attachedGoogleIdTokenIssuer(configuration) {
|
|
45
|
+
const identity = identityOf(configuration);
|
|
46
|
+
const auth = new Compute({ scopes: [SCOPE] });
|
|
47
|
+
return async () => {
|
|
48
|
+
try {
|
|
49
|
+
const response = await auth.request({
|
|
50
|
+
url: `https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/${identity.serviceAccount}:generateIdToken`,
|
|
51
|
+
method: "POST",
|
|
52
|
+
data: { audience: identity.audience, includeEmail: true },
|
|
53
|
+
timeout: 10_000,
|
|
54
|
+
});
|
|
55
|
+
const idToken = response.data.token;
|
|
56
|
+
return { idToken, expiresAt: tokenExpiry(idToken, identity, Date.now()) };
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
throw fail();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* GET /identity for a separate provisioning credential source. Deploy with its own enrollment
|
|
65
|
+
* reader and attached issuer, outside the runtime broker. OIDC tokens last up to one hour:
|
|
66
|
+
* revocation must remove federation/impersonation trust as well as stopping new issuance.
|
|
67
|
+
*/
|
|
68
|
+
export function provisioningIdentityBroker(options) {
|
|
69
|
+
const identity = identityOf(options.identity);
|
|
70
|
+
return enrollmentBroker({
|
|
71
|
+
path: "/identity",
|
|
72
|
+
method: "GET",
|
|
73
|
+
enrollments: options.enrollments,
|
|
74
|
+
accept: (enrollment) => enrollment.serviceAccount === identity.serviceAccount,
|
|
75
|
+
issue: () => options.issue(),
|
|
76
|
+
valid: (token, now) => token.expiresAt === tokenExpiry(token.idToken, identity, now),
|
|
77
|
+
body: (token) => ({ idToken: token.idToken, expiresAt: token.expiresAt }),
|
|
78
|
+
audit: options.audit,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=provisioning-identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provisioning-identity.js","sourceRoot":"","sources":["../src/provisioning-identity.ts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ource.d.ts
CHANGED
|
@@ -33,6 +33,26 @@ export interface FieldReference {
|
|
|
33
33
|
* declared one. Without it, the field holds the resource's `name`, and is compared as it is.
|
|
34
34
|
*/
|
|
35
35
|
readonly by?: readonly string[];
|
|
36
|
+
/**
|
|
37
|
+
* A dotted path in that resource's state: apply and drift give this field the named resource's
|
|
38
|
+
* state at this path, as a whole (a list or an object), read in the same run or made by an
|
|
39
|
+
* earlier step of it (`records: mail` takes a `resend.domain`'s `dns_records`). A data file may
|
|
40
|
+
* give a literal value here instead. `desired` holds the resource's `name` until then, which the
|
|
41
|
+
* schema does not judge. Where the same apply changes that resource at the path (creates or
|
|
42
|
+
* replaces it, or updates it with the path `unknown` or another value there in its plan), or,
|
|
43
|
+
* for a create, it has no state yet or nothing at the path, a plan is given `null` there (known
|
|
44
|
+
* after apply: the type's `plan` must accept it and report the path in `unknown`), so a change it
|
|
45
|
+
* makes is planned, and approved, up front. A plan of a bound object leaves the field out while
|
|
46
|
+
* its resource is absent, gone or unreadable and not about to change, as drift does, and its step
|
|
47
|
+
* runs without it. A step given `null` for the field whose value is still not known (its
|
|
48
|
+
* resource's step failed or did not run) fails before its driver is called, and drift leaves the
|
|
49
|
+
* field out. An empty list or object at the path counts as known: a vendor that answers `[]`
|
|
50
|
+
* while it is still filling the list makes the dependent write an empty one. The path must be a
|
|
51
|
+
* field of each type it may name (`checkFromRefs`, when a config is resolved). Not on a
|
|
52
|
+
* write-only field, nor one holding a write-only field (refused). Not yet on a bridge-backed type
|
|
53
|
+
* (`tfConnector`): an OpenTofu provider's plan reads `null` as unset, not as known after apply.
|
|
54
|
+
*/
|
|
55
|
+
readonly from?: string;
|
|
36
56
|
}
|
|
37
57
|
/** A resource type's `fields.references`: by dotted path, the resource each names. */
|
|
38
58
|
export type References = {
|
|
@@ -166,9 +186,10 @@ export interface Declared<Id extends string = string, T = State> {
|
|
|
166
186
|
}
|
|
167
187
|
/**
|
|
168
188
|
* What a resource type's constructor takes: its fields, where `R` (its `fields.references`)
|
|
169
|
-
* names a path, a declared resource of that type instead of a value (`repository_id: site`),
|
|
170
|
-
*
|
|
171
|
-
*
|
|
189
|
+
* names a path, a declared resource of that type instead of a value (`repository_id: site`), in
|
|
190
|
+
* place of the whole field for a `from` reference (`records: mail`) and of each item for a list
|
|
191
|
+
* otherwise, and where a string goes, a secret (`secret("NAME")`), which the constructor allows
|
|
192
|
+
* at a write-only field only.
|
|
172
193
|
*/
|
|
173
194
|
export type Declaring<T, R extends References = {}> = [keyof R] extends [never] ? WithSecrets<T> : DeclaringAt<T, R, "">;
|
|
174
195
|
type WithSecrets<V> = V extends string ? V | Secret : V extends readonly (infer I)[] ? WithSecrets<I>[] : V extends object ? {
|
|
@@ -177,7 +198,9 @@ type WithSecrets<V> = V extends string ? V | Secret : V extends readonly (infer
|
|
|
177
198
|
type DeclaringAt<T, R extends References, P extends string> = T extends readonly (infer I)[] ? DeclaringAt<I, R, P>[] : T extends object ? {
|
|
178
199
|
[K in keyof T]: K extends string ? DeclaringField<T[K], R, P extends "" ? K : `${P}.${K}`> : T[K];
|
|
179
200
|
} : WithSecrets<T>;
|
|
180
|
-
type DeclaringField<V, R extends References, P extends string> = P extends keyof R ?
|
|
201
|
+
type DeclaringField<V, R extends References, P extends string> = P extends keyof R ? R[P] extends {
|
|
202
|
+
readonly from: string;
|
|
203
|
+
} ? WithSecrets<V> | DeclaredOf<R[P]["type"]> : V extends readonly (infer I)[] ? (WithSecrets<I> | DeclaredOf<R[P]["type"]>)[] : WithSecrets<V> | DeclaredOf<R[P]["type"]> : [Extract<keyof R, `${P}.${string}`>] extends [never] ? WithSecrets<V> : DeclaringAt<V, R, P>;
|
|
181
204
|
type DeclaredOf<Id> = Id extends string ? Declared<Id> : Id extends readonly (infer E)[] ? DeclaredOf<E> : never;
|
|
182
205
|
/** What a plan of a change says will happen, as `PlanResponse.Action` names it. */
|
|
183
206
|
export declare const PLAN_ACTIONS: readonly ["none", "create", "update", "replace", "delete"];
|
|
@@ -366,10 +389,34 @@ export declare function holderOf(value: unknown, path: string): {
|
|
|
366
389
|
holder: State;
|
|
367
390
|
key: string;
|
|
368
391
|
} | undefined;
|
|
392
|
+
/** What `withFrom` makes of a `from` field it cannot fill: `null` (known after apply), or nothing. */
|
|
393
|
+
export type Missing = "unknown" | "drop";
|
|
394
|
+
/** A `from` reference `withFrom` could not fill: the resource it names has no state, or nothing at its path. */
|
|
395
|
+
export interface Unfilled {
|
|
396
|
+
at: string;
|
|
397
|
+
named: string;
|
|
398
|
+
from: string;
|
|
399
|
+
/** True when the resource has a state, with nothing at the path. */
|
|
400
|
+
stated: boolean;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* `desired` with each field a `from` reference names given the state of the resource it names
|
|
404
|
+
* at that path (a copy), `stateOf` that resource (by what `refs` holds there, and the path read);
|
|
405
|
+
* and the references it could not fill, where that resource has no state or nothing there, each
|
|
406
|
+
* such field `null` (`unknown`, a value known after apply) or left out (`drop`), as `missing` says
|
|
407
|
+
* (for each reference, given a function). A reference with no place in `desired` to fill is
|
|
408
|
+
* unfilled too. `desired` itself when there is no such field.
|
|
409
|
+
*/
|
|
410
|
+
export declare function withFrom(references: References | undefined, desired: State, refs: Readonly<Record<string, string>>, stateOf: (named: string, from: string) => State | undefined, missing: Missing | ((named: string, from: string) => Missing)): {
|
|
411
|
+
desired: State;
|
|
412
|
+
unfilled: Unfilled[];
|
|
413
|
+
};
|
|
369
414
|
/** A field's dotted path as `fields` names it, without a list item's index: `teams.0` is `teams`. */
|
|
370
415
|
export declare const fieldPathOf: (at: string) => string;
|
|
371
416
|
/** The value at a dotted path, a list item's by its index. */
|
|
372
417
|
export declare const valueAt: (value: unknown, path: string) => unknown;
|
|
418
|
+
/** True when the two are the same JSON, where a missing value is `null`. */
|
|
419
|
+
export declare function same(a: unknown, b: unknown): boolean;
|
|
373
420
|
/**
|
|
374
421
|
* `desired` without the values at the fields the type marks write-only (a webhook's `secret`):
|
|
375
422
|
* what a run may record of a declaration. A list's items lose them too. A secret marker
|
|
@@ -403,6 +450,12 @@ export declare function withoutWriteOnly(fields: ResourceFields, desired: State)
|
|
|
403
450
|
* - `update` takes `{ id, state?, handle?, desired, expect? }` and returns the same; given
|
|
404
451
|
* `expect` (a plan's `action` and `replace`), it refuses a fresh plan that differs
|
|
405
452
|
* (`DriverError`, `vendorCode` `plan_changed`).
|
|
453
|
+
*
|
|
454
|
+
* A type whose fields take a `from` reference (`FieldReference.from`) is given `null` there by
|
|
455
|
+
* apply's `plan` while the value is known only after apply, so its `plan` must accept `null` and
|
|
456
|
+
* report the path in `unknown`; and its `update` must treat a field left out of `desired` as
|
|
457
|
+
* keeping what the vendor holds, since a bound object whose `from` resource is gone is updated
|
|
458
|
+
* with that field left out.
|
|
406
459
|
* - `delete` takes `{ id, state?, handle? }` and returns `{ id, gone: true }`.
|
|
407
460
|
*
|
|
408
461
|
* `desired` may hold secret markers at write-only fields, which the driver resolves; no output
|
|
@@ -415,8 +468,10 @@ export declare function withoutWriteOnly(fields: ResourceFields, desired: State)
|
|
|
415
468
|
* schema does not have, fields the vendor owns (unless the identity names them), values the
|
|
416
469
|
* schema rejects, and an empty identity. Where `fields.references` allows it, a field may name
|
|
417
470
|
* another declared resource of that type (`repository_id: site`): `desired` holds, and the
|
|
418
|
-
* schema and `find` read, that resource's `name`, and `refs` says where it was named. A
|
|
419
|
-
*
|
|
471
|
+
* schema and `find` read, that resource's `name`, and `refs` says where it was named. A `from`
|
|
472
|
+
* reference names one in place of the whole field, which apply and drift fill from its state, so
|
|
473
|
+
* the schema does not judge the name there. A type without `find` declares resources without a
|
|
474
|
+
* `name`, found only by their bindings.
|
|
420
475
|
*/
|
|
421
476
|
export declare function defineResource<S extends z.ZodObject, const V extends string, const T extends string, const R extends References = {}, const W extends boolean = false>(spec: ResourceSpec<S> & {
|
|
422
477
|
vendor: V;
|
|
@@ -426,6 +481,12 @@ export declare function defineResource<S extends z.ZodObject, const V extends st
|
|
|
426
481
|
};
|
|
427
482
|
writable?: W;
|
|
428
483
|
}): Resource<S, `${V}.${T}`, R, W>;
|
|
484
|
+
/**
|
|
485
|
+
* Throws where a `from` reference (`FieldReference.from`) names a path that a type it may name
|
|
486
|
+
* has no field at, among `types` (a config's): `dns_record` for `dns_records` would otherwise
|
|
487
|
+
* fail every create. A type not among them is left to the data files' check.
|
|
488
|
+
*/
|
|
489
|
+
export declare function checkFromRefs(types: ReadonlyMap<string, Resource>): void;
|
|
429
490
|
/** Every resource type the connectors declare, by `<vendor>.<type>`. */
|
|
430
491
|
export declare function resourceTypesOf(connectors: readonly Connector<any, any>[]): Map<string, Resource>;
|
|
431
492
|
export {};
|