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
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ RUN apt-get update \
&& apt-get install --no-install-recommends -y \
sqitch=1.1.0000-1 \
&& mkdir -p /run/secrets \
&& echo "grafana" > /run/secrets/postgres_role_service_grafana_username \
&& echo "postgres" > /run/secrets/postgres_password \
&& echo "postgraphile" > /run/secrets/postgres_role_service_postgraphile_username \
&& echo "vibetype" > /run/secrets/postgres_role_service_vibetype_username \
&& echo "placeholder" | tee \
/run/secrets/postgres_role_service_grafana_password \
/run/secrets/postgres_role_service_postgraphile_password \
/run/secrets/postgres_role_service_vibetype_password \
/dev/null
Expand Down
8 changes: 8 additions & 0 deletions src/deploy/database_grafana.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
\set role_service_grafana_username `cat /run/secrets/postgres_role_service_grafana_username`

SELECT 'CREATE DATABASE grafana OWNER "' || :'role_service_grafana_username' || '";'
WHERE NOT EXISTS (
SELECT FROM pg_database WHERE datname = 'grafana'
)\gexec
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleverly done


COMMENT ON DATABASE grafana IS 'The observation dashboard''s database.';
9 changes: 9 additions & 0 deletions src/deploy/role_grafana.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
BEGIN;

\set role_service_grafana_password `cat /run/secrets/postgres_role_service_grafana_password`
\set role_service_grafana_username `cat /run/secrets/postgres_role_service_grafana_username`

DROP ROLE IF EXISTS :role_service_grafana_username;
CREATE ROLE :role_service_grafana_username LOGIN PASSWORD :'role_service_grafana_password';

COMMIT;
4 changes: 4 additions & 0 deletions src/deploy/schema_private.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
BEGIN;

\set role_service_grafana_username `cat /run/secrets/postgres_role_service_grafana_username`

CREATE SCHEMA vibetype_private;

COMMENT ON SCHEMA vibetype_private IS 'Contains account information and is not used by PostGraphile.';

GRANT USAGE ON SCHEMA vibetype_private TO :role_service_grafana_username;

COMMIT;
4 changes: 4 additions & 0 deletions src/deploy/table_account_private.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
BEGIN;

\set role_service_grafana_username `cat /run/secrets/postgres_role_service_grafana_username`

CREATE TABLE vibetype_private.account (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),

Expand Down Expand Up @@ -86,4 +88,6 @@ CREATE TRIGGER vibetype_private_account_password_reset_verification_valid_until
FOR EACH ROW
EXECUTE PROCEDURE vibetype_private.account_password_reset_verification_valid_until();

GRANT SELECT ON TABLE vibetype_private.account TO :role_service_grafana_username;

COMMIT;
1 change: 1 addition & 0 deletions src/revert/database_grafana.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP DATABASE grafana WITH (FORCE);
7 changes: 7 additions & 0 deletions src/revert/role_grafana.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BEGIN;

\set role_service_grafana_username `cat /run/secrets/postgres_role_service_grafana_username`

DROP ROLE :role_service_grafana_username;

COMMIT;
2 changes: 2 additions & 0 deletions src/sqitch
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ function docker_sudo() {
docker_sudo run --rm --network host \
--mount "type=bind,src=$THIS,dst=/repo" \
--mount "type=bind,src=$HOME,dst=$homedst" \
--mount "type=bind,src=$THIS/../../stack/src/development/secrets/postgres/role_service_grafana_password.secret,dst=/run/secrets/postgres_role_service_grafana_password" \
--mount "type=bind,src=$THIS/../../stack/src/development/secrets/postgres/role_service_grafana_username.secret,dst=/run/secrets/postgres_role_service_grafana_username" \
--mount "type=bind,src=$THIS/../../stack/src/development/secrets/postgres/role_service_postgraphile_password.secret,dst=/run/secrets/postgres_role_service_postgraphile_password" \
--mount "type=bind,src=$THIS/../../stack/src/development/secrets/postgres/role_service_postgraphile_username.secret,dst=/run/secrets/postgres_role_service_postgraphile_username" \
--mount "type=bind,src=$THIS/../../stack/src/development/secrets/postgres/role_service_vibetype_password.secret,dst=/run/secrets/postgres_role_service_vibetype_password" \
Expand Down
2 changes: 2 additions & 0 deletions src/sqitch.plan
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
%uri=https://github.com/maevsi/vibetype/

privilege_execute_revoke 1970-01-01T00:00:00Z Jonas Thelemann <e-mail+vibetype/sqitch@jonas-thelemann.de> # Revoke execute privilege from public.
role_grafana 1970-01-01T00:00:00Z Jonas Thelemann <e-mail+maevsi/sqitch@jonas-thelemann.de> # Add role grafana.
database_grafana [role_grafana] 1970-01-01T00:00:00Z Jonas Thelemann <e-mail+maevsi/sqitch@jonas-thelemann.de> # Add the database for grafana.
role_postgraphile 1970-01-01T00:00:00Z Jonas Thelemann <e-mail+vibetype/sqitch@jonas-thelemann.de> # Add role postgraphile.
role_anonymous [role_postgraphile] 1970-01-01T00:00:00Z Jonas Thelemann <e-mail+vibetype/sqitch@jonas-thelemann.de> # Add role anonymous.
role_account [role_postgraphile] 1970-01-01T00:00:00Z Jonas Thelemann <e-mail+vibetype/sqitch@jonas-thelemann.de> # Add role account.
Expand Down
8 changes: 8 additions & 0 deletions src/verify/database_grafana.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
BEGIN;

DO $$
BEGIN
ASSERT (SELECT 1 FROM pg_database WHERE datname='grafana') = 1;
END $$;

ROLLBACK;
13 changes: 13 additions & 0 deletions src/verify/role_grafana.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
BEGIN;

\set role_service_grafana_username `cat /run/secrets/postgres_role_service_grafana_username`

SET LOCAL role.service_grafana_username TO :'role_service_grafana_username';

DO $$
BEGIN
ASSERT (SELECT pg_catalog.pg_has_role(current_setting('role.service_grafana_username'), 'USAGE'));
-- Other accounts might not exist yet for a NOT-check.
END $$;

ROLLBACK;
14 changes: 14 additions & 0 deletions test/fixture/schema.definition.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6486,6 +6486,13 @@ GRANT USAGE ON SCHEMA vibetype TO vibetype_account;
GRANT USAGE ON SCHEMA vibetype TO vibetype;


--
-- Name: SCHEMA vibetype_private; Type: ACL; Schema: -; Owner: ci
--

GRANT USAGE ON SCHEMA vibetype_private TO grafana;


--
-- Name: FUNCTION armor(bytea); Type: ACL; Schema: public; Owner: ci
--
Expand Down Expand Up @@ -7314,6 +7321,13 @@ GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE vibetype.upload TO vibetype_account;
GRANT SELECT,UPDATE ON TABLE vibetype.upload TO vibetype;


--
-- Name: TABLE account; Type: ACL; Schema: vibetype_private; Owner: ci
--

GRANT SELECT ON TABLE vibetype_private.account TO grafana;


--
-- Name: TABLE achievement_code; Type: ACL; Schema: vibetype_private; Owner: ci
--
Expand Down
Loading