Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,16 @@ jobs:
SUPABASE_DB_PASSWORD: ${{ secrets.SUPABASE_DB_PASSWORD }}
SUPABASE_AUTH_EXTERNAL_GOOGLE_SECRET: ${{ secrets.SUPABASE_AUTH_EXTERNAL_GOOGLE_SECRET }}
SUPABASE_AUTH_EXTERNAL_APPLE_SECRET: ${{ secrets.SUPABASE_AUTH_EXTERNAL_APPLE_SECRET }}
SUPABASE_AUTH_SMTP_PASSWORD: ${{ secrets.SUPABASE_AUTH_SMTP_PASSWORD }}
SUPABASE_YES: '1'
run: |
# config.toml turns on custom SMTP for production. Without the key, config push would
# still switch the project to Resend, just with no password, and auth email would stop.
# Stop before anything reaches production instead.
if [ -z "$SUPABASE_AUTH_SMTP_PASSWORD" ]; then
echo "::error::SUPABASE_AUTH_SMTP_PASSWORD is not set in the production environment. Add the Resend API key there and rerun."
exit 1
fi
supabase link --project-ref ${{ vars.SUPABASE_PROJECT_REF || 'mzotlkpghnrwbezcazld' }}
supabase db push --remote --yes
supabase config push --yes
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ coverage
supabase/.temp
supabase/.branches
.claude/worktrees
# Email HTML for Supabase Auth: Go template actions must not be wrapped across lines.
supabase/templates
6 changes: 3 additions & 3 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ flowchart LR

frankfurter[("Frankfurter API<br/>ECB reference rates")]
pushsvc[("Browser push services<br/>FCM, Mozilla, Apple")]
smtp[("Supabase SMTP<br/>auth emails")]
smtp[("Resend SMTP<br/>auth emails")]

member --> web
guest --> web
Expand Down Expand Up @@ -930,7 +930,7 @@ Accounts can add an authenticator app (Supabase Auth TOTP). Supabase hands out a
- The app sends such a session to `/two-factor` (`needsSecondFactor()` in `apps/web/src/lib/auth.ts`, checked by the `_app` and `/welcome` routes). Turning two-step sign in off takes a fresh code; Supabase refuses to remove a verified factor from an `aal1` session.
- Storage: a restrictive policy on `storage.objects` ("two-step sign in done", every command, every bucket) applies the same check.
- Recovery: the caller's `aal1` token plus one recovery code, posted to the `mfa-recover` edge function, removes every factor (admin API) and then every code. Five tries per account per fifteen minutes (`record_mfa_recover_attempt`). The app refreshes the session, which no longer needs a second step. Turning two-step sign in off from Me clears the codes (`clear_mfa_recovery_codes`).
- Auth settings that back this up: TOTP on, `secure_password_change` (an emailed code for password changes from sessions older than a day), and security emails for password, email and authenticator changes (`supabase/config.toml`).
- Auth settings that back this up: TOTP on, `secure_password_change` (an emailed code for password changes from sessions older than a day), and security emails for password, email and authenticator changes and a newly linked sign in method (`supabase/config.toml`, bodies in `supabase/templates/`).

### Storage

Expand Down Expand Up @@ -1038,4 +1038,4 @@ There is no `og-invite` function yet. Invite links render the SPA, so link previ

