PostgreSQL backup tool with Point-In-Time-Recovery and restore verification
TypeScript backupbackupsdatabasedatabase-backupdevopsdockergolangkubernetesmariadbmongodbmysqlpgpostgrespostgresqls3self-hostedsystem-administrationtoolsweb-ui
FIX (docker): Ship the image without a baked .env, so developer SMTP settings no longer turn an unset security mode into none or log in to relays with test credentials
Rostislav Dugin8167dcdab76c
diff --git a/.dockerignore b/.dockerignoreindex 0831f60e..5a5970fd 100644--- a/.dockerignore+++ b/.dockerignore@@ -39,9 +39,9 @@ notifiers# Dist (will be built fresh)frontend/dist-# Environment files (handled separately)-.env.local-.env.development+# Environment files never enter the image, neither the backend's nor Vite's+**/.env+**/.env.*# Logs and temp files**/*.logdiff --git a/Dockerfile b/Dockerfileindex 8573b729..51d4cad5 100644--- a/Dockerfile+++ b/Dockerfile@@ -11,13 +11,6 @@ COPY frontend/package.json frontend/pnpm-lock.yaml ./RUN corepack enable && pnpm install --frozen-lockfileCOPY frontend/ ./-# Copy .env file (with fallback to .env.production.example)-RUN if [ ! -f .env ]; then \- if [ -f .env.production.example ]; then \- cp .env.production.example .env; \- fi; \- fi-RUN pnpm build# ========= BUILD BACKEND =========@@ -186,16 +179,9 @@ COPY --from=backend-build /app/ui/build ./ui/buildRUN mkdir -p ./agent-binariesCOPY --from=verification-agent-build /verification-agent-binaries/* ./agent-binaries/-# Bake .env.example as /.env so the binary has defaults when no env file is-# mounted. The backend looks for .env at the parent of cwd (= /app), i.e. /.-# Real env vars (-e, compose, k8s) win, then the connection string start.sh-# publishes for the embedded database, then these defaults. godotenv.Load does-# not overwrite already-set variables, which is what puts these defaults last.-# DATABASE_DSN is stripped because its development password cannot authenticate-# against the embedded database, whose password is generated at every start.-# Keeping it would turn a missing configuration into an authentication failure.-COPY .env.example /.env-RUN sed -i '/^DATABASE_DSN=/d' /.env+# The image carries no .env file. Every setting comes from the operator (-e,+# compose, k8s) or from the default the backend defines in code, so nothing+# from a development environment can reach a running instance.COPY --chmod=0755 docker/start.sh /app/start.shdiff --git a/backend/internal/config/config.go b/backend/internal/config/config.goindex 335c7ceb..8e4be1ad 100644--- a/backend/internal/config/config.go+++ b/backend/internal/config/config.go@@ -141,12 +141,17 @@ func loadEnvVariables() {adoptPublishedDatabaseDsnIfUnset(publishedDatabaseDsnPath)- log.Info("trying to load .env", "path", envPath)- if err := godotenv.Load(envPath); err != nil {+ isEnvFileLoaded, err := loadEnvFileIfPresent(envPath)+ if err != nil {log.Error("error loading .env file from repo root", "path", envPath, "error", err)logger.ExitAfterFlush(1)}- log.Info("successfully loaded .env", "path", envPath)++ if isEnvFileLoaded {+ log.Info("successfully loaded .env", "path", envPath)+ } else {+ log.Info("no .env file found, using the process environment only", "path", envPath)+ }// Empty values for non-string fields (e.g. SMTP_PORT=) crash cleanenv's// strconv parsing. Drop them so cleanenv falls back to the Go zero value.@@ -262,8 +267,27 @@ func validateSMTPSettings(env *EnvVariables) error {return nil}+// The Docker image carries no .env, so every setting there comes from the operator or from a+// code default. A development checkout still reads its own .env. Variables that are already+// set, even to an empty value, keep their value.+func loadEnvFileIfPresent(envPath string) (bool, error) {+ if _, err := os.Stat(envPath); err != nil {+ if errors.Is(err, os.ErrNotExist) {+ return false, nil+ }++ return false, err+ }++ if err := godotenv.Load(envPath); err != nil {+ return false, err+ }++ return true, nil+}+// An operator-supplied connection string wins, then the one startup published, then-// whatever the baked defaults still carry.+// whatever a development .env carries.func adoptPublishedDatabaseDsnIfUnset(publishedDsnPath string) {if _, isSet := os.LookupEnv(databaseDsnEnvVariable); isSet {returndiff --git a/backend/internal/config/config_test.go b/backend/internal/config/config_test.goindex eb85ac83..a306b40f 100644--- a/backend/internal/config/config_test.go+++ b/backend/internal/config/config_test.go@@ -227,3 +227,74 @@ func Test_ValidateSMTPSettings_AcceptsUsableValues(t *testing.T) {})}}++const envFileTestVariable = "DATABASUS_ENV_FILE_TEST_VALUE"++func Test_LoadEnvFileIfPresent_WhenFileIsMissing_ReportsNotLoadedWithoutError(t *testing.T) {+ missingEnvPath := filepath.Join(t.TempDir(), ".env")++ isLoaded, err := loadEnvFileIfPresent(missingEnvPath)++ require.NoError(t, err)+ assert.False(t, isLoaded)+}++func Test_LoadEnvFileIfPresent_WhenVariableIsUnset_SetsItFromTheFile(t *testing.T) {+ clearEnvFileTestVariable(t)+ envPath := writeEnvFile(t, envFileTestVariable+"=from-file\n")++ isLoaded, err := loadEnvFileIfPresent(envPath)++ require.NoError(t, err)+ assert.True(t, isLoaded)+ assert.Equal(t, "from-file", os.Getenv(envFileTestVariable))+}++func Test_LoadEnvFileIfPresent_WhenVariableIsAlreadySet_KeepsTheProcessValue(t *testing.T) {+ testCases := []struct {+ name string+ processValue string+ }{+ {name: "non-empty value", processValue: "from-process"},+ {name: "empty value", processValue: ""},+ }++ for _, testCase := range testCases {+ t.Run(testCase.name, func(t *testing.T) {+ t.Setenv(envFileTestVariable, testCase.processValue)+ envPath := writeEnvFile(t, envFileTestVariable+"=from-file\n")++ isLoaded, err := loadEnvFileIfPresent(envPath)++ require.NoError(t, err)+ assert.True(t, isLoaded)+ assert.Equal(t, testCase.processValue, os.Getenv(envFileTestVariable))+ })+ }+}++func Test_LoadEnvFileIfPresent_WhenFileIsMalformed_ReturnsError(t *testing.T) {+ clearEnvFileTestVariable(t)+ envPath := writeEnvFile(t, "not a variable assignment\n")++ isLoaded, err := loadEnvFileIfPresent(envPath)++ require.Error(t, err)+ assert.False(t, isLoaded)+}++func clearEnvFileTestVariable(t *testing.T) {+ t.Helper()++ t.Setenv(envFileTestVariable, "")+ require.NoError(t, os.Unsetenv(envFileTestVariable))+}++func writeEnvFile(t *testing.T, contents string) string {+ t.Helper()++ envPath := filepath.Join(t.TempDir(), ".env")+ require.NoError(t, os.WriteFile(envPath, []byte(contents), 0o600))++ return envPath+}diff --git a/backend/internal/features/email/email_test.go b/backend/internal/features/email/email_test.goindex cdf891f5..926f7d9a 100644--- a/backend/internal/features/email/email_test.go+++ b/backend/internal/features/email/email_test.go@@ -64,3 +64,12 @@ func Test_NewEmailSMTPSenderFromEnv_WithoutSecurity_UsesPortDefault(t *testing.Tassert.Equal(t, "tls", string(implicitTLSSender.connection.Security))assert.Equal(t, "starttls", string(upgradeSender.connection.Security))}++func Test_NewEmailSMTPSenderFromEnv_ForRelayWithoutCredentials_UsesStartTLSWithoutAuth(t *testing.T) {+ relaySender := newEmailSMTPSenderFromEnv(&config.EnvVariables{SMTPHost: "relay.example.com", SMTPPort: 25})++ assert.True(t, relaySender.IsConfigured())+ assert.Equal(t, "starttls", string(relaySender.connection.Security))+ assert.Empty(t, relaySender.connection.Username)+ assert.Empty(t, relaySender.connection.Password)+}diff --git a/backend/internal/util/smtp_transport/auth_test.go b/backend/internal/util/smtp_transport/auth_test.goindex 8359654d..66f1b2cd 100644--- a/backend/internal/util/smtp_transport/auth_test.go+++ b/backend/internal/util/smtp_transport/auth_test.go@@ -86,6 +86,25 @@ func Test_Send_WhenServerOffersNoKnownMechanism_Fails(t *testing.T) {require.ErrorIs(t, err, ErrAuthMechanismNotOffered)}+func Test_Send_WithStartTLSAndNoCredentials_DeliversWithoutAuth(t *testing.T) {+ server := startFakeServer(t, fakeServerOptions{startTLSConfig: newSelfSignedTLSConfig(t)})++ relayConnection := server.getConnection(SecurityStartTLS)+ relayConnection.Username = ""+ relayConnection.Password = ""++ err := Send(t.Context(), relayConnection, newTestMessage(t))+ require.NoError(t, err)++ server.waitForSessionEnd(t)+ assert.Equal(+ t,+ []string{"EHLO", "STARTTLS", "EHLO", "MAIL", "RCPT", "DATA", "QUIT"},+ server.getCommandVerbs(),+ )+ assert.Len(t, server.getMessages(), 1)+}+func Test_Auth_OnUnencryptedConnectionWithoutOptIn_Refuses(t *testing.T) {unencryptedServer := &smtp.ServerInfo{Name: "relay.example.com", TLS: false}userCredentials := credentials{fakeServerUsername, fakeServerPassword, false}diff --git a/openspec/changes/archive/2026-10-10-drop-baked-env-from-image/.openspec.yaml b/openspec/changes/archive/2026-10-10-drop-baked-env-from-image/.openspec.yamlnew file mode 100644index 00000000..53f62d70--- /dev/null+++ b/openspec/changes/archive/2026-10-10-drop-baked-env-from-image/.openspec.yaml@@ -0,0 +1,2 @@+schema: spec-driven+created: 2026-10-10diff --git a/openspec/changes/archive/2026-10-10-drop-baked-env-from-image/design.md b/openspec/changes/archive/2026-10-10-drop-baked-env-from-image/design.mdnew file mode 100644index 00000000..ba7bb802--- /dev/null+++ b/openspec/changes/archive/2026-10-10-drop-baked-env-from-image/design.md@@ -0,0 +1,92 @@+## Context++See proposal.md for the motivation. The current state that shapes the approach:++- `Dockerfile:197` copies the developer `.env.example` to `/.env`, and `Dockerfile:198` strips only `DATABASE_DSN` from it. The comment at `Dockerfile:189-196` explains the copy as a source of defaults, but no production setting depends on it (see the table below).+- `backend/internal/config/config.go:145` calls `godotenv.Load` and exits the process when the file is missing. The image keeps a file only to satisfy this call.+- `godotenv.Load` does not overwrite a variable that already exists, even with an empty value. `unsetEmptyEnvVars` (`config.go:298`) then removes empty variables, so the code sees them as unset. That is why `SMTP_USER=` worked as a workaround while a missing `SMTP_USER` picked up the baked test login.+- `backend/internal/util/logger/settings.go:244` loads the same file and already ignores a missing one.+- `backend/internal/features/email/di.go` derives the security mode from the port only when `SMTP_SECURITY` is empty. `smtp_transport.openSession` skips authentication when either the username or the password is empty. Both defaults are correct, and the baked file is what bypassed them.+- `docker/start.sh:147` decides the frontend's "mail configured" flag from the real environment, while the backend reads the merged one. With no SMTP variables set, the two disagree today.+- The frontend stage at `Dockerfile:14-18` looks for `frontend/.env.production.example`, which was deleted in 082f8f9c. `COPY frontend/ ./` carries any local `frontend/.env`, `frontend/.env.local`, `frontend/.env.production` or `frontend/.env.production.local` into the build, because the `.env.local` and `.env.development` entries in `.dockerignore` match only at the root. Vite reads those files in `pnpm build`, and `frontend/src/constants.ts:32-43` falls back to `import.meta.env.VITE_*` for the OAuth client IDs, the mail flag and the Turnstile key, so their values would be baked into the bundle.++What production reads from the baked file today, and what replaces it:++| Variable | Replacement after the change |+|---|---|+| `ENV_MODE` | `ENV ENV_MODE=production` in the Dockerfile already wins |+| `DATABASE_DSN` | already stripped; `start.sh` publishes the embedded one |+| `LOG_LEVEL`, `LOG_FILE_IS_ENABLED` | the code defaults (info, enabled) equal the baked values |+| `SHOW_DB_INSTALLATION_VERIFICATION_LOGS` | `config.go` sets `true` when empty, equal to the baked value |+| `SMTP_*` | unset; this is the fix |+| `TEST_*`, `GOOSE_*`, `DEV_DB_*`, `WAL_BACKUP_*`, `DATABASE_URL`, `VITE_*` | not read by the production binary; migrations take their DSN from the config (`backend/cmd/main.go:502-503`) |+| OAuth, Turnstile, `DATABASUS_URL`, `OPEN_TELEMETRY_*` | empty in the file, so nothing changes |++## Goals / Non-Goals++**Goals:**++- The image contains no environment file at all, so no future addition to `.env.example` can reach production.+- A developer's local `.env` files never enter a Docker build context.+- Startup without an environment file succeeds and says so in the log.++**Non-Goals:**++- Changing the precedence between the process environment, the published embedded DSN and the file.+- Making `logger/settings.go` and `config.go` share one loader. They load the same file for different reasons at different times, and merging them is a separate refactor.++## Decisions++### Remove the file from the image instead of shipping an empty or production-only one++The Dockerfile drops the `COPY` and the `sed` line, and the backend stops requiring the file.++Alternatives rejected:++- **An empty `/.env` (`RUN touch /.env`).** This is a one-line fix, but it keeps the slot open. The next person who needs a default would put it there, and we would be back to values that bypass the code defaults.+- **A separate `docker/.env.production` with production values.** Every value it could hold already exists as a code default or a Dockerfile `ENV`. A second source of defaults would drift from the first. The previous `backend/.env.production.example` did exactly that and carried a development database password.+- **Stripping `SMTP_*` with `sed`.** This fixes the symptom for one prefix and leaves every other development value in the image.++### Make the file optional in `config.go`; a missing required variable stays fatal++Before calling `godotenv.Load`, `config.go` checks whether the file exists. A missing file logs at info level that no environment file was loaded, and startup continues. A file that exists but cannot be read or parsed stays fatal, because silently ignoring a broken file would hide a misconfiguration. The existing required-field checks keep catching a development checkout that has no `.env`.++The existence check and the load go into a small helper that returns whether the file was loaded and any error. That makes it testable without running `loadEnvVariables`, which exits the process on failure.++Alternatives rejected:++- **Fatal in development, optional in production.** The mode comes from `ENV_MODE`, which the file itself may set, so the decision would depend on the thing being loaded. The missing-variable checks already give a developer a precise message.+- **Ignoring every load error, the way `logger/settings.go` does.** A malformed file would then disappear silently from the configuration.++### Exclude every `.env` file from the build context and delete the dead frontend block++`.dockerignore` gets `**/.env` and `**/.env.*`, which replace the root-only `.env.local` and `.env.development` entries. The root `.env.example` no longer needs to be in the context once the copy is gone, so no exception is needed for it. `Dockerfile:14-18` is deleted. The frontend build reads `VITE_APP_VERSION` from the `ENV` at `Dockerfile:8`, and runtime flags come from `runtime-config.js`, which `start.sh` generates. The frontend build needs no file.++Alternatives rejected:++- **Keep the block and only add the ignore rule.** The block would still refer to a file that does not exist.+- **Exclude only `**/.env`.** Vite also reads `.env.local`, `.env.production` and `.env.production.local`, so local values would still reach the bundle.++### Pin the behavior with Go tests, not an image test++Tests in `config_test.go` cover the helper: a missing file, a file that loads, a file that does not override a variable already set, even to an empty value, and a malformed file. A test in `features/email` covers a host and port with no credentials and no security mode, which must give `starttls`. A transport test against the existing fake SMTP server sends with empty credentials over STARTTLS and asserts that the delivery succeeds and no `AUTH` command is issued. The tests run the binary's real loading path, so they would catch a code-level regression.++Alternative rejected: a CI step that runs the built image and asserts that `/.env` does not exist. It would catch a re-added `COPY`, but it costs an image build per run, and the proposal scopes it out. A Dockerfile comment at the former copy site records why there is no environment file, which is the cheaper guard.++### Constraints from module rules++- Root `AGENTS.md`: keep Dockerfiles free of secrets. The baked file carried development passwords, so removing it also satisfies this rule.+- Root `AGENTS.md`: no unrequested backward compatibility. Nothing replaces the baked file, and the BREAKING note in the proposal states what operators lose.+- `backend/AGENTS.md`: never log secrets. The new log line names only the file path and whether it was loaded.+- No ADR in `adr/` covers configuration loading, so this change does not conflict with an accepted decision.++## Risks / Trade-offs++- [An operator unknowingly relied on a baked SMTP value, for example a working relay that accepted the test login] → The relay would have needed to accept `[email protected]`/`password`, which is implausible. The release notes name the change, and the logged SMTP failure points at the missing variable.+- [Someone re-adds a `COPY` of an env file to the Dockerfile] → The Dockerfile comment explains why there is none, and the review hooks see the diff. A CI image check stays out of scope by decision.+- [A developer runs the backend without `.env` and sees an unfamiliar error] → The info line saying no environment file was loaded comes right before the configuration error. A manual run from a directory without `.env` and with an empty environment logged `DATABASE_DSN is empty` and exited with status 1.+- [An operator mounts their own file at `/.env`] → It keeps working, because the backend still loads the file when it exists.++## Migration Plan++Nothing to migrate in data. Operators upgrading an image that relied on a baked value set that variable explicitly. Rolling back means reverting the commit; no state depends on it.diff --git a/openspec/changes/archive/2026-10-10-drop-baked-env-from-image/proposal.md b/openspec/changes/archive/2026-10-10-drop-baked-env-from-image/proposal.mdnew file mode 100644index 00000000..15e5dbbe--- /dev/null+++ b/openspec/changes/archive/2026-10-10-drop-baked-env-from-image/proposal.md@@ -0,0 +1,37 @@+## Why++The Docker image ships the developer `.env.example` as `/.env`, and the backend loads it for every variable the operator did not set. Since v3.34 every production instance has silently inherited the developer mail settings: a mailpit host, test credentials, a `databasus.com` sender and, since v3.60, the `none` security mode. An operator who sets `SMTP_HOST` and `SMTP_PORT` for a relay without authentication gets an authentication attempt with the test credentials, which the relay rejects. An operator who sets real credentials but leaves `SMTP_SECURITY` unset gets the `none` mode, which sends the password unencrypted instead of using STARTTLS. Nothing a developer puts in `.env.example` should reach a production instance.++## What Changes++- The Docker image no longer contains any environment file. Every setting an operator does not supply stays unset, and the backend falls back to its own defaults in code.+- The backend treats the environment file as optional. When the file is missing, it starts from the process environment alone and logs that no file was loaded. A missing required variable still stops startup with a message saying a required setting is missing.+- **BREAKING:** An image-based instance that relied on a value from the baked file now sees that variable unset. With no SMTP variables set, the backend no longer thinks a mail server exists, so it matches the settings screen. With SMTP partly configured, the unset variables fall back to their defined defaults: no authentication without both a username and a password, a security mode derived from the port, and the sender checks that already apply. No production default is lost, since every non-SMTP value in the file either matches the code default or is overridden by the image. The bake step and its `DATABASE_DSN` stripping are deleted, with no fallback file left in their place.+- The frontend build stage drops its lookup of `frontend/.env.production.example`, a file that no longer exists. The Docker build context excludes every `.env` and `.env.*` file at any depth, so neither the backend's nor the frontend's local environment (including Vite's `.env.local` and `.env.production` variants) can reach a locally built image.++## Capabilities++### New Capabilities++- `runtime-configuration`: where the application's settings come from in a deployed image and in development, and what happens when the environment file is missing.++### Modified Capabilities++- `outgoing-email`: the instance mail server reads only values the operator supplied. A variable the operator did not set counts as unset, so an unset `SMTP_SECURITY` falls back to the port-based default and an unset username or password means no authentication.++## Out of scope++- Reworking `.env.example` itself or the development workflow around it. Developers still copy it to `.env`.+- Changing any SMTP default, validation rule or delivery behavior already defined in `outgoing-email`.+- A CI step that inspects the built image. Go tests pin the loading and delivery behavior; a re-added copy step in the Dockerfile is guarded only by the Dockerfile comment and review.+- Replying on the GitHub issue or publishing a workaround for v3.60.0 users.+- Other env-driven subsystems (OAuth, Turnstile, logging) beyond confirming that their code defaults match what the baked file supplied.++## Impact++- `Dockerfile`: remove `COPY .env.example /.env`, the `DATABASE_DSN` `sed` line and the dead frontend `.env.production.example` block.+- `.dockerignore`: exclude `**/.env` and `**/.env.*`, replacing the root-only `.env.local` and `.env.development` entries.+- `backend/internal/config/config.go`: load the environment file only when it exists.+- `backend/internal/config/config_test.go`: cover startup without a file.+- `backend/internal/util/smtp_transport` tests: cover delivery without credentials over STARTTLS.+- Module rules: root `AGENTS.md` (Dockerfile, build context) and `backend/AGENTS.md` (config loading).diff --git a/openspec/changes/archive/2026-10-10-drop-baked-env-from-image/specs/outgoing-email/spec.md b/openspec/changes/archive/2026-10-10-drop-baked-env-from-image/specs/outgoing-email/spec.mdnew file mode 100644index 00000000..1ec306a3--- /dev/null+++ b/openspec/changes/archive/2026-10-10-drop-baked-env-from-image/specs/outgoing-email/spec.md@@ -0,0 +1,58 @@+## MODIFIED Requirements++### Requirement: Instance mail server configuration++The instance mail server SHALL be configured through environment variables: `SMTP_HOST`, `SMTP_PORT`, `SMTP_USER`, `SMTP_PASSWORD`, `SMTP_FROM`, `SMTP_SECURITY`, `SMTP_HELO_NAME` and `SMTP_INSECURE_SKIP_VERIFY`. `SMTP_INSECURE_SKIP_VERIFY` has no effect in the `none` mode. A variable the operator did not set, or set to an empty value, SHALL count as unset.++When `SMTP_SECURITY` is not set, the mode SHALL be `tls` for port 465 and `starttls` for every other port. When `SMTP_USER` or `SMTP_PASSWORD` is not set, instance mail SHALL be delivered without authentication. The instance SHALL refuse to start, with a message naming the variable, when `SMTP_HOST` is set without a positive `SMTP_PORT`, when `SMTP_SECURITY` holds a value other than `tls`, `starttls` or `none`, when `SMTP_HELO_NAME` is set to something that is neither a host name nor an address literal, or when `SMTP_FROM` is set to something that is neither an email address nor a display name followed by an address in angle brackets.++#### Scenario: Security mode left unset on port 587++- **WHEN** the instance starts with `SMTP_HOST` set, `SMTP_PORT=587` and no `SMTP_SECURITY`+- **THEN** instance mail is delivered in the `starttls` mode++#### Scenario: Security mode left unset on port 465++- **WHEN** the instance starts with `SMTP_HOST` set, `SMTP_PORT=465` and no `SMTP_SECURITY`+- **THEN** instance mail is delivered in the `tls` mode++#### Scenario: Relay without credentials++- **WHEN** the published image starts with only `SMTP_HOST`, `SMTP_PORT=25` and `SMTP_FROM` set, against a relay that offers STARTTLS but no authentication+- **THEN** instance mail is delivered in the `starttls` mode without any authentication attempt++#### Scenario: Unknown security mode++- **WHEN** the instance starts with `SMTP_SECURITY=ssl`+- **THEN** it refuses to start and names `SMTP_SECURITY` and the accepted values++#### Scenario: Unreadable sender address++- **WHEN** the instance starts with `SMTP_FROM=noreply at example.com`+- **THEN** it refuses to start and names `SMTP_FROM`++#### Scenario: Invalid greeting name++- **WHEN** the instance starts with `SMTP_HELO_NAME=my relay`+- **THEN** it refuses to start and names `SMTP_HELO_NAME`++## ADDED Requirements++### Requirement: Instance mail settings come only from the operator++The instance mail server SHALL use only values the operator supplied, plus the defaults this specification defines. In the published image, no host, credential, sender or security mode SHALL come from a file shipped inside the image or from an environment file present on the machine that built it. In particular, an unset `SMTP_SECURITY` SHALL never resolve to `none`, so credentials are never sent unencrypted unless the operator chose `none` explicitly.++#### Scenario: Real credentials without a security mode++- **WHEN** the published image starts with `SMTP_HOST`, `SMTP_PORT=587`, `SMTP_USER` and `SMTP_PASSWORD` set and no `SMTP_SECURITY`+- **THEN** the connection is upgraded with STARTTLS before the credentials are sent, and if the server does not offer the upgrade, the delivery fails without sending them++#### Scenario: No mail settings at all++- **WHEN** the published image starts without any `SMTP_*` variable+- **THEN** the settings screen reports the mail server as not configured, the sign-in screen offers no password reset link, a test message from the settings screen is refused because no mail server is configured, and an invitation is logged as skipped instead of being sent++#### Scenario: Sender left unset++- **WHEN** the published image starts with `SMTP_HOST=relay.example.com`, `SMTP_PORT=25` and no `SMTP_USER` or `SMTP_FROM`+- **THEN** the envelope sender is `[email protected]`, and `databasus.com` appears nowhere in the senderdiff --git a/openspec/changes/archive/2026-10-10-drop-baked-env-from-image/specs/runtime-configuration/spec.md b/openspec/changes/archive/2026-10-10-drop-baked-env-from-image/specs/runtime-configuration/spec.mdnew file mode 100644index 00000000..5330e35e--- /dev/null+++ b/openspec/changes/archive/2026-10-10-drop-baked-env-from-image/specs/runtime-configuration/spec.md@@ -0,0 +1,40 @@+## Purpose++Defines where Databasus takes its settings from in the published Docker image and in a development checkout, and how startup behaves when no environment file is present.++## ADDED Requirements++### Requirement: The published image carries no preset settings++The published Docker image SHALL NOT contain an environment file or any other source of setting values beyond the few the image itself defines to run: the application mode, the version, the processor architecture and the connection to the embedded database, which the container prepares at every start. Every other setting SHALL come from the operator or, when the operator leaves it unset, from the default the application defines for it. No environment file from the build machine SHALL reach the image, neither the backend's nor the frontend's.++The application defaults for an unset setting are: log level `info`, log file enabled, database installation verification logs shown, and the instance mail server, OAuth sign-in, bot protection and log export all off.++#### Scenario: Operator sets nothing optional++- **WHEN** an operator starts the published image without any optional setting+- **THEN** the settings screen reports the mail server as not configured, the sign-in screen offers neither GitHub nor Google sign-in nor a bot check, informational messages are logged, a log file is written, and the database installation verification output appears in the startup log++#### Scenario: Image built on a developer machine++- **WHEN** a developer whose checkout contains environment files for the backend and the frontend, including local and production variants, builds the image locally+- **THEN** the resulting image contains none of those files, and the built frontend contains none of their values++### Requirement: The environment file is optional++When the application starts without an environment file, it SHALL read its settings from the process environment alone and SHALL report in its log that no environment file was loaded. When an environment file exists, the application SHALL read it and SHALL NOT let it override a variable that is already set in the process environment, even one set to an empty value. A required setting that is missing from both SHALL still stop startup with a log message saying that a required setting is missing.++#### Scenario: Container without an environment file++- **WHEN** the published image starts with only the variables the operator passed in+- **THEN** the application starts and logs that no environment file was loaded++#### Scenario: Development checkout without an environment file++- **WHEN** a developer starts the backend from a checkout that has no environment file, with neither the application mode nor the database connection set in the shell+- **THEN** the log says that no environment file was loaded, startup stops with a message saying a required setting is missing, and the process exits with a non-zero status++#### Scenario: Operator value wins over the file++- **WHEN** a variable is set in the process environment and the environment file sets it to a different value+- **THEN** the application uses the value from the process environmentdiff --git a/openspec/changes/archive/2026-10-10-drop-baked-env-from-image/tasks.md b/openspec/changes/archive/2026-10-10-drop-baked-env-from-image/tasks.mdnew file mode 100644index 00000000..3ea331fe--- /dev/null+++ b/openspec/changes/archive/2026-10-10-drop-baked-env-from-image/tasks.md@@ -0,0 +1,21 @@+## 1. Optional environment file in the backend++- [x] 1.1 In `backend/internal/config/config.go`, replace the unconditional `godotenv.Load` with a helper that loads the file only when it exists and returns whether it was loaded. Log at info level when no file was found. Keep a read or parse failure of an existing file fatal. Verify with `go test ./internal/config/... -count=1` after task 1.2.+- [x] 1.2 Add tests to `backend/internal/config/config_test.go` for the helper: a missing file is reported as not loaded without an error; an existing file sets an unset variable; an existing file does not override a variable already set in the process environment, including one set to an empty value; a malformed file returns an error. Verify that `go test ./internal/config/... -count=1` passes.+- [x] 1.3 Add a test to `backend/internal/features/email/email_test.go` for a host and port 25 with no username, password or security mode: the sender is configured, the mode is `starttls` and the connection carries no credentials. Verify that `go test ./internal/features/email/... -count=1` passes.+- [x] 1.4 Add a test to `backend/internal/util/smtp_transport/auth_test.go` that uses the existing fake server offering STARTTLS and no `AUTH`, sends with an empty username and password in the `starttls` mode, and asserts that the delivery succeeds and the recorded commands contain no `AUTH`. Verify that `go test ./internal/util/smtp_transport/... -count=1` passes.+- [x] 1.5 Move the checkout's `.env` aside, unset `ENV_MODE` and `DATABASE_DSN` in the shell and start the backend with `go run ./cmd/main.go` from `backend/`. Verify that the log says no environment file was loaded, then reports a missing required setting, and that the process exits with a non-zero status. Restore `.env` afterwards.++## 2. Image and build context++- [x] 2.1 In `Dockerfile`, delete `COPY .env.example /.env`, the `sed` line that strips `DATABASE_DSN` and the comment above them. Replace them with a short comment saying that the image carries no environment file and that settings come from the operator or from code defaults. Verify that `grep -n '\.env' Dockerfile` shows no copy of an env file.+- [x] 2.2 In `Dockerfile`, delete the frontend block that looks for `.env.production.example`. Verify that `docker build .` completes and the frontend stage still runs `pnpm build`.+- [x] 2.3 In `.dockerignore`, replace the root-only `.env.local` and `.env.development` entries with `**/.env` and `**/.env.*`. Create a dummy `frontend/.env` and a dummy `frontend/.env.local` with `VITE_GITHUB_CLIENT_ID=leak-check`, build the image, then delete both files. Verify that `find / -name '.env*'` in the image returns nothing and that `grep -r leak-check /app/ui/build` finds nothing.+- [x] 2.4 Run the built image with no optional variable. Verify that the log says no environment file was loaded, that informational messages and the database installation verification output appear in the startup log, and that a log file is written under the data folder. Verify that the generated `runtime-config.js` has empty OAuth client IDs and Turnstile key and `IS_EMAIL_CONFIGURED: 'false'`, that the settings screen reports the mail server as not configured, that the sign-in screen shows no password reset link, and that a test message from the settings screen is refused because no mail server is configured.+- [x] 2.5 Run the built image with only `SMTP_HOST` and `SMTP_PORT` set. Verify that the settings screen reports the mail server as configured and the sign-in screen shows the password reset link.++## 3. Documentation and verification++- [x] 3.1 Check the published configuration docs and `.env.example` comments for any statement that the image ships defaults from `.env.example`, and correct it. Verify with `grep -rn "env.example" website/ docs/ AGENTS.md backend/AGENTS.md` that no remaining text claims the image uses it.+- [x] 3.2 Run `make lint` and `make test` in `backend/` (or `make test-fedora` on a Fedora host). Verify that both pass.+- [x] 3.3 Run `openspec validate drop-baked-env-from-image --strict` and the mandatory implementation review hook. Verify that validation passes and every blocking review finding is resolved.diff --git a/openspec/specs/outgoing-email/spec.md b/openspec/specs/outgoing-email/spec.mdindex 50b9e10b..5a140313 100644--- a/openspec/specs/outgoing-email/spec.md+++ b/openspec/specs/outgoing-email/spec.md@@ -70,9 +70,9 @@ An error produced by a delivery SHALL NOT contain the mail server password, wher### Requirement: Instance mail server configuration-The instance mail server SHALL be configured through environment variables: `SMTP_HOST`, `SMTP_PORT`, `SMTP_USER`, `SMTP_PASSWORD`, `SMTP_FROM`, `SMTP_SECURITY`, `SMTP_HELO_NAME` and `SMTP_INSECURE_SKIP_VERIFY`. `SMTP_INSECURE_SKIP_VERIFY` has no effect in the `none` mode.+The instance mail server SHALL be configured through environment variables: `SMTP_HOST`, `SMTP_PORT`, `SMTP_USER`, `SMTP_PASSWORD`, `SMTP_FROM`, `SMTP_SECURITY`, `SMTP_HELO_NAME` and `SMTP_INSECURE_SKIP_VERIFY`. `SMTP_INSECURE_SKIP_VERIFY` has no effect in the `none` mode. A variable the operator did not set, or set to an empty value, SHALL count as unset.-When `SMTP_SECURITY` is not set, the mode SHALL be `tls` for port 465 and `starttls` for every other port. The instance SHALL refuse to start, with a message naming the variable, when `SMTP_HOST` is set without a positive `SMTP_PORT`, when `SMTP_SECURITY` holds a value other than `tls`, `starttls` or `none`, when `SMTP_HELO_NAME` is set to something that is neither a host name nor an address literal, or when `SMTP_FROM` is set to something that is neither an email address nor a display name followed by an address in angle brackets.+When `SMTP_SECURITY` is not set, the mode SHALL be `tls` for port 465 and `starttls` for every other port. When `SMTP_USER` or `SMTP_PASSWORD` is not set, instance mail SHALL be delivered without authentication. The instance SHALL refuse to start, with a message naming the variable, when `SMTP_HOST` is set without a positive `SMTP_PORT`, when `SMTP_SECURITY` holds a value other than `tls`, `starttls` or `none`, when `SMTP_HELO_NAME` is set to something that is neither a host name nor an address literal, or when `SMTP_FROM` is set to something that is neither an email address nor a display name followed by an address in angle brackets.#### Scenario: Security mode left unset on port 587@@ -84,6 +84,11 @@ When `SMTP_SECURITY` is not set, the mode SHALL be `tls` for port 465 and `start- **WHEN** the instance starts with `SMTP_HOST` set, `SMTP_PORT=465` and no `SMTP_SECURITY`- **THEN** instance mail is delivered in the `tls` mode+#### Scenario: Relay without credentials++- **WHEN** the published image starts with only `SMTP_HOST`, `SMTP_PORT=25` and `SMTP_FROM` set, against a relay that offers STARTTLS but no authentication+- **THEN** instance mail is delivered in the `starttls` mode without any authentication attempt+#### Scenario: Unknown security mode- **WHEN** the instance starts with `SMTP_SECURITY=ssl`@@ -99,6 +104,25 @@ When `SMTP_SECURITY` is not set, the mode SHALL be `tls` for port 465 and `start- **WHEN** the instance starts with `SMTP_HELO_NAME=my relay`- **THEN** it refuses to start and names `SMTP_HELO_NAME`+### Requirement: Instance mail settings come only from the operator++The instance mail server SHALL use only values the operator supplied, plus the defaults this specification defines. In the published image, no host, credential, sender or security mode SHALL come from a file shipped inside the image or from an environment file present on the machine that built it. In particular, an unset `SMTP_SECURITY` SHALL never resolve to `none`, so credentials are never sent unencrypted unless the operator chose `none` explicitly.++#### Scenario: Real credentials without a security mode++- **WHEN** the published image starts with `SMTP_HOST`, `SMTP_PORT=587`, `SMTP_USER` and `SMTP_PASSWORD` set and no `SMTP_SECURITY`+- **THEN** the connection is upgraded with STARTTLS before the credentials are sent, and if the server does not offer the upgrade, the delivery fails without sending them++#### Scenario: No mail settings at all++- **WHEN** the published image starts without any `SMTP_*` variable+- **THEN** the settings screen reports the mail server as not configured, the sign-in screen offers no password reset link, a test message from the settings screen is refused because no mail server is configured, and an invitation is logged as skipped instead of being sent++#### Scenario: Sender left unset++- **WHEN** the published image starts with `SMTP_HOST=relay.example.com`, `SMTP_PORT=25` and no `SMTP_USER` or `SMTP_FROM`+- **THEN** the envelope sender is `[email protected]`, and `databasus.com` appears nowhere in the sender+### Requirement: One answer to whether the instance mail server is configuredThe instance mail server SHALL count as configured exactly when `SMTP_HOST` is set. `DATABASUS_URL` SHALL NOT affect that answer. The settings screen, the second-factor switch, the sign-in screen's password reset link and the backend's own checks SHALL all rely on this one answer.diff --git a/openspec/specs/runtime-configuration/spec.md b/openspec/specs/runtime-configuration/spec.mdnew file mode 100644index 00000000..72e8695e--- /dev/null+++ b/openspec/specs/runtime-configuration/spec.md@@ -0,0 +1,42 @@+# Runtime Configuration Specification++## Purpose++Defines where Databasus takes its settings from in the published Docker image and in a development checkout, and how startup behaves when no environment file is present.++## Requirements++### Requirement: The published image carries no preset settings++The published Docker image SHALL NOT contain an environment file or any other source of setting values beyond the few the image itself defines to run: the application mode, the version, the processor architecture and the connection to the embedded database, which the container prepares at every start. Every other setting SHALL come from the operator or, when the operator leaves it unset, from the default the application defines for it. No environment file from the build machine SHALL reach the image, neither the backend's nor the frontend's.++The application defaults for an unset setting are: log level `info`, log file enabled, database installation verification logs shown, and the instance mail server, OAuth sign-in, bot protection and log export all off.++#### Scenario: Operator sets nothing optional++- **WHEN** an operator starts the published image without any optional setting+- **THEN** the settings screen reports the mail server as not configured, the sign-in screen offers neither GitHub nor Google sign-in nor a bot check, informational messages are logged, a log file is written, and the database installation verification output appears in the startup log++#### Scenario: Image built on a developer machine++- **WHEN** a developer whose checkout contains environment files for the backend and the frontend, including local and production variants, builds the image locally+- **THEN** the resulting image contains none of those files, and the built frontend contains none of their values++### Requirement: The environment file is optional++When the application starts without an environment file, it SHALL read its settings from the process environment alone and SHALL report in its log that no environment file was loaded. When an environment file exists, the application SHALL read it and SHALL NOT let it override a variable that is already set in the process environment, even one set to an empty value. A required setting that is missing from both SHALL still stop startup with a log message saying that a required setting is missing.++#### Scenario: Container without an environment file++- **WHEN** the published image starts with only the variables the operator passed in+- **THEN** the application starts and logs that no environment file was loaded++#### Scenario: Development checkout without an environment file++- **WHEN** a developer starts the backend from a checkout that has no environment file, with neither the application mode nor the database connection set in the shell+- **THEN** the log says that no environment file was loaded, startup stops with a message saying a required setting is missing, and the process exits with a non-zero status++#### Scenario: Operator value wins over the file++- **WHEN** a variable is set in the process environment and the environment file sets it to a different value+- **THEN** the application uses the value from the process environment