From 78a6cb247f1c37287bf88687c3309b5be99ee720 Mon Sep 17 00:00:00 2001 From: Anastasia Lubennikova Date: Thu, 7 Apr 2022 20:37:42 +0300 Subject: [PATCH] allow the users to create extensions: GRANT CREATE ON DATABASE --- compute_tools/src/bin/zenith_ctl.rs | 1 + compute_tools/src/spec.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/compute_tools/src/bin/zenith_ctl.rs b/compute_tools/src/bin/zenith_ctl.rs index a5dfb1c875..3685f8e8b4 100644 --- a/compute_tools/src/bin/zenith_ctl.rs +++ b/compute_tools/src/bin/zenith_ctl.rs @@ -129,6 +129,7 @@ fn run_compute(state: &Arc>) -> Result { handle_roles(&read_state.spec, &mut client)?; handle_databases(&read_state.spec, &mut client)?; + handle_grants(&read_state.spec, &mut client)?; create_writablity_check_data(&mut client)?; // 'Close' connection diff --git a/compute_tools/src/spec.rs b/compute_tools/src/spec.rs index 1dd7c0044e..27114b8202 100644 --- a/compute_tools/src/spec.rs +++ b/compute_tools/src/spec.rs @@ -244,3 +244,24 @@ pub fn handle_databases(spec: &ClusterSpec, client: &mut Client) -> Result<()> { Ok(()) } + +// Grant CREATE ON DATABASE to the database owner +// to allow clients create trusted extensions. +pub fn handle_grants(spec: &ClusterSpec, client: &mut Client) -> Result<()> { + info!("cluster spec grants:"); + + for db in &spec.cluster.databases { + let dbname = &db.name; + + let query: String = format!( + "GRANT CREATE ON DATABASE {} TO {}", + dbname.quote(), + db.owner.quote() + ); + info!("grant query {}", &query); + + client.execute(query.as_str(), &[])?; + } + + Ok(()) +}