summary refs log tree commit diff
path: root/install.sql
diff options
context:
space:
mode:
authorThe Fox in the Shell <KellerFuchs@hashbang.sh>2017-04-15 04:09:28 +0000
committerMykola Bilokonsky <mbilokonsky@gmail.com>2017-04-15 06:09:28 +0200
commitedc506770093fb5745ab7db3c17379f1b8d5596a (patch)
treed7a2da5f57d2fa7e39fa1d48c63228af0bb3209f /install.sql
parentca9c013cdf700617199e1c97ac8ec9cb08486da4 (diff)
Avoid unrestricted access to the Mastodon DB (#5)
* Use a limited, read-only view of public toots

This is less scary than unrestricted access to the production database...

* README: Update install process

* README: Update SQL query

* README: Update paragraph on direct DB access
Diffstat (limited to 'install.sql')
-rw-r--r--install.sql25
1 files changed, 25 insertions, 0 deletions
diff --git a/install.sql b/install.sql
new file mode 100644
index 0000000..5fe7c82
--- /dev/null
+++ b/install.sql
@@ -0,0 +1,25 @@
+-- -*- mode: sql; sql-product: postgres -*-
+
+-- Create a login role for ambassador
+CREATE USER ambassador;
+
+-- Use this if your deployment uses passwords rather than peer authentication:
+-- ALTER ROLE mastodon_ambassador WITH PASSWORD 'something secret, hopefully';
+--
+-- Note that PostgreSQL supports setting “encrypted” (hashed) passwords,
+-- which is a better option if the password must be stored in some configuration
+-- management tool.
+
+
+-- Now, create the view that ambassador actually uses
+CREATE VIEW public_toots AS
+  SELECT *
+    FROM statuses
+   WHERE visibility = 0
+;
+
+-- Make sure the role doesn't have access to anything undesireable
+REVOKE ALL FROM ambassador;
+
+-- Let ambassador select from the view
+GRANT SELECT ON public_toots TO ambassador;