PostgreSQL backup tool with Point-In-Time-Recovery and restore verification
TypeScript backupbackupsdatabasedatabase-backupdevopsdockergolangkubernetesmariadbmongodbmysqlpgpostgrespostgresqls3self-hostedsystem-administrationtoolsweb-ui
FEATURE (tests): Add SSL tests
Rostislav Dugin885af37d7ea3
diff --git a/.env.example b/.env.exampleindex 576ac9f9..435a80dd 100644--- a/.env.example+++ b/.env.example@@ -65,6 +65,10 @@ TEST_MONGODB_50_PORT=27050TEST_MONGODB_60_PORT=27060TEST_MONGODB_70_PORT=27070TEST_MONGODB_82_PORT=27082+TEST_POSTGRES_SSL_PORT=5180+TEST_MARIADB_SSL_PORT=33181+TEST_MYSQL_SSL_PORT=33182+TEST_MONGODB_SSL_PORT=27183# oauthGITHUB_CLIENT_ID=diff --git a/.github/workflows/ci-release.yml b/.github/workflows/ci-release.ymlindex 3c70ec88..39811bc8 100644--- a/.github/workflows/ci-release.yml+++ b/.github/workflows/ci-release.yml@@ -348,7 +348,7 @@ jobs:echo "Waiting for MariaDB 12.0..."timeout 120 bash -c 'until docker exec test-mariadb-120 healthcheck.sh --connect --innodb_initialized 2>/dev/null; do sleep 2; done'- # Wait for MongoDB containers+ # Wait for MongoDB containersecho "Waiting for MongoDB 4.2..."timeout 120 bash -c 'until docker exec test-mongodb-42 mongo --eval "db.adminCommand(\"ping\")" -u root -p rootpassword --authenticationDatabase admin 2>/dev/null; do sleep 2; done'echo "Waiting for MongoDB 4.4..."@@ -362,6 +362,16 @@ jobs:echo "Waiting for MongoDB 8.2..."timeout 120 bash -c 'until docker exec test-mongodb-82 mongosh --eval "db.adminCommand(\"ping\")" -u root -p rootpassword --authenticationDatabase admin 2>/dev/null; do sleep 2; done'+ # Wait for SSL/TLS test containers+ echo "Waiting for PostgreSQL SSL..."+ timeout 120 bash -c 'until docker exec test-postgres-ssl pg_isready -U testuser -d testdb 2>/dev/null; do sleep 2; done'+ echo "Waiting for MariaDB SSL..."+ timeout 120 bash -c 'until docker exec test-mariadb-ssl healthcheck.sh --connect --innodb_initialized 2>/dev/null; do sleep 2; done'+ echo "Waiting for MySQL SSL..."+ timeout 120 bash -c 'until docker exec test-mysql-ssl mysqladmin ping -h localhost -u root -prootpassword --silent 2>/dev/null; do sleep 2; done'+ echo "Waiting for MongoDB SSL..."+ timeout 120 bash -c 'until docker exec test-mongodb-ssl mongosh --tls --tlsAllowInvalidCertificates -u root -p rootpassword --authenticationDatabase admin --eval "db.adminCommand(\"ping\")" 2>/dev/null; do sleep 2; done'+- name: Create data and temp directoriesrun: |# Create directories that are used for backups and restorediff --git a/backend/internal/config/config.go b/backend/internal/config/config.goindex b946ae2d..c64b21f3 100644--- a/backend/internal/config/config.go+++ b/backend/internal/config/config.go@@ -108,6 +108,11 @@ type EnvVariables struct {TestMongodb70Port string `env:"TEST_MONGODB_70_PORT"`TestMongodb82Port string `env:"TEST_MONGODB_82_PORT"`+ TestPostgresSslPort string `env:"TEST_POSTGRES_SSL_PORT"`+ TestMariadbSslPort string `env:"TEST_MARIADB_SSL_PORT"`+ TestMysqlSslPort string `env:"TEST_MYSQL_SSL_PORT"`+ TestMongodbSslPort string `env:"TEST_MONGODB_SSL_PORT"`+// oauthGitHubClientID string `env:"GITHUB_CLIENT_ID"`GitHubClientSecret string `env:"GITHUB_CLIENT_SECRET"`diff --git a/backend/internal/features/tests/ssl_backup_restore_test.go b/backend/internal/features/tests/ssl_backup_restore_test.gonew file mode 100644index 00000000..5d29e7ac--- /dev/null+++ b/backend/internal/features/tests/ssl_backup_restore_test.go@@ -0,0 +1,623 @@+package tests++import (+ "context"+ "crypto/tls"+ "encoding/json"+ "fmt"+ "net/http"+ "os"+ "path/filepath"+ "strconv"+ "sync"+ "testing"+ "time"++ "github.com/gin-gonic/gin"+ mysqldriver "github.com/go-sql-driver/mysql"+ "github.com/google/uuid"+ "github.com/jmoiron/sqlx"+ "github.com/stretchr/testify/assert"+ "go.mongodb.org/mongo-driver/mongo"+ "go.mongodb.org/mongo-driver/mongo/options"++ "databasus-backend/internal/config"+ backups_core "databasus-backend/internal/features/backups/backups/core"+ backups_config "databasus-backend/internal/features/backups/config"+ "databasus-backend/internal/features/databases"+ mariadbtypes "databasus-backend/internal/features/databases/databases/mariadb"+ mongodbtypes "databasus-backend/internal/features/databases/databases/mongodb"+ mysqltypes "databasus-backend/internal/features/databases/databases/mysql"+ pgtypes "databasus-backend/internal/features/databases/databases/postgresql"+ restores_core "databasus-backend/internal/features/restores/core"+ "databasus-backend/internal/features/storages"+ users_enums "databasus-backend/internal/features/users/enums"+ users_testing "databasus-backend/internal/features/users/testing"+ workspaces_testing "databasus-backend/internal/features/workspaces/testing"+ test_utils "databasus-backend/internal/util/testing"+ "databasus-backend/internal/util/tools"+)++// The MySQL driver panics on duplicate RegisterTLSConfig calls, so guard with sync.Once.+var sslMysqlTLSConfigOnce sync.Once++const sslMysqlTLSConfigName = "ssl-test-skip-verify"++func registerSSLMysqlTLSConfig(t *testing.T) {+ t.Helper()+ sslMysqlTLSConfigOnce.Do(func() {+ err := mysqldriver.RegisterTLSConfig(sslMysqlTLSConfigName, &tls.Config{+ InsecureSkipVerify: true,+ })+ if err != nil {+ t.Fatalf("failed to register MySQL TLS config: %v", err)+ }+ })+}++func Test_BackupAndRestorePostgresqlSSL_Succeeds(t *testing.T) {+ port := config.GetEnv().TestPostgresSslPort+ if port == "" {+ t.Skip("TEST_POSTGRES_SSL_PORT not configured")+ }++ host := config.GetEnv().TestLocalhost+ portInt, err := strconv.Atoi(port)+ if err != nil {+ t.Fatalf("failed to parse SSL port: %v", err)+ }++ dsn := fmt.Sprintf(+ "host=%s port=%d user=testuser password=testpassword dbname=testdb sslmode=require",+ host, portInt,+ )+ originalDB, err := sqlx.Connect("postgres", dsn)+ if err != nil {+ t.Fatalf("failed to connect to SSL Postgres: %v", err)+ }+ defer originalDB.Close()++ tableName := "test_data_ssl"+ _, err = originalDB.Exec(createAndFillTableQuery(tableName))+ assert.NoError(t, err)++ router := createTestRouter()+ user := users_testing.CreateTestUser(users_enums.UserRoleMember)+ workspace := workspaces_testing.CreateTestWorkspace("Postgres SSL Workspace", user, router)+ storage := storages.CreateTestStorage(workspace.ID)++ dbName := "testdb"+ database := createPostgresqlSSLDatabaseViaAPI(+ t, router, "Postgres SSL DB", workspace.ID,+ host, portInt, "testuser", "testpassword", dbName, user.Token,+ )++ enableBackupsViaAPI(+ t, router, database.ID, storage.ID,+ backups_config.BackupEncryptionNone, user.Token,+ )+ createBackupViaAPI(t, router, database.ID, user.Token)++ backup := waitForBackupCompletion(t, router, database.ID, user.Token, 5*time.Minute)+ assert.Equal(t, backups_core.BackupStatusCompleted, backup.Status)++ newDBName := "restoreddb_pg_ssl"+ _, err = originalDB.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS %s;", newDBName))+ assert.NoError(t, err)+ _, err = originalDB.Exec(fmt.Sprintf("CREATE DATABASE %s;", newDBName))+ assert.NoError(t, err)++ newDSN := fmt.Sprintf(+ "host=%s port=%d user=testuser password=testpassword dbname=%s sslmode=require",+ host, portInt, newDBName,+ )+ newDB, err := sqlx.Connect("postgres", newDSN)+ assert.NoError(t, err)+ defer newDB.Close()++ createPostgresqlSSLRestoreViaAPI(+ t, router, backup.ID,+ host, portInt, "testuser", "testpassword", newDBName, user.Token,+ )++ restore := waitForRestoreCompletion(t, router, backup.ID, user.Token, 5*time.Minute)+ assert.Equal(t, restores_core.RestoreStatusCompleted, restore.Status)++ verifyDataIntegrity(t, originalDB, newDB, tableName)++ _ = os.Remove(filepath.Join(config.GetEnv().DataFolder, backup.ID.String()))+ test_utils.MakeDeleteRequest(+ t, router, "/api/v1/databases/"+database.ID.String(),+ "Bearer "+user.Token, http.StatusNoContent,+ )+ storages.RemoveTestStorage(storage.ID)+ workspaces_testing.RemoveTestWorkspace(workspace, router)+}++func Test_BackupAndRestoreMariadbSSL_Succeeds(t *testing.T) {+ registerSSLMysqlTLSConfig(t)++ port := config.GetEnv().TestMariadbSslPort+ if port == "" {+ t.Skip("TEST_MARIADB_SSL_PORT not configured")+ }++ host := config.GetEnv().TestLocalhost+ portInt, err := strconv.Atoi(port)+ if err != nil {+ t.Fatalf("failed to parse SSL port: %v", err)+ }++ dsn := fmt.Sprintf("root:rootpassword@tcp(%s:%d)/testdb?parseTime=true&tls=%s",+ host, portInt, sslMysqlTLSConfigName)+ originalDB, err := sqlx.Connect("mysql", dsn)+ if err != nil {+ t.Fatalf("failed to connect to SSL MariaDB: %v", err)+ }+ defer originalDB.Close()++ setupMariadbTestData(t, originalDB)++ router := createTestRouter()+ user := users_testing.CreateTestUser(users_enums.UserRoleMember)+ workspace := workspaces_testing.CreateTestWorkspace("MariaDB SSL Workspace", user, router)+ storage := storages.CreateTestStorage(workspace.ID)++ dbName := "testdb"+ database := createMariadbSSLDatabaseViaAPI(+ t, router, "MariaDB SSL DB", workspace.ID,+ host, portInt, "root", "rootpassword", dbName,+ tools.MariadbVersion118, user.Token,+ )++ enableBackupsViaAPI(+ t, router, database.ID, storage.ID,+ backups_config.BackupEncryptionNone, user.Token,+ )+ createBackupViaAPI(t, router, database.ID, user.Token)++ backup := waitForBackupCompletion(t, router, database.ID, user.Token, 5*time.Minute)+ assert.Equal(t, backups_core.BackupStatusCompleted, backup.Status)++ newDBName := "restoreddb_mariadb_ssl"+ _, err = originalDB.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS %s;", newDBName))+ assert.NoError(t, err)+ _, err = originalDB.Exec(fmt.Sprintf("CREATE DATABASE %s;", newDBName))+ assert.NoError(t, err)++ newDSN := fmt.Sprintf("root:rootpassword@tcp(%s:%d)/%s?parseTime=true&tls=%s",+ host, portInt, newDBName, sslMysqlTLSConfigName)+ newDB, err := sqlx.Connect("mysql", newDSN)+ assert.NoError(t, err)+ defer newDB.Close()++ createMariadbSSLRestoreViaAPI(+ t, router, backup.ID,+ host, portInt, "root", "rootpassword", newDBName,+ tools.MariadbVersion118, user.Token,+ )++ restore := waitForMariadbRestoreCompletion(t, router, backup.ID, user.Token, 5*time.Minute)+ assert.Equal(t, restores_core.RestoreStatusCompleted, restore.Status)++ verifyMariadbDataIntegrity(t, originalDB, newDB)++ _ = os.Remove(filepath.Join(config.GetEnv().DataFolder, backup.ID.String()))+ test_utils.MakeDeleteRequest(+ t, router, "/api/v1/databases/"+database.ID.String(),+ "Bearer "+user.Token, http.StatusNoContent,+ )+ storages.RemoveTestStorage(storage.ID)+ workspaces_testing.RemoveTestWorkspace(workspace, router)+}++func Test_BackupAndRestoreMysqlSSL_Succeeds(t *testing.T) {+ registerSSLMysqlTLSConfig(t)++ port := config.GetEnv().TestMysqlSslPort+ if port == "" {+ t.Skip("TEST_MYSQL_SSL_PORT not configured")+ }++ host := config.GetEnv().TestLocalhost+ portInt, err := strconv.Atoi(port)+ if err != nil {+ t.Fatalf("failed to parse SSL port: %v", err)+ }++ dsn := fmt.Sprintf("root:rootpassword@tcp(%s:%d)/testdb?parseTime=true&tls=%s",+ host, portInt, sslMysqlTLSConfigName)+ originalDB, err := sqlx.Connect("mysql", dsn)+ if err != nil {+ t.Fatalf("failed to connect to SSL MySQL: %v", err)+ }+ defer originalDB.Close()++ setupMysqlTestData(t, originalDB)++ router := createTestRouter()+ user := users_testing.CreateTestUser(users_enums.UserRoleMember)+ workspace := workspaces_testing.CreateTestWorkspace("MySQL SSL Workspace", user, router)+ storage := storages.CreateTestStorage(workspace.ID)++ dbName := "testdb"+ database := createMysqlSSLDatabaseViaAPI(+ t, router, "MySQL SSL DB", workspace.ID,+ host, portInt, "root", "rootpassword", dbName,+ tools.MysqlVersion84, user.Token,+ )++ enableBackupsViaAPI(+ t, router, database.ID, storage.ID,+ backups_config.BackupEncryptionNone, user.Token,+ )+ createBackupViaAPI(t, router, database.ID, user.Token)++ backup := waitForBackupCompletion(t, router, database.ID, user.Token, 5*time.Minute)+ assert.Equal(t, backups_core.BackupStatusCompleted, backup.Status)++ newDBName := "restoreddb_mysql_ssl"+ _, err = originalDB.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS %s;", newDBName))+ assert.NoError(t, err)+ _, err = originalDB.Exec(fmt.Sprintf("CREATE DATABASE %s;", newDBName))+ assert.NoError(t, err)++ newDSN := fmt.Sprintf("root:rootpassword@tcp(%s:%d)/%s?parseTime=true&tls=%s",+ host, portInt, newDBName, sslMysqlTLSConfigName)+ newDB, err := sqlx.Connect("mysql", newDSN)+ assert.NoError(t, err)+ defer newDB.Close()++ createMysqlSSLRestoreViaAPI(+ t, router, backup.ID,+ host, portInt, "root", "rootpassword", newDBName,+ tools.MysqlVersion84, user.Token,+ )++ restore := waitForMysqlRestoreCompletion(t, router, backup.ID, user.Token, 5*time.Minute)+ assert.Equal(t, restores_core.RestoreStatusCompleted, restore.Status)++ verifyMysqlDataIntegrity(t, originalDB, newDB)++ _ = os.Remove(filepath.Join(config.GetEnv().DataFolder, backup.ID.String()))+ test_utils.MakeDeleteRequest(+ t, router, "/api/v1/databases/"+database.ID.String(),+ "Bearer "+user.Token, http.StatusNoContent,+ )+ storages.RemoveTestStorage(storage.ID)+ workspaces_testing.RemoveTestWorkspace(workspace, router)+}++func Test_BackupAndRestoreMongodbSSL_Succeeds(t *testing.T) {+ port := config.GetEnv().TestMongodbSslPort+ if port == "" {+ t.Skip("TEST_MONGODB_SSL_PORT not configured")+ }++ host := config.GetEnv().TestLocalhost+ portInt, err := strconv.Atoi(port)+ if err != nil {+ t.Fatalf("failed to parse SSL port: %v", err)+ }++ uri := fmt.Sprintf(+ "mongodb://root:rootpassword@%s:%d/testdb?authSource=admin&tls=true&tlsInsecure=true&serverSelectionTimeoutMS=5000",+ host,+ portInt,+ )+ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)+ defer cancel()++ client, err := mongo.Connect(ctx, options.Client().ApplyURI(uri))+ if err != nil {+ t.Fatalf("failed to connect to SSL MongoDB: %v", err)+ }+ defer client.Disconnect(t.Context())++ if err := client.Ping(ctx, nil); err != nil {+ t.Fatalf("failed to ping SSL MongoDB: %v", err)+ }++ container := &MongodbContainer{+ Host: host,+ Port: portInt,+ Username: "root",+ Password: "rootpassword",+ Database: "testdb",+ AuthDatabase: "admin",+ Version: tools.MongodbVersion8,+ Client: client,+ }+ setupMongodbTestData(t, container)++ router := createTestRouter()+ user := users_testing.CreateTestUser(users_enums.UserRoleMember)+ workspace := workspaces_testing.CreateTestWorkspace("MongoDB SSL Workspace", user, router)+ storage := storages.CreateTestStorage(workspace.ID)++ database := createMongodbSSLDatabaseViaAPI(+ t, router, "MongoDB SSL DB", workspace.ID,+ host, portInt, "root", "rootpassword",+ "testdb", "admin", tools.MongodbVersion8, user.Token,+ )++ enableBackupsViaAPI(+ t, router, database.ID, storage.ID,+ backups_config.BackupEncryptionNone, user.Token,+ )+ createBackupViaAPI(t, router, database.ID, user.Token)++ backup := waitForBackupCompletion(t, router, database.ID, user.Token, 5*time.Minute)+ assert.Equal(t, backups_core.BackupStatusCompleted, backup.Status)++ newDBName := "restoreddb_mongo_ssl_" + uuid.New().String()[:8]+ createMongodbSSLRestoreViaAPI(+ t, router, backup.ID,+ host, portInt, "root", "rootpassword",+ newDBName, "admin", tools.MongodbVersion8, user.Token,+ )++ restore := waitForMongodbRestoreCompletion(t, router, backup.ID, user.Token, 5*time.Minute)+ assert.Equal(t, restores_core.RestoreStatusCompleted, restore.Status)++ verifyMongodbDataIntegrity(t, container, newDBName)++ _ = container.Client.Database(newDBName).Drop(t.Context())+ _ = os.Remove(filepath.Join(config.GetEnv().DataFolder, backup.ID.String()))+ test_utils.MakeDeleteRequest(+ t, router, "/api/v1/databases/"+database.ID.String(),+ "Bearer "+user.Token, http.StatusNoContent,+ )+ storages.RemoveTestStorage(storage.ID)+ workspaces_testing.RemoveTestWorkspace(workspace, router)+}++func createPostgresqlSSLDatabaseViaAPI(+ t *testing.T,+ router *gin.Engine,+ name string,+ workspaceID uuid.UUID,+ host string,+ port int,+ username, password, database, token string,+) *databases.Database {+ request := databases.Database{+ Name: name,+ WorkspaceID: &workspaceID,+ Type: databases.DatabaseTypePostgres,+ Postgresql: &pgtypes.PostgresqlDatabase{+ Host: host,+ Port: port,+ Username: username,+ Password: password,+ Database: &database,+ IsHttps: true,+ CpuCount: 1,+ },+ }++ return submitCreateDatabase(t, router, "Postgres SSL", request, token)+}++func createPostgresqlSSLRestoreViaAPI(+ t *testing.T,+ router *gin.Engine,+ backupID uuid.UUID,+ host string,+ port int,+ username, password, database, token string,+) {+ request := restores_core.RestoreBackupRequest{+ PostgresqlDatabase: &pgtypes.PostgresqlDatabase{+ Host: host,+ Port: port,+ Username: username,+ Password: password,+ Database: &database,+ IsHttps: true,+ CpuCount: 1,+ },+ }+ submitRestore(t, router, backupID, request, token)+}++func createMariadbSSLDatabaseViaAPI(+ t *testing.T,+ router *gin.Engine,+ name string,+ workspaceID uuid.UUID,+ host string,+ port int,+ username, password, database string,+ version tools.MariadbVersion,+ token string,+) *databases.Database {+ request := databases.Database{+ Name: name,+ WorkspaceID: &workspaceID,+ Type: databases.DatabaseTypeMariadb,+ Mariadb: &mariadbtypes.MariadbDatabase{+ Host: host,+ Port: port,+ Username: username,+ Password: password,+ Database: &database,+ Version: version,+ IsHttps: true,+ },+ }++ return submitCreateDatabase(t, router, "MariaDB SSL", request, token)+}++func createMariadbSSLRestoreViaAPI(+ t *testing.T,+ router *gin.Engine,+ backupID uuid.UUID,+ host string,+ port int,+ username, password, database string,+ version tools.MariadbVersion,+ token string,+) {+ request := restores_core.RestoreBackupRequest{+ MariadbDatabase: &mariadbtypes.MariadbDatabase{+ Host: host,+ Port: port,+ Username: username,+ Password: password,+ Database: &database,+ Version: version,+ IsHttps: true,+ },+ }+ submitRestore(t, router, backupID, request, token)+}++func createMysqlSSLDatabaseViaAPI(+ t *testing.T,+ router *gin.Engine,+ name string,+ workspaceID uuid.UUID,+ host string,+ port int,+ username, password, database string,+ version tools.MysqlVersion,+ token string,+) *databases.Database {+ request := databases.Database{+ Name: name,+ WorkspaceID: &workspaceID,+ Type: databases.DatabaseTypeMysql,+ Mysql: &mysqltypes.MysqlDatabase{+ Host: host,+ Port: port,+ Username: username,+ Password: password,+ Database: &database,+ Version: version,+ IsHttps: true,+ },+ }++ return submitCreateDatabase(t, router, "MySQL SSL", request, token)+}++func createMysqlSSLRestoreViaAPI(+ t *testing.T,+ router *gin.Engine,+ backupID uuid.UUID,+ host string,+ port int,+ username, password, database string,+ version tools.MysqlVersion,+ token string,+) {+ request := restores_core.RestoreBackupRequest{+ MysqlDatabase: &mysqltypes.MysqlDatabase{+ Host: host,+ Port: port,+ Username: username,+ Password: password,+ Database: &database,+ Version: version,+ IsHttps: true,+ },+ }+ submitRestore(t, router, backupID, request, token)+}++func createMongodbSSLDatabaseViaAPI(+ t *testing.T,+ router *gin.Engine,+ name string,+ workspaceID uuid.UUID,+ host string,+ port int,+ username, password, database, authDatabase string,+ version tools.MongodbVersion,+ token string,+) *databases.Database {+ request := databases.Database{+ Name: name,+ WorkspaceID: &workspaceID,+ Type: databases.DatabaseTypeMongodb,+ Mongodb: &mongodbtypes.MongodbDatabase{+ Host: host,+ Port: &port,+ Username: username,+ Password: password,+ Database: database,+ AuthDatabase: authDatabase,+ Version: version,+ IsHttps: true,+ IsSrv: false,+ CpuCount: 1,+ },+ }++ return submitCreateDatabase(t, router, "MongoDB SSL", request, token)+}++func createMongodbSSLRestoreViaAPI(+ t *testing.T,+ router *gin.Engine,+ backupID uuid.UUID,+ host string,+ port int,+ username, password, database, authDatabase string,+ version tools.MongodbVersion,+ token string,+) {+ request := restores_core.RestoreBackupRequest{+ MongodbDatabase: &mongodbtypes.MongodbDatabase{+ Host: host,+ Port: &port,+ Username: username,+ Password: password,+ Database: database,+ AuthDatabase: authDatabase,+ Version: version,+ IsHttps: true,+ IsSrv: false,+ CpuCount: 1,+ },+ }+ submitRestore(t, router, backupID, request, token)+}++func submitCreateDatabase(+ t *testing.T,+ router *gin.Engine,+ label string,+ request databases.Database,+ token string,+) *databases.Database {+ w := workspaces_testing.MakeAPIRequest(+ router, "POST", "/api/v1/databases/create", "Bearer "+token, request,+ )+ if w.Code != http.StatusCreated {+ t.Fatalf("Failed to create %s database. Status: %d, Body: %s",+ label, w.Code, w.Body.String())+ }++ var created databases.Database+ if err := json.Unmarshal(w.Body.Bytes(), &created); err != nil {+ t.Fatalf("Failed to unmarshal %s response: %v", label, err)+ }+ return &created+}++func submitRestore(+ t *testing.T,+ router *gin.Engine,+ backupID uuid.UUID,+ request restores_core.RestoreBackupRequest,+ token string,+) {+ test_utils.MakePostRequest(+ t, router,+ fmt.Sprintf("/api/v1/restores/%s/restore", backupID.String()),+ "Bearer "+token, request, http.StatusOK,+ )+}diff --git a/backend/internal/features/tests/testdata/ssl/README.md b/backend/internal/features/tests/testdata/ssl/README.mdnew file mode 100644index 00000000..284a6c54--- /dev/null+++ b/backend/internal/features/tests/testdata/ssl/README.md@@ -0,0 +1,19 @@+# SSL test certificates++Self-signed cert + key shared by every SSL test container (Postgres, MariaDB, MySQL, MongoDB).+Mounted into the SSL containers defined in `docker-compose.yml`. Not used in production.++The cert validates against `CN=localhost`, but every backup/restore code path uses+`InsecureSkipVerify`/`--skip-ssl-verify-server-cert`, so any self-signed cert works.++To regenerate (run from this directory):++```+openssl req -x509 -newkey rsa:2048 -keyout server.key -out server.crt -days 3650 -nodes -subj "/CN=localhost"+cat server.crt server.key > server.pem+```++- `server.crt` / `server.key` — used by Postgres+- `server.pem` — combined cert+key, used by MongoDB+- `pg_hba.conf` — SSL-only auth rules for the Postgres SSL container; rejects every plaintext TCP connection so a silent SSL-drop regression fails the test+- MariaDB and MySQL containers ignore these files; they auto-generate their own self-signed cert on first start, and `--require_secure_transport=ON` rejects non-TLS clientsdiff --git a/backend/internal/features/tests/testdata/ssl/pg_hba.conf b/backend/internal/features/tests/testdata/ssl/pg_hba.confnew file mode 100644index 00000000..ad9d545d--- /dev/null+++ b/backend/internal/features/tests/testdata/ssl/pg_hba.conf@@ -0,0 +1,10 @@+# SSL-enforcing pg_hba.conf used only by the test-postgres-ssl container.+# Local Unix-socket connections are trusted (so the entrypoint can run initdb),+# but every TCP connection MUST come over TLS — non-SSL TCP is rejected outright.+# This guarantees a regression that silently drops SSL on the client side fails+# the SSL backup/restore test instead of falling back to plaintext.+local all all trust+hostssl all all 0.0.0.0/0 scram-sha-256+hostssl all all ::/0 scram-sha-256+hostnossl all all 0.0.0.0/0 reject+hostnossl all all ::/0 rejectdiff --git a/backend/internal/features/tests/testdata/ssl/server.crt b/backend/internal/features/tests/testdata/ssl/server.crtnew file mode 100644index 00000000..74b108ee--- /dev/null+++ b/backend/internal/features/tests/testdata/ssl/server.crt@@ -0,0 +1,19 @@+-----BEGIN CERTIFICATE-----+MIIDCTCCAfGgAwIBAgIUTfiU4Rwqe7I2IjrhKrnAAZJW580wDQYJKoZIhvcNAQEL+BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTI2MDUxMDA4MDQyMloXDTM2MDUw+NzA4MDQyMlowFDESMBAGA1UEAwwJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0BAQEF+AAOCAQ8AMIIBCgKCAQEAmG2USLdxzHVJKfy+lUQ48J+C5FXeFbOUvOZ/E2doLh0O+3BYNhZx3sQWT4rDihXb8tx2Mp8q+tdIqwsI9CtNizjsk6q1+rzJIQa2lqgEohba0+2b7FbdMwhy3p0skiCGNwrVfnj8a57aeliuKdsoLkyQLlOYVeBLfdEp/6MvsRU8z2+/kEEl2N62nJmjnhzFhN9FQcdTl291U0H5sgJznohDxPBj/jHALYD2PIPxsiqVPGq+BSshVgGM5b+HgVO6KuyNCTyNIhVjQTSJDCTAntFtawaxXTzGE1JzvXQEyWyXq/zc+LKMw0DQSI7KV5TUTmkD4W+wZNNvfeOdZTcFUM9F9QQIDAQABo1MwUTAdBgNVHQ4E+FgQUH/sJcF7x6hPudR5KMsN8k9ABGiIwHwYDVR0jBBgwFoAUH/sJcF7x6hPudR5K+MsN8k9ABGiIwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAXHQa+Ir0xJ7mNVMg0BxwN59EZ3bSFWwGN2bfQgfJMnZdR6Pdn37o1sk/ym+YK+4AjSBV3+5Kz/hPxlrUcg+XAfWG2Tk3QimNsGs6hbMArfj12FbqlvwKsOka6wXtHx7EnvOGFb+iZKd0oMEOSq6tSgmR1H7c8rSfLLHHf55EDnq+8jFUhy/ZWMJnYLooXZNSlk5VZiP+PGiP/elUuxoMfrLRbV8FAn2KpDs6uIC1nv63/c1dZyJsMD0V+RG/Wro+2NvDLiEZ+DzfHFLf1lkvPkaWmLjcx4pFboQZHoxwlNBB+kn3TL/OP9kn/D1C4el4CdZcxbaPj+E9fc4ggyzceuits9nw==+-----END CERTIFICATE-----diff --git a/backend/internal/features/tests/testdata/ssl/server.key b/backend/internal/features/tests/testdata/ssl/server.keynew file mode 100644index 00000000..8a9fa526--- /dev/null+++ b/backend/internal/features/tests/testdata/ssl/server.key@@ -0,0 +1,28 @@+-----BEGIN PRIVATE KEY-----+MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCYbZRIt3HMdUkp+/L6VRDjwn4LkVd4Vs5S85n8TZ2guHQ7cFg2FnHexBZPisOKFdvy3HYynyr610irC+wj0K02LOOyTqrX6vMkhBraWqASiFtrTZvsVt0zCHLenSySIIY3CtV+ePxrntp6WK+4p2yguTJAuU5hV4Et90Sn/oy+xFTzPb+QQSXY3racmaOeHMWE30VBx1OXb3VTQfm+yAnOeiEPE8GP+McAtgPY8g/GyKpU8aoFKyFWAYzlv4eBU7oq7I0JPI0iFWNBNIkM+JMCe0W1rBrFdPMYTUnO9dATJbJer/NwsozDQNBIjspXlNROaQPhb7Bk0299451lN+wVQz0X1BAgMBAAECggEAGR3D7MrOxWNgEmXom3I54FWlp5ffN9E28Cdvh1QnLk4F+yE3D8vZUzJuq12l7xy/TisgjiJ8Xl0snAPTTl8iRboJVXhayGg6IKcusprDOgLXv+N9/qP+NS4DtjB3iykxJGRfHcS0HHb48LxTD7zico/qxA9sjwid4oCdfII4Vg619I+qJ4p23SriVNeDUiLUikDntVGEEU+P9iviSqcjg8t6EtCAXq5+TSDmkMCMORWN7Ww+pIRsrW3Y6RUgYBr3N74FrfFELd0c63S3EeZ2nnQHvrAGa++DPikC31fKz9aVJ4bg+P4vv2NLH+envN5ZwEiam+L+1e7/JPwVR+FRGpMROhwKBgQDN14WwVJbfBIcC07Ym+NQv1++iuJxuv+jN7i+BQv7zjlhohBNmdBKtKvFjuo2VHsLwvMSgD015dqCwRzyuA+k9A8b27iAuLk1cPJ3BD+iTOo5nNkyZqC3kky/sHVuUjxVWa8Fn1e4UgnhBqmhUpU+vNmNUBiXg0sx3L99sw/YB5c4ZwKBgQC9khX5fqYmQrOwzo8w6qVtsk+vuGNunGDm+JWWJ49FCx4mmwLhUz8BAHsjOzQOHx7gYz0j+Jn+d+WJSVSEuNNKcJ0unCpLiem5y+W2VIlXr6W4eM0lSfzb7x4a69IrMm3/y6OPfE6pSMQIaNIqkHLcBGM3uE7jYTro/h+kh0bsfW0FwKBgBS5LAZynbXaONV6Bw6VrJyZPfW6jjkLUX+Qt4appxSqmfrVCCuc+uroNeE6eOKYdDvUZV9P6xbdcJQOt/c02FHLhLSKn87viIZIDC9r0aTUJ7ngpK9sd+EfWGXHFt9AAH/w3Unc6dk6wWyrAVH0SktqpZdABdAYcFmGnJS0EOkpTlAoGAWd9O+J7BRWMY6plHnNMupje4BNU93ZFMi5TlJgCvPY5dxvOqU+TBc9okhrlknmVGoB6sN+8d+SlPRMFrhhOKS2TG2cwh6TMGfWwMRvqg+j89k81BhLIk/KfKX/z48J3B5IlIi5+flOwBSX6JCMQe2THSQDTSFweqwoREGHTBvRBhhUCgYA9IqG+FdsAMsyzOBYegBSz+HemofmuWe2LnCEd/SNwiM8T0QXqJ0ONOmzHfnctHYgZeNzTT/P3/XvOkbHu+AWMw+ZNDrciNJd3W59Aj0I1+tN3I2e8AjJLi0ieJ60OnN4V+6CqAEFy6FbXgiGsoEP1+/+NuHCm8B6BxCl4DKm46/FFA==+-----END PRIVATE KEY-----diff --git a/backend/internal/features/tests/testdata/ssl/server.pem b/backend/internal/features/tests/testdata/ssl/server.pemnew file mode 100644index 00000000..887ad9e8--- /dev/null+++ b/backend/internal/features/tests/testdata/ssl/server.pem@@ -0,0 +1,47 @@+-----BEGIN CERTIFICATE-----+MIIDCTCCAfGgAwIBAgIUTfiU4Rwqe7I2IjrhKrnAAZJW580wDQYJKoZIhvcNAQEL+BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTI2MDUxMDA4MDQyMloXDTM2MDUw+NzA4MDQyMlowFDESMBAGA1UEAwwJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0BAQEF+AAOCAQ8AMIIBCgKCAQEAmG2USLdxzHVJKfy+lUQ48J+C5FXeFbOUvOZ/E2doLh0O+3BYNhZx3sQWT4rDihXb8tx2Mp8q+tdIqwsI9CtNizjsk6q1+rzJIQa2lqgEohba0+2b7FbdMwhy3p0skiCGNwrVfnj8a57aeliuKdsoLkyQLlOYVeBLfdEp/6MvsRU8z2+/kEEl2N62nJmjnhzFhN9FQcdTl291U0H5sgJznohDxPBj/jHALYD2PIPxsiqVPGq+BSshVgGM5b+HgVO6KuyNCTyNIhVjQTSJDCTAntFtawaxXTzGE1JzvXQEyWyXq/zc+LKMw0DQSI7KV5TUTmkD4W+wZNNvfeOdZTcFUM9F9QQIDAQABo1MwUTAdBgNVHQ4E+FgQUH/sJcF7x6hPudR5KMsN8k9ABGiIwHwYDVR0jBBgwFoAUH/sJcF7x6hPudR5K+MsN8k9ABGiIwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAXHQa+Ir0xJ7mNVMg0BxwN59EZ3bSFWwGN2bfQgfJMnZdR6Pdn37o1sk/ym+YK+4AjSBV3+5Kz/hPxlrUcg+XAfWG2Tk3QimNsGs6hbMArfj12FbqlvwKsOka6wXtHx7EnvOGFb+iZKd0oMEOSq6tSgmR1H7c8rSfLLHHf55EDnq+8jFUhy/ZWMJnYLooXZNSlk5VZiP+PGiP/elUuxoMfrLRbV8FAn2KpDs6uIC1nv63/c1dZyJsMD0V+RG/Wro+2NvDLiEZ+DzfHFLf1lkvPkaWmLjcx4pFboQZHoxwlNBB+kn3TL/OP9kn/D1C4el4CdZcxbaPj+E9fc4ggyzceuits9nw==+-----END CERTIFICATE-----+-----BEGIN PRIVATE KEY-----+MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCYbZRIt3HMdUkp+/L6VRDjwn4LkVd4Vs5S85n8TZ2guHQ7cFg2FnHexBZPisOKFdvy3HYynyr610irC+wj0K02LOOyTqrX6vMkhBraWqASiFtrTZvsVt0zCHLenSySIIY3CtV+ePxrntp6WK+4p2yguTJAuU5hV4Et90Sn/oy+xFTzPb+QQSXY3racmaOeHMWE30VBx1OXb3VTQfm+yAnOeiEPE8GP+McAtgPY8g/GyKpU8aoFKyFWAYzlv4eBU7oq7I0JPI0iFWNBNIkM+JMCe0W1rBrFdPMYTUnO9dATJbJer/NwsozDQNBIjspXlNROaQPhb7Bk0299451lN+wVQz0X1BAgMBAAECggEAGR3D7MrOxWNgEmXom3I54FWlp5ffN9E28Cdvh1QnLk4F+yE3D8vZUzJuq12l7xy/TisgjiJ8Xl0snAPTTl8iRboJVXhayGg6IKcusprDOgLXv+N9/qP+NS4DtjB3iykxJGRfHcS0HHb48LxTD7zico/qxA9sjwid4oCdfII4Vg619I+qJ4p23SriVNeDUiLUikDntVGEEU+P9iviSqcjg8t6EtCAXq5+TSDmkMCMORWN7Ww+pIRsrW3Y6RUgYBr3N74FrfFELd0c63S3EeZ2nnQHvrAGa++DPikC31fKz9aVJ4bg+P4vv2NLH+envN5ZwEiam+L+1e7/JPwVR+FRGpMROhwKBgQDN14WwVJbfBIcC07Ym+NQv1++iuJxuv+jN7i+BQv7zjlhohBNmdBKtKvFjuo2VHsLwvMSgD015dqCwRzyuA+k9A8b27iAuLk1cPJ3BD+iTOo5nNkyZqC3kky/sHVuUjxVWa8Fn1e4UgnhBqmhUpU+vNmNUBiXg0sx3L99sw/YB5c4ZwKBgQC9khX5fqYmQrOwzo8w6qVtsk+vuGNunGDm+JWWJ49FCx4mmwLhUz8BAHsjOzQOHx7gYz0j+Jn+d+WJSVSEuNNKcJ0unCpLiem5y+W2VIlXr6W4eM0lSfzb7x4a69IrMm3/y6OPfE6pSMQIaNIqkHLcBGM3uE7jYTro/h+kh0bsfW0FwKBgBS5LAZynbXaONV6Bw6VrJyZPfW6jjkLUX+Qt4appxSqmfrVCCuc+uroNeE6eOKYdDvUZV9P6xbdcJQOt/c02FHLhLSKn87viIZIDC9r0aTUJ7ngpK9sd+EfWGXHFt9AAH/w3Unc6dk6wWyrAVH0SktqpZdABdAYcFmGnJS0EOkpTlAoGAWd9O+J7BRWMY6plHnNMupje4BNU93ZFMi5TlJgCvPY5dxvOqU+TBc9okhrlknmVGoB6sN+8d+SlPRMFrhhOKS2TG2cwh6TMGfWwMRvqg+j89k81BhLIk/KfKX/z48J3B5IlIi5+flOwBSX6JCMQe2THSQDTSFweqwoREGHTBvRBhhUCgYA9IqG+FdsAMsyzOBYegBSz+HemofmuWe2LnCEd/SNwiM8T0QXqJ0ONOmzHfnctHYgZeNzTT/P3/XvOkbHu+AWMw+ZNDrciNJd3W59Aj0I1+tN3I2e8AjJLi0ieJ60OnN4V+6CqAEFy6FbXgiGsoEP1+/+NuHCm8B6BxCl4DKm46/FFA==+-----END PRIVATE KEY-----diff --git a/docker-compose.yml b/docker-compose.ymlindex 2b23284c..813b9939 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -634,3 +634,98 @@ services:interval: 5stimeout: 5sretries: 10++ # ================================================================+ # SSL / TLS test containers+ # One representative version per engine — the goal is to catch SSL+ # handshake regressions without multiplying the version matrix.+ # ================================================================++ test-postgres-ssl:+ image: postgres:18+ ports:+ - "${TEST_POSTGRES_SSL_PORT}:5432"+ environment:+ - POSTGRES_DB=testdb+ - POSTGRES_USER=testuser+ - POSTGRES_PASSWORD=testpassword+ volumes:+ - ./backend/internal/features/tests/testdata/ssl:/etc/ssl-test:ro+ command:+ - bash+ - -c+ - install -m 600 -o postgres -g postgres /etc/ssl-test/server.key /tmp/server.key && install -m 644 -o postgres -g postgres /etc/ssl-test/server.crt /tmp/server.crt && exec docker-entrypoint.sh postgres -c ssl=on -c ssl_cert_file=/tmp/server.crt -c ssl_key_file=/tmp/server.key -c hba_file=/etc/ssl-test/pg_hba.conf+ container_name: test-postgres-ssl+ shm_size: 1gb+ healthcheck:+ test: ["CMD-SHELL", "pg_isready -U testuser -d testdb"]+ interval: 5s+ timeout: 5s+ retries: 10++ test-mariadb-ssl:+ image: mariadb:11.8+ ports:+ - "${TEST_MARIADB_SSL_PORT}:3306"+ environment:+ - MARIADB_ROOT_PASSWORD=rootpassword+ - MARIADB_DATABASE=testdb+ - MARIADB_USER=testuser+ - MARIADB_PASSWORD=testpassword+ command:+ - --character-set-server=utf8mb4+ - --collation-server=utf8mb4_unicode_ci+ - --require-secure-transport=ON+ volumes:+ - ./mariadbdata/mariadb-ssl:/var/lib/mysql+ container_name: test-mariadb-ssl+ healthcheck:+ test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]+ interval: 5s+ timeout: 5s+ retries: 10++ test-mysql-ssl:+ image: mysql:8.4+ ports:+ - "${TEST_MYSQL_SSL_PORT}:3306"+ environment:+ - MYSQL_ROOT_PASSWORD=rootpassword+ - MYSQL_DATABASE=testdb+ - MYSQL_USER=testuser+ - MYSQL_PASSWORD=testpassword+ command:+ - --character-set-server=utf8mb4+ - --collation-server=utf8mb4_unicode_ci+ - --require_secure_transport=ON+ volumes:+ - ./mysqldata/mysql-ssl:/var/lib/mysql+ container_name: test-mysql-ssl+ healthcheck:+ test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-prootpassword"]+ interval: 5s+ timeout: 5s+ retries: 10++ test-mongodb-ssl:+ image: mongo:8.2.3-noble+ container_name: test-mongodb-ssl+ ports:+ - "${TEST_MONGODB_SSL_PORT}:27017"+ environment:+ MONGO_INITDB_ROOT_USERNAME: root+ MONGO_INITDB_ROOT_PASSWORD: rootpassword+ MONGO_INITDB_DATABASE: testdb+ volumes:+ - ./backend/internal/features/tests/testdata/ssl:/etc/ssl-test:ro+ command:+ - bash+ - -c+ - install -m 600 -o mongodb -g mongodb /etc/ssl-test/server.pem /tmp/server.pem && install -m 644 -o mongodb -g mongodb /etc/ssl-test/server.crt /tmp/server.crt && exec docker-entrypoint.sh mongod --auth --tlsMode requireTLS --tlsCertificateKeyFile /tmp/server.pem --tlsCAFile /tmp/server.crt --tlsAllowConnectionsWithoutCertificates+ healthcheck:+ test: ["CMD", "mongosh", "--tls", "--tlsAllowInvalidCertificates",+ "-u", "root", "-p", "rootpassword", "--authenticationDatabase", "admin",+ "--eval", "db.adminCommand('ping')"]+ interval: 5s+ timeout: 5s+ retries: 10diff --git a/plan.md b/plan.mdnew file mode 100644index 00000000..f6475577--- /dev/null+++ b/plan.md@@ -0,0 +1,85 @@+# Security remediation plan++Based on a third-party Trivy scan against `databasus/databasus@sha256:5676...7b97b` (v3.33.0). All findings below are verified against the current code in this repo — versions, file paths, and behaviors are confirmed real.++Order is by combined risk × ease, not by CVSS.++---++## 1. Fix deterministic AES-GCM nonce in field encryption (CRITICAL — own code)++**Where:** `backend/internal/util/encryption/secret_key_field_encryptor.go:48,112-121`++**The bug:** `deriveNonce(itemID, masterKey, nonceSize)` returns `HMAC-SHA256(masterKey, itemID)[:12]`. The nonce is fully determined by `itemID` + `masterKey`. Re-encrypting the same field on the same item (e.g. user rotates a DB password, S3 key, Slack bot token, Google Drive refresh token) reuses the same `(key, nonce)` pair on different plaintexts.++**Impact:** Nonce reuse under AES-GCM is catastrophic, not just a weakening of authentication:+- XOR of any two plaintexts encrypted under the same `(key, nonce)` is recoverable from the XOR of their ciphertexts.+- The GHASH authentication subkey `H` becomes recoverable, allowing forgery of valid auth tags for arbitrary chosen ciphertexts under that key.++**Reach:** This encryptor is used for every secret stored in the app — see callers in:+- `backend/internal/features/databases/databases/{postgresql,mysql,mariadb,mongodb}/model.go` — DB passwords+- `backend/internal/features/notifiers/models/{slack,telegram,teams,discord,email_notifier,webhook}/model.go` — bot tokens, webhook URLs, SMTP passwords, header values+- `backend/internal/features/storages/models/{s3,azure_blob,sftp,ftp,nas,google_drive,rclone}/model.go` — access keys, secret keys, connection strings, private keys, OAuth tokens++**Fix:**+- Replace `deriveNonce` with `crypto/rand.Read` to generate a fresh 12-byte random nonce for each `Encrypt` call.+- The on-wire format `enc:<base64-nonce>:<base64-ciphertext>` already stores the nonce alongside the ciphertext, so no schema migration is needed — `Decrypt` already reads the nonce from the format.+- `itemID` parameter becomes unused in `Encrypt`; either drop it from the interface or keep it as `_` argument for additional-data binding (recommend the latter — pass `itemID[:]` as AAD to `gcm.Seal`/`gcm.Open` so a ciphertext can't be moved between rows).+- Existing ciphertexts decrypt unchanged (same format, same key) — no data migration needed.++**Tests:**+- Add `Test_Encrypt_SameItem_TwiceWithDifferentPlaintext_ProducesDifferentNonces` — verify two encryptions of the same `itemID` produce different `<nonce>` parts.+- Update `Test_Encrypt_AlreadyEncrypted_ReturnsAsIs` — current behavior (idempotent on already-encrypted input) stays.+- If AAD binding is added: `Test_Decrypt_WithDifferentItemID_Fails` — ciphertext for item A must not decrypt under item B's ID.++---++## 2. Replace Debian rclone package with source build++**Where:** `Dockerfile:127` — `rclone` is currently installed via `apt-get install`, which on Debian bookworm pulls `rclone 1.60.1+dfsg-2+b5` compiled with Go 1.21.12. That binary carries its own ~15 stdlib/x-crypto/grpc CVEs entirely separate from the main Go binaries.++We already depend on `github.com/rclone/rclone v1.72.1` as a Go library (`backend/go.mod:22`), and the report recommends bumping to v1.73.5.++**Approach options:**++**Option A — Compile rclone CLI from source in a build stage** (recommended):+- Add a new build stage `FROM --platform=$BUILDPLATFORM golang:1.26.2 AS rclone-build` that clones rclone at the chosen tag and runs `go build` for both target archs.+- Drop `rclone` from the `apt-get install` line.+- `COPY --from=rclone-build /rclone-binaries/... /usr/local/bin/rclone` in the runtime stage.++**Option B — Drop the CLI entirely** if all rclone usage in the backend is via the Go library and never shells out to the binary. Worth grepping `exec.Command("rclone"` and `Path("rclone")` first.++**Steps:**+1. `grep -rn "rclone" backend/ agent/ Dockerfile` — list all CLI usages.+2. If any shell-out exists, go with Option A; else Option B.+3. Bump `github.com/rclone/rclone` in `backend/go.mod` to v1.73.5 either way (closes two critical CVEs in the library code path).+4. Verify image scan after rebuild — the ~15 stale-Go-1.21 CVEs should disappear.++---++## 3. Default external `sslmode` to `require`, not `prefer` (BREAKING — discuss first)++**Where:**+- `backend/internal/features/backups/backups/usecases/postgresql/create_backup_uc.go:462,465`+- `backend/internal/features/restores/usecases/postgresql/restore_backup_uc.go:730,733`+- `backend/internal/features/databases/databases/postgresql/model.go:1158-1170`++Currently external connections fall back to `PGSSLMODE=prefer`, which silently downgrades to plaintext if the server rejects TLS. `require` enforces TLS but errors out for self-signed-only or non-TLS PG instances.++**This is user-visible behavior change.** Need product call before shipping:+- Option A: change default to `require`, add an explicit per-database opt-out toggle in the UI for users with non-TLS PG.+- Option B: keep `prefer`, surface a warning in the UI when a connection negotiated plaintext.++Recommend Option A — safer default, opt-out is rare.++---++## Sequencing++| Order | Item | Rationale |+|---|---|---|+| 1 | Nonce fix (#1) | Own-code crypto bug; small diff; high impact |+| 2 | rclone source build + bump (#2) | Larger Dockerfile change, biggest CVE-count win |+| 3 | sslmode default (#3) | Needs product decision before code |++Item 1 is a pure code fix and can ship in a single PR. Item 2 needs Dockerfile + go.mod work. Item 3 needs a product call.