@flytedesk/app-kit 12.5.0 → 12.6.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.
Files changed (59) hide show
  1. package/README.md +135 -0
  2. package/dist/auth/idpRequest.d.ts +16 -0
  3. package/dist/auth/idpRequest.js +37 -0
  4. package/dist/auth/idpRequest.js.map +1 -0
  5. package/dist/auth/jwks.d.ts +16 -0
  6. package/dist/auth/jwks.js +38 -0
  7. package/dist/auth/jwks.js.map +1 -0
  8. package/dist/auth/oidc-client.js +7 -25
  9. package/dist/auth/oidc-client.js.map +1 -1
  10. package/dist/auth/people/lookup.js +9 -16
  11. package/dist/auth/people/lookup.js.map +1 -1
  12. package/dist/auth/service/index.js +12 -19
  13. package/dist/auth/service/index.js.map +1 -1
  14. package/dist/connections/cipher/index.d.ts +20 -0
  15. package/dist/connections/cipher/index.js +26 -0
  16. package/dist/connections/cipher/index.js.map +1 -0
  17. package/dist/connections/cipher/kmsDecrypt.d.ts +3 -0
  18. package/dist/connections/cipher/kmsDecrypt.js +25 -0
  19. package/dist/connections/cipher/kmsDecrypt.js.map +1 -0
  20. package/dist/connections/cipher/kmsEncrypt.d.ts +3 -0
  21. package/dist/connections/cipher/kmsEncrypt.js +24 -0
  22. package/dist/connections/cipher/kmsEncrypt.js.map +1 -0
  23. package/dist/connections/cipher/localDecrypt.d.ts +3 -0
  24. package/dist/connections/cipher/localDecrypt.js +25 -0
  25. package/dist/connections/cipher/localDecrypt.js.map +1 -0
  26. package/dist/connections/cipher/localEncrypt.d.ts +3 -0
  27. package/dist/connections/cipher/localEncrypt.js +22 -0
  28. package/dist/connections/cipher/localEncrypt.js.map +1 -0
  29. package/dist/connections/cipher/localFormat.d.ts +5 -0
  30. package/dist/connections/cipher/localFormat.js +18 -0
  31. package/dist/connections/cipher/localFormat.js.map +1 -0
  32. package/dist/connections/cipher/types.d.ts +39 -0
  33. package/dist/connections/cipher/types.js +2 -0
  34. package/dist/connections/cipher/types.js.map +1 -0
  35. package/dist/connections/client.d.ts +52 -0
  36. package/dist/connections/client.js +227 -0
  37. package/dist/connections/client.js.map +1 -0
  38. package/dist/connections/contract.d.ts +63 -0
  39. package/dist/connections/contract.js +38 -0
  40. package/dist/connections/contract.js.map +1 -0
  41. package/dist/connections/errors.d.ts +36 -0
  42. package/dist/connections/errors.js +54 -0
  43. package/dist/connections/errors.js.map +1 -0
  44. package/dist/connections/index.d.ts +27 -0
  45. package/dist/connections/index.js +27 -0
  46. package/dist/connections/index.js.map +1 -0
  47. package/dist/connections/kinds.d.ts +151 -0
  48. package/dist/connections/kinds.js +61 -0
  49. package/dist/connections/kinds.js.map +1 -0
  50. package/dist/connections/testHandler.d.ts +44 -0
  51. package/dist/connections/testHandler.js +92 -0
  52. package/dist/connections/testHandler.js.map +1 -0
  53. package/dist/connections/testers/mysql.d.ts +14 -0
  54. package/dist/connections/testers/mysql.js +74 -0
  55. package/dist/connections/testers/mysql.js.map +1 -0
  56. package/dist/connections/testers/postgres.d.ts +41 -0
  57. package/dist/connections/testers/postgres.js +249 -0
  58. package/dist/connections/testers/postgres.js.map +1 -0
  59. package/package.json +6 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/connections/errors.ts"],"names":[],"mappings":"AAKA;4BAC4B;AAC5B,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAGtB;IAFlB,YACE,OAAe,EACC,KAAe;QAE/B,KAAK,CAAC,OAAO,CAAC,CAAC;QAFC,UAAK,GAAL,KAAK,CAAU;QAG/B,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC;CACF;AAED,iGAAiG;AACjG,MAAM,OAAO,sBAAuB,SAAQ,eAAe;IAEvC;IACA;IACA;IAHlB,YACkB,IAAY,EACZ,MAA8B,EAC9B,IAAqC,EACrD,KAAe;QAEf,KAAK,CAAC,eAAe,IAAI,qBAAqB,MAAM,EAAE,EAAE,KAAK,CAAC,CAAC;QAL/C,SAAI,GAAJ,IAAI,CAAQ;QACZ,WAAM,GAAN,MAAM,CAAwB;QAC9B,SAAI,GAAJ,IAAI,CAAiC;IAIvD,CAAC;CACF;AAED,qGAAqG;AACrG,MAAM,OAAO,qBAAsB,SAAQ,eAAe;IAEtC;IADlB,YACkB,IAAY,EAC5B,MAAc,EACd,KAAe;QAEf,KAAK,CAAC,eAAe,IAAI,kDAAkD,MAAM,GAAG,EAAE,KAAK,CAAC,CAAC;QAJ7E,SAAI,GAAJ,IAAI,CAAQ;IAK9B,CAAC;CACF;AAED,yEAAyE;AACzE,MAAM,OAAO,2BAA4B,SAAQ,eAAe;IAE5C;IACA;IACA;IAHlB,YACkB,IAAY,EACZ,QAAgB,EAChB,MAAc;QAE9B,KAAK,CAAC,eAAe,IAAI,WAAW,MAAM,sBAAsB,QAAQ,GAAG,CAAC,CAAC;QAJ7D,SAAI,GAAJ,IAAI,CAAQ;QACZ,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAQ;IAGhC,CAAC;CACF;AAED,+FAA+F;AAC/F,MAAM,OAAO,sBAAuB,SAAQ,eAAe;IAEvC;IADlB,YACkB,IAAY,EAC5B,MAAc,EACd,KAAe;QAEf,KAAK,CAAC,eAAe,IAAI,kBAAkB,MAAM,EAAE,EAAE,KAAK,CAAC,CAAC;QAJ5C,SAAI,GAAJ,IAAI,CAAQ;IAK9B,CAAC;CACF;AAED,+FAA+F;AAC/F,MAAM,OAAO,qBAAsB,SAAQ,eAAe;CAAG"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * `@flytedesk/app-kit/connections` — the shared side of flytedesk ID's secrets manager
