TL-DP-01 · A read-only user on v1 production
Why: every data-phase run reads v1 production: the copy on your Mac now (row 1, #184), the nightly rehearsal later (row 9, D36), and the cutover run at the end. None of them should hold v1's admin password. This step makes one Postgres login on v1, v2_reader, that can read v1's public tables and do nothing else. Creating it writes to v1 production, so it is L0 for good: you run it by hand in v1's SQL editor, once (the automation ladder). Reading through it may climb to L2 later, once clean L0 and L1 runs are logged (D36).
What v2_reader can do, and why:
- SELECT on every table, view and sequence in v1's public schema, now and in future: v1 is still developing (D75), and a table it adds is read from the night it appears. pg_dump needs SELECT on the sequences too.
- It bypasses row-level security. v1's tables most likely have RLS on, and a role no policy names would read no rows. pg_dump refuses to dump a table it can't read in full, and the rehearsal's foreign tables would come back empty (Supabase's note on this). Bypassing RLS changes which rows it sees, never what it may do to them.
- Nothing in auth or storage. v1's logins (auth.users, D50) and its files (D60) are read by later steps that decide how, on their own issues. The Check only reports whether those grants would be possible.
- Read-only twice over. Its grants allow only SELECT, and its sessions start read-only, so a mistaken write fails even before the grants are checked.
- What it can't be stopped from: like every role, it may run v1's public functions that PUBLIC may run. v1's anon key already reaches those through v1's API, so v2_reader can do nothing there that an anonymous visitor can't. The Check counts the security-definer ones, so you see the number.
The password stays in your password manager. You type it only at a psql prompt. v1 receives only its SCRAM hash, made on your Mac in block 2, so the password itself never sits in v1's SQL editor history or its logs. It reaches the rehearsal's GitHub environment in row 9, and nowhere else.
ID TL-DP-01 · Level L0 · Run order data phase row 8 · Issue #183
v1 production has a login role v2_reader, member of no other role, that reads every table, view and sequence in public, bypasses RLS, starts each session read-only, and holds no other grant. Its password is in your password manager entry "Opleet v1 · v2_reader" and nowhere else. A select through v1's session pooler works, and an insert is refused.
Before
Section titled “Before”- Owner access to v1's Supabase project in the dashboard, so you can open its SQL editor.
- Docker Desktop is running. Your Mac has no psql (BE-M0-01), so the blocks below run psql 17 from Docker's postgres:17 image. The first block downloads it once, about 150 MB; nothing is installed.
- A new password manager entry, "Opleet v1 · v2_reader", with these fields filled from v1's dashboard. None of them is a secret.
- Project ref: the 20 letters and digits after /project/ in the dashboard's address. Below it is <V1_PROJECT_REF>.
- Session pooler host: in the dashboard, Connect › Session pooler. The connection string reads postgresql://postgres.<V1_PROJECT_REF>:[YOUR-PASSWORD]@ followed by the host, then :5432/postgres. Copy the host only, which looks like aws-0-ap-southeast-1.pooler.supabase.com. Below it is <V1_POOLER_HOST>.
- Post both on #183 if you haven't yet, with v1's Postgres version (block 5 prints it), so row 1 and row 9 can be written with the real values. Never the password.
1 · Generate the password
Section titled “1 · Generate the password”In the password manager entry, generate a password of 32 characters, letters and digits only: a symbol would have to be escaped in every connection string. Save the entry. Below, the password is <V1_READONLY_PASSWORD>. You paste it only at psql's prompts.
2 · Make its hash on your Mac
Section titled “2 · Make its hash on your Mac”A throwaway local Postgres turns the password into a SCRAM hash, the form Postgres stores. Only the hash goes to v1.
docker run -d --name pwhash -e POSTGRES_PASSWORD=pwhash postgres:17docker exec pwhash sh -c 'until pg_isready -q -h 127.0.0.1 -U postgres; do sleep 1; done'docker exec -it pwhash psql -U postgres -c "create role v2_reader"docker exec -it pwhash psql -U postgresYou are now at a postgres=# prompt. Type these two lines one at a time. \password asks for the password twice: paste <V1_READONLY_PASSWORD> each time (nothing shows as you paste).
\password v2_readerselect rolpassword from pg_authid where rolname = 'v2_reader';Copy the one line it prints, which starts with SCRAM-SHA-256$4096: and is about 130 characters. Below it is <V2_READER_SCRAM_HASH>. Leave psql with \q, then remove the container:
docker rm -f pwhashThe hash isn't the password: it can't be used to log in, and a 32-character random password can't be guessed back from it. Still, it goes only into block 3 and isn't kept anywhere.
3 · Create v2_reader in v1's SQL editor
Section titled “3 · Create v2_reader in v1's SQL editor”In v1's dashboard: SQL Editor › New query. Paste this, replace <V2_READER_SCRAM_HASH> with the line from block 2 (keep the single quotes around it), and select Run.
create role v2_reader with login nosuperuser nocreatedb nocreaterole noinherit noreplication bypassrls connection limit 3 password '<V2_READER_SCRAM_HASH>';
alter role v2_reader set default_transaction_read_only = on;alter role v2_reader set idle_in_transaction_session_timeout = '10min';
grant usage on schema public to v2_reader;grant select on all tables in schema public to v2_reader;grant select on all sequences in schema public to v2_reader;
alter default privileges for role postgres in schema public grant select on tables to v2_reader;alter default privileges for role postgres in schema public grant select on sequences to v2_reader;- connection limit 3: a dump uses one connection and the rehearsal's foreign tables one more; three leaves room for a check while either runs.
- idle_in_transaction_session_timeout: a session left open by mistake doesn't hold v1's tables for long.
- The default privileges make a table or sequence that the postgres role adds to public later readable too.
4 · Delete the query from the SQL editor
Section titled “4 · Delete the query from the SQL editor”The editor saves every query. Find this one under the editor's list of queries (it is named Untitled query, or after its first line), open its menu, and delete it. The hash then sits only in v1's role table, where Postgres keeps it.
Expect
Section titled “Expect”- Block 2: the first command prints a long container id, after the download the first time; the second waits a few seconds and prints nothing; the
create rolecommand prints CREATE ROLE;\passwordasks "Enter new password for user "v2_reader":" and then "Enter it again:"; the select prints one row starting with SCRAM-SHA-256$4096:. The last command prints pwhash. - Block 3: "Success. No rows returned".
- Block 4: the query is gone from the list.
5 · As v1's owner, in a new SQL editor query
Section titled “5 · As v1's owner, in a new SQL editor query”This reads only v1's catalog: role settings, privileges and counts, no data. Delete the query afterwards, as in block 4; it holds nothing secret, but the editor needn't keep it.
select 'server_version' as item, current_setting('server_version') as valueunion allselect 'role', concat_ws(' ', case when rolcanlogin then 'login' end, case when rolsuper then 'SUPERUSER' end, case when rolcreaterole then 'CREATEROLE' end, case when rolcreatedb then 'CREATEDB' end, case when rolreplication then 'REPLICATION' end, case when rolinherit then 'INHERIT' end, case when rolbypassrls then 'bypassrls' end, 'limit=' || rolconnlimit, array_to_string(rolconfig, ' '))from pg_roles where rolname = 'v2_reader'union allselect 'member_of', count(*)::text from pg_auth_members where member = 'v2_reader'::regroleunion allselect 'public_relations readable/writable/total', count(*) filter (where has_table_privilege('v2_reader', c.oid, 'select')) || '/' || count(*) filter (where has_table_privilege('v2_reader', c.oid, 'insert, update, delete, truncate, references, trigger')) || '/' || count(*)from pg_class c join pg_namespace n on n.oid = c.relnamespacewhere n.nspname = 'public' and c.relkind in ('r', 'p', 'v', 'm', 'f')union allselect 'public_sequences readable/writable/total', count(*) filter (where has_sequence_privilege('v2_reader', c.oid, 'select')) || '/' || count(*) filter (where has_sequence_privilege('v2_reader', c.oid, 'usage, update')) || '/' || count(*)from pg_class c join pg_namespace n on n.oid = c.relnamespacewhere n.nspname = 'public' and c.relkind = 'S'union allselect 'public_tables_with_rls', count(*)::textfrom pg_class c join pg_namespace n on n.oid = c.relnamespacewhere n.nspname = 'public' and c.relkind in ('r', 'p') and c.relrowsecurityunion allselect 'public_security_definer_functions_runnable', count(*)::textfrom pg_proc p join pg_namespace n on n.oid = p.pronamespacewhere n.nspname = 'public' and p.prosecdef and has_function_privilege('v2_reader', p.oid, 'execute')union allselect 'auth_or_storage_usage', (has_schema_privilege('v2_reader', 'auth', 'usage') or has_schema_privilege('v2_reader', 'storage', 'usage'))::textunion allselect 'for_later: postgres may grant auth.users / storage.objects', has_table_privilege('postgres', 'auth.users', 'select with grant option') || ' / ' || has_table_privilege('postgres', 'storage.objects', 'select with grant option');| Item | It should read |
|---|---|
| server_version | A number such as 15.8 or 17.4. Post it on #183: row 1's pg_dump must be the same major version or newer. |
| role | login bypassrls limit=3 default_transaction_read_only=on idle_in_transaction_session_timeout=10min, with no word in capitals. |
| member_of | 0 |
| public_relations | N/0/N: every table and view readable, none writable. |
| public_sequences | M/0/M |
| public_tables_with_rls | Any number. Post it: it says whether bypassrls was needed. |
| public_security_definer_functions_runnable | Any number. Post it. |
| auth_or_storage_usage | false |
| for_later | Two words, true or false. Post them: they decide how row 5's access step reads v1's logins and how row 6 reads its files. |
6 · As v2_reader, through the session pooler
Section titled “6 · As v2_reader, through the session pooler”Replace <V1_POOLER_HOST> and <V1_PROJECT_REF> with the values in the password manager entry. psql asks for the password: paste <V1_READONLY_PASSWORD>.
docker run --rm -it postgres:17 psql "host=<V1_POOLER_HOST> port=5432 dbname=postgres user=v2_reader.<V1_PROJECT_REF> sslmode=require"At the postgres=> prompt, paste these lines one at a time. The second line picks v1's first public table by name and keeps it in a psql variable, so no table name is typed and no row is ever shown: only a count.
select current_user, current_setting('transaction_read_only') as read_only;select c.relname as t from pg_class c join pg_namespace n on n.oid = c.relnamespace where n.nspname = 'public' and c.relkind = 'r' order by c.relname limit 1 \gsetselect :'t' as sample_table, count(*) as rows from public.:"t";insert into public.:"t" default values;begin read write;insert into public.:"t" default values;rollback;begin read write;create table public.v2_reader_probe (id int);rollback;select count(*) from auth.users;\q| Line | It should print |
|---|---|
| current_user | v2_reader and on |
| \gset | Nothing |
| count | The table's name and a number. Post the name and the number on #183. |
| insert | ERROR: cannot execute INSERT in a read-only transaction: the session guard |
| begin read write · insert · rollback | BEGIN, then ERROR: permission denied for table and the table's name: the grants. ROLLBACK undoes the transaction either way, so nothing is ever written. |
| begin read write · create table · rollback | BEGIN, then ERROR: permission denied for schema public, then ROLLBACK |
| auth.users | ERROR: permission denied for schema auth (or for table users) |
If it fails
Section titled “If it fails”- Block 3 errors with "must have bypassrls to grant it" or "permission denied to create role": the postgres role can't give that here. Stop, run nothing else, and paste the error on #183. The role isn't half made: the editor runs the block as one transaction.
- "role "v2_reader" already exists": it was made before. Run block 5 and post its output on #183 before changing anything.
- Block 5's public_relations reads N/0/T with N lower than T: some objects in public aren't owned by postgres, so its grant missed them. Post the line; the CTO adds a grant for each such owner.
- The role line shows a word in capitals, or member_of isn't 0: run the Undo below and post block 5's output on #183.
- psql says "password authentication failed" or "Tenant or user not found": check that the user is
v2_reader.followed by the project ref, that the host is the session pooler's and the port is 5432 (not 6543). Paste the password again from the entry. If it still fails, post the error without the command's host on #183. - The insert in the read-write transaction is accepted (prints INSERT 0 1): don't run anything else. Type
rollback;, which undoes it, then run the Undo below and post on #183. - The create table is accepted (prints CREATE TABLE): the ROLLBACK on the next line undoes it. Post on #183: v1 lets every role create tables in public, which the CTO answers with a revoke for v2_reader.
- The count fails with "query would be affected by row-level security": bypassrls didn't take. Post block 5's role line.
In v1's SQL editor, as the owner. It writes to v1 production: run it only for this step's own role.
drop owned by v2_reader;drop role v2_reader;drop owned removes v2_reader's grants and the default privileges above; v2_reader owns no objects. Then delete the password manager entry's password. A new password later (rotating it) is blocks 1 to 4 with alter role v2_reader password '<V2_READER_SCRAM_HASH>'; in place of block 3, and stays L0 for good (the automation ladder).
Log each run as a comment on #183: the date, the blocks you ran, block 5's table, and block 6's sample table, count and errors. Never paste the password or the hash.