Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4315bd8

Browse files
committed
Grant needed perms in add_node instead of requiring DBA to set up them.
Previous commit doc fix reverted accordingly.
1 parent e8dfc7b commit 4315bd8

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

pg_shardman--0.0.2.sql

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ DECLARE
105105
master_node_id int;
106106
sys_id bigint;
107107
conn_string_effective text = COALESCE(conn_string, super_conn_string);
108+
conn_string_effective_user text;
108109
BEGIN
109110
IF NOT shardman.is_shardlord()
110111
THEN
@@ -113,18 +114,19 @@ BEGIN
113114
super_conn_string, conn_string, repl_group))::int;
114115
END IF;
115116

116-
-- Insert new node in nodes table
117+
-- Insert new node in nodes table.
118+
-- We have to update system_id (and repl_group, for which we probably need
119+
-- system_id) only after insert, because broadcast fetches connstring from
120+
-- shardman.nodes itself.
117121
INSERT INTO shardman.nodes (system_id, super_connection_string,
118122
connection_string, replication_group)
119123
VALUES (0, super_conn_string, conn_string_effective, '')
120124
RETURNING id INTO new_node_id;
121125

122-
-- We have to update system_id along with dependant repl_group after insert,
123-
-- because otherwise broadcast will not work.
124126
sys_id := shardman.broadcast(
125127
format('%s:SELECT shardman.get_system_identifier();',
126-
new_node_id))::bigint;
127-
IF EXISTS(SELECT 1 FROM shardman.nodes where system_id = sys_id) THEN
128+
new_node_id), super_connstr => true)::bigint;
129+
IF EXISTS(SELECT 1 FROM shardman.nodes WHERE system_id = sys_id) THEN
128130
RAISE EXCEPTION 'Node with system id % is already in the cluster', sys_id;
129131
END IF;
130132
UPDATE shardman.nodes SET system_id = sys_id WHERE id = new_node_id;
@@ -133,6 +135,19 @@ BEGIN
133135
(CASE WHEN repl_group IS NULL THEN sys_id::text ELSE repl_group END)
134136
WHERE id = new_node_id;
135137

138+
-- If conn_string is provided, make sure effective user has permissions on
139+
-- shardman schema and postgres_fdw.
140+
IF conn_string IS NOT NULL THEN
141+
conn_string_effective_user := shardman.broadcast(
142+
format('%s:SELECT current_user;', new_node_id),
143+
super_connstr => false);
144+
PERFORM shardman.broadcast(
145+
format('{%s:GRANT USAGE ON FOREIGN DATA WRAPPER postgres_fdw TO %s;
146+
GRANT USAGE ON SCHEMA shardman TO %s;}',
147+
new_node_id, conn_string_effective_user, conn_string_effective_user),
148+
super_connstr => true);
149+
END IF;
150+
136151
-- Adjust replication channels within replication group.
137152
-- We need all-to-all replication channels between all group members.
138153
FOR node IN SELECT * FROM shardman.nodes WHERE replication_group = repl_group

readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,6 @@ former is used for configuring logical replication, the latter for DDL and for
469469
setting up FDW, i.e. accessing the data. This separation serves two purposes:
470470
* It allows to work with the data without requiring superuser privileges.
471471
* It allows to set up pgbouncer, as replication can't go through it.
472-
If `conn_string` is employed, PostgreSQL user it allows to authenticate as must
473-
have `USAGE` permission on `postgres_fdw` FDW and on `shardman` schema.
474472
If `conn_string` is `NULL`, `super_conn_string` is used everywhere.
475473

476474
`repl_group` is the name of node's replication group. We have no explicit

tests/python/tests.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ def test_copy_from(self):
839839
self.lord.safe_psql(DBNAME, "drop table pt_text;")
840840
self.lord.destroy_cluster()
841841

842-
# Create user joe and allow it to use shardman; configure pg_hba accordingly.
842+
# Create user joe for accessing data; configure pg_hba accordingly.
843843
# Unfortunately, we must use password, because postgres_fdw forbids passwordless
844844
# access for non-superusers
845845
def non_super_user_cbk(worker):
@@ -848,8 +848,6 @@ def non_super_user_cbk(worker):
848848
set synchronous_commit to local;
849849
drop role if exists joe;
850850
create role joe login password '12345';
851-
grant usage on foreign data wrapper postgres_fdw to joe;
852-
grant all privileges on schema shardman to group joe;
853851
""")
854852
worker.stop()
855853
hba_conf_path = os.path.join(worker.data_dir, "pg_hba.conf")

0 commit comments

Comments
 (0)