3
+ * (PLAN-113): the connection kinds, the wire contract, the client an app's server reads
4
+ * its own connections with, the cipher behind it, and the handler that runs a connection's
5
+ * test. Like `../postgres` and `../bigquery`, it takes structural clients from the app
6
+ * (a Cloud KMS client, a database `connect`) and never builds or imports one. Never
7
+ * imports Fastify.
8
+ *
9
+ * const client = createConnectionsClient({
10
+ * issuer, appId, tokenSource,
11
+ * cipher: createConnectionCipher({ cipher: "kms", production: true, kms: new KeyManagementServiceClient() }),
12
+ * });
13
+ * const db = await client.get("main-db", "postgres"); // { settings, secrets }
14
+ */
15
+ export * from "./contract.js";
16
+ export * from "./errors.js";
17
+ export * from "./kinds.js";
18
+ export * from "./client.js";
19
+ export * from "./testHandler.js";
20
+ export { createConnectionCipher, type ConnectionCipherOptions } from "./cipher/index.js";
21
+ export { createKmsDecryptor } from "./cipher/kmsDecrypt.js";
22
+ export { createKmsEncryptor } from "./cipher/kmsEncrypt.js";
23
+ export { createLocalDecryptor } from "./cipher/localDecrypt.js";
24
+ export { createLocalEncryptor } from "./cipher/localEncrypt.js";
25
+ export type { ConnectionCipher, ConnectionDecryptor, ConnectionEncryptor, KmsClient } from "./cipher/types.js";
26
+ export * from "./testers/postgres.js";
27
+ export * from "./testers/mysql.js";
@@ -0,0 +1,27 @@
1
+ /**
2
+ * `@flytedesk/app-kit/connections` — the shared side of flytedesk ID's secrets manager
3
+ * (PLAN-113): the connection kinds, the wire contract, the client an app's server reads
4
+ * its own connections with, the cipher behind it, and the handler that runs a connection's
5
+ * test. Like `../postgres` and `../bigquery`, it takes structural clients from the app
6
+ * (a Cloud KMS client, a database `connect`) and never builds or imports one. Never
7
+ * imports Fastify.
8
+ *
9
+ * const client = createConnectionsClient({
10
+ * issuer, appId, tokenSource,
11
+ * cipher: createConnectionCipher({ cipher: "kms", production: true, kms: new KeyManagementServiceClient() }),
12
+ * });
13
+ * const db = await client.get("main-db", "postgres"); // { settings, secrets }
14
+ */
15
+ export * from "./contract.js";
16
+ export * from "./errors.js";
17
+ export * from "./kinds.js";
18
+ export * from "./client.js";
19
+ export * from "./testHandler.js";
20
+ export { createConnectionCipher } from "./cipher/index.js";
21
+ export { createKmsDecryptor } from "./cipher/kmsDecrypt.js";
22
+ export { createKmsEncryptor } from "./cipher/kmsEncrypt.js";
23
+ export { createLocalDecryptor } from "./cipher/localDecrypt.js";
24
+ export { createLocalEncryptor } from "./cipher/localEncrypt.js";
25
+ export * from "./testers/postgres.js";
26
+ export * from "./testers/mysql.js";
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/connections/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAAgC,MAAM,mBAAmB,CAAC;AACzF,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,151 @@
1
+ /**
2
+ * The kinds of connection an app can hold, defined once (DEC-347): flytedesk ID renders its
3
+ * Connections form and refuses undeclared fields from these entries, and apps get typed
4
+ * values from them. Adding a kind is one entry in `CONNECTION_KINDS`.
5
+ */
6
+ export type SettingType = "string" | "number";
7
+ export interface SettingSpec {
8
+ readonly type: SettingType;
9
+ readonly optional?: true;
10
+ }
11
+ export interface ConnectionKindSpec {
12
+ readonly settings: Readonly<Record<string, SettingSpec>>;
13
+ readonly secrets: readonly string[];
14
+ }
15
+ export type ConnectionKindRegistry = Readonly<Record<string, ConnectionKindSpec>>;
16
+ export declare const CONNECTION_KINDS: {
17
+ readonly postgres: {
18
+ readonly settings: {
19
+ readonly host: {
20
+ readonly type: "string";
21
+ };
22
+ readonly port: {
23
+ readonly type: "number";
24
+ };
25
+ readonly database: {
26
+ readonly type: "string";
27
+ };
28
+ readonly user: {
29
+ readonly type: "string";
30
+ };
31
+ };
32
+ readonly secrets: readonly ["password"];
33
+ };
34
+ readonly mysql: {
35
+ readonly settings: {
36
+ readonly host: {
37
+ readonly type: "string";
38
+ };
39
+ readonly port: {
40
+ readonly type: "number";
41
+ };
42
+ readonly database: {
43
+ readonly type: "string";
44
+ };
45
+ readonly user: {
46
+ readonly type: "string";
47
+ };
48
+ };
49
+ readonly secrets: readonly ["password"];
50
+ };
51
+ readonly postgres_iam: {
52
+ readonly settings: {
53
+ readonly instanceConnectionName: {
54
+ readonly type: "string";
55
+ };
56
+ readonly database: {
57
+ readonly type: "string";
58
+ };
59
+ readonly user: {
60
+ readonly type: "string";
61
+ };
62
+ readonly serviceAccount: {
63
+ readonly type: "string";
64
+ };
65
+ };
66
+ readonly secrets: readonly [];
67
+ };
68
+ readonly bigquery: {
69
+ readonly settings: {
70
+ readonly projectId: {
71
+ readonly type: "string";
72
+ };
73
+ readonly serviceAccount: {
74
+ readonly type: "string";
75
+ };
76
+ };
77
+ readonly secrets: readonly [];
78
+ };
79
+ readonly slack: {
80
+ readonly settings: {
81
+ readonly teamId: {
82
+ readonly type: "string";
83
+ };
84
+ };
85
+ readonly secrets: readonly ["botToken", "signingSecret"];
86
+ };
87
+ readonly trello: {
88
+ readonly settings: {
89
+ readonly apiKey: {
90
+ readonly type: "string";
91
+ };
92
+ };
93
+ readonly secrets: readonly ["apiSecret", "token"];
94
+ };
95
+ readonly anthropic: {
96
+ readonly settings: {};
97
+ readonly secrets: readonly ["apiKey"];
98
+ };
99
+ readonly api_key: {
100
+ readonly settings: {
101
+ readonly baseUrl: {
102
+ readonly type: "string";
103
+ readonly optional: true;
104
+ };
105
+ };
106
+ readonly secrets: readonly ["apiKey"];
107
+ };
108
+ };
109
+ export type ConnectionKind = keyof typeof CONNECTION_KINDS;
110
+ type ValueOf<S extends SettingSpec> = S["type"] extends "number" ? number : string;
111
+ type RequiredKeys<T extends Readonly<Record<string, SettingSpec>>> = {
112
+ [K in keyof T]: T[K] extends {
113
+ optional: true;
114
+ } ? never : K;
115
+ }[keyof T];
116
+ type OptionalKeys<T extends Readonly<Record<string, SettingSpec>>> = Exclude<keyof T, RequiredKeys<T>>;
117
+ type Flatten<T> = {
118
+ [K in keyof T]: T[K];
119
+ };
120
+ export type SettingsOf<K extends ConnectionKindSpec> = Flatten<{
121
+ [F in RequiredKeys<K["settings"]>]: ValueOf<K["settings"][F]>;
122
+ } & {
123
+ [F in OptionalKeys<K["settings"]>]?: ValueOf<K["settings"][F]>;
124
+ }>;
125
+ export type SecretsOf<K extends ConnectionKindSpec> = {
126
+ [F in K["secrets"][number]]: string;
127
+ };
128
+ /** A secret's value before its latest replacement, and when it was replaced. */
129
+ export interface PreviousSecret {
130
+ value: string;
131
+ replacedAt: Date;
132
+ }
133
+ export type PreviousOf<K extends ConnectionKindSpec> = {
134
+ [F in K["secrets"][number]]?: PreviousSecret;
135
+ };
136
+ /** A connection's typed values. `previous` holds, per secret that has an earlier version, that
137
+ * value, so an app can accept what was signed with the old secret for a grace period. */
138
+ export interface ConnectionValues<K extends ConnectionKindSpec> {
139
+ settings: SettingsOf<K>;
140
+ secrets: SecretsOf<K>;
141
+ previous: PreviousOf<K>;
142
+ }
143
+ export interface ConnectionFormField {
144
+ name: string;
145
+ secret: boolean;
146
+ type: SettingType;
147
+ optional: boolean;
148
+ }
149
+ /** The fields of a kind, settings first, in the shape a form is rendered from. */
150
+ export declare function connectionFormFields(kind: string, registry?: ConnectionKindRegistry): ConnectionFormField[];
151
+ export {};
@@ -0,0 +1,61 @@
1
+ /**
2
+ * The kinds of connection an app can hold, defined once (DEC-347): flytedesk ID renders its
3
+ * Connections form and refuses undeclared fields from these entries, and apps get typed
4
+ * values from them. Adding a kind is one entry in `CONNECTION_KINDS`.
5
+ */
6
+ export const CONNECTION_KINDS = {
7
+ postgres: {
8
+ settings: { host: { type: "string" }, port: { type: "number" }, database: { type: "string" }, user: { type: "string" } },
9
+ secrets: ["password"],
10
+ },
11
+ mysql: {
12
+ settings: { host: { type: "string" }, port: { type: "number" }, database: { type: "string" }, user: { type: "string" } },
13
+ secrets: ["password"],
14
+ },
15
+ postgres_iam: {
16
+ // A Cloud SQL IAM database login: no password, so no secret.
17
+ settings: {
18
+ instanceConnectionName: { type: "string" },
19
+ database: { type: "string" },
20
+ user: { type: "string" },
21
+ serviceAccount: { type: "string" },
22
+ },
23
+ secrets: [],
24
+ },
25
+ bigquery: {
26
+ settings: { projectId: { type: "string" }, serviceAccount: { type: "string" } },
27
+ secrets: [],
28
+ },
29
+ slack: {
30
+ settings: { teamId: { type: "string" } },
31
+ secrets: ["botToken", "signingSecret"],
32
+ },
33
+ trello: {
34
+ settings: { apiKey: { type: "string" } },
35
+ secrets: ["apiSecret", "token"],
36
+ },
37
+ anthropic: {
38
+ settings: {},
39
+ secrets: ["apiKey"],
40
+ },
41
+ api_key: {
42
+ settings: { baseUrl: { type: "string", optional: true } },
43
+ secrets: ["apiKey"],
44
+ },
45
+ };
46
+ /** The fields of a kind, settings first, in the shape a form is rendered from. */
47
+ export function connectionFormFields(kind, registry = CONNECTION_KINDS) {
48
+ const spec = registry[kind];
49
+ if (!spec)
50
+ throw new Error(`unknown connection kind "${kind}"`);
51
+ return [
52
+ ...Object.entries(spec.settings).map(([name, s]) => ({
53
+ name,
54
+ secret: false,
55
+ type: s.type,
56
+ optional: s.optional === true,
57
+ })),
58
+ ...spec.secrets.map((name) => ({ name, secret: true, type: "string", optional: false })),
59
+ ];
60
+ }
61
+ //# sourceMappingURL=kinds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kinds.js","sourceRoot":"","sources":["../../src/connections/kinds.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAgBH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,EAAE;QACR,QAAQ,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,E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AAO,EAAE,CAAC,QAAQ,CAAC;KACpB;IACD,OAAO,EAAE;QACP,QAAQ,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE;QACzD,OAAO,EAAE,CAAC,QAAQ,CAAC;KACpB;CACwC,CAAC;AA2C5C,kFAAkF;AAClF,MAAM,UAAU,oBAAoB,CAClC,IAAY,EACZ,WAAmC,gBAAgB;IAEnD,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,IAAI,GAAG,CAAC,CAAC;IAChE,OAAO;QACL,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACnD,IAAI;YACJ,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,QAAQ,EAAE,CAAC,CAAC,QAAQ,KAAK,IAAI;SAC9B,CAAC,CAAC;QACH,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAiB,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;KAClG,CAAC;AACJ,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * The app's side of a connection test (DEC-334, DEC-348): flytedesk ID cannot decrypt a
3
+ * connection, so when a person presses Test it asks the app, with a short token it signs.
4
+ * This handler is framework-neutral (`{authorization, body}` in, `{status, body}` out); the
5
+ * app mounts it on its own web server at the URL it registered with flytedesk ID. Never
6
+ * imports Fastify.
7
+ */
8
+ import { type JWTVerifyGetKey } from "jose";
9
+ import type { ConnectionsClient } from "./client.js";
10
+ import { type ConnectionTestAnswer, type ConnectionTestResult } from "./contract.js";
11
+ import type { CONNECTION_KINDS, ConnectionKindRegistry, ConnectionValues } from "./kinds.js";
12
+ /** How long a tester may run. */
13
+ export declare const CONNECTION_TEST_TIMEOUT_MS = 15000;
14
+ /** Runs one kind's test with the connection's decrypted values; its detail must not hold a value. */
15
+ export type ConnectionTester<V extends {
16
+ settings: unknown;
17
+ secrets: unknown;
18
+ }> = (connection: Pick<V, "settings" | "secrets">) => Promise<ConnectionTestResult>;
19
+ export type ConnectionTesters<R extends ConnectionKindRegistry> = {
20
+ [K in keyof R]?: ConnectionTester<ConnectionValues<R[K]>>;
21
+ };
22
+ export interface ConnectionTestHandlerOptions<R extends ConnectionKindRegistry = typeof CONNECTION_KINDS> {
23
+ /** flytedesk ID's issuer URL (no trailing slash): the test token's `iss`. */
24
+ issuer: string;
25
+ /** The app id: the test token's `aud`. */
26
+ appId: string;
27
+ client: Pick<ConnectionsClient<R>, "read">;
28
+ testers: ConnectionTesters<R>;
29
+ /** Key lookup for the token's signature. Default flytedesk ID's published keys, `{issuer}/jwks`. */
30
+ jwks?: JWTVerifyGetKey;
31
+ }
32
+ export interface ConnectionTestRequest {
33
+ /** The `Authorization` header's value. */
34
+ authorization: string | undefined;
35
+ /** The parsed JSON body. */
36
+ body: unknown;
37
+ }
38
+ export interface ConnectionTestResponse {
39
+ status: 200 | 400 | 401 | 503;
40
+ body: ConnectionTestAnswer | {
41
+ error: string;
42
+ };
43
+ }
44
+ export declare function createConnectionTestHandler<R extends ConnectionKindRegistry = typeof CONNECTION_KINDS>(options: ConnectionTestHandlerOptions<R>): (request: ConnectionTestRequest) => Promise<ConnectionTestResponse>;
@@ -0,0 +1,92 @@
1
+ /**
2
+ * The app's side of a connection test (DEC-334, DEC-348): flytedesk ID cannot decrypt a
3
+ * connection, so when a person presses Test it asks the app, with a short token it signs.
4
+ * This handler is framework-neutral (`{authorization, body}` in, `{status, body}` out); the
5
+ * app mounts it on its own web server at the URL it registered with flytedesk ID. Never
6
+ * imports Fastify.
7
+ */
8
+ import { jwtVerify } from "jose";
9
+ import { IdpUnavailableError } from "../auth/errors.js";
10
+ import { assertBareIssuer } from "../auth/idpRequest.js";
11
+ import { createLazyRemoteJwks, outageAwareKeys } from "../auth/jwks.js";
12
+ import { CONNECTION_TEST_CLAIMS, CONNECTION_TEST_KIND, CONNECTION_TEST_TOKEN_ALG, CONNECTION_TEST_TOKEN_TYP, } from "./contract.js";
13
+ /** How long a tester may run. */
14
+ export const CONNECTION_TEST_TIMEOUT_MS = 15_000;
15
+ const REDACTED = "[redacted]";
16
+ export function createConnectionTestHandler(options) {
17
+ assertBareIssuer(options.issuer, "connection test handler");
18
+ // A key set that cannot be fetched is an outage (503), not a verdict about the token (401).
19
+ const jwks = outageAwareKeys(options.jwks ?? createLazyRemoteJwks(() => `${options.issuer}/jwks`));
20
+ const testers = options.testers;
21
+ /** The slug the token authorizes a test of, or undefined when the token is not acceptable. */
22
+ async function authorize(authorization) {
23
+ const match = /^Bearer (\S+)$/.exec(authorization ?? "");
24
+ if (!match)
25
+ return undefined;
26
+ try {
27
+ const { payload } = await jwtVerify(match[1], jwks, {
28
+ issuer: options.issuer,
29
+ audience: options.appId,
30
+ typ: CONNECTION_TEST_TOKEN_TYP,
31
+ algorithms: [CONNECTION_TEST_TOKEN_ALG],
32
+ requiredClaims: ["exp"],
33
+ });
34
+ const slug = payload[CONNECTION_TEST_CLAIMS.connection];
35
+ if (payload[CONNECTION_TEST_CLAIMS.kind] !== CONNECTION_TEST_KIND || typeof slug !== "string")
36
+ return undefined;
37
+ return { slug };
38
+ }
39
+ catch (err) {
40
+ return err instanceof IdpUnavailableError ? "unavailable" : undefined;
41
+ }
42
+ }
43
+ return async ({ authorization, body }) => {
44
+ const authorized = await authorize(authorization);
45
+ if (authorized === "unavailable")
46
+ return { status: 503, body: { error: "signing keys unavailable" } };
47
+ if (!authorized)
48
+ return { status: 401, body: { error: "unauthorized" } };
49
+ const slug = body?.slug;
50
+ if (typeof slug !== "string" || slug.length === 0)
51
+ return { status: 400, body: { error: "slug is required" } };
52
+ if (slug !== authorized.slug)
53
+ return { status: 401, body: { error: "unauthorized" } };
54
+ let secrets = [];
55
+ let tested = {};
56
+ const result = await (async () => {
57
+ try {
58
+ const connection = await options.client.read(slug, { fresh: true });
59
+ secrets = [...Object.values(connection.secrets), ...Object.values(connection.previous).map((p) => p.value)];
60
+ tested = connection.versions;
61
+ const tester = testers[connection.kind];
62
+ if (!tester)
63
+ return { ok: false, detail: `no test for the "${connection.kind}" kind` };
64
+ return await runWithin(CONNECTION_TEST_TIMEOUT_MS, tester({ settings: connection.settings, secrets: connection.secrets }));
65
+ }
66
+ catch (err) {
67
+ return { ok: false, detail: `the test failed: ${err instanceof Error ? err.message : String(err)}` };
68
+ }
69
+ })();
70
+ const answer = { ok: result.ok === true, detail: scrub(String(result.detail), secrets), tested };
71
+ return { status: 200, body: answer };
72
+ };
73
+ }
74
+ async function runWithin(ms, work) {
75
+ let timer;
76
+ const timeout = new Promise((resolve) => {
77
+ timer = setTimeout(() => resolve({ ok: false, detail: `the test did not finish within ${ms / 1000} seconds` }), ms);
78
+ });
79
+ try {
80
+ return await Promise.race([work, timeout]);
81
+ }
82
+ finally {
83
+ clearTimeout(timer);
84
+ }
85
+ }
86
+ function scrub(detail, secrets) {
87
+ return [...secrets]
88
+ .filter((s) => s.length > 0)
89
+ .sort((a, b) => b.length - a.length)
90
+ .reduce((text, secret) => text.split(secret).join(REDACTED), detail);
91
+ }
92
+ //# sourceMappingURL=testHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testHandler.js","sourceRoot":"","sources":["../../src/connections/testHandler.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,SAAS,EAAwB,MAAM,MAAM,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,oB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AG,IAAI,OAAO,CAAuB,CAAC,OAAO,EAAE,EAAE;QAC5D,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,kCAAkC,EAAE,GAAG,IAAI,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IACtH,CAAC,CAAC,CAAC;IACH,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IAC7C,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACH,CAAC;AAED,SAAS,KAAK,CAAC,MAAc,EAAE,OAA0B;IACvD,OAAO,CAAC,GAAG,OAAO,CAAC;SAChB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;SAC3B,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;SACnC,MAAM,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;AACzE,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { CONNECTION_KINDS, ConnectionValues } from "../kinds.js";
2
+ import type { ConnectionTester } from "../testHandler.js";
3
+ export type MysqlConnectionValues = ConnectionValues<(typeof CONNECTION_KINDS)["mysql"]>;
4
+ /** What the test needs of an open connection: each result row as an object. */
5
+ export interface MysqlProbeConnection {
6
+ query(sql: string): Promise<Record<string, unknown>[]>;
7
+ end(): Promise<void>;
8
+ }
9
+ export type ConnectMysql = (settings: MysqlConnectionValues["settings"], secrets: MysqlConnectionValues["secrets"]) => Promise<MysqlProbeConnection>;
10
+ /** What one `SHOW GRANTS` line grants beyond read, as `<privilege> on <scope>` (empty when nothing). */
11
+ export declare function disallowedGrantsOf(grant: string): string[];
12
+ /** Roles the server gives every account; SHOW GRANTS does not list their privileges. */
13
+ export declare const MYSQL_MANDATORY_ROLES_QUERY = "SELECT @@global.mandatory_roles AS mandatory_roles";
14
+ export declare function createMysqlTester(connect: ConnectMysql): ConnectionTester<MysqlConnectionValues>;
@@ -0,0 +1,74 @@
1
+ /** The only privileges a read-only login may hold; anything else (a write, DDL, FILE, ALL, a
2
+ * dynamic privilege) fails the test. USAGE is "no privileges". */
3
+ const READ_PRIVILEGES = new Set(["SELECT", "SHOW VIEW", "USAGE", "SHOW DATABASES"]);
4
+ /** Splits `SELECT, INSERT (`a`, `b`)` at the commas outside parentheses. */
5
+ function splitPrivileges(list) {
6
+ const parts = [];
7
+ let depth = 0;
8
+ let current = "";
9
+ for (const ch of list) {
10
+ if (ch === "(")
11
+ depth++;
12
+ if (ch === ")")
13
+ depth--;
14
+ if (ch === "," && depth === 0) {
15
+ parts.push(current);
16
+ current = "";
17
+ }
18
+ else {
19
+ current += ch;
20
+ }
21
+ }
22
+ parts.push(current);
23
+ return parts.map((p) => p.replace(/\(.*\)/s, "").trim().toUpperCase()).filter((p) => p.length > 0);
24
+ }
25
+ /** What one `SHOW GRANTS` line grants beyond read, as `<privilege> on <scope>` (empty when nothing). */
26
+ export function disallowedGrantsOf(grant) {
27
+ const match = /^GRANT\s+(.*?)\s+ON\s+(.+?)\s+TO\s/is.exec(grant);
28
+ const grantOption = /\sWITH\s+GRANT\s+OPTION\s*$/i.test(grant);
29
+ if (!match) {
30
+ // `GRANT role TO user`: the role's own privileges are not in this line, so it cannot be vouched for.
31
+ return /^GRANT\s.+\sTO\s/is.test(grant) ? [`a role grant (${grant.split(/\sTO\s/i)[0].slice(6).trim()})`] : [];
32
+ }
33
+ return [
34
+ ...splitPrivileges(match[1])
35
+ .filter((privilege) => !READ_PRIVILEGES.has(privilege))
36
+ .map((privilege) => `${privilege} on ${match[2]}`),
37
+ // The right to grant what it holds on to others is more than read.
38
+ ...(grantOption ? [`GRANT OPTION on ${match[2]}`] : []),
39
+ ];
40
+ }
41
+ /** Roles the server gives every account; SHOW GRANTS does not list their privileges. */
42
+ export const MYSQL_MANDATORY_ROLES_QUERY = "SELECT @@global.mandatory_roles AS mandatory_roles";
43
+ export function createMysqlTester(connect) {
44
+ return async ({ settings, secrets }) => {
45
+ let connection;
46
+ try {
47
+ connection = await connect(settings, secrets);
48
+ }
49
+ catch (err) {
50
+ return { ok: false, detail: `could not connect: ${err instanceof Error ? err.message : String(err)}` };
51
+ }
52
+ try {
53
+ const mandatory = String((await connection.query(MYSQL_MANDATORY_ROLES_QUERY))[0]?.mandatory_roles ?? "").trim();
54
+ if (mandatory.length > 0) {
55
+ return {
56
+ ok: false,
57
+ detail: `the server sets mandatory_roles (${mandatory}): every account holds those roles' privileges, which SHOW GRANTS does not list`,
58
+ };
59
+ }
60
+ const rows = await connection.query("SHOW GRANTS FOR CURRENT_USER()");
61
+ const writes = rows.flatMap((row) => disallowedGrantsOf(String(Object.values(row)[0] ?? "")));
62
+ if (writes.length === 0)
63
+ return { ok: true, detail: "connected; the login holds read privileges only" };
64
+ return { ok: false, detail: `connected, but the login holds more than read privileges: ${writes.slice(0, 5).join("; ")}` };
65
+ }
66
+ catch (err) {
67
+ return { ok: false, detail: `the privilege check failed: ${err instanceof Error ? err.message : String(err)}` };
68
+ }
69
+ finally {
70
+ await connection.end().catch(() => undefined);
71
+ }
72
+ };
73
+ }
74
+ //# sourceMappingURL=mysql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mysql.js","sourceRoot":"","sources":["../../../src/connections/testers/mysql.ts"],"names":[],"mappings":"AAqBA;mEACmE;AACnE,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAEpF,4EAA4E;AAC5E,SAAS,eAAe,CAAC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;oBACL,EAAE,EAAE,KAAK;oBACT,MAAM,EAAE,oCAAoC,SAAS,iFAAiF;iBACvI,CAAC;YACJ,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;YACtE,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAC9F,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,iDAAiD,EAAE,CAAC;YACxG,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,6DAA6D,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;QAC7H,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,+BAA+B,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QAClH,CAAC;gBAAS,CAAC;YACT,MAAM,UAAU,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAChD,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,41 @@
1
+ import type { CONNECTION_KINDS, ConnectionValues } from "../kinds.js";
2
+ import type { ConnectionTester } from "../testHandler.js";
3
+ export type PostgresConnectionValues = ConnectionValues<(typeof CONNECTION_KINDS)["postgres"]>;
4
+ /** What the test needs of an open connection; a `pg` `Client` satisfies it. */
5
+ export interface PostgresProbeConnection {
6
+ query(sql: string): Promise<{
7
+ rows: Record<string, unknown>[];
8
+ }>;
9
+ end(): Promise<void>;
10
+ }
11
+ export type ConnectPostgres = (settings: PostgresConnectionValues["settings"], secrets: PostgresConnectionValues["secrets"]) => Promise<PostgresProbeConnection>;
12
+ /** The only roles a read-only login may be a member of, directly or through another role. */
13
+ export declare const POSTGRES_ALLOWED_ROLES: readonly ["pg_read_all_data", "pg_read_all_settings", "pg_read_all_stats", "pg_stat_scan_tables", "pg_monitor"];
14
+ /** Oldest supported server: pg_parameter_acl exists, and the public schema no longer grants CREATE to everyone. */
15
+ export declare const POSTGRES_MIN_VERSION = 150000;
16
+ /** The server's version (checked against POSTGRES_MIN_VERSION) and the database actually connected to. */
17
+ export declare const POSTGRES_SERVER_INFO_QUERY = "select current_setting('server_version_num')::int as version, current_database()::text as database";
18
+ /**
19
+ * One row per thing the login holds beyond read rights; empty for a read-only login
20
+ * (DEC-352). Threat model: a login an administrator set up with a way to write (a grant,
21
+ * membership, ownership, role attribute or server setting). Not a superuser rewriting the
22
+ * definition of a system object: that is a compromised server, and no catalog check bounds it.
23
+ * Scope: the connected database plus cluster-wide objects and role state.
24
+ *
25
+ * One allow-list over every privilege-bearing catalog, in every schema (none is excluded):
26
+ * SELECT on relations and columns; USAGE on schemas, types and trusted languages; CONNECT and
27
+ * TEMPORARY on any database; EXECUTE on caller-rights functions that are in a trusted
28
+ * language, type-made, aggregates whose support functions pass, or an extension's untrusted
29
+ * ones through the untouched default PUBLIC grant (proacl null) or a grant the extension
30
+ * recorded in pg_init_privs ('e') to PUBLIC or one of POSTGRES_ALLOWED_ROLES; membership of POSTGRES_ALLOWED_ROLES. An object
31
+ * initdb shipped (oid below 16384) is judged against initdb's own grants (pg_init_privs 'i',
32
+ * or the default when it recorded none); a grant that repeats what a held role already has from
33
+ * initdb (USAGE on public next to PUBLIC's) adds no capability and passes.
34
+ *
35
+ * Everything else is a row: any other privilege or grant, any grant or admin option, any
36
+ * owned object (pg_shdepend; only objects in temporary schemas, per pg_identify_object and
37
+ * never the name, are excepted), a default privilege beyond the list, lo_compat_privileges
38
+ * on, a role attribute beyond LOGIN, any other role membership.
39
+ */
40
+ export declare function postgresPrivilegeQuery(): string;
41
+ export declare function createPostgresTester(connect: ConnectPostgres): ConnectionTester<PostgresConnectionValues>;