@runeditrun/rer 0.2.17 → 0.2.19

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 (45) hide show
  1. package/cli/contract.mjs +3 -0
  2. package/cli/demo-host.mjs +2 -0
  3. package/cli/deploy-command.mjs +1 -1
  4. package/cli/inspect.mjs +4 -2
  5. package/cli/main.mjs +2 -0
  6. package/cli/output.mjs +7 -3
  7. package/cli/parse.mjs +5 -4
  8. package/cli/signin.mjs +41 -0
  9. package/cli/stdio.mjs +12 -0
  10. package/global/CHANGELOG.md +9 -0
  11. package/global/main.mjs +3 -3
  12. package/global/output.mjs +1 -12
  13. package/modules/demo-host/README.md +25 -6
  14. package/modules/demo-host/capacity.mjs +27 -6
  15. package/modules/demo-host/container.mjs +37 -9
  16. package/modules/demo-host/entrypoint.sh +9 -0
  17. package/modules/demo-host/image.mjs +18 -0
  18. package/modules/demo-host/pages.mjs +7 -7
  19. package/modules/demo-host/plan.mjs +1 -1
  20. package/modules/demo-host/prepare.mjs +28 -0
  21. package/modules/demo-host/start-script.mjs +11 -4
  22. package/modules/demo-host/startup.mjs +25 -0
  23. package/modules/demo-host/template.mjs +71 -0
  24. package/modules/demo-host/worker.mjs +74 -31
  25. package/modules/deploy-kit/README.md +2 -0
  26. package/modules/deploy-kit/owner-cli.mjs +5 -2
  27. package/modules/deploy-kit/owner-signin.mjs +34 -0
  28. package/modules/mail/README.md +44 -2
  29. package/modules/mail/src/adapters/rer/contract.mjs +22 -0
  30. package/modules/mail/src/adapters/rer/index.mjs +30 -0
  31. package/modules/mail/src/core/transport.mjs +1 -1
  32. package/modules/mail/src/core/validation.mjs +6 -2
  33. package/modules/mail/src/sender.mjs +2 -1
  34. package/modules/operator-auth/README.md +43 -0
  35. package/modules/operator-auth/accounts/email-change.mjs +34 -0
  36. package/modules/operator-auth/accounts/owner-signin.mjs +50 -0
  37. package/modules/operator-auth/accounts/schema/owner-signin.sql +10 -0
  38. package/modules/operator-auth/identity/email-link/confirmation.mjs +3 -3
  39. package/modules/operator-auth/identity/email-link/index.mjs +1 -1
  40. package/modules/operator-auth/index.d.mts +8 -2
  41. package/modules/operator-auth/owner-signin-grant.mjs +10 -0
  42. package/modules/operator-auth/routes.mjs +11 -1
  43. package/modules/operator-auth/service.mjs +4 -0
  44. package/modules/portability/provider-data.mjs +1 -1
  45. package/package.json +1 -1
@@ -0,0 +1,10 @@
1
+ -- One-time owner sign-in links minted by `rer signin` with the deployment's own
2
+ -- Cloudflare credentials, written straight into this table through the D1 API.
3
+ -- Apply as a NEW numbered migration under the seed's next unused number; never
4
+ -- rewrite an applied migration. Additive only. token_hash is the SHA-256 of the
5
+ -- link token (owner-signin-grant.mjs); the token itself is never stored.
6
+ CREATE TABLE IF NOT EXISTS oa_owner_signins (
7
+ id TEXT PRIMARY KEY, token_hash TEXT NOT NULL UNIQUE,
8
+ operator_id TEXT NOT NULL REFERENCES oa_operators(id), operator_version INTEGER NOT NULL,
9
+ created_at INTEGER NOT NULL, expires_at INTEGER NOT NULL, consumed_at INTEGER
10
+ );
@@ -1,13 +1,13 @@
1
1
  import { escapeHtml } from '../../http.mjs';
2
2
  import { pageResponse } from '../../page.mjs';
3
3
 
4
- const HEADINGS = { invite: 'Accept your invitation to', magic: 'Confirm sign-in to', step_up: "Confirm it's you in" };
4
+ const HEADINGS = { invite: 'Accept your invitation to', magic: 'Confirm sign-in to', step_up: "Confirm it's you in", owner: 'Sign in as the owner of' };
5
5
 
6
- export async function confirmationResponse({ branding, preview, token, method }) {
6
+ export async function confirmationResponse({ branding, preview, token, method, action = '/auth/confirm' }) {
7
7
  const product = escapeHtml(branding.productName);
8
8
  const heading = preview ? `${HEADINGS[preview.kind]} ${product}` : 'This link is invalid or expired';
9
9
  const content = preview
10
- ? `<p>This link works once and expires in ${preview.expiresInMinutes} ${preview.expiresInMinutes === 1 ? 'minute' : 'minutes'}.</p><form method="post" action="/auth/confirm"><input type="hidden" name="token" value="${escapeHtml(token)}"><button type="submit">Confirm</button></form>`
10
+ ? `<p>This link works once and expires in ${preview.expiresInMinutes} ${preview.expiresInMinutes === 1 ? 'minute' : 'minutes'}.</p><form method="post" action="${escapeHtml(action)}"><input type="hidden" name="token" value="${escapeHtml(token)}"><button type="submit">Confirm</button></form>`
11
11
  : `<p>This link may have expired or already been used. Request a new link to continue.</p><a class="action" href="${escapeHtml(branding.signInPath)}">Request a new link</a>`;
12
12
  // Native form POSTs need their Origin; never disclose the token path/query.
13
13
  return pageResponse({ branding, heading, content, status: preview ? 200 : 400, method, referrer: preview ? 'strict-origin' : undefined });
@@ -7,7 +7,7 @@ import { isActiveOperator } from '../../accounts/roles.mjs';
7
7
  import { isLocalCli } from '../../local-cli.mjs';
8
8
  import { linkMessage } from './message.mjs';
9
9
  import { completionHook } from '../after-confirm.mjs';
10
- export const STEP_UP_ACTIONS = Object.freeze(['providers:unlink', 'providers:relink', 'domains:change', 'owner:transfer', 'export', 'delete', 'credentials:mint']);
10
+ export const STEP_UP_ACTIONS = Object.freeze(['providers:unlink', 'providers:relink', 'domains:change', 'owner:transfer', 'export', 'delete', 'credentials:mint', 'email:change']);
11
11
  export const STEP_UP_SECONDS = 600;
12
12
 
13
13
  // Persistence owns the atomic authority check, proof consumption and session
@@ -7,10 +7,10 @@ export interface MailMessage { deliveryId: string; from: string; to: string[]; s
7
7
  export interface MailSender { send(message: MailMessage): Promise<{ status: 'accepted' | 'rejected' | 'rate_limited' | 'uncertain' | 'development'; provider: string; providerMessageId: string | null; code?: string }> }
8
8
  export interface AuthBranding { productName?: string; accentColor?: string; signInPath?: string; /** Same-origin path of the seed's served rer-theme.css. */ theme?: string }
9
9
  export interface AuthPresentation { readonly productName: string; readonly accentColor: string; readonly signInPath: string; readonly theme?: string }
10
- export interface LinkPreview { kind: 'magic' | 'invite' | 'step_up'; expiresInMinutes: number }
10
+ export interface LinkPreview { kind: 'magic' | 'invite' | 'step_up' | 'owner'; expiresInMinutes: number }
11
11
  /** A step-up confirmation proves the session's operator again; it issues no new session. */
12
12
  export interface StepUpConfirmed { stepUp: StepUpAction; returnTo: string; cookie?: undefined }
13
- export type StepUpAction = 'providers:unlink' | 'providers:relink' | 'domains:change' | 'owner:transfer' | 'export' | 'delete' | 'credentials:mint';
13
+ export type StepUpAction = 'providers:unlink' | 'providers:relink' | 'domains:change' | 'owner:transfer' | 'export' | 'delete' | 'credentials:mint' | 'email:change';
14
14
  export const STEP_UP_ACTIONS: readonly StepUpAction[];
15
15
  export type ProviderPreset = 'auth' | 'google' | 'microsoft' | 'okta' | 'legacy-rs256';
16
16
  /** One identity provider. Secrets and the private key are server bindings, never source text. */
@@ -183,6 +183,12 @@ export interface OperatorAuth<R extends string = Role> {
183
183
  requestStepUp(request: Request, input: { action: StepUpAction; returnTo?: string }): Promise<{ status: 'accepted' }>;
184
184
  /** Refuse unless this session holds a fresh (10-minute) app-local email-link proof. Provider sessions never do by themselves. */
185
185
  requireStepUp(request: Request, action: StepUpAction): Promise<Session<R>>;
186
+ /** The `rer signin` owner link (GET /auth/owner-signin): its preview, or null when invalid, used, expired or not the active owner's. Absent with native accounts. */
187
+ previewOwnerSignIn?(request: Request, token: string | null): Promise<LinkPreview | null>;
188
+ /** Consume the owner link once; records 'owner:signin-link' in oa_auth_audit and counts as a fresh step-up. */
189
+ confirmOwnerSignIn?(request: Request, input: { token: string }): Promise<CompletedSession<R>>;
190
+ /** The signed-in operator's own sign-in email; needs a fresh step-up proof. */
191
+ changeEmail?(request: Request, input: { email: string }): Promise<Operator<R>>;
186
192
  listDomainRules(request: Request): Promise<DomainRule[]>;
187
193
  /** provider null lifts the rule. Needs a fresh step-up proof. */
188
194
  setDomainRule(request: Request, input: { domain: string; provider: string | null }): Promise<DomainRule[]>;
@@ -0,0 +1,10 @@
1
+ // The one-time owner sign-in link that `rer signin` mints with the deployment's
2
+ // own Cloudflare credentials. rer writes the grant straight into the auth D1
3
+ // (accounts/schema/owner-signin.sql) and prints the link once; the Worker
4
+ // consumes it (accounts/owner-signin.mjs). Only this digest is stored.
5
+ export const OWNER_SIGNIN_SECONDS = 900;
6
+ export const OWNER_SIGNIN_PATH = '/auth/owner-signin';
7
+ export async function ownerSigninDigest(token) {
8
+ const bytes = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(`owner-signin\0${token}`));
9
+ return Array.from(new Uint8Array(bytes), (b) => b.toString(16).padStart(2, '0')).join('');
10
+ }
@@ -6,6 +6,7 @@ import { AuthError } from './errors.mjs';
6
6
  import { securityHeaders, requireLoopback } from './http.mjs';
7
7
  import { safeReturnTo } from './policy.mjs';
8
8
  import { readInput, readParameters } from './input.mjs';
9
+ import { OWNER_SIGNIN_PATH } from './owner-signin-grant.mjs';
9
10
  function json(value, status = 200) { return Response.json(value, { status, headers: securityHeaders() }); }
10
11
  function seeOther(location, cookie) { return new Response(null, { status: 303, headers: { ...securityHeaders(), ...(cookie ? { 'Set-Cookie': cookie } : {}), Location: location } }); }
11
12
  // A native HTML form (the sign-in page before any script) gets a page back; an
@@ -36,6 +37,13 @@ export function createAuthHandler(auth) {
36
37
  const preview = await auth.previewLink(request, token);
37
38
  return await confirmationResponse({ branding: auth.presentation, preview, token, method: request.method });
38
39
  }
40
+ // Composition without the owner link or email change (native accounts) does not own these paths.
41
+ if ((path === OWNER_SIGNIN_PATH && !auth.confirmOwnerSignIn) || (path === '/auth/email' && !auth.changeEmail)) return json({ error: 'not_found' }, 404);
42
+ if (path === OWNER_SIGNIN_PATH && ['GET', 'HEAD'].includes(request.method)) {
43
+ const token = readParameters(url.searchParams).token ?? null;
44
+ const preview = await auth.previewOwnerSignIn(request, token);
45
+ return await confirmationResponse({ branding: auth.presentation, preview, token, method: request.method, action: OWNER_SIGNIN_PATH });
46
+ }
39
47
  if (path === '/auth/session' && request.method === 'GET') {
40
48
  const session = await auth.getSession(request);
41
49
  return session ? json(session) : json({ error: 'unauthenticated' }, 401);
@@ -46,7 +54,7 @@ export function createAuthHandler(auth) {
46
54
  if (path === '/auth/settings/identity' && request.method === 'GET') {const value=await auth.identitySettings(request);return /text\/html/.test(request.headers.get('accept')??'')?await identitySettingsPage(value,auth.presentation):json(value);}
47
55
  if (path === '/auth/providers' && request.method === 'GET') return json(await auth.listProviders(request));
48
56
  const posts = new Set(['/auth/bootstrap', '/auth/magic-link', '/auth/confirm', '/auth/signout', '/auth/invite', '/auth/invite/cancel', '/auth/review-session',
49
- '/auth/operator/status', '/auth/operator/role', '/auth/session/revoke', '/auth/step-up', '/auth/domain-rules', '/auth/providers/unlink', '/auth/providers/relink', '/auth/settings/identity', '/auth/setup-complete']);
57
+ '/auth/operator/status', '/auth/operator/role', '/auth/session/revoke', '/auth/step-up', '/auth/domain-rules', '/auth/providers/unlink', '/auth/providers/relink', '/auth/settings/identity', '/auth/setup-complete', OWNER_SIGNIN_PATH, '/auth/email']);
50
58
  if (!posts.has(path)) return json({ error: 'not_found' }, 404);
51
59
  if (request.method !== 'POST') return json({ error: 'method_not_allowed' }, 405);
52
60
  const query = readParameters(url.searchParams);
@@ -64,6 +72,8 @@ export function createAuthHandler(auth) {
64
72
  return form ? seeOther(notice(auth, 'sent', { returnTo: safeReturnTo(input.returnTo) === '/app' ? undefined : safeReturnTo(input.returnTo), provider: result.requiredProvider })) : json(result, 202);
65
73
  }
66
74
  case '/auth/confirm': { const value = await auth.confirmLink(request, input); return seeOther(value.returnTo, value.cookie); }
75
+ case OWNER_SIGNIN_PATH: { const value = await auth.confirmOwnerSignIn(request, input); return seeOther(value.returnTo, value.cookie); }
76
+ case '/auth/email': return json(await auth.changeEmail(request, input));
67
77
  case '/auth/review-session': { const value = await auth.issueReviewSession(request, input); return seeOther(value.returnTo, value.cookie); }
68
78
  case '/auth/step-up': {
69
79
  const result = await auth.requestStepUp(request, input);
@@ -16,6 +16,8 @@ import { emailAllowed, isActiveOperator, defaultRolePolicy } from './accounts/ro
16
16
  import { oaSessions, createOaAccounts } from './accounts/oa.mjs';
17
17
  import { createAdmission, legacyAdmission } from './identity/admission.mjs';
18
18
  import { createOidcProviders } from './identity/oidc/index.mjs';
19
+ import { ownerSignIn } from './accounts/owner-signin.mjs';
20
+ import { emailChange } from './accounts/email-change.mjs';
19
21
  import { isLocalCli } from './local-cli.mjs';
20
22
  import { devAdmitted } from './dev-admission.mjs';
21
23
 
@@ -74,6 +76,8 @@ export function createOperatorAuth(options) {
74
76
  ...admin,
75
77
  ...providerControl({ store, accounts, authenticate, config, clock }),
76
78
  ...fencedCredentials({store,authenticate,requireFreshProof,config,clock,hash}),
79
+ ...ownerSignIn({ config, store, clock, sessions, limit }),
80
+ ...emailChange({ config, store, clock, authenticate, requireFreshProof }),
77
81
  presentation: config.branding,
78
82
  emailSignInAvailable: Boolean(mailSender),
79
83
  /** Identity providers (null when none is configured): routes, the sign-in page's list and owner actions. */
@@ -1,6 +1,6 @@
1
1
  import { all, quote, insist } from './storage.mjs';
2
2
  import { sidecar, copyRowid } from './copies.mjs';
3
- const TRANSIENT=['oa_setup_links','rer_dependency_keys','rer_dependency_pending','rer_dependency_codes','oa_provider_sessions','oa_provider_session_pins','oa_oidc_transactions','oa_step_up_challenges','oa_identity_provider_health'];
3
+ const TRANSIENT=['oa_setup_links','rer_dependency_keys','rer_dependency_pending','rer_dependency_codes','oa_provider_sessions','oa_provider_session_pins','oa_oidc_transactions','oa_step_up_challenges','oa_identity_provider_health','oa_owner_signins'];
4
4
  // Mandatory secret/session filtering even when a product explicitly includes a table.
5
5
  export async function dropProviderData(db,tables,copies) {
6
6
  const commands=[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runeditrun/rer",
3
- "version": "0.2.17",
3
+ "version": "0.2.19",
4
4
  "description": "The rer command: install, set up, run and launch Run Edit Run checkouts.",
5
5
  "license": "MIT",
6
6
  "type": "module",