Skip to content

Commit 78c2462

Browse files
committed
Merge remote-tracking branch 'origin/develop' into pcnc/build-glibc227-bin
2 parents 7d9a785 + bccf3e4 commit 78c2462

File tree

8 files changed

+108
-15
lines changed

8 files changed

+108
-15
lines changed

ansible/tasks/setup-extensions.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
- name: Install auto_explain
6767
import_tasks: tasks/postgres-extensions/21-auto_explain.yml
6868

69-
# - name: Install vault
70-
# import_tasks: tasks/postgres-extensions/23-vault.yml
69+
- name: Install vault
70+
import_tasks: tasks/postgres-extensions/23-vault.yml
7171

7272
- name: Install PGroonga
7373
import_tasks: tasks/postgres-extensions/24-pgroonga.yml

ansible/vars.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ postgrest_release: "10.1.2"
1414
postgrest_arm_release_checksum: sha1:bc1a811dc0482853b226c644551f290411573f23
1515
postgrest_x86_release_checksum: sha1:96844c1c66d16d6bde41b4c34173f92fe4a3385b
1616

17-
gotrue_release: v2.54.0
18-
gotrue_release_checksum: sha1:65758bdf551ad5055c766dfe20f34860674cd874
17+
gotrue_release: v2.57.2
18+
gotrue_release_checksum: sha1:71667c0a4525c477b70b8e8065b937a282d60699
1919

2020
aws_cli_release: "2.2.7"
2121

common.vars.pkr.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
postgres-version = "15.1.0.64"
1+
postgres-version = "15.1.0.67"

ebssurrogate/files/unit-tests/unit-test-01.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ SELECT extensions_are(
1212
'pg_graphql',
1313
'pgcrypto',
1414
'pgjwt',
15-
'uuid-ossp'
15+
'uuid-ossp',
16+
'supabase_vault'
1617
]
1718
);
1819

