From 83920cb3fbbdb8b85ec647968d5b0b802f3bd5e5 Mon Sep 17 00:00:00 2001 From: boojack Date: Sun, 1 Nov 2026 21:35:34 +0800 Subject: [PATCH] chore(cmd): warn at startup about unread /etc/secrets configuration files 26.10.0 stopped reading the v0.31 deployment configuration files (memos-idp-*.json, memos-instance-setting-*.json) without a migration, so an instance that kept them through the upgrade gave no sign of it beyond the settings that had silently reverted. Startup now logs one warning naming any such files still present under /etc/secrets, without reading them, and points at the configuration directory. --- cmd/memos/config_test.go | 17 +++++++++++++ cmd/memos/main.go | 31 ++++++++++++++++++++++++ docs/design/declarative-configuration.md | 9 +++++++ 3 files changed, 57 insertions(+) diff --git a/cmd/memos/config_test.go b/cmd/memos/config_test.go index 806cd6705..ccbdb87eb 100644 --- a/cmd/memos/config_test.go +++ b/cmd/memos/config_test.go @@ -159,3 +159,20 @@ func TestConfigApplyCreatesTheDatabase(t *testing.T) { require.Contains(t, stdout.String(), "Apply complete.", "apply bootstraps a fresh instance") require.FileExists(t, filepath.Join(data, "memos_prod.db")) } + +func TestLegacySecretsFiles(t *testing.T) { + require.Nil(t, legacySecretsFiles(filepath.Join(t.TempDir(), "missing"))) + + dir := t.TempDir() + for _, name := range []string{"memos-idp-company-sso.json", "memos-instance-setting-storage.json", "memos-instance-setting-storage.json.bak", "other.json", "README"} { + require.NoError(t, os.WriteFile(filepath.Join(dir, name), []byte("{}"), 0o600)) + } + require.NoError(t, os.Mkdir(filepath.Join(dir, "memos-idp-dir.json"), 0o700)) + require.NoError(t, os.Symlink(filepath.Join(dir, "other.json"), filepath.Join(dir, "memos-instance-setting-general.json"))) + + require.Equal(t, []string{ + filepath.Join(dir, "memos-idp-company-sso.json"), + filepath.Join(dir, "memos-instance-setting-general.json"), + filepath.Join(dir, "memos-instance-setting-storage.json"), + }, legacySecretsFiles(dir)) +} diff --git a/cmd/memos/main.go b/cmd/memos/main.go index f5eb140f9..7451f2224 100644 --- a/cmd/memos/main.go +++ b/cmd/memos/main.go @@ -6,6 +6,8 @@ import ( "log/slog" "os" "os/signal" + "path/filepath" + "regexp" "strings" "syscall" @@ -165,6 +167,9 @@ func runServer() error { if err := applyConfigurationAtStartup(ctx, storeInstance); err != nil { return errors.Wrap(err, "failed to apply the declarative configuration") } + if files := legacySecretsFiles(legacySecretsDir); len(files) > 0 { + slog.Warn("deployment configuration files are no longer read since 26.10.0; declare them in the configuration directory instead", "files", files, "configDir", viper.GetString("config-dir")) + } if instanceProfile.Demo { // After the apply, so the demo content attaches to the declared users. if err := storeInstance.Seed(ctx); err != nil { @@ -308,3 +313,29 @@ type exitCodeError struct { func (e exitCodeError) Error() string { return fmt.Sprintf("exit status %d", e.code) } + +// legacySecretsDir held the v0.31 deployment configuration files +// (memos-idp-*.json and memos-instance-setting-*.json), which 26.10.0 stopped +// reading without a migration. +const legacySecretsDir = "/etc/secrets" + +var legacySecretsFilenameMatcher = regexp.MustCompile(`^memos-(?:idp|instance-setting)-[a-z0-9]+(?:-[a-z0-9]+)*\.json$`) + +// legacySecretsFiles lists the v0.31 deployment configuration files still +// present in dir, so startup can say that nothing reads them: an operator who +// kept the files through the upgrade would otherwise learn it only from the +// settings they expected to be in effect. The files are not opened, and a +// missing or unreadable directory yields nothing. +func legacySecretsFiles(dir string) []string { + entries, err := os.ReadDir(dir) + if err != nil { + return nil + } + var files []string + for _, entry := range entries { + if !entry.IsDir() && legacySecretsFilenameMatcher.MatchString(entry.Name()) { + files = append(files, filepath.Join(dir, entry.Name())) + } + } + return files +} diff --git a/docs/design/declarative-configuration.md b/docs/design/declarative-configuration.md index 4a2f93041..90393d2e0 100644 --- a/docs/design/declarative-configuration.md +++ b/docs/design/declarative-configuration.md @@ -825,3 +825,12 @@ comments and less quoting. Protobuf JSON is already the API's wire format and ne - Keycloak: [Importing and exporting realms](https://www.keycloak.org/server/importExport) - Google AIP: [AIP-122 Resource names](https://google.aip.dev/122), [AIP-193 Errors](https://google.aip.dev/193), [AIP-203 Field behavior](https://google.aip.dev/203) + +## Amendments + +### 2026-11-01: startup warns about leftover `/etc/secrets` files + +The v0.31 deployment configuration files (`/etc/secrets/memos-idp-*.json` and `memos-instance-setting-*.json`) stopped being read in +26.10.0 without a migration, and an instance that kept them through the upgrade gave no sign of it beyond the settings that had silently +reverted (usememos/memos#6515). Startup now logs one warning naming any such files still present, without reading them, and points at the +configuration directory. A missing `/etc/secrets` stays silent.