mirror of
https://github.com/usememos/memos.git
synced 2026-11-19 10:29:11 +01:00
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.
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user