From 3be9ad7d7869bc58d7beaed33106d49957632f26 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 6 Feb 2024 15:47:47 +0000 Subject: [PATCH] Disable schema dumping for Postgres in Budicloud. --- .../data/datasource/[datasourceId]/index.svelte | 12 +++++++++++- packages/server/src/integrations/postgres.ts | 9 +++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[datasourceId]/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[datasourceId]/index.svelte index 090cffeb7e..b69201865f 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[datasourceId]/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/[datasourceId]/index.svelte @@ -12,12 +12,16 @@ import PromptQueryModal from "./_components/PromptQueryModal.svelte" import SettingsPanel from "./_components/panels/Settings.svelte" import { helpers } from "@budibase/shared-core" + import { admin } from "stores/portal" + import { IntegrationTypes } from "constants/backend" let selectedPanel = null let panelOptions = [] $: datasource = $datasources.selected + $: isCloud = $admin.cloud + $: isPostgres = datasource?.source === IntegrationTypes.POSTGRES $: getOptions(datasource) const getOptions = datasource => { @@ -41,7 +45,13 @@ } // always the last option for SQL if (helpers.isSQL(datasource)) { - panelOptions.push("Settings") + if (isCloud && isPostgres) { + // We don't show the settings panel for Postgres on Budicloud because + // it requires pg_dump to work and we don't want to enable shell injection + // attacks. + } else { + panelOptions.push("Settings") + } } } diff --git a/packages/server/src/integrations/postgres.ts b/packages/server/src/integrations/postgres.ts index e1f4cc2fc7..9949dee6bb 100644 --- a/packages/server/src/integrations/postgres.ts +++ b/packages/server/src/integrations/postgres.ts @@ -29,6 +29,7 @@ import { Client, ClientConfig, types } from "pg" import { getReadableErrorMessage } from "./base/errorMapping" import { exec } from "child_process" import { storeTempFile } from "../utilities/fileSystem" +import { env } from "@budibase/backend-core" // Return "date" and "timestamp" types as plain strings. // This lets us reference the original stored timezone. @@ -433,6 +434,14 @@ class PostgresIntegration extends Sql implements DatasourcePlus { } async getExternalSchema() { + if (!env.SELF_HOSTED) { + // This is because it relies on shelling out to pg_dump and we don't want + // to enable shell injection attacks. + throw new Error( + "schema export for Postgres is not supported in Budibase Cloud" + ) + } + const dumpCommandParts = [ `user=${this.config.user}`, `host=${this.config.host}`,