ducklake safety for instance_settings.yaml users (#6844)

This commit is contained in:
Diego Imbert
2025-10-16 22:39:11 +02:00
committed by GitHub
parent c3e284bc96
commit b779cb7e02
3 changed files with 31 additions and 0 deletions
@@ -0,0 +1,27 @@
-- Copy of 20250731132157_ducklake_instance_settings.up.sql
-- Pushing a instance_settings.yaml without ducklake_user_pg_pwd will remove it from the global settings
-- And the next migration will fail because it will try to insert a NULL value
INSERT INTO global_settings (name, value)
VALUES ('ducklake_user_pg_pwd', ('"' || gen_random_uuid()::text || '"')::jsonb)
ON CONFLICT DO NOTHING;
-- Cannot simply create the user because Postgres expect a static string for the password
-- Also we cannot drop the user easily in the down migration because databases will depend on it
-- And we cannot drop databases in transactions (migrations)
DO $$
DECLARE
pwd text;
BEGIN
SELECT trim(both '"' from value::text) INTO pwd FROM global_settings WHERE name = 'ducklake_user_pg_pwd';
IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'ducklake_user') THEN
EXECUTE format('CREATE USER ducklake_user WITH PASSWORD %L', pwd);
ELSE
EXECUTE format('ALTER USER ducklake_user WITH PASSWORD %L', pwd);
END IF;
EXCEPTION
WHEN others THEN
RAISE NOTICE 'ducklake_user migration error, skipping.';
END
$$;
+4
View File
@@ -218,6 +218,10 @@ pub struct Value {
}
pub async fn delete_global_setting(db: &DB, key: &str) -> error::Result<()> {
if key == "ducklake_user_pg_pwd" || key == "ducklake_settings" {
tracing::error!("Tried to unset global setting {}, ignored", key);
return Ok(());
}
sqlx::query!("DELETE FROM global_settings WHERE name = $1", key,)
.execute(db)
.await?;