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(()) +}