Skip to content

Commit a157038

Browse files
authored
chore: enable Vault (#598)
* chore: re-enable Vault * chore: bump version * chore: version as rc * fix: formatting * chore: build test image from branch * chore: trigger build * chore: remove branch * chore: bump version
1 parent b9f9723 commit a157038

File tree

6 files changed

+74
-6
lines changed

6 files changed

+74
-6
lines changed

ansible/tasks/setup-extensions.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
- name: Install auto_explain
6565
import_tasks: tasks/postgres-extensions/21-auto_explain.yml
6666

67-
# - name: Install vault
68-
# import_tasks: tasks/postgres-extensions/23-vault.yml
67+
- name: Install vault
68+
import_tasks: tasks/postgres-extensions/23-vault.yml
6969

7070
- name: Install PGroonga
7171
import_tasks: tasks/postgres-extensions/24-pgroonga.yml

common.vars.pkr.hcl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
postgres-version = "15.1.0.64"
1+
postgres-version = "15.1.0.65"

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

+2-1
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/db/migrations/20221207154255_create_pgsodium_and_vault.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ grant execute on function pgsodium.crypto_aead_det_decrypt(bytea, bytea, uuid, b
1010
grant execute on function pgsodium.crypto_aead_det_encrypt(bytea, bytea, uuid, bytea) to service_role;
1111
grant execute on function pgsodium.crypto_aead_det_keygen to service_role;
1212

13-
-- create extension if not exists supabase_vault;
13+
create extension if not exists supabase_vault;
1414

1515
-- migrate:down

migrations/schema.sql

+67
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

+1-1
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)