migrations/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Additionally, [supabase/postgres](https://github.com/supabase/postgres/blob/deve
2727
## Guidelines
2828

2929
- Migrations are append only. Never edit existing migrations once they are on master.
30+
- Migrations in `migrations/db/migrations` have to be idempotent.
3031
- Self contained components (gotrue, storage, realtime) may contain their own migrations.
3132
- Self hosted Supabase users should update role passwords separately after running all migrations.
3233
- Prod release is done by publishing a new GitHub release on master branch.
Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,39 @@
11
-- migrate:up
22

3-
create extension if not exists pgsodium;
3+
DO $$
4+
DECLARE
5+
pgsodium_exists boolean;
6+
vault_exists boolean;
7+
BEGIN
8+
pgsodium_exists = (
9+
select count(*) = 1
10+
from pg_available_extensions
11+
where name = 'pgsodium'
12+
);
13+
14+
vault_exists = (
15+
select count(*) = 1
16+
from pg_available_extensions
17+
where name = 'supabase_vault'
18+
);
419

5-
grant pgsodium_keyiduser to postgres with admin option;
6-
grant pgsodium_keyholder to postgres with admin option;
7-
grant pgsodium_keymaker to postgres with admin option;
20+
IF pgsodium_exists
21+
THEN
22+
create extension if not exists pgsodium;
823

9-
grant execute on function pgsodium.crypto_aead_det_decrypt(bytea, bytea, uuid, bytea) to service_role;
10-
grant execute on function pgsodium.crypto_aead_det_encrypt(bytea, bytea, uuid, bytea) to service_role;
11-
grant execute on function pgsodium.crypto_aead_det_keygen to service_role;
24+
grant pgsodium_keyiduser to postgres with admin option;
25+
grant pgsodium_keyholder to postgres with admin option;
26+
grant pgsodium_keymaker to postgres with admin option;
1227

13-
-- create extension if not exists supabase_vault;
28+
grant execute on function pgsodium.crypto_aead_det_decrypt(bytea, bytea, uuid, bytea) to service_role;
29+
grant execute on function pgsodium.crypto_aead_det_encrypt(bytea, bytea, uuid, bytea) to service_role;
30+
grant execute on function pgsodium.crypto_aead_det_keygen to service_role;
31+
32+
IF vault_exists
33+
THEN
34+
create extension if not exists supabase_vault;
35+
END IF;
36+
END IF;
37+
END $$;
1438

1539
-- migrate:down

migrations/schema.sql

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ CREATE SCHEMA realtime;
7979
CREATE SCHEMA storage;
8080

8181

82+
--
83+
-- Name: vault; Type: SCHEMA; Schema: -; Owner: -
84+
--
85+
86+
CREATE SCHEMA vault;
87+
88+
8289
--
8390
-- Name: pg_graphql; Type: EXTENSION; Schema: -; Owner: -
8491
--
@@ -135,6 +142,20 @@ CREATE EXTENSION IF NOT EXISTS pgjwt WITH SCHEMA extensions;
135142
COMMENT ON EXTENSION pgjwt IS 'JSON Web Token API for Postgresql';
136143

137144

145+
--
146+
-- Name: supabase_vault; Type: EXTENSION; Schema: -; Owner: -
147+
--
148+
149+
CREATE EXTENSION IF NOT EXISTS supabase_vault WITH SCHEMA vault;
150+
151+
152+
--
153+
-- Name: EXTENSION supabase_vault; Type: COMMENT; Schema: -; Owner: -
154+
--
155+
156+
COMMENT ON EXTENSION supabase_vault IS 'Supabase Vault Extension';
157+
158+
138159
--
139160
-- Name: uuid-ossp; Type: EXTENSION; Schema: -; Owner: -
140161
--
@@ -552,6 +573,28 @@ END
552573
$$;
553574

554575

576+
--
577+
-- Name: secrets_encrypt_secret_secret(); Type: FUNCTION; Schema: vault; Owner: -
578+
--
579+
580+
CREATE FUNCTION vault.secrets_encrypt_secret_secret() RETURNS trigger
581+
LANGUAGE plpgsql
582+
AS $$
583+
BEGIN
584+
new.secret = CASE WHEN new.secret IS NULL THEN NULL ELSE
585+
CASE WHEN new.key_id IS NULL THEN NULL ELSE pg_catalog.encode(
586+
pgsodium.crypto_aead_det_encrypt(
587+
pg_catalog.convert_to(new.secret, 'utf8'),
588+
pg_catalog.convert_to((new.id::text || new.description::text || new.created_at::text || new.updated_at::text)::text, 'utf8'),
589+
new.key_id::uuid,
590+
new.nonce
591+
),
592+
'base64') END END;
593+
RETURN new;
594+
END;
595+
$$;
596+
597+
555598
SET default_tablespace = '';
556599

557600
SET default_table_access_method = heap;
@@ -738,6 +781,30 @@ CREATE TABLE storage.objects (
738781
);
739782

740783

784+
--
785+
-- Name: decrypted_secrets; Type: VIEW; Schema: vault; Owner: -
786+
--
787+
788+
CREATE VIEW vault.decrypted_secrets AS
789+
SELECT secrets.id,
790+
secrets.name,
791+
secrets.description,
792+
secrets.secret,
793+
CASE
794+
WHEN (secrets.secret IS NULL) THEN NULL::text
795+
ELSE
796+
CASE
797+
WHEN (secrets.key_id IS NULL) THEN NULL::text
798+
ELSE convert_from(pgsodium.crypto_aead_det_decrypt(decode(secrets.secret, 'base64'::text), convert_to(((((secrets.id)::text || secrets.description) || (secrets.created_at)::text) || (secrets.updated_at)::text), 'utf8'::name), secrets.key_id, secrets.nonce), 'utf8'::name)
799+
END
800+
END AS decrypted_secret,
801+
secrets.key_id,
802+
secrets.nonce,
803+
secrets.created_at,
804+
secrets.updated_at
805+
FROM vault.secrets;
806+
807+
741808
--
742809
-- Name: refresh_tokens id; Type: DEFAULT; Schema: auth; Owner: -
743810
--

migrations/tests/extensions/test.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
\ir 20-pg_stat_monitor.sql
2222
\ir 21-auto_explain.sql
2323
\ir 22-pg_jsonschema.sql
24-
-- \ir 23-vault.sql
24+
\ir 23-vault.sql
2525
\ir 24-pgroonga.sql
2626
\ir 25-wrappers.sql
2727
\ir 26-hypopg.sql

0 commit comments

Comments
 (0)