@pithy-sh/auth 0.15.3 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/attestation/appAttest/assertion.d.ts +32 -0
- package/dist/attestation/appAttest/assertion.d.ts.map +1 -0
- package/dist/attestation/appAttest/assertion.js +59 -0
- package/dist/attestation/appAttest/attestation.d.ts +49 -0
- package/dist/attestation/appAttest/attestation.d.ts.map +1 -0
- package/dist/attestation/appAttest/attestation.js +111 -0
- package/dist/attestation/appAttest/authData.d.ts +24 -0
- package/dist/attestation/appAttest/authData.d.ts.map +1 -0
- package/dist/attestation/appAttest/authData.js +32 -0
- package/dist/attestation/appAttest/base64.d.ts +8 -0
- package/dist/attestation/appAttest/base64.d.ts.map +1 -0
- package/dist/attestation/appAttest/base64.js +27 -0
- package/dist/attestation/appAttest/bytes.d.ts +7 -0
- package/dist/attestation/appAttest/bytes.d.ts.map +1 -0
- package/dist/attestation/appAttest/bytes.js +19 -0
- package/dist/attestation/appAttest/cbor.d.ts +20 -0
- package/dist/attestation/appAttest/cbor.d.ts.map +1 -0
- package/dist/attestation/appAttest/cbor.js +96 -0
- package/dist/attestation/appAttest/der.d.ts +38 -0
- package/dist/attestation/appAttest/der.d.ts.map +1 -0
- package/dist/attestation/appAttest/der.js +106 -0
- package/dist/attestation/appAttest/keys.d.ts +15 -0
- package/dist/attestation/appAttest/keys.d.ts.map +1 -0
- package/dist/attestation/appAttest/keys.js +37 -0
- package/dist/attestation/appAttest/root.d.ts +9 -0
- package/dist/attestation/appAttest/root.d.ts.map +1 -0
- package/dist/attestation/appAttest/root.js +12 -0
- package/dist/attestation/appAttest/verifier.d.ts +39 -0
- package/dist/attestation/appAttest/verifier.d.ts.map +1 -0
- package/dist/attestation/appAttest/verifier.js +121 -0
- package/dist/attestation/appAttest/x509.d.ts +50 -0
- package/dist/attestation/appAttest/x509.d.ts.map +1 -0
- package/dist/attestation/appAttest/x509.js +163 -0
- package/dist/attestation/challenge.d.ts +26 -0
- package/dist/attestation/challenge.d.ts.map +1 -0
- package/dist/attestation/challenge.js +47 -0
- package/dist/attestation/config.d.ts +72 -0
- package/dist/attestation/config.d.ts.map +1 -0
- package/dist/attestation/config.js +52 -0
- package/dist/attestation/errors.d.ts +30 -0
- package/dist/attestation/errors.d.ts.map +1 -0
- package/dist/attestation/errors.js +45 -0
- package/dist/attestation/gate.d.ts +27 -0
- package/dist/attestation/gate.d.ts.map +1 -0
- package/dist/attestation/gate.js +78 -0
- package/dist/attestation/playIntegrity/google.d.ts +47 -0
- package/dist/attestation/playIntegrity/google.d.ts.map +1 -0
- package/dist/attestation/playIntegrity/google.js +178 -0
- package/dist/attestation/playIntegrity/verdict.d.ts +40 -0
- package/dist/attestation/playIntegrity/verdict.d.ts.map +1 -0
- package/dist/attestation/playIntegrity/verdict.js +93 -0
- package/dist/attestation/playIntegrity/verifier.d.ts +22 -0
- package/dist/attestation/playIntegrity/verifier.d.ts.map +1 -0
- package/dist/attestation/playIntegrity/verifier.js +64 -0
- package/dist/attestation/verifier.d.ts +60 -0
- package/dist/attestation/verifier.d.ts.map +1 -0
- package/dist/attestation/verifier.js +46 -0
- package/dist/attestation/wire.d.ts +42 -0
- package/dist/attestation/wire.d.ts.map +1 -0
- package/dist/attestation/wire.js +72 -0
- package/dist/capability.d.ts +49 -6
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +42 -7
- package/dist/client/api.d.ts +37 -24
- package/dist/client/api.d.ts.map +1 -1
- package/dist/client/api.js +52 -41
- package/dist/client/attestation.d.ts +148 -0
- package/dist/client/attestation.d.ts.map +1 -0
- package/dist/client/attestation.js +321 -0
- package/dist/client/projection.d.ts +29 -4
- package/dist/client/projection.d.ts.map +1 -1
- package/dist/data/appAttestKey.d.ts +30 -0
- package/dist/data/appAttestKey.d.ts.map +1 -0
- package/dist/data/appAttestKey.js +25 -0
- package/dist/data/attestationChallenge.d.ts +17 -0
- package/dist/data/attestationChallenge.d.ts.map +1 -0
- package/dist/data/attestationChallenge.js +19 -0
- package/dist/data/tables.d.ts +19 -1
- package/dist/data/tables.d.ts.map +1 -1
- package/dist/data/tables.js +6 -2
- package/dist/data/userLifecycle.d.ts +1 -0
- package/dist/data/userLifecycle.d.ts.map +1 -1
- package/dist/data/userLifecycle.js +3 -2
- package/dist/hooks/runtime.d.ts +32 -0
- package/dist/hooks/runtime.d.ts.map +1 -0
- package/dist/hooks/runtime.js +25 -0
- package/dist/http/adminRoutes.d.ts.map +1 -1
- package/dist/http/adminRoutes.js +4 -2
- package/dist/http/devLoginRoute.js +3 -3
- package/dist/http/resolve.d.ts.map +1 -1
- package/dist/http/resolve.js +3 -2
- package/dist/http/responses.d.ts +15 -0
- package/dist/http/responses.d.ts.map +1 -1
- package/dist/http/responses.js +13 -2
- package/dist/http/routes.d.ts +5 -1
- package/dist/http/routes.d.ts.map +1 -1
- package/dist/http/routes.js +92 -25
- package/dist/http/schemas.d.ts +7 -0
- package/dist/http/schemas.d.ts.map +1 -1
- package/dist/http/schemas.js +7 -1
- package/dist/index.js +1 -1
- package/dist/instance/secrets.d.ts +86 -7
- package/dist/instance/secrets.d.ts.map +1 -1
- package/dist/instance/secrets.js +54 -8
- package/dist/lifecycle/erasure.d.ts.map +1 -1
- package/dist/lifecycle/erasure.js +2 -1
- package/dist/lifecycle/hooks.d.ts +18 -10
- package/dist/lifecycle/hooks.d.ts.map +1 -1
- package/dist/lifecycle/request.d.ts +2 -1
- package/dist/lifecycle/request.d.ts.map +1 -1
- package/dist/lifecycle/request.js +4 -1
- package/dist/lifecycle/transitions.d.ts +24 -16
- package/dist/lifecycle/transitions.d.ts.map +1 -1
- package/dist/lifecycle/transitions.js +27 -16
- package/dist/migrations/0009_attestation_challenges.d.ts +9 -0
- package/dist/migrations/0009_attestation_challenges.d.ts.map +1 -0
- package/dist/migrations/0009_attestation_challenges.js +21 -0
- package/dist/migrations/0010_app_attest_keys.d.ts +9 -0
- package/dist/migrations/0010_app_attest_keys.d.ts.map +1 -0
- package/dist/migrations/0010_app_attest_keys.js +17 -0
- package/dist/migrations/0011_retained_basis_key.d.ts +10 -0
- package/dist/migrations/0011_retained_basis_key.d.ts.map +1 -0
- package/dist/migrations/0011_retained_basis_key.js +18 -0
- package/dist/migrations/set.d.ts +4 -1
- package/dist/migrations/set.d.ts.map +1 -1
- package/dist/migrations/set.js +8 -2
- package/dist/purge/run.d.ts +11 -11
- package/dist/purge/run.d.ts.map +1 -1
- package/dist/purge/run.js +9 -8
- package/dist/purge/workflow.d.ts +7 -1
- package/dist/purge/workflow.d.ts.map +1 -1
- package/dist/purge/workflow.js +6 -2
- package/dist/seeds/devSession.js +1 -1
- package/dist/test-utils/appAttestDevice.d.ts +92 -0
- package/dist/test-utils/appAttestDevice.d.ts.map +1 -0
- package/dist/test-utils/appAttestDevice.js +282 -0
- package/dist/test-utils/appAttestSample.d.ts +22 -0
- package/dist/test-utils/appAttestSample.d.ts.map +1 -0
- package/dist/test-utils/appAttestSample.js +24 -0
- package/dist/test-utils/googlePlay.d.ts +47 -0
- package/dist/test-utils/googlePlay.d.ts.map +1 -0
- package/dist/test-utils/googlePlay.js +117 -0
- package/dist/test-utils/liveApp.d.ts +76 -36
- package/dist/test-utils/liveApp.d.ts.map +1 -1
- package/dist/test-utils/liveApp.js +16 -5
- package/dist/test-utils/rollbackThrough.d.ts +11 -0
- package/dist/test-utils/rollbackThrough.d.ts.map +1 -0
- package/dist/test-utils/rollbackThrough.js +16 -0
- package/dist/test-utils/scopedBackend.d.ts +25 -0
- package/dist/test-utils/scopedBackend.d.ts.map +1 -1
- package/dist/test-utils/scopedBackend.js +1 -1
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/docs/account-lifecycle.md +46 -10
- package/docs/attestation.md +173 -0
- package/package.json +5 -5
- package/pithy.manifest.json +14 -0
- package/src/attestation/appAttest/assertion.ts +65 -0
- package/src/attestation/appAttest/attestation.ts +159 -0
- package/src/attestation/appAttest/authData.ts +45 -0
- package/src/attestation/appAttest/base64.ts +29 -0
- package/src/attestation/appAttest/bytes.ts +18 -0
- package/src/attestation/appAttest/cbor.ts +116 -0
- package/src/attestation/appAttest/der.ts +126 -0
- package/src/attestation/appAttest/keys.ts +57 -0
- package/src/attestation/appAttest/root.ts +13 -0
- package/src/attestation/appAttest/verifier.ts +113 -0
- package/src/attestation/appAttest/x509.ts +209 -0
- package/src/attestation/challenge.ts +56 -0
- package/src/attestation/config.ts +118 -0
- package/src/attestation/errors.ts +60 -0
- package/src/attestation/gate.ts +105 -0
- package/src/attestation/playIntegrity/google.ts +239 -0
- package/src/attestation/playIntegrity/verdict.ts +149 -0
- package/src/attestation/playIntegrity/verifier.ts +77 -0
- package/src/attestation/verifier.ts +87 -0
- package/src/attestation/wire.ts +79 -0
- package/src/capability.ts +85 -16
- package/src/client/api.ts +73 -40
- package/src/client/attestation.ts +404 -0
- package/src/client/projection.ts +29 -4
- package/src/data/appAttestKey.ts +45 -0
- package/src/data/attestationChallenge.ts +23 -0
- package/src/data/tables.ts +5 -1
- package/src/data/userLifecycle.ts +9 -2
- package/src/hooks/runtime.ts +41 -0
- package/src/http/adminRoutes.ts +14 -7
- package/src/http/resolve.ts +8 -4
- package/src/http/responses.ts +29 -1
- package/src/http/routes.ts +128 -38
- package/src/http/schemas.ts +24 -0
- package/src/instance/secrets.ts +88 -9
- package/src/lifecycle/erasure.ts +2 -1
- package/src/lifecycle/hooks.ts +22 -10
- package/src/lifecycle/request.ts +4 -1
- package/src/lifecycle/transitions.ts +47 -28
- package/src/migrations/0009_attestation_challenges.ts +28 -0
- package/src/migrations/0010_app_attest_keys.ts +27 -0
- package/src/migrations/0011_retained_basis_key.ts +19 -0
- package/src/migrations/set.ts +7 -1
- package/src/purge/run.ts +29 -17
- package/src/purge/workflow.ts +7 -3
- package/src/test-utils/appAttestDevice.ts +399 -0
- package/src/test-utils/appAttestSample.ts +20 -0
- package/src/test-utils/googlePlay.ts +144 -0
- package/src/test-utils/liveApp.ts +31 -5
- package/src/test-utils/rollbackThrough.ts +24 -0
- package/src/version.generated.ts +1 -1
package/src/http/schemas.ts
CHANGED
|
@@ -62,6 +62,30 @@ export const HandoffExchangeBody = z
|
|
|
62
62
|
.describe("The code a native app trades for its session after a redirect sign-in, with the verifier that binds it.");
|
|
63
63
|
export type HandoffExchangeBody = z.output<typeof HandoffExchangeBody>;
|
|
64
64
|
|
|
65
|
+
/** `POST {base}/attestation/ios/keys`: an App Attest key and Apple's attestation of it. */
|
|
66
|
+
export const AppAttestKeyBody = z
|
|
67
|
+
.object({
|
|
68
|
+
challenge: z
|
|
69
|
+
.string()
|
|
70
|
+
.min(1)
|
|
71
|
+
.max(128)
|
|
72
|
+
.describe(
|
|
73
|
+
"A challenge from `POST {base}/attestation/challenge`. The app passes SHA-256 of its characters to `attestKey` as the client data hash. Spent by this request, pass or fail.",
|
|
74
|
+
),
|
|
75
|
+
keyId: z
|
|
76
|
+
.string()
|
|
77
|
+
.min(1)
|
|
78
|
+
.max(256)
|
|
79
|
+
.describe("The key identifier `generateKey` returned, base64 as Apple hands it over."),
|
|
80
|
+
attestation: z
|
|
81
|
+
.string()
|
|
82
|
+
.min(1)
|
|
83
|
+
.max(16_384)
|
|
84
|
+
.describe("The attestation object `attestKey` returned, base64 as Apple hands it over."),
|
|
85
|
+
})
|
|
86
|
+
.describe("A new App Attest key for this server to verify and register before the app makes assertions with it.");
|
|
87
|
+
export type AppAttestKeyBody = z.output<typeof AppAttestKeyBody>;
|
|
88
|
+
|
|
65
89
|
/** The providers a native app can sign in with through the system browser: every redirect provider auth offers. */
|
|
66
90
|
export const RedirectProvider = z
|
|
67
91
|
.enum(["apple", "facebook", "github", "google", "microsoft"])
|
package/src/instance/secrets.ts
CHANGED
|
@@ -29,6 +29,9 @@ import type { SessionSecretVersions } from "./sessionSecrets";
|
|
|
29
29
|
* - `auth-microsoft-credentials` — the Microsoft Entra ID app registration's client id, client secret,
|
|
30
30
|
* and tenant, as a typed JSON value. The tenant rides inside because it means nothing apart from the
|
|
31
31
|
* registration it belongs to. Rotatable: an Entra client secret expires (24 months at most).
|
|
32
|
+
* - `auth-play-integrity-service-account` — the Google Cloud service account JSON key the Worker decodes Play
|
|
33
|
+
* Integrity tokens with. Read only when an Android attestation arrives; rotated by adding a key in Google
|
|
34
|
+
* Cloud Console, not on our schedule.
|
|
32
35
|
*/
|
|
33
36
|
export const AUTH_SESSION_SECRET = "auth-session-secret";
|
|
34
37
|
export const AUTH_GOOGLE_CREDENTIALS = "auth-google-credentials";
|
|
@@ -36,9 +39,10 @@ export const AUTH_APPLE_CREDENTIALS = "auth-apple-credentials";
|
|
|
36
39
|
export const AUTH_FACEBOOK_CREDENTIALS = "auth-facebook-credentials";
|
|
37
40
|
export const AUTH_GITHUB_CREDENTIALS = "auth-github-credentials";
|
|
38
41
|
export const AUTH_MICROSOFT_CREDENTIALS = "auth-microsoft-credentials";
|
|
42
|
+
export const AUTH_PLAY_INTEGRITY_SERVICE_ACCOUNT = "auth-play-integrity-service-account";
|
|
39
43
|
|
|
40
44
|
/**
|
|
41
|
-
* The JWKS private keys, as `auth-session-secret`'s overlap names them
|
|
45
|
+
* The JWKS private keys, as `auth-session-secret`'s overlap names them.
|
|
42
46
|
*
|
|
43
47
|
* Better Auth encrypts every key in `pithy_auth_jwks` under the session secret, and a key never expires —
|
|
44
48
|
* so retiring the version one is sealed under would leave a signing key nothing can open. The session
|
|
@@ -181,6 +185,52 @@ export const MicrosoftOAuthCredentials = z
|
|
|
181
185
|
.describe("A Microsoft Entra ID credential set (`clientId` + `clientSecret` + `tenantId`) for one environment.");
|
|
182
186
|
export type MicrosoftOAuthCredentials = z.infer<typeof MicrosoftOAuthCredentials>;
|
|
183
187
|
|
|
188
|
+
/**
|
|
189
|
+
* The Google Cloud service account key Play Integrity tokens are decoded with: the JSON file Google Cloud
|
|
190
|
+
* Console downloads, pasted whole. Fields auth does not read are dropped on write.
|
|
191
|
+
*/
|
|
192
|
+
export const PlayIntegrityServiceAccount = z
|
|
193
|
+
.object({
|
|
194
|
+
type: z
|
|
195
|
+
.literal("service_account")
|
|
196
|
+
.optional()
|
|
197
|
+
.meta({ multiline: false })
|
|
198
|
+
.describe("The key file's kind. Google writes `service_account`."),
|
|
199
|
+
project_id: z
|
|
200
|
+
.string()
|
|
201
|
+
.optional()
|
|
202
|
+
.meta({ multiline: false })
|
|
203
|
+
.describe("The Google Cloud project the service account belongs to, linked to the app in Play Console."),
|
|
204
|
+
private_key_id: z
|
|
205
|
+
.string()
|
|
206
|
+
.optional()
|
|
207
|
+
.meta({ multiline: false })
|
|
208
|
+
.describe("The key's id, sent as the assertion's `kid` so Google picks the right public key."),
|
|
209
|
+
private_key: z
|
|
210
|
+
.string()
|
|
211
|
+
.min(1)
|
|
212
|
+
.meta({ multiline: true })
|
|
213
|
+
.describe("The RSA private key, a PKCS#8 PEM. It spans many lines, so paste the whole JSON file."),
|
|
214
|
+
client_email: z
|
|
215
|
+
.string()
|
|
216
|
+
.min(1)
|
|
217
|
+
.meta({ multiline: false })
|
|
218
|
+
.describe("The service account's address, such as `play-integrity@my-project.iam.gserviceaccount.com`."),
|
|
219
|
+
client_id: z
|
|
220
|
+
.string()
|
|
221
|
+
.optional()
|
|
222
|
+
.meta({ multiline: false })
|
|
223
|
+
.describe("The service account's numeric id. Not read; kept so the stored value matches the file."),
|
|
224
|
+
token_uri: z
|
|
225
|
+
.string()
|
|
226
|
+
.regex(/^https:\/\//, "The token endpoint is an https URL.")
|
|
227
|
+
.optional()
|
|
228
|
+
.meta({ multiline: false })
|
|
229
|
+
.describe("Google's OAuth token endpoint. Defaults to `https://oauth2.googleapis.com/token`."),
|
|
230
|
+
})
|
|
231
|
+
.describe("A Google Cloud service account JSON key, for decoding Play Integrity tokens in one environment.");
|
|
232
|
+
export type PlayIntegrityServiceAccount = z.infer<typeof PlayIntegrityServiceAccount>;
|
|
233
|
+
|
|
184
234
|
/**
|
|
185
235
|
* Where a human goes for each OAuth credential pair, and where the same human rotates it.
|
|
186
236
|
*
|
|
@@ -195,6 +245,7 @@ const FACEBOOK_APPS_PAGE = "https://developers.facebook.com/apps/";
|
|
|
195
245
|
const GITHUB_OAUTH_APPS_PAGE = "https://github.com/settings/developers";
|
|
196
246
|
const MICROSOFT_APP_REGISTRATIONS_PAGE =
|
|
197
247
|
"https://entra.microsoft.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade";
|
|
248
|
+
const GOOGLE_SERVICE_ACCOUNTS_PAGE = "https://console.cloud.google.com/iam-admin/serviceaccounts";
|
|
198
249
|
|
|
199
250
|
export const authSecretsRegistry = defineSecretRegistry({
|
|
200
251
|
// `devValue` is the whole difference between an app that runs after `pithy add auth` and one that
|
|
@@ -210,11 +261,11 @@ export const authSecretsRegistry = defineSecretRegistry({
|
|
|
210
261
|
// a session signature, so the kit both makes it and replaces it.
|
|
211
262
|
origin: { kind: "minted", recipe: { kind: "random", bytes: 32, encoding: "base64url" } },
|
|
212
263
|
rotation: { kind: "local" },
|
|
213
|
-
// The default session lifetime's overlap, and the JWKS keys sealed under it
|
|
264
|
+
// The default session lifetime's overlap, and the JWKS keys sealed under it. `auth()` declares
|
|
214
265
|
// its own from the configured `sessionExpiresIn`; this is what a module reading the secret sees.
|
|
215
266
|
overlap: { days: 7, minimumDays: 7, reencrypt: [AUTH_JWKS_DEPENDENT] },
|
|
216
267
|
},
|
|
217
|
-
// The
|
|
268
|
+
// The six below are `obtained` and rotate `manual`, and each names the page rather than the product.
|
|
218
269
|
// An adopter searching Google's console for which of four credential types "client secret" means is the
|
|
219
270
|
// gap this closes — and nothing will ever mint one, so saying where is the whole of what the kit can do.
|
|
220
271
|
[AUTH_GOOGLE_CREDENTIALS]: {
|
|
@@ -262,10 +313,19 @@ export const authSecretsRegistry = defineSecretRegistry({
|
|
|
262
313
|
origin: { kind: "obtained", issuer: "microsoft", documentation: MICROSOFT_APP_REGISTRATIONS_PAGE },
|
|
263
314
|
rotation: { kind: "manual", issuer: "microsoft", documentation: MICROSOFT_APP_REGISTRATIONS_PAGE },
|
|
264
315
|
},
|
|
316
|
+
[AUTH_PLAY_INTEGRITY_SERVICE_ACCOUNT]: {
|
|
317
|
+
backend: "d1",
|
|
318
|
+
scope: "environment",
|
|
319
|
+
rotatable: false,
|
|
320
|
+
valueType: "json",
|
|
321
|
+
schema: PlayIntegrityServiceAccount,
|
|
322
|
+
origin: { kind: "obtained", issuer: "google", documentation: GOOGLE_SERVICE_ACCOUNTS_PAGE },
|
|
323
|
+
rotation: { kind: "manual", issuer: "google", documentation: GOOGLE_SERVICE_ACCOUNTS_PAGE },
|
|
324
|
+
},
|
|
265
325
|
});
|
|
266
326
|
|
|
267
327
|
/**
|
|
268
|
-
* **The registry `auth()` contributes, from its own configuration
|
|
328
|
+
* **The registry `auth()` contributes, from its own configuration.**
|
|
269
329
|
*
|
|
270
330
|
* The session secret's overlap follows the configured session lifetime — {@link sessionSecretOverlapDays} —
|
|
271
331
|
* and it is both the overlap and its floor: an adopter who lengthens sessions lengthens the overlap with
|
|
@@ -308,7 +368,7 @@ export function authSecretsRegistryFor(config: {
|
|
|
308
368
|
}
|
|
309
369
|
|
|
310
370
|
/**
|
|
311
|
-
* Which provider a credential belongs to — the join the CLI must never make by spelling
|
|
371
|
+
* Which provider a credential belongs to — the join the CLI must never make by spelling.
|
|
312
372
|
*
|
|
313
373
|
* `auth-apple-credentials` and the `apple` config key look like each other and that is a coincidence:
|
|
314
374
|
* nothing makes a secret name and a config key the same thing, and a reporting command that matched
|
|
@@ -329,9 +389,9 @@ export type AuthProviderToggles = Record<(typeof PROVIDER_CREDENTIALS)[number][0
|
|
|
329
389
|
* **The provider credentials this composition cannot reach**, as the `inapplicableSecrets` contribution.
|
|
330
390
|
*
|
|
331
391
|
* Auth declares five credentials whether or not a project runs five providers, so a project on Google
|
|
332
|
-
* and GitHub carries two secrets nothing will ever read.
|
|
333
|
-
*
|
|
334
|
-
*
|
|
392
|
+
* and GitHub carries two secrets nothing will ever read. A disabled provider's credential is listed as not
|
|
393
|
+
* applicable rather than as outstanding work: "set it until you need it" is wrong about a provider the
|
|
394
|
+
* configuration has not enabled.
|
|
335
395
|
*
|
|
336
396
|
* **The session secret is never in here**, and that is the line this draws: it is read on every sign-in
|
|
337
397
|
* whatever the providers are, so it is outstanding work in every project that has not set it.
|
|
@@ -355,7 +415,7 @@ export async function resolveSessionSecret(env: SecretsStoreEnv): Promise<string
|
|
|
355
415
|
}
|
|
356
416
|
|
|
357
417
|
/**
|
|
358
|
-
* Resolve every retained version of the session secret
|
|
418
|
+
* Resolve every retained version of the session secret: what an instance needs to open values sealed
|
|
359
419
|
* under the previous version, and what a credential signed under it is verified against. One read through
|
|
360
420
|
* the same cached accessor as {@link resolveSessionSecret}.
|
|
361
421
|
*/
|
|
@@ -388,6 +448,25 @@ export async function resolveGithubCredentials(env: SecretsStoreEnv): Promise<Gi
|
|
|
388
448
|
return secrets.get(AUTH_GITHUB_CREDENTIALS);
|
|
389
449
|
}
|
|
390
450
|
|
|
451
|
+
/**
|
|
452
|
+
* The Play Integrity service account when no environment of this composition allows an Android app: nothing
|
|
453
|
+
* there reads it.
|
|
454
|
+
*/
|
|
455
|
+
export function inapplicablePlayIntegritySecret(attestation: {
|
|
456
|
+
environments: Record<string, { android: readonly unknown[] }>;
|
|
457
|
+
}): Record<string, string> {
|
|
458
|
+
const allowsAndroid = Object.values(attestation.environments).some((block) => block.android.length > 0);
|
|
459
|
+
return allowsAndroid
|
|
460
|
+
? {}
|
|
461
|
+
: { [AUTH_PLAY_INTEGRITY_SERVICE_ACCOUNT]: "auth() allows no Android app to attest in any environment" };
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/** Resolve the Play Integrity service account for this invocation (only call for an Android attestation). */
|
|
465
|
+
export async function resolvePlayIntegrityServiceAccount(env: SecretsStoreEnv): Promise<PlayIntegrityServiceAccount> {
|
|
466
|
+
const secrets = await sharedSecretsStore(env, authSecretsRegistry);
|
|
467
|
+
return secrets.get(AUTH_PLAY_INTEGRITY_SERVICE_ACCOUNT);
|
|
468
|
+
}
|
|
469
|
+
|
|
391
470
|
/** Resolve the Microsoft Entra ID credentials for this invocation (only call when Microsoft is enabled). */
|
|
392
471
|
export async function resolveMicrosoftCredentials(env: SecretsStoreEnv): Promise<MicrosoftOAuthCredentials> {
|
|
393
472
|
const secrets = await sharedSecretsStore(env, authSecretsRegistry);
|
package/src/lifecycle/erasure.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { UserLifecycleEvent } from "../data/userLifecycle";
|
|
|
9
9
|
import { resolveDb } from "../http/resolve";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* **A user's erasure record, read back for the control plane's attestation
|
|
12
|
+
* **A user's erasure record, read back for the control plane's attestation.**
|
|
13
13
|
*
|
|
14
14
|
* `pithy_auth_user_lifecycle` is the one `pithy_auth_*` table a purge leaves behind, and it names the account by id
|
|
15
15
|
* and nothing else. This reads the rows an erasure is made of — the deletion, any restore, each step, a failure, the
|
|
@@ -45,6 +45,7 @@ export function userErasureReader(db: AuthDatabase): ErasureHistoryReader {
|
|
|
45
45
|
actorType: row.actorType,
|
|
46
46
|
reason: row.reason,
|
|
47
47
|
step: row.step,
|
|
48
|
+
basisKey: row.basisKey,
|
|
48
49
|
mode: row.mode,
|
|
49
50
|
purgeAfter: row.purgeAfter,
|
|
50
51
|
at: row.createdAt,
|
package/src/lifecycle/hooks.ts
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
import type { D1Database } from "@cloudflare/workers-types";
|
|
5
5
|
import type { UserLifecycleActorType } from "../data/userLifecycle";
|
|
6
|
+
import type { HookRuntime } from "../hooks/runtime";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
|
-
* The
|
|
9
|
+
* The five seams an adopter's own code follows the account lifecycle through, without polling.
|
|
9
10
|
*
|
|
10
11
|
* **On the transition, not on a route.** An account is suspended from the management surface today and may be
|
|
11
12
|
* from somewhere else tomorrow; a listener hung off one route would miss the others, which is the argument
|
|
@@ -36,19 +37,30 @@ export interface UserLifecycleHookEvent {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
/**
|
|
39
|
-
* One hook. Handed the
|
|
40
|
-
*
|
|
40
|
+
* One hook. Handed the run's D1 binding, for the reason `SessionRevokedListener` is: the listener almost certainly
|
|
41
|
+
* writes to the same database under a different capability's view of it. And handed the Worker it runs in, so it
|
|
42
|
+
* can reach a secret or another binding — start a Workflow, send to a queue, call out. `runtime.waitUntil` is there
|
|
43
|
+
* in a request and absent in the purge Workflow. A hook that takes only `(event, d1)` is still one.
|
|
41
44
|
*/
|
|
42
|
-
export type UserLifecycleListener =
|
|
45
|
+
export type UserLifecycleListener<Env = Record<string, unknown>> = (
|
|
46
|
+
event: UserLifecycleHookEvent,
|
|
47
|
+
d1: D1Database,
|
|
48
|
+
runtime: HookRuntime<Env>,
|
|
49
|
+
) => void | Promise<void>;
|
|
43
50
|
|
|
44
|
-
/** The
|
|
45
|
-
export interface UserLifecycleHooks {
|
|
51
|
+
/** The five hooks, each optional. Passed to `auth()` beside the config; `Env` is the adopter's Worker env. */
|
|
52
|
+
export interface UserLifecycleHooks<Env = Record<string, unknown>> {
|
|
46
53
|
/** An account was suspended. */
|
|
47
|
-
readonly onUserSuspended?: UserLifecycleListener
|
|
54
|
+
readonly onUserSuspended?: UserLifecycleListener<Env>;
|
|
48
55
|
/** A suspended account was reinstated. */
|
|
49
|
-
readonly onUserReinstated?: UserLifecycleListener
|
|
56
|
+
readonly onUserReinstated?: UserLifecycleListener<Env>;
|
|
50
57
|
/** An account was deleted — by an operator or by its owner — and its purge window began. */
|
|
51
|
-
readonly onUserDeleted?: UserLifecycleListener
|
|
58
|
+
readonly onUserDeleted?: UserLifecycleListener<Env>;
|
|
59
|
+
/**
|
|
60
|
+
* A deleted account was restored inside its purge window. The undo for whatever `onUserDeleted` did: the account
|
|
61
|
+
* is back, and a suspension it was under is still in force.
|
|
62
|
+
*/
|
|
63
|
+
readonly onUserRestored?: UserLifecycleListener<Env>;
|
|
52
64
|
/** A deleted account's data was erased. The last thing that happens to it. */
|
|
53
|
-
readonly onUserPurged?: UserLifecycleListener
|
|
65
|
+
readonly onUserPurged?: UserLifecycleListener<Env>;
|
|
54
66
|
}
|
package/src/lifecycle/request.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { EmailEnqueueEnv } from "@pithy-sh/email/src/capability";
|
|
|
6
6
|
import type { Context } from "hono";
|
|
7
7
|
import type { AuthWiring } from "../capability";
|
|
8
8
|
import { authDatabase } from "../data/tables";
|
|
9
|
+
import { requestRuntime } from "../hooks/runtime";
|
|
9
10
|
import { resolveDb } from "../http/resolve";
|
|
10
11
|
import type { LifecycleAuditContext, LifecycleDeps } from "./transitions";
|
|
11
12
|
|
|
@@ -14,7 +15,8 @@ import type { LifecycleAuditContext, LifecycleDeps } from "./transitions";
|
|
|
14
15
|
*
|
|
15
16
|
* One function so every route resolves them the same way: this request's database, its audit seam and logger,
|
|
16
17
|
* the composed email capability's enqueue bound to this request's env, and the adopter's hooks as `auth()` was
|
|
17
|
-
* handed them. A route that assembled its own would be the second
|
|
18
|
+
* handed them, with this request's env and `waitUntil` to run in. A route that assembled its own would be the second
|
|
19
|
+
* place a hook could be forgotten.
|
|
18
20
|
*
|
|
19
21
|
* `context` is what the caller adds to each audit event: the request's correlation, and for a management call
|
|
20
22
|
* the connection it came through. The caller passes it because only the caller knows who it is.
|
|
@@ -32,6 +34,7 @@ export function lifecycleDeps(
|
|
|
32
34
|
emit: c.var.emit,
|
|
33
35
|
config: wiring.config,
|
|
34
36
|
hooks: wiring.lifecycleHooks ?? {},
|
|
37
|
+
runtime: requestRuntime(c),
|
|
35
38
|
enqueueEmail: enqueue ? (input) => enqueue(c.env as unknown as EmailEnqueueEnv, input) : undefined,
|
|
36
39
|
log: c.var.log?.child("auth"),
|
|
37
40
|
...(context ? { context } : {}),
|
|
@@ -16,14 +16,15 @@ import { type AuthAuditAction, AuthAuditActions } from "../audit/actions";
|
|
|
16
16
|
import type { AuthConfig } from "../capability";
|
|
17
17
|
import type { AuthDatabase } from "../data/tables";
|
|
18
18
|
import type { UserLifecycleAction, UserLifecycleActorType } from "../data/userLifecycle";
|
|
19
|
+
import type { HookRuntime } from "../hooks/runtime";
|
|
19
20
|
import type { UserLifecycleHookEvent, UserLifecycleHooks, UserLifecycleListener } from "./hooks";
|
|
20
21
|
import { MAX_REASON } from "./reason";
|
|
21
22
|
import { accountStanding, LifecycleColumns } from "./state";
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
|
-
* The account-lifecycle transitions — the one place an account's state is ever changed
|
|
25
|
+
* The account-lifecycle transitions — the one place an account's state is ever changed.
|
|
25
26
|
*
|
|
26
|
-
* The admin routes
|
|
27
|
+
* The admin routes, the self-service deletion, and the purge Workflow call these and write
|
|
27
28
|
* nothing themselves, so each transition happens the same way whoever asked for it:
|
|
28
29
|
*
|
|
29
30
|
* 1. **The columns move, conditionally, and the history row is written with them.** The `update` names the
|
|
@@ -66,6 +67,8 @@ export interface LifecycleDeps {
|
|
|
66
67
|
readonly config: Pick<AuthConfig, "retention" | "lifecycleEmails">;
|
|
67
68
|
/** The adopter's hooks. */
|
|
68
69
|
readonly hooks: UserLifecycleHooks;
|
|
70
|
+
/** The Worker the hooks run in: this run's env, and `waitUntil` inside a request. */
|
|
71
|
+
readonly runtime: HookRuntime;
|
|
69
72
|
/** The email capability's enqueue, bound to this run's env. Absent, nothing is mailed. */
|
|
70
73
|
readonly enqueueEmail?: ((input: EnqueueInput) => Promise<unknown>) | undefined;
|
|
71
74
|
/** Where a swallowed failure is reported. Absent, it is swallowed silently. */
|
|
@@ -102,7 +105,7 @@ export interface LifecycleTransition {
|
|
|
102
105
|
/** What a suspension did, and the suspension it left in force. */
|
|
103
106
|
export interface SuspendTransition extends LifecycleTransition {
|
|
104
107
|
/**
|
|
105
|
-
* True when the account was already suspended and this call restated the reason and the end instead
|
|
108
|
+
* True when the account was already suspended and this call restated the reason and the end instead.
|
|
106
109
|
* That is not a transition — `changed` is false and no hook fires — but it is written, audited and mailed.
|
|
107
110
|
*/
|
|
108
111
|
readonly updated: boolean;
|
|
@@ -167,10 +170,12 @@ interface HistoryRow {
|
|
|
167
170
|
readonly step?: string | null;
|
|
168
171
|
/** A hard deletion's choice for the purge's last mail; see `UserLifecycleEvent.notify`. */
|
|
169
172
|
readonly notify?: boolean | null;
|
|
170
|
-
/** A deletion's mode, kept for the erasure attestation
|
|
173
|
+
/** A deletion's mode, kept for the erasure attestation. */
|
|
171
174
|
readonly mode?: DeletionMode | null;
|
|
172
|
-
/** When a deletion's purge comes due, kept for the erasure attestation
|
|
175
|
+
/** When a deletion's purge comes due, kept for the erasure attestation. */
|
|
173
176
|
readonly purgeAfter?: Date | null;
|
|
177
|
+
/** A retained step's catalog key for the basis in `reason`. */
|
|
178
|
+
readonly basisKey?: string | null;
|
|
174
179
|
}
|
|
175
180
|
|
|
176
181
|
/** The history row's values, as the table stores them. */
|
|
@@ -186,6 +191,7 @@ function encoded(row: HistoryRow) {
|
|
|
186
191
|
notify: row.notify === undefined || row.notify === null ? null : SQLiteBoolean.encode(row.notify),
|
|
187
192
|
mode: row.mode ?? null,
|
|
188
193
|
purgeAfter: row.purgeAfter ? SQLiteDate.encode(row.purgeAfter) : null,
|
|
194
|
+
basisKey: row.basisKey ?? null,
|
|
189
195
|
createdAt: SQLiteDate.encode(row.at),
|
|
190
196
|
};
|
|
191
197
|
}
|
|
@@ -304,7 +310,7 @@ async function fire(
|
|
|
304
310
|
): Promise<void> {
|
|
305
311
|
if (!hook) return;
|
|
306
312
|
try {
|
|
307
|
-
await hook(event, deps.d1);
|
|
313
|
+
await hook(event, deps.d1, deps.runtime);
|
|
308
314
|
} catch (error) {
|
|
309
315
|
deps.log?.warn(`${name} threw; the transition stands`, { userId: event.userId, reason: messageOf(error) });
|
|
310
316
|
}
|
|
@@ -338,7 +344,7 @@ function raced(userId: string): ConflictError {
|
|
|
338
344
|
}
|
|
339
345
|
|
|
340
346
|
/**
|
|
341
|
-
* The instant a purge-window guard compares against, **read when the statement runs**, as ms-epoch
|
|
347
|
+
* The instant a purge-window guard compares against, **read when the statement runs**, as ms-epoch.
|
|
342
348
|
*
|
|
343
349
|
* A restore and a purge's `due` check race for one account, and each has to see the window the other saw. A
|
|
344
350
|
* timestamp the restore took before its statement went out is stale by the time D1 runs it: the window can
|
|
@@ -369,7 +375,7 @@ function windowClosed(userId: string, closes: Date): ConflictError {
|
|
|
369
375
|
* conflict rather than a no-op, and names `restoreRoute` when the caller gives one. A suspension whose end has
|
|
370
376
|
* passed is not in force, and a new one replaces it.
|
|
371
377
|
*
|
|
372
|
-
* **An account already suspended has its terms restated
|
|
378
|
+
* **An account already suspended has its terms restated.** The reason and the end are replaced, a
|
|
373
379
|
* `suspended` row records the new reason — the newest one is what the person is shown — and the audit event
|
|
374
380
|
* and the mail say so. The start is kept, and no hook fires: the account was suspended and still is, so
|
|
375
381
|
* nothing transitioned. A fresh suspension that loses the race to another suspension finds the account
|
|
@@ -559,7 +565,7 @@ export interface DeleteTransition extends LifecycleTransition {
|
|
|
559
565
|
* Restorable until then. The deletion-scheduled mail carries the purge date and, when the config names one,
|
|
560
566
|
* the restore path. A deleted account deleted softly again is no transition.
|
|
561
567
|
*
|
|
562
|
-
* **Hard
|
|
568
|
+
* **Hard**: `purgeAfter` is now, so the window is already closed — nothing can restore it — and the
|
|
563
569
|
* caller starts the purge. No deletion-scheduled mail, because nothing is scheduled; the purge sends the
|
|
564
570
|
* deletion-complete one. An account already deleted softly has its purge brought forward to now, which is
|
|
565
571
|
* written and audited but fires no hook: the account was deleted and still is. One already due is unchanged.
|
|
@@ -577,9 +583,9 @@ export async function deleteUser(
|
|
|
577
583
|
const purgeAfter = hard ? at : new Date(at.getTime() + userPurgeWindowDays(deps.config) * 86_400_000);
|
|
578
584
|
const subject = await subjectOf(deps.db, input.userId);
|
|
579
585
|
// A hard deletion's `notify` is the purge's to read, so it is written on the row: the purge that sends the last
|
|
580
|
-
// mail may be one the daily pass started, with no request to carry it
|
|
586
|
+
// mail may be one the daily pass started, with no request to carry it.
|
|
581
587
|
// The mode and the due instant ride on the row too, because the purge erases the account's own column and the
|
|
582
|
-
// erasure attestation still has to say both
|
|
588
|
+
// erasure attestation still has to say both.
|
|
583
589
|
const row: HistoryRow = {
|
|
584
590
|
userId: input.userId,
|
|
585
591
|
action: "deleted",
|
|
@@ -678,7 +684,8 @@ export interface RestoreTransition extends LifecycleTransition {
|
|
|
678
684
|
* 404 whose action says the data is gone — read off the history row the purge leaves behind, so it is told
|
|
679
685
|
* apart from an id that never existed.
|
|
680
686
|
*
|
|
681
|
-
* An account that is not deleted is no transition. A suspension it was under is still in force
|
|
687
|
+
* An account that is not deleted is no transition, and fires nothing. A suspension it was under is still in force
|
|
688
|
+
* after. `onUserRestored` fires once the restore is written, so an adopter can undo what it did on `onUserDeleted`.
|
|
682
689
|
*/
|
|
683
690
|
export async function restoreUser(
|
|
684
691
|
deps: LifecycleDeps,
|
|
@@ -723,6 +730,12 @@ export async function restoreUser(
|
|
|
723
730
|
}
|
|
724
731
|
|
|
725
732
|
await audit(deps, AuthAuditActions.adminUserRestored, input.userId, input.actor, { reason });
|
|
733
|
+
await fire(deps, "onUserRestored", deps.hooks.onUserRestored, {
|
|
734
|
+
userId: input.userId,
|
|
735
|
+
actor: input.actor,
|
|
736
|
+
reason,
|
|
737
|
+
at,
|
|
738
|
+
});
|
|
726
739
|
return { changed: true, mailed: false, state };
|
|
727
740
|
}
|
|
728
741
|
|
|
@@ -748,13 +761,17 @@ async function purgedRefusal(db: AuthDatabase, userId: string): Promise<NotFound
|
|
|
748
761
|
}
|
|
749
762
|
|
|
750
763
|
/**
|
|
751
|
-
* The account's
|
|
752
|
-
* purge erased it, and the plain one otherwise. For a route that reads an account outside a transition: the
|
|
753
|
-
* export.
|
|
764
|
+
* The account's stored locale, or the refusal for an account that is not there — the 404 that says the data is gone
|
|
765
|
+
* when the purge erased it, and the plain one otherwise. For a route that reads an account outside a transition: the
|
|
766
|
+
* export, which answers in the person's own language.
|
|
754
767
|
*/
|
|
755
|
-
export async function requirePresent(db: AuthDatabase, userId: string): Promise<
|
|
756
|
-
const row = await db
|
|
757
|
-
|
|
768
|
+
export async function requirePresent(db: AuthDatabase, userId: string): Promise<{ locale: string | null }> {
|
|
769
|
+
const row = await db
|
|
770
|
+
.selectFrom("pithyAuthUsers")
|
|
771
|
+
.select(["id", "locale"])
|
|
772
|
+
.where("id", "=", userId)
|
|
773
|
+
.executeTakeFirst();
|
|
774
|
+
if (row) return { locale: row.locale ?? null };
|
|
758
775
|
throw (
|
|
759
776
|
(await purgedRefusal(db, userId)) ??
|
|
760
777
|
new NotFoundError({ message: "No such user.", detail: `no pithy_auth_users row for ${userId}` })
|
|
@@ -772,7 +789,7 @@ export interface PurgeRecipient {
|
|
|
772
789
|
}
|
|
773
790
|
|
|
774
791
|
/**
|
|
775
|
-
* Whether one account is due for its purge, who its last mail goes to, and whether it goes
|
|
792
|
+
* Whether one account is due for its purge, who its last mail goes to, and whether it goes.
|
|
776
793
|
*
|
|
777
794
|
* `due` only for an account that is deleted and whose `purgeAfter` has passed — the cron and a hard deletion
|
|
778
795
|
* both start a purge, and this is the one check either passes through, so an account restored in between is
|
|
@@ -790,7 +807,7 @@ export async function purgeSubject(
|
|
|
790
807
|
{ state: "due"; recipient: PurgeRecipient; notify: boolean | null } | { state: "not_due" } | { state: "gone" }
|
|
791
808
|
> {
|
|
792
809
|
// The instant is the database's, read in the same statement as the row — the clock `restoreUser` guards on, so
|
|
793
|
-
// a restore and this check agree on whether the window has closed, whichever runs first
|
|
810
|
+
// a restore and this check agree on whether the window has closed, whichever runs first.
|
|
794
811
|
const row = await deps.db
|
|
795
812
|
.selectFrom("pithyAuthUsers")
|
|
796
813
|
.select(["email", "name", "locale", "suspendedAt", "suspendedUntil", "deletedAt", "purgeAfter"])
|
|
@@ -816,7 +833,7 @@ export async function purgeSubject(
|
|
|
816
833
|
}
|
|
817
834
|
|
|
818
835
|
/**
|
|
819
|
-
* The account's address, as a purge step reads it
|
|
836
|
+
* The account's address, as a purge step reads it — `null` when there is no account, or no address. Read
|
|
820
837
|
* inside the step that asks, so it is never carried in a Workflow's journal.
|
|
821
838
|
*/
|
|
822
839
|
export async function purgeAddress(db: AuthDatabase, userId: string): Promise<string | null> {
|
|
@@ -831,7 +848,7 @@ export interface DuePurge {
|
|
|
831
848
|
}
|
|
832
849
|
|
|
833
850
|
/**
|
|
834
|
-
* The accounts whose purge is due — deleted, with `purgeAfter` passed — oldest first, at most `limit
|
|
851
|
+
* The accounts whose purge is due — deleted, with `purgeAfter` passed — oldest first, at most `limit`.
|
|
835
852
|
* What the daily cron starts a purge for. An account still inside its window is not here, and neither is one
|
|
836
853
|
* that was restored. Each carries its deletion's start, which names the purge's instance (`../purge/start.ts`).
|
|
837
854
|
*/
|
|
@@ -853,23 +870,25 @@ export async function duePurges(deps: LifecycleDeps, limit: number): Promise<Due
|
|
|
853
870
|
/**
|
|
854
871
|
* Record that one purge step — one capability's contribution — erased its rows. The contribution's summary is
|
|
855
872
|
* the row's reason, so the history says what the step erased and not only that it ran. With `retained`, the step
|
|
856
|
-
* kept its rows instead
|
|
873
|
+
* kept its rows instead: the row is `purge_retained`, its reason is the basis the capability gave, and its
|
|
874
|
+
* `basisKey` the catalog key that translates it, when the capability names one.
|
|
857
875
|
*/
|
|
858
876
|
export async function recordPurgeStep(
|
|
859
877
|
deps: LifecycleDeps,
|
|
860
|
-
input: { userId: string; step: string; summary?: string | null; retained?: boolean },
|
|
878
|
+
input: { userId: string; step: string; summary?: string | null; retained?: boolean; basisKey?: string },
|
|
861
879
|
): Promise<void> {
|
|
862
880
|
const at = (deps.now ?? (() => new Date()))();
|
|
863
881
|
await record(deps, {
|
|
864
882
|
userId: input.userId,
|
|
865
|
-
// A retained step kept its rows
|
|
883
|
+
// A retained step kept its rows: its own action, so the trail never reads a kept step as an erased one.
|
|
866
884
|
action: input.retained ? "purge_retained" : "purge_step",
|
|
867
885
|
actor: PURGE,
|
|
868
886
|
reason: input.summary?.trim() ? input.summary.trim().slice(0, MAX_REASON) : null,
|
|
869
887
|
at,
|
|
870
888
|
step: input.step,
|
|
889
|
+
basisKey: input.retained ? (input.basisKey ?? null) : null,
|
|
871
890
|
});
|
|
872
|
-
// The trail's record of the step, which the erasure attestation cites by id and chain position
|
|
891
|
+
// The trail's record of the step, which the erasure attestation cites by id and chain position. The step's
|
|
873
892
|
// name and disposition only: the summary is the row's, and the trail never holds anything about the person.
|
|
874
893
|
await audit(deps, AuthAuditActions.adminUserPurgeStep, input.userId, PURGE, {
|
|
875
894
|
step: input.step,
|
|
@@ -878,7 +897,7 @@ export async function recordPurgeStep(
|
|
|
878
897
|
}
|
|
879
898
|
|
|
880
899
|
/**
|
|
881
|
-
* Record that a purge gave up
|
|
900
|
+
* Record that a purge gave up: the step it stopped at, in the history and in the trail. The daily pass starts
|
|
882
901
|
* the purge again tomorrow, so this is where it stands until then, not an end. The failure's message is never
|
|
883
902
|
* written: it is code the kit did not write, and it may name the person.
|
|
884
903
|
*/
|
|
@@ -896,7 +915,7 @@ export async function recordPurgeFailure(deps: LifecycleDeps, input: { userId: s
|
|
|
896
915
|
}
|
|
897
916
|
|
|
898
917
|
/**
|
|
899
|
-
* The deletion-complete mail, sent **before the address is erased
|
|
918
|
+
* The deletion-complete mail, sent **before the address is erased**. The purge calls this after every
|
|
900
919
|
* other capability's rows are gone and before auth's own, which holds the address, so the last mail is
|
|
901
920
|
* enqueued while there is still an account to have sent it to. The address is handed in, captured before the
|
|
902
921
|
* first step. `notify: false` sends nothing, whatever the config says.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import type { Kysely } from "kysely";
|
|
5
|
+
import type { Migration } from "kysely/migration";
|
|
6
|
+
|
|
7
|
+
/** How the issue path finds the challenges that have run out. */
|
|
8
|
+
const EXPIRES_INDEX = "pithyAuthAttestationChallengesExpiresAtIdx";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* `pithy_auth_attestation_challenges`: one row per challenge the attestation challenge route issued and nobody
|
|
12
|
+
* has presented yet. See `../attestation/challenge.ts`. Every date is `integer`, ms-epoch.
|
|
13
|
+
*/
|
|
14
|
+
export const auth_0009_attestation_challenges: Migration = {
|
|
15
|
+
async up(db: Kysely<unknown>): Promise<void> {
|
|
16
|
+
await db.schema
|
|
17
|
+
.createTable("pithyAuthAttestationChallenges")
|
|
18
|
+
.addColumn("id", "text", (c) => c.primaryKey())
|
|
19
|
+
.addColumn("issuedAt", "integer", (c) => c.notNull())
|
|
20
|
+
.addColumn("expiresAt", "integer", (c) => c.notNull())
|
|
21
|
+
.execute();
|
|
22
|
+
await db.schema.createIndex(EXPIRES_INDEX).on("pithyAuthAttestationChallenges").column("expiresAt").execute();
|
|
23
|
+
},
|
|
24
|
+
async down(db: Kysely<unknown>): Promise<void> {
|
|
25
|
+
await db.schema.dropIndex(EXPIRES_INDEX).execute();
|
|
26
|
+
await db.schema.dropTable("pithyAuthAttestationChallenges").execute();
|
|
27
|
+
},
|
|
28
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import type { Kysely } from "kysely";
|
|
5
|
+
import type { Migration } from "kysely/migration";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* `pithy_auth_app_attest_keys`: one row per App Attest key an iOS app registered. See `../data/appAttestKey.ts`.
|
|
9
|
+
* Every date is `integer`, ms-epoch.
|
|
10
|
+
*/
|
|
11
|
+
export const auth_0010_app_attest_keys: Migration = {
|
|
12
|
+
async up(db: Kysely<unknown>): Promise<void> {
|
|
13
|
+
await db.schema
|
|
14
|
+
.createTable("pithyAuthAppAttestKeys")
|
|
15
|
+
.addColumn("id", "text", (c) => c.primaryKey())
|
|
16
|
+
.addColumn("publicKey", "text", (c) => c.notNull())
|
|
17
|
+
.addColumn("appId", "text", (c) => c.notNull())
|
|
18
|
+
.addColumn("environment", "text", (c) => c.notNull())
|
|
19
|
+
.addColumn("counter", "integer", (c) => c.notNull())
|
|
20
|
+
.addColumn("createdAt", "integer", (c) => c.notNull())
|
|
21
|
+
.addColumn("lastUsedAt", "integer")
|
|
22
|
+
.execute();
|
|
23
|
+
},
|
|
24
|
+
async down(db: Kysely<unknown>): Promise<void> {
|
|
25
|
+
await db.schema.dropTable("pithyAuthAppAttestKeys").execute();
|
|
26
|
+
},
|
|
27
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import type { Kysely } from "kysely";
|
|
5
|
+
import type { Migration } from "kysely/migration";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* `basis_key` on `pithy_auth_user_lifecycle`: the catalog key a retained step's basis translates through, beside the
|
|
9
|
+
* English basis in `reason`. Null on every other row, on a retained step that names no key, and on one recorded
|
|
10
|
+
* before this ran. Appended: the chain is released history.
|
|
11
|
+
*/
|
|
12
|
+
export const auth_0011_retained_basis_key: Migration = {
|
|
13
|
+
async up(db: Kysely<unknown>): Promise<void> {
|
|
14
|
+
await db.schema.alterTable("pithyAuthUserLifecycle").addColumn("basisKey", "text").execute();
|
|
15
|
+
},
|
|
16
|
+
async down(db: Kysely<unknown>): Promise<void> {
|
|
17
|
+
await db.schema.alterTable("pithyAuthUserLifecycle").dropColumn("basisKey").execute();
|
|
18
|
+
},
|
|
19
|
+
};
|
package/src/migrations/set.ts
CHANGED
|
@@ -9,6 +9,9 @@ import { auth_0005_purge_once } from "./0005_purge_once";
|
|
|
9
9
|
import { auth_0006_verification_outcomes } from "./0006_verification_outcomes";
|
|
10
10
|
import { auth_0007_erasure_record } from "./0007_erasure_record";
|
|
11
11
|
import { auth_0008_last_active } from "./0008_last_active";
|
|
12
|
+
import { auth_0009_attestation_challenges } from "./0009_attestation_challenges";
|
|
13
|
+
import { auth_0010_app_attest_keys } from "./0010_app_attest_keys";
|
|
14
|
+
import { auth_0011_retained_basis_key } from "./0011_retained_basis_key";
|
|
12
15
|
|
|
13
16
|
/**
|
|
14
17
|
* Every migration `@pithy-sh/auth` ships, keyed as `pithy migrate` composes them.
|
|
@@ -20,7 +23,7 @@ import { auth_0008_last_active } from "./0008_last_active";
|
|
|
20
23
|
* migration. Adding a `0002` turned all five into a schema one column short of the code, and the symptom
|
|
21
24
|
* was `table pithy_auth_sessions has no column named authenticated_at` in thirteen unrelated tests.
|
|
22
25
|
*
|
|
23
|
-
*
|
|
26
|
+
* Every later migration is appended here and reaches every reader, which is the point. `0001_init.workers.test.ts` is deliberately not a reader:
|
|
24
27
|
* its subject is that one migration's own `up` and `down`, so it names it directly.
|
|
25
28
|
*/
|
|
26
29
|
export const AUTH_MIGRATIONS = {
|
|
@@ -32,4 +35,7 @@ export const AUTH_MIGRATIONS = {
|
|
|
32
35
|
"0006_verification_outcomes": auth_0006_verification_outcomes,
|
|
33
36
|
"0007_erasure_record": auth_0007_erasure_record,
|
|
34
37
|
"0008_last_active": auth_0008_last_active,
|
|
38
|
+
"0009_attestation_challenges": auth_0009_attestation_challenges,
|
|
39
|
+
"0010_app_attest_keys": auth_0010_app_attest_keys,
|
|
40
|
+
"0011_retained_basis_key": auth_0011_retained_basis_key,
|
|
35
41
|
} as const;
|