Skip to content

Commit 710987a

Browse files
authored
Fix data table creds setup (#7516)
* fix wrong pg_creds * revoke permissions
1 parent 7ca0945 commit 710987a

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-- Add down migration script here
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- Revoke default privileges first
2+
ALTER DEFAULT PRIVILEGES IN SCHEMA public
3+
REVOKE SELECT, INSERT, UPDATE, DELETE ON TABLES FROM custom_instance_user;
4+
REVOKE CREATE ON SCHEMA public FROM custom_instance_user;
5+
REVOKE USAGE ON SCHEMA public FROM custom_instance_user;
6+
7+
DO $$
8+
DECLARE
9+
dbname text := current_database();
10+
BEGIN
11+
EXECUTE format('REVOKE CREATE ON DATABASE %I FROM custom_instance_user', dbname);
12+
EXECUTE format('REVOKE CONNECT ON DATABASE %I FROM custom_instance_user', dbname);
13+
END $$;
14+

backend/windmill-api/src/settings.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ async fn setup_custom_instance_pg_database_inner(
703703
) -> Result<()> {
704704
require_super_admin(db, &authed.email).await?;
705705
logs.super_admin = "OK".to_string();
706-
let pg_creds = PgDatabase::parse_uri(&get_database_url().await?.as_str().await)?;
706+
let wmill_pg_creds = PgDatabase::parse_uri(&get_database_url().await?.as_str().await)?;
707707
logs.database_credentials = "OK".to_string();
708708

709709
// Validate name to ensure it only contains alphanumeric characters
@@ -716,7 +716,7 @@ async fn setup_custom_instance_pg_database_inner(
716716
"Catalog name must be alphanumeric, underscores allowed".to_string(),
717717
));
718718
}
719-
if pg_creds.dbname.trim().eq_ignore_ascii_case(dbname.trim()) {
719+
if wmill_pg_creds.dbname.trim().eq_ignore_ascii_case(dbname.trim()) {
720720
return Err(error::Error::BadRequest(
721721
"Database name cannot be the same as the main database".to_string(),
722722
));
@@ -731,6 +731,11 @@ async fn setup_custom_instance_pg_database_inner(
731731
.await?
732732
.unwrap_or(false);
733733

734+
let pg_creds = PgDatabase {
735+
dbname: dbname.to_string(),
736+
..wmill_pg_creds
737+
};
738+
734739
logs.created_database = "SKIP".to_string();
735740
if !db_exists {
736741
sqlx::query(&format!("CREATE DATABASE \"{dbname}\""))

0 commit comments

Comments
 (0)