Skip to content

Commit 8b8a406

Browse files
fix: Alter privileges when creating user (#46)
1 parent 97b20a7 commit 8b8a406

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

operator/src/postgres.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ impl Postgres {
3131

3232
let query_create_user = format!("create user \"{username}\" with password '{password}';");
3333
let query_grant = format!("grant select on all tables in schema public to \"{username}\";");
34+
let query_privileges = format!("alter default privileges in schema public grant all privileges on tables to \"{username}\";");
3435

3536
let timeout = get_config().statement_timeout;
3637
let query_set_timeout =
@@ -53,6 +54,12 @@ impl Postgres {
5354
return Err(Error::PgError(err.to_string()));
5455
}
5556

57+
let privileges_stmt = tx.prepare(&query_privileges).await?;
58+
if let Err(err) = tx.execute(&privileges_stmt, &[]).await {
59+
tx.rollback().await?;
60+
return Err(Error::PgError(err.to_string()));
61+
}
62+
5663
let set_timeout_stmt = tx.prepare(&query_set_timeout).await?;
5764
let set_timeout_result = tx.execute(&set_timeout_stmt, &[]).await;
5865
if let Err(err) = set_timeout_result {

0 commit comments

Comments
 (0)