- Web: Cloudflare Workers static assets, worker `potluck` (`apps/web/wrangler.jsonc`), https://potluck.fermulate.com (custom domain, [ADR 10](adr/0010-custom-domains.md)); https://potluck.potluck-web.workers.dev still serves the same worker. PR previews are worker versions with a `pr-<number>` alias. User guide: https://docs.potluck.fermulate.com (repo `Fermulate/potluck-docs`).
- Backend: Supabase project `mzotlkpghnrwbezcazld`.
- Email: auth email uses Supabase built-in SMTP for now (rate-limited); swap to Resend with a sender on `fermulate.com`. Notification email is built and off until the same provider is configured ([launch checklist](launch-checklist.md#3-email)).
- Email: auth email goes through Resend SMTP from `Potluck <[email protected]>` (`[remotes.production.auth.email.smtp]` in `supabase/config.toml`, 30 an hour), with the templates in `supabase/templates/`. Notification email is built and off until `app_config.email_notifications` is turned on ([launch checklist](launch-checklist.md#3-email)).
30 changes: 17 additions & 13 deletions docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ Set these under **Settings > Secrets and variables > Actions**. Variables are vi

### Secrets

| Name | Used for |
| -------------------------------------- | ---------------------------------------------------------------------------------------- |
| `CLOUDFLARE_API_TOKEN` | Wrangler. Needs the "Edit Cloudflare Workers" template permissions on the account |
| `SUPABASE_ACCESS_TOKEN` | Supabase CLI (personal access token from the dashboard) |
| `SUPABASE_DB_PASSWORD` | Optional. The pinned CLI signs in with a temporary role made from the access token |
| `SUPABASE_URL` | `keepalive.yml` daily ping |
| `SUPABASE_PUBLISHABLE_KEY` | `keepalive.yml` daily ping |
| `SUPABASE_AUTH_EXTERNAL_GOOGLE_SECRET` | `supabase config push` for Google sign in, which is on (`production` environment secret) |
| `SUPABASE_AUTH_EXTERNAL_APPLE_SECRET` | `supabase config push`, once Apple sign in is enabled (`production` environment secret) |

Missing credentials do not fail the workflow. Without `CLOUDFLARE_API_TOKEN` the web job builds and skips the upload. Without `SUPABASE_ACCESS_TOKEN` the `migrate` job logs a notice and skips. That keeps forks green.
| Name | Used for |
| -------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
| `CLOUDFLARE_API_TOKEN` | Wrangler. Needs the "Edit Cloudflare Workers" template permissions on the account |
| `SUPABASE_ACCESS_TOKEN` | Supabase CLI (personal access token from the dashboard) |
| `SUPABASE_DB_PASSWORD` | Optional. The pinned CLI signs in with a temporary role made from the access token |
| `SUPABASE_URL` | `keepalive.yml` daily ping |
| `SUPABASE_PUBLISHABLE_KEY` | `keepalive.yml` daily ping |
| `SUPABASE_AUTH_EXTERNAL_GOOGLE_SECRET` | `supabase config push` for Google sign in, which is on (`production` environment secret) |
| `SUPABASE_AUTH_EXTERNAL_APPLE_SECRET` | `supabase config push`, once Apple sign in is enabled (`production` environment secret) |
| `SUPABASE_AUTH_SMTP_PASSWORD` | `supabase config push`: the Resend API key auth email is sent with (`production` environment secret). Required |

Missing credentials do not fail the workflow. Without `CLOUDFLARE_API_TOKEN` the web job builds and skips the upload. Without `SUPABASE_ACCESS_TOKEN` the `migrate` job logs a notice and skips. That keeps forks green. The one exception: once `SUPABASE_ACCESS_TOKEN` is there, `migrate` fails before touching production if `SUPABASE_AUTH_SMTP_PASSWORD` is empty. `config.toml` turns custom SMTP on for production, and the CLI never sends an unset `env()` secret, so without the guard a first push would point auth email at Resend with no password.

## What a production deploy does

Expand All @@ -66,11 +67,14 @@ Migrations go first so the database is never behind the client. Because migratio

- `auth.site_url` is the custom domain. `additional_redirect_urls`: the custom domain, the old workers.dev URL, every `*-potluck.potluck-web.workers.dev` preview, and localhost.
- `minimum_password_length = 8`, email confirmations on (seats and email-bound invites rely on it, see [security](security.md#sign-in)), one email per 60 s per address.
- Auth email goes out through Resend (`[remotes.production.auth.email.smtp]`: `smtp.resend.com:465`, user `resend`, password from `SUPABASE_AUTH_SMTP_PASSWORD`, sent as `Potluck <[email protected]>`).
- At most 30 auth emails an hour across the project (`[remotes.production.auth.rate_limit] email_sent`). Resend's free plan allows 100 a day and 3,000 a month; 30 lets a group sign up together while one busy hour stays under a third of the daily allowance.
- Google sign in on (`[remotes.production.auth.external.google]`, client secret from `SUPABASE_AUTH_EXTERNAL_GOOGLE_SECRET`).
- Security notice email subjects (password, email address and verification method changes) are Supabase's defaults, because the built-in sender refuses custom ones. They go once a custom SMTP provider is set ([launch checklist](launch-checklist.md#3-email)).
- TOTP MFA enroll and verify on.
- Pooler sizes, and the vector bucket feature off.

Shared by both, and so pushed to production too: the branded auth email templates in `supabase/templates/` (sign up confirmation, sign in link, password reset, email change, the reauthentication code) and the security notices (password, email, two-step sign in, and a newly linked sign in method), each with a Potluck subject (`[auth.email.template.*]`, `[auth.email.notification.*]`). `content_path` is relative to the repo root. Every action link (confirmation, sign in link, reset, email change) is `{{ .ConfirmationURL }}`, which `apps/web/e2e/support/mail.ts` reads; the reauthentication code and the notices link to the app (`{{ .SiteURL }}`). The local stack picks up template changes on its next `supabase start`, not on `db reset`.

`verify_jwt` per function (`[functions.*]`) is applied by `supabase functions deploy`.

## Edge function secrets
Expand Down Expand Up @@ -150,7 +154,7 @@ You can run your own Potluck on your own Supabase project and Cloudflare account
6. **Set edge function secrets and Vault entries** as above, with your URLs.
7. **Push to `main`.** Once CI is green, the deploy workflow applies migrations, pushes auth config, deploys functions and the web app, and smoke tests it.
8. **Backfill FX rates** with the `fx-sync?from=` call.
9. **Auth email.** The built-in Supabase SMTP is rate limited and meant for testing. For real users, configure your own SMTP server under `[auth.email.smtp]` or in the dashboard.
9. **Auth email.** Production sends through Resend from `fermulate.com`. Point `[remotes.production.auth.email.smtp]` at your own SMTP server and sender, and set `SUPABASE_AUTH_SMTP_PASSWORD` (the deploy stops without it). Supabase's built-in sender only reaches your Supabase team and refuses custom templates, so it cannot replace this.

`SUPABASE_URL` and `SUPABASE_PUBLISHABLE_KEY` secrets keep a free project from pausing; skip them on a paid plan.

Expand Down
16 changes: 9 additions & 7 deletions docs/launch-checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ What is live, what still needs a person with the right account, and how to finis
| Custom domains | `potluck.fermulate.com` and `docs.potluck.fermulate.com` attached to the `potluck` and `potluck-docs` Workers, pinned as `custom_domain` routes in each `wrangler.jsonc`. The `*.potluck-web.workers.dev` URLs still work ([ADR 10](adr/0010-custom-domains.md)) |
| Database | Supabase project `mzotlkpghnrwbezcazld`, every migration in `supabase/migrations` applied |
| Auth settings | Site URL and redirect URLs pushed with `supabase config push` (`[remotes.production]` in `supabase/config.toml`) |
| Auth email | Resend SMTP from `[email protected]`, Potluck templates in `supabase/templates/`, pushed with the auth settings (`SUPABASE_AUTH_SMTP_PASSWORD` secret) |
| Edge functions | `notify`, `fx-sync`, `ics-feed`, `delete-account`, with their secrets set |
| Vault entries | `project_url` and `edge_secret`, so push notifications and the daily FX job fire |
| FX rates | Backfilled from 2026-08-01, refreshed daily by pg_cron at 16:30 UTC |
Expand All @@ -35,14 +36,15 @@ The `migrate` job skips until `SUPABASE_ACCESS_TOKEN` exists (Supabase dashboard

### 3. Email

Auth email uses Supabase's built-in sender, which is rate limited and meant for testing. Email confirmation is on in production and must stay on (seats and email-bound invites trust a confirmed address). The built-in sender only delivers to members of the Supabase team, so until custom SMTP is set, people signing up with email never get their confirmation link; Google sign in works without it. Notification email (new expenses, payments, the monthly summary, with one-click unsubscribe) is built but off: `app_config.email_notifications` is `false`, so nothing is queued. To send from `fermulate.com`:
**Auth email is done.** Sign up confirmations, sign in links, password resets, email changes, reauthentication codes and the security notices go out through Resend from `Potluck <[email protected]>`, with the Potluck templates in `supabase/templates/` and Potluck subjects. It is all in `supabase/config.toml` (`[remotes.production.auth.email.smtp]`), pushed by every deploy; the Resend API key is the `production` environment secret `SUPABASE_AUTH_SMTP_PASSWORD` ([deployment](deployment.md#supabase-config-push)). Email confirmation is on in production and must stay on (seats and email-bound invites trust a confirmed address). Production allows 30 auth emails an hour, inside Resend's free plan (100 a day, 3,000 a month).

1. Create a Resend account and verify the domain.
2. Supabase dashboard, Authentication, SMTP settings: enter Resend's SMTP details (auth email).
3. In `supabase/config.toml`, delete the four `[remotes.production.auth.email.notification.*]` blocks so production sends the Potluck security notice subjects. The built-in sender refuses custom subjects, so do this only after step 2.
4. Optionally raise `[auth.rate_limit] email_sent` for production.
5. Notification email: set the function secrets `RESEND_API_KEY` and `EMAIL_FROM` (for example `Potluck <[email protected]>`, optionally `EMAIL_REPLY_TO`), and deploy the `unsubscribe` function with the others.
6. Flip it on: `update public.app_config set value = 'true' where key = 'email_notifications';`. The Me page then shows the Email column, and the `email-notifications` job starts sending within a minute. Setting it back to `false` stops new email right away.
Keep the `fermulate.com` domain verified in Resend (SPF and DKIM records in DNS) and `[email protected]` as the sender. Settings entered in the dashboard's SMTP page are overwritten by the next deploy: change them in the file.

**Notification email is still off.** New expenses, payments and the monthly summary, with one-click unsubscribe, are built, but `app_config.email_notifications` is `false`, so nothing is queued. It can reuse the same Resend account and domain. To turn it on:

1. Set the function secrets `RESEND_API_KEY` (a separate Resend key is fine, so either can be revoked alone) and `EMAIL_FROM` (for example `Potluck <[email protected]>`, optionally `EMAIL_REPLY_TO`), and deploy the `unsubscribe` function with the others.
2. Check the volume first: auth and notification email share the Resend account's 100 a day. A few active groups will pass that, so move to a paid Resend plan before turning it on for everyone.
3. Flip it on: `update public.app_config set value = 'true' where key = 'email_notifications';`. The Me page then shows the Email column, and the `email-notifications` job starts sending within a minute. Setting it back to `false` stops new email right away.

Nothing else changes: the sender, the outbox, the monthly summary job and the unsubscribe links are already deployed ([ADR 11](adr/0011-notification-prefs-and-email.md)).

Expand Down
3 changes: 2 additions & 1 deletion docs/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ There is no analytics or tracking code in the app.
- **FX sync** sends nothing about users to Frankfurter. It requests public reference rates.
- **Exports and backups** (Me, Your data; group settings) are built in the browser and saved to the person's device; nothing is sent elsewhere. `export_my_data()` returns only groups the caller is in now, with the names of everyone those groups mention, and the caller's own sign in email; anon cannot call it. Imports run as the importing member with every check `create_expense_v2` makes ([ADR 18](adr/0018-export-backup-and-import.md)).
- **Calendar feeds** contain event titles, descriptions, locations and group names for whoever has the URL.
- **Auth emails** go out through Supabase's SMTP.
- **Auth emails** (sign up, sign in links, password resets, email changes, codes and security notices) go out through Resend's SMTP in production. They carry the address and a one-time link or code, so Resend could read them; the links expire within the hour and work once.
- **Notification emails** (off until `app_config.email_notifications` is on) go through the configured provider (Resend). They carry the recipient's address, names, amounts and comment excerpts, so the provider can read them. That includes invites to people who are not on Potluck yet, sent to the address a group mate typed in.
- **Friend invites by email** are not sent by Potluck: the app opens the inviter's own mail app with the link.

Expand All @@ -114,6 +114,7 @@ Closed accounts get `account_deleted` from every RPC and never receive notificat
- **The service role key never leaves Supabase.** Only edge functions use it, through `_shared/admin.ts`, and only after they have authorized the caller. It is never in GitHub, in `.env` files or in the web app.
- **`EDGE_SECRET` lives in two places**: the edge function secrets and the Vault entry `edge_secret`. Rotate both together ([deployment.md](deployment.md#vault-entries)).
- **`RESEND_API_KEY`** is an edge function secret only. Without it no notification email is sent.
- **`SUPABASE_AUTH_SMTP_PASSWORD`** (the Resend key for auth email) is a GitHub `production` environment secret. `config push` sends it to Supabase Auth; `config.toml` only names it with `env()`. Anyone holding it can send mail as `fermulate.com`, so rotate it in Resend and in GitHub together, then redeploy.
- **The unsubscribe signing key** is generated by a migration into `private.signing_keys` and never leaves the database. Replacing that row breaks every unsubscribe link already sent.
- **VAPID private key** is an edge function secret only. Rotating it invalidates every existing push subscription, and browsers have to subscribe again.
- **CI secrets** (listed in [deployment.md](deployment.md#secrets)) are GitHub Actions secrets, scoped as narrowly as the providers allow. Fork PRs do not receive them.
Expand Down
Loading
Loading