You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(config): read secrets from files named by _FILE variables - #4656
Related issue: N/A
Discussion: #4653 (file-backed secrets, which #4498 left out)
Validation tasks: none
Other clients: Apple N/A (no client-visible change); Android N/A (no client-visible change); Roku N/A (no client-visible change)
Docker and Kubernetes give a container its secrets as files, but Silo read every secret from its environment, so a deployment had to copy each one into a variable first. With this change, each secret can come from the file its _FILE variant names:
DATABASE_URL, SECRET_KEY and REDIS_URL
a transcode node's SILO_NODE_KEY
the backup restore command's S3 keys
each secret setting in the environment table: the SMTP password, the S3 keys and token secret, the Discord client secret and bot token, and the Meilisearch, TMDB and MDBList keys
Approach
internal/envutil gains LookupSecret: NAME_FILE names a file to read NAME from, and one trailing line ending is removed. Startup stops when both are set, or when the file is missing, unreadable, empty or not a regular file. The error names the variable and the cause, and never quotes the file.
Callers.
The bootstrap loader: API servers, proxies, and the maintenance commands that use LoadDatabaseURL.
The transcode node.
The backup restore, verify and decrypt commands. A restore now reads REDIS_URL before it replaces the database.
The environment settings table. Only keys in catalog.SensitiveSettingKeys, the settings stored encrypted, get a file variant.
managed_by_env_vars names the variable that supplied the value, such as SILO_SMTP_PASSWORD_FILE or REDIS_URL_FILE, so the read-only note in web admin names it too. The web app is unchanged.
The provisioning document reader (internal/provisiondoc, shared by SILO_PLUGINS_FILE, SILO_TRANSCODE_NODES_FILE, and their fromFile references) uses the same file reader, so a secret file means the same value wherever it is referenced.
Omnibus image.
init-config counts DATABASE_URL_FILE, REDIS_URL_FILE and SILO_MEILISEARCH_API_KEY_FILE as set when it picks bundled services.
migrate-compose-stack refuses to run while a _FILE variable hides a URL it has to check.
Values read from files are not copied into Silo's own environment, so the child processes Silo starts don't inherit them. The backup commands still hand the database password to pg_dump and pg_restore, as they do for a direct DATABASE_URL, since those tools need it to connect.
silo secret check reads a key from the first line of stdin, as on main, so a key pasted at a prompt is checked at Enter. silo secret check --file <path> reads a key file through the same SECRET_KEY_FILE lookup startup uses, and the startup hint for a key mismatch points at it.
Validation
Go: build, gofmt, go mod tidy -diff, go vet, make lint-changed, make lint-router-recovery, make verify-shellcheck, make verify-local-paths, make verify-bidi and make verify-case-collisions pass.
make test-go: passes except six tests that fail the same way on main on the macOS host used. Those are real-FFmpeg playback tests, and scanner and subsync tests that create non-UTF-8 file names. None is in a package this change touches.
New tests:
the bootstrap loader reads all three secrets from files with LF and CRLF endings, and refuses both forms set and an empty or missing file;
the transcode node reads its key from a file;
the environment table reads a secret setting from a file and reports its _FILE variable.
The first two fail on main.
Live, before: a dev deployment ran the AIO image against external PostgreSQL and Redis, with only _FILE variables set. On main the image chose its bundled services and Silo never started (SECRET_KEY is required).
Live, after: on this branch, the deployment:
chose the external services and started;
listed SILO_SMTP_PASSWORD_FILE and REDIS_URL_FILE in managed_by_env_vars;
refused an admin save of the SMTP password with 422, and stored the password encrypted;
ran silo plugins restore-hold with only DATABASE_URL_FILE set;
stopped startup with SECRET_KEY_FILE: the file does not exist when that file was missing.
Not checked live: a transcode node or proxy using the file variants, and the backup restore command. Tests and the shared reader cover them.
Surface and build: server startup and the admin settings API, verified at 246c7d3e4e. Later commits merge main (#4665, #4654) and add the review fixes (blank secret files refused, _FILE secret whitespace preserved in ReadEnvSettings, silo secret check aligned with ReadSecretFile, supplying *_FILE variable names in length/malformed errors, early restore target checks, and unit tests); none changes the checked behavior. The review fixes in 3de6b01 change silo secret check and docs only; the review summary comment links their evidence.
Risks
Line endings. The secret is the file's content less one line ending. The omnibus image's FILE__NAME loader strips every trailing newline. A key file that ends in more than one newline therefore gives a different SECRET_KEY through SECRET_KEY_FILE than through FILE__SECRET_KEY. The stored key check value catches this: the server refuses to start rather than misread data.
File permissions. Silo reads a _FILE path itself, as the account it runs as (PUID in the omnibus image), where FILE__ is read by root. The file has to be readable by that account.
Compose.docker-compose.yml still sets SECRET_KEY itself. Using SECRET_KEY_FILE there means replacing that line, which .env.example now says.
Backup commands. A _FILE variable that is set but can't be read now stops silo backup verify and a restore into a separate database. Before, both ran without those variables. Ignoring a secret the deployment named would skip the restore's check that it isn't writing over the live database.
Fixed: the silo secret check hint, whitespace-only _FILE values (refused; plugin fromFile secrets keep their rule), the migration guard's advice and Meilisearch messages, the omnibus docs, test isolation, and small cleanups. Answered: the omnibus init not reading Silo's own .env (unchanged from main, where a direct value there was already shadowed), the bundled Meilisearch key (same rule as SILO_MEILISEARCH_API_KEY), the migration's recovery order (shared by every guard on main), and keeping the transcode node's wiring test.
No visual review: nothing a user sees changes beyond the variable name inside an existing note.
AI Disclosure
Harness: Claude Code in T3 Code
Tool(s): Claude Code subagents, Codex and Antigravity (council members), GitHub CLI
Model(s): claude-opus-5-5 (implementation, code review), claude-sonnet-5-5 (code-review cleanup finder and validation check), gpt-6.2-sol and gemini-4-neon (plan review)
Involvement: Fully AI-generated, directed by the maintainer; not yet human-reviewed
Adversarial review:
Plan round (Sol, Opus, Gemini), before any code. Sol found that the omnibus image decides on bundled services before Silo runs. Sol and Gemini found that the backup restore read REDIS_URL after the swap. Gemini found an import cycle in the first design, and Opus cut the plan's scope.
Code review at xhigh: three finders, a validation check and a sweep. Fixed: whitespace-only paths, error messages that hid the cause, --keep-redis, the transcode node's warnings, a shared file reader, the docs, the migration guard and test isolation. Answered: why the backup commands fail closed, and why secrets are not copied into the environment.
Add support for reading secrets from files named by _FILE variables
Adds envutil.LookupSecret and ReadSecretFile in secret.go: reads a regular file up to 1 MiB, removes one trailing LF/CRLF, rejects empty, whitespace-only, invalid UTF-8, or oversized files, and returns which variable supplied the value.
Wires the file variants into config loading: DATABASE_URL_FILE, SECRET_KEY_FILE, REDIS_URL_FILE, SILO_NODE_KEY_FILE, and backup S3 keys, plus sensitive keys in ReadEnvSettings (env_settings.go, bootstrap.go, backup_command.go, node_keys.go).
Restores now resolve target database, Redis, and separate-restore blob inputs via restoreTargetEnv before opening the backup source, so a bad _FILE setting fails early.
silo secret check accepts --file <path> and returns a result after the first stdin line. The omnibus image treats _FILE variables as external-service indicators, and migrate-compose-stack refuses migration when DATABASE_URL_FILE or REDIS_URL_FILE is set.
Behavioral Change: setting both the direct variable and its _FILE variant to nonempty values is now an error; direct values get trimmed as before, but file values bypass trim-and-blank handling before normalization. Errors now name the supplying variable.
Docker and Kubernetes mount secrets as files, and Silo read every secret
from its environment alone. DATABASE_URL, SECRET_KEY, REDIS_URL,
SILO_NODE_KEY, the backup restore command's S3 keys, and each secret
setting in the environment table can now come from the file their _FILE
variant names. One trailing line ending is removed, the same rule as the
plugin provisioning document's fromFile references, which now share the
reader. Setting both a variable and its _FILE variant, or naming a file
that is missing or empty, stops startup with the variable's name.
The omnibus image counts DATABASE_URL_FILE, REDIS_URL_FILE and
SILO_MEILISEARCH_API_KEY_FILE as set when it chooses bundled services.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This change adds shared support for loading selected environment values from files named by _FILE variables. It applies that support to configuration loading, backup and restore commands, transcode node keys, provisioning secrets, and omnibus service selection.
Changes: File-based secret inputs
Layer / File(s)
Summary
Secret file lookup and provisioning internal/envutil/secret.go, internal/plugins/provision_document.go, .env.example
Shared utilities resolve _FILE variables, validate and read regular files, and remove one trailing line ending from secret values. Provisioning uses the shared readers. The example environment file documents supported variables and the direct-versus-file rule.
Bootstrap and settings loading internal/config/bootstrap.go, internal/config/env_settings.go, cmd/silo/main.go, internal/config/*_test.go, internal/api/handlers/admin_settings_env_test.go, docs/admin-settings-api.md
Bootstrap and marked secret settings use the shared lookup. Bootstrap records the variable that supplied the Redis URL, and settings report the selected source variable. Tests cover file values and lookup errors.
Backup and restore environment inputs cmd/silo/backup_command.go, cmd/silo/backup_redis.go, cmd/silo/backup_wiring_test.go, cmd/silo/backup_*_test.go, docs/architecture/backups.md
Backup and restore resolve supported S3 credentials, database URLs, secret keys, and Redis URLs through the shared lookup. Restore planning uses the resolved Redis URL when present and otherwise retains the database-settings fallback.
Transcode node startup accepts the key from SILO_NODE_KEY_FILE, and ignored-variable reporting includes selected _FILE variables. The development target and tests account for the file-based key.
Omnibus service selection and migration omnibus/rootfs/etc/s6-overlay/scripts/init-config, omnibus/rootfs/etc/silo-omnibus/migrate-compose-stack, docs/architecture/omnibus-image.md
Omnibus service selection recognizes database and Redis _FILE variables and accepts a Meilisearch key file. Compose-stack migration stops when database or Redis URLs are supplied through _FILE variables.
sequenceDiagram
participant ConfigLoader
participant LookupSecret
participant ReadSecretFile
participant FileSystem
ConfigLoader->>LookupSecret: Resolve environment variable
LookupSecret->>ReadSecretFile: Read path from _FILE variable
ReadSecretFile->>FileSystem: Read regular file
FileSystem-->>ReadSecretFile: File contents
ReadSecretFile-->>LookupSecret: Validated secret value
LookupSecret-->>ConfigLoader: Value and source variable
Loading
Possibly related PRs
Silo-Server/silo-server#4498: Adds the environment settings and sensitive-status reporting path extended here to record the source variable for file-based values.
Silo-Server/silo-server#3118: Adds the omnibus startup path whose service-selection behavior this change updates for _FILE variables.
Suggested reviewers:blurbery
Merge Risk: Low · up to 0a474
The shared _FILE secret loading works as described. Two small operator-facing problems remain. The key-mismatch recovery hint can point to a check command that does not read SECRET_KEY_FILE and can normalize trailing line endings differently from the server. One migration doc passage tells operators to set a direct URL that the migration then refuses. Neither blocks merging, but both should be fixed.
Security architecture risk: Minimal · up to 0a474
The inspected change adds file-backed sources for existing credentials without expanding their authority. Conflicting or unreadable sources fail before settings application or database replacement. No introduced security or failure-containment regression was established.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
inferred — The affected authority is that of the configured server or node and the database, Redis, storage and node credentials it already uses. Selecting a file adds a local filesystem dependency under the process account; inspected callers obtain paths from deployment configuration rather than request parameters.
Trust Boundaries and Controls
observed — The shared source boundary rejects ambiguous input instead of silently choosing a credential. File failures name the variable and a fixed cause without quoting the selected path or contents. Filesystem ownership and mount integrity remain deployment responsibilities; the reader does not make writable files immutable.
observed — The migration command's credential-safe parse-error mapping and fallback pool-error output predate this PR. New secret-source errors do not include credential contents. Whether third-party connection errors can disclose credentials remains unverified on that unchanged output path.
Resilience and Maintainability Implications
observed — Replace restore resolves the live database and Redis URL before replacement and reuses the captured values. After replacement, Redis cleanup targets one configured database, closes its client and runs with a cancellation-independent timeout. Skipped or failed cleanup produces explicit operator instructions rather than silently implying stale state was cleared.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "feat(config): read secrets from files named by _FILE variables" matches the main change. The changeset adds a LookupSecret helper in internal/envutil and uses it for bootstrap secrets, tran…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
The description is specific and on-topic. It explains that Silo can now read secrets from files named by _FILE variables (DATABASE_URL, SECRET_KEY, REDIS_URL, SILO_NODE_KEY, backup S3 keys, and sensit…
Full details: Title check
Explanation
The title "feat(config): read secrets from files named by _FILE variables" matches the main change. The changeset adds a LookupSecret helper in internal/envutil and uses it for bootstrap secrets, transcode node keys, backup S3 keys, sensitive settings, and omnibus init. The title is concise, specific, and follows a conventional-commit style.
Full details: Description check
Explanation
The description is specific and on-topic. It explains that Silo can now read secrets from files named by _FILE variables (DATABASE_URL, SECRET_KEY, REDIS_URL, SILO_NODE_KEY, backup S3 keys, and sensitive settings). It also covers the approach through internal/envutil, the omnibus image changes, validation performed, and risks. This matches the changeset described in the raw summary.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
The reason will be displayed to describe this comment to others. Learn more.
File-backed Meilisearch key can differ from the bundled server key
With bundled Meilisearch enabled, setting only SILO_MEILISEARCH_API_KEY_FILE can cause authentication failures and stop search. Configure the bundled server and client with compatible credentials, or reject a file key that cannot authenticate to the generated server.
Prompt for LLM
File omnibus/rootfs/etc/s6-overlay/scripts/init-config, line 183:
File-backed Meilisearch key can differ from the bundled server key
With bundled Meilisearch enabled, setting only `SILO_MEILISEARCH_API_KEY_FILE` leaves the server using an independently generated master key, so the documented file-backed key fails authentication and search stops working. Configure the bundled server and client from compatible credentials or reject a file key that cannot authenticate to the generated server.
The reason will be displayed to describe this comment to others. Learn more.
Not changed. This matches what SILO_MEILISEARCH_API_KEY already does: init-config gives Silo its own key only when the deployment doesn't set one, and the bundled Meilisearch keeps MEILI_MASTER_KEY or its generated key either way. A deployment that names the key Silo uses also sets the bundled server's key (MEILI_MASTER_KEY, or FILE__MEILI_MASTER_KEY for a mounted secret). The omnibus doc now says this in 02b9c36.
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. The _FILE variant preserves the existing behavior of SILO_MEILISEARCH_API_KEY: when a deployment supplies the client key, it is responsible for ensuring that key can authenticate with the bundled Meilisearch server.
The documented requirement to configure MEILI_MASTER_KEY or FILE__MEILI_MASTER_KEY addresses the concern. I’d withdraw the suggestion as a regression specific to this PR.
The reason will be displayed to describe this comment to others. Learn more.
S1 (high) — The omnibus image rejects file settings from Silo’s own .env. If DATABASE_URL_FILE is set only in the .env that svc-silo loads, this check selects bundled PostgreSQL and exports DATABASE_URL. Go then loads .env and rejects both names. I reproduced that error using this branch and LoadDatabaseURL. The same order creates conflicts for REDIS_URL_FILE when Redis is bundled and SILO_MEILISEARCH_API_KEY_FILE when Meilisearch is bundled. Load the relevant settings before s6 chooses services, using the same dotenv syntax and precedence as Go, and cover both configuration sources in an omnibus startup test.
The reason will be displayed to describe this comment to others. Learn more.
Not changed. The init has never read /config/silo/.env: on main, a DATABASE_URL placed there is already shadowed by the bundled URL the init exports, because godotenv doesn't override a set variable, so Silo silently runs on the bundled database. With this PR, a DATABASE_URL_FILE in that file stops startup naming both variables instead of running on the wrong database. The documented place for these variables in the image is the container environment (Compose environment/env_file, a Kubernetes pod spec). Making the init parse Silo's .env would be a change to how the image chooses services, separate from file-backed secrets. The omnibus doc now says that only the container's environment counts for the init (02b9c36).
This pass looked for code the change could drop and for correctness bugs. It found no correctness bugs in the Go wiring, the omnibus init changes or the backup ordering. It found four small items, all optional. Dropping any of them still leaves every secret readable from a mounted file and still stops startup on a bad file: LookupSecret (internal/envutil/secret.go:29-45) and its callers in bootstrap.go, env_settings.go, node_keys.go and backup_command.go are unchanged by these suggestions.
O1 (nit): the new silo secret check < "$SECRET_KEY_FILE" hint can print a different check value than the server computes for the same file.
O2 (nit, tests): TestLoadTranscodeNodeEnvReadsKeyFile is a second wiring test of the same helper, through a pass-through.
O3 (nit, tests): one assertion in TestLoadBootstrapReadsSecretFiles repeats what the previous one already proves.
O4 (nit): MaxFileBytes is exported but only used inside its own package.
Docs: in docs/architecture/backups.md the added sentence repeats the one before it (both name SECRET_KEY and DATABASE_URL as coming from the environment). Merging them into one sentence would say the same thing in less text.
The reason will be displayed to describe this comment to others. Learn more.
O2 (nit, tests). transcodeNodeKey (node_keys.go:49-53) only passes getenv to envutil.LookupSecret. CONTRIBUTING's "Decide what to test" says to test a behavior once, plus at most one wiring test, and not to test adapters that pass values through. TestLoadBootstrapReadsSecretFiles already covers the file rules (one line ending, both set, empty, missing), and TestReadEnvSettingsReadsSecretFiles covers the table's own logic. This test only catches someone reverting the call to plain getenv. Suggested repair: delete it, and drop the envNodeKey+"_FILE" filter that comes with it at line 164 only if nothing else needs it. That filter keeps a host SILO_NODE_KEY_FILE from colliding with the test's SILO_NODE_KEY, so it probably should stay. Uncertain: if the maintainers count the node key under "tokens and API keys", keeping the test is defensible.
The reason will be displayed to describe this comment to others. Learn more.
Kept. The transcode node reads its key in its own process, through loadTranscodeNodeEnv, not through the bootstrap loader the other test covers. This is the one wiring test for that process, and it's the test that fails on main for the node.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Additional comments: 1
docs/architecture/backups.md-1780-1783: 1
1780-1783: Minor · Maintainability & Code Quality · Quick win
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Move restore configuration guidance to the user manual.
This paragraph tells operators how to configure restore-command secrets. Put the instructions in the user manual and keep only contributor-facing implementation details here.
As per coding guidelines, “Guides for installing, configuring, operating, or troubleshooting Silo belong in the user manual.”
Source: Coding guidelines
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: b30d788e-1727-419a-8c55-0fbffbd53d33
Commits
Reviewing files that changed from the base of the PR and between 88b825d and 9c42e84.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
Three findings are attached inline (cmd/silo/main.go, internal/config/env_settings.go, docs/architecture/omnibus-image.md). Two remaining low-severity findings sit outside the diff:
Trigger: Opening the setup wizard's Storage step on a server started with REDIS_URL_FILE (and no REDIS_URL).
Impact: The server reports managed_by_env_vars: {"redis.url": "REDIS_URL_FILE", "redis.db": "REDIS_URL_FILE"}. StorageStep.tsx:538 renders web.setup.storage.redisManagedDescription ("Shared queue and cache. This server reads REDIS_URL from its environment."), which contradicts the expanded redis.url and redis.db fields directly below it (StorageStep.tsx:559,567), where form.envVar(...) shows REDIS_URL_FILE.
Suggested repair: Update web.setup.storage.redisManagedDescription (via silo-translations) to interpolate the variable from form.envVar("redis.url") or stop naming REDIS_URL directly, since the expanded fields already show the exact variable.
Existing tests setting secret env vars do not clear their _FILE counterparts
Severity: Low
Trigger: Running go test ./scripts/ci/migrate/... ./cmd/silo/... in a shell where DATABASE_URL_FILE, SECRET_KEY_FILE, SILO_BACKUP_S3_ACCESS_KEY_FILE, or SILO_BACKUP_S3_SECRET_KEY_FILE is set.
Impact: Unlike internal/config/bootstrap_test.go, cmd/silo/backup_wiring_test.go, and cmd/silo/transcode_node_test.go, three untouched test suites inherit those _FILE variables from the host environment while setting the direct variables, causing envutil.LookupSecret to fail with set only one of ....
Suggested repair: Clear DATABASE_URL_FILE in scripts/ci/migrate/main_test.go, clear SECRET_KEY_FILE, DATABASE_URL_FILE, SILO_BACKUP_S3_ACCESS_KEY_FILE, and SILO_BACKUP_S3_SECRET_KEY_FILE in TestBackupCommandsReadS3DB, and unset the matching _FILE variables in TestBackupInterruptCleansUp's child cmd.Env.
A secret file holding only whitespace now stops startup, as an empty one
does; before, the environment table trimmed it to nothing and treated the
variable as unset. The key-mismatch hint no longer suggests reading
SECRET_KEY_FILE through `silo secret check`, which parses its input
differently. The omnibus migration guard asks for the URL in the plain
variable while an earlier install moves, the omnibus doc says what
SILO_MEILISEARCH_API_KEY_FILE does and that only the container's environment
counts for the init, and tests that set secrets directly clear their file
variants.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Tests that set secrets directly (scripts/ci/migrate, the backup command and interrupt tests) now clear their _FILE variants, so a shell that exports one can't make them fail.
docs/architecture/backups.md: the two sentences about where restore reads its secrets are merged into one.
Setup wizard storage note ("This server reads REDIS_URL from its environment"): not changed. Silo does read REDIS_URL from its environment when it comes from REDIS_URL_FILE, and the fields below the note name the exact variable. Naming it in the note would need a catalog change for one wizard line.
The four points from the previous Opus pass are resolved: the silo secret check file hint is gone, the duplicate LoadDatabaseURL assertion is removed, maxFileBytes is unexported, and the transcode node key test was kept on purpose as that process's wiring test. The other fixes in 9c42e84..02b9c36 are as small as they can be and add nothing beyond what was asked: one TrimSpace check in ReadSecretFile, _FILE variables cleared in the tests, a rewritten migration message, and doc wording. The config, migrate, plugins and touched cmd/silo tests pass at this head.
The whitespace-only refusal moves from the shared file reader to the
_FILE lookup, so plugin fromFile secrets keep the rule they had: a file
must hold a nonempty value. The message now says the file holds only
whitespace. The omnibus migration's Meilisearch messages also name
SILO_MEILISEARCH_API_KEY_FILE among the variables to remove.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Round 2 of the adversarial review, on 02b9c36 (Sol's findings, summarized here because its review didn't post):
The blank-file refusal also reached plugin fromFile secrets through the shared reader, changing what main accepted. Fixed in 0a47478: the check now applies to _FILE variables only.
The omnibus migration's two Meilisearch messages now name SILO_MEILISEARCH_API_KEY_FILE among the variables to remove (0a47478).
An interrupted migration retried with a guard failing clears its pending record first. That ordering applies to every guard in migrate-compose-stack, since they all run after the recovery block on main, so it isn't changed here.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
The migration guard told an operator with DATABASE_URL_FILE or
REDIS_URL_FILE to move the URL into DATABASE_URL or REDIS_URL. When the
earlier stack's own PostgreSQL or Redis held the data, the next guard
refuses that URL. Say to remove the variable, and to set the direct URL
only for an external service.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.
Reviewing changes in Silo
Include the related issue, expected behavior, and validation steps in the PR description.
For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
Follow this repository's AGENTS.md and CONTRIBUTING.md.
Request another review with @kody start-review in a PR comment.
React with 👍 or 👎 to give feedback on individual suggestions.
Review settingsReview Options
The following review options are enabled or disabled:
Options
Enabled
Bug
✅
Performance
✅
Security
✅
Business Logic
❌
⚠️ 4 Kody Rule(s) were not evaluated
These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:
Preserve optional store capabilities through production wrappers
Detach mandatory cleanup from request cancellation and bound its lifetime
Preserve durable media identity and share identity-evidence precedence
Bound decoder throughput trades and share direct-play eligibility
The reason will be displayed to describe this comment to others. Learn more.
Review of 1d335a8a62 (after merging main to pick up #4665's ReadEnvSettings callers).
The _FILE secret reader and omnibus guards fit cleanly, and all four items below are bounded fixes that I'm pushing to this branch now, so there is no need to change them yourself:
Medium (cmd/silo/backup_command.go:783, cmd/silo/main.go:685, continuing the earlier silo secret check thread):runSecretCommand reads only up to the first \n (64 KiB cap) and calls strings.TrimRight(key, "\r\n"), while SECRET_KEY_FILE (envutil.ReadSecretFile) reads up to 1 MiB and removes only one trailing LF/CRLF. On a key file with two trailing newlines (<key>\n\n), an embedded newline (such as openssl rand -base64 64), or more than 64 KiB, silo secret check < "$SECRET_KEY_FILE" prints a different check value from the one the server loaded, and settingsLoadError only shows the $SECRET_KEY pipe command. I'm updating runSecretCommand to share the same 1 MiB limit and single-line-ending rule as envutil.ReadSecretFile, restoring the < "$SECRET_KEY_FILE" hint in settingsLoadError, and adding a regression test.
Inline comments below cover ReadEnvSettings trimming _FILE values, usedVar in length/malformed errors, and reading restore secret files before downloading --from.
…d fail early on restore
- Keep values read from _FILE secret settings verbatim past the single
removed line ending instead of calling strings.TrimSpace in
ReadEnvSettings.
- Make `silo secret check` share the 1 MiB limit and single-line-ending
rule with envutil.ReadSecretFile, and restore the SECRET_KEY_FILE hint
in settingsLoadError.
- Name the supplying _FILE variable in short SECRET_KEY and malformed
SILO_NODE_KEY errors.
- Resolve target DATABASE_URL, REDIS_URL, and separate-mode --blobs-into
credentials before openBackupSource downloads or decrypts --from.
Resolve merge conflicts with #4654 in docs/architecture/transcode-nodes.md
and internal/plugins/provision_document.go, and delegate
internal/provisiondoc's ReadFile and ReadSecretFile to internal/envutil so
both provisioning documents and _FILE variables share one file reader.
Resolved a compile mismatch against feat(config): set backups, Discord, MDBList and more from the environment #4665 (two new config.ReadEnvSettings calls for SILO_BACKUP_ENABLED using the old one-argument signature); SILO_DISCORD_CLIENT_SECRET, SILO_DISCORD_BOT_TOKEN, and SILO_MDBLIST_API_KEY now also gain _FILE variants through catalog.SensitiveSettingKeys.
Resolved merge conflicts against feat(nodepool): create transcode nodes and their keys from the API servers' configuration #4654 (docs/architecture/transcode-nodes.md and internal/plugins/provision_document.go) and delegated internal/provisiondoc.ReadFile / ReadSecretFile to internal/envutil, so plugin provisioning, transcode-node provisioning, and _FILE variables share one file reader.
Preserved _FILE secret whitespace (5ffbc4c6e3):config.ReadEnvSettings now skips strings.TrimSpace when envutil.LookupSecret resolved from a *_FILE variable (blank files are already rejected by LookupSecret), so edge spaces and extra trailing newlines survive past the single removed line ending, matching NormalizeAdminSetting and db_loader.go.
Aligned silo secret check with SECRET_KEY_FILE (5ffbc4c6e3):runSecretCommand now uses envutil.ReadBounded (1 MiB) and envutil.TrimOneLineEnding instead of ReadString('\n') + strings.TrimRight("\r\n"), so silo secret check < "$SECRET_KEY_FILE" matches envutil.ReadSecretFile on multi-line keys and multiple trailing newlines. Restored the < "$SECRET_KEY_FILE" hint in settingsLoadError.
Named supplying *_FILE variables in post-read errors (5ffbc4c6e3):LoadBootstrap, backupMasterKey, and transcodeNodeKey now pass usedVar from LookupSecret into short-key and malformed-key errors.
Failed early in silo backup restore (5ffbc4c6e3):restoreTargetEnv now resolves DATABASE_URL, REDIS_URL, and separate-mode --blobs-into credentials before openBackupSource downloads or decrypts --from.
Added targeted tests (5ffbc4c6e3): Added internal/envutil/secret_test.go (double LF, non-regular directory, invalid UTF-8, >1 MiB limit), asserted bc.RedisURLVar and vars in bootstrap/Redis tests, and added regression tests for ReadEnvSettings, LoadBootstrap, runSecretCommand, and restore pre-fetch validation.
Remaining notes
Omnibus /config/silo/.env conflict (init-config:102) and transcode node wiring test (transcode_node_test.go:43): Both were already answered on the PR with rationale and documentation; TestLoadTranscodeNodeEnvReadsKeyFile was verified to fail on main.
Bundled Meilisearch key (init-config:183): Kody already withdrew its suggestion after the doc update.
Other council notes not changed:LoadBootstrap reading REDIS_URL_FILE before --migrate-only/--migrate-status/--migrate-down-to matches how LoadBootstrap already treats SECRET_KEY (maintenance commands that run without other bootstrap secrets use LoadDatabaseURL). ReadRegularFile's os.Stat then os.Open matches the existing provisioning reader on deployment-owned mounts without introducing OS build-tag splits.
Validated features
Validation tasks: none
Checked all 18 passed 1.0 validation areas against the diff: Distributed transcode nodes (#1177, #1178), Plugin management (#1224, #1225), Notifications (#1234, #1235), Server branding (#1227–#1229), and API keys (#1190, #1191) have no behavior change under direct env vars and stored settings. The remaining 13 passed areas share no code with the diff.
Validation status
Local Go gate on ca683c683b:gofmt, go mod tidy -diff, go build ./..., go vet ./..., make lint-changed (0 issues), make lint-router-recovery (0 issues), make verify-local-paths, make verify-bidi, make verify-case-collisions, and go test -count=1 across internal/envutil, internal/provisiondoc, internal/nodepool/..., internal/plugins/..., internal/config, internal/api/handlers, cmd/silo, and scripts/ci/migrate all pass. (shellcheck is not installed on this review host; CI runs it.)
fails-on-base:
Against origin/main (3516fb41ef): TestLoadBootstrapReadsSecretFiles failed (DATABASE_URL is required) and TestLoadTranscodeNodeEnvReadsKeyFile failed (SILO_NODE_KEY is required). TestReadEnvSettingsReadsSecretFiles does not compile on base because ReadEnvSettings gained the secretKeys parameter.
Against 1d335a8a62 (before 5ffbc4c6e3): TestReadEnvSettingsReadsSecretFiles, TestLoadBootstrapReadsSecretFiles, TestSecretCheckMatchesSecretFile, and TestBackupRestoreChecksSecretFilesBeforeOpeningSource all failed for the reported causes and pass on ca683c683b.
Formal checks:silo-formal check touched reported no covered files.
Evidence: The published evidence page (https://evidence.siloserver.org/r/silo-server/env-secret-files/) still holds; none of the 1d335a8a62, 5ffbc4c6e3, or ca683c683b commits alters the captured omnibus startup, managed_by_env_vars, 422 save refusal, silo plugins restore-hold, or missing SECRET_KEY_FILE checks.
User manual & cross-client parity
User manual: Covered by open Silo-Server/siloserver.org#406 (whose comment already accounts for both #4656 and #4665, including Discord and MDBList _FILE variants) and open docs PR Silo-Server/siloserver.org#440. When #406 is written, running-a-server/restore.md, running-a-server/transcode-nodes.md, and running-a-server/updates.md also mention SECRET_KEY, SILO_NODE_KEY, and SILO_BACKUP_S3_* and are worth a short cross-reference.
Apple / Android / Roku / Jellyfin parity: N/A — no client-visible API or contract changes; managed_by_env_vars is web-admin only and already renders supplying variable names dynamically.
Council review (review round on 1d335a8a62)
Member
Model & effort
Score
Sol
gpt-6.2-sol (xhigh)
6.5/10
Opus
claude-opus-5-5 (high)
8.5/10
Gemini
gemini-4-neon (xhigh)
8/10
Verdict
Fit: 9/10 · Readiness: 9/10 — ready (assuming CI is green)
Fit (9/10): Adds standard Docker/Kubernetes _FILE secret support cleanly in one shared package, works across omnibus, slim/rootless, proxy, transcode, and CLI commands, keeps secret values out of child process environments, and needs no new UI surface or settings.
The reason will be displayed to describe this comment to others. Learn more.
Review of ca683c6. One medium finding, one low and three nits, all inline; I'm fixing all five on this branch, and a summary comment follows once the fixes are pushed.
`silo secret check` read stdin to the end, so a key pasted at a prompt
printed nothing until Ctrl-D. Stdin reads one line again, as on main, and
`--file` reads a key file through SECRET_KEY_FILE's own lookup, so its
value and refusals match startup. The startup hint points at it.
Also: .env.example names docker-compose.advanced.yml's SECRET_KEY,
DATABASE_URL and REDIS_URL and the image's FILE__ passwords; the
migration's advice no longer says Redis always runs; the transcode node
doc says the key is trimmed; and the S3 restore test clears
DATABASE_URL_FILE.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewed ca683c6. The fixes are in 3de6b01, pushed to this branch.
Fixed (5):
silo secret check waited for the end of input, so a key pasted at a prompt printed nothing until Ctrl-D. Stdin reads one line again, and silo secret check --file <path> reads a key file through SECRET_KEY_FILE's own lookup; the startup hint points at it.
.env.example now names docker-compose.advanced.yml's SECRET_KEY, DATABASE_URL and REDIS_URL, and says the image's own POSTGRES_PASSWORD, REDIS_PASSWORD and MEILI_MASTER_KEY load through FILE__NAME.
The Compose migration's advice for REDIS_URL_FILE no longer says Redis always runs.
The S3 restore test clears DATABASE_URL_FILE.
The transcode node doc says SILO_NODE_KEY_FILE is trimmed like SILO_NODE_KEY.
Answered, unchanged:
A secret setting read from a _FILE variant keeps edge whitespace, where a direct value is trimmed, and the SMTP, Meilisearch and Discord readers trim again. The end result is the same either way: SMTP authenticates with the trimmed password whichever way it arrived, and the S3 keys, which nothing trims, keep their bytes.
ReadRegularFile checks the path with Stat, then opens it, so a file swapped for a FIFO in between could block the open. The provisioning reader already had this, and it needs write access to the secret's directory.
A restore reads REDIS_URL_FILE once, before the swap, and flushes that target afterwards. A secret file replaced during an offline restore is outside what the command handles.
A _FILE variable given on the command line beside a direct value in the working directory's .env stops a CLI command with "set only one of …". That fails closed, and -env "" skips the .env.
Validated features: the validation board couldn't be read, because the review's gh token lacks the read:project scope. The body's Validation tasks: none is unconfirmed.
Validation:TestSecretCheck's stdin case failed on ca683c6 and passes at 3de6b01. go vet and go test pass for cmd/silo, internal/envutil, internal/config, internal/provisiondoc, internal/plugins and internal/nodepool. Built binaries at a pseudo-terminal: ca683c6 printed nothing in the 3 s after Enter, and 3de6b01 printed the check value 0.16 s after Enter. --file on a key file ending in two newlines printed the check value of the key plus one newline, and a blank file got "SECRET_KEY_FILE: the file holds only whitespace". The PR's own live checks of startup and the settings API still hold, since the fixes don't touch them.
User manual:Silo-Server/siloserver.org#406 and the docs PR Silo-Server/siloserver.org#440 cover the _FILE variables. The backups page shows printf %s "$SECRET_KEY" | silo secret check, which still works; #406 could also mention silo secret check --file there.
Apple and Android: server only; nothing to pair.
Council (round 1, ca683c6): Sol (gpt-6.2-sol, xhigh) 6.5/10, Opus (claude-opus-5-5, high) 8/10, Gemini (gemini-4-neon, xhigh) 8/10. All three found the secret check hang; Gemini found the .env.example gaps.
Fit: 8/10 · Readiness: 9/10 — conditional (assuming CI is green)
Fit: _FILE variables are the standard way Docker and Kubernetes pass secrets, and they reach deployments the image's FILE__ loader can't, such as the binary run directly, a transcode node outside the image, or the backup CLI on another host. They add no API surface. What holds it below 9 is new surface: file variants of about sixteen variables, and a second file-secret mechanism in the all-in-one image with different newline and permission rules, which the body discloses.
Readiness: every finding is fixed. The startup paths are covered by tests that fail on main and by the PR's live run, and the CLI fix was shown with built binaries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enhancementNew feature or requestgoPull requests that update go codepriority: P2Limited scope, workaround exists, or polishsize/XL500–999 added + deleted lines (all files); change volume, not priority.
1 participant
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Related issue: N/A
Discussion: #4653 (file-backed secrets, which #4498 left out)
Validation tasks: none
Other clients: Apple N/A (no client-visible change); Android N/A (no client-visible change); Roku N/A (no client-visible change)
Docker and Kubernetes give a container its secrets as files, but Silo read every secret from its environment, so a deployment had to copy each one into a variable first. With this change, each secret can come from the file its
_FILEvariant names:DATABASE_URL,SECRET_KEYandREDIS_URLSILO_NODE_KEYApproach
internal/envutilgainsLookupSecret:NAME_FILEnames a file to readNAMEfrom, and one trailing line ending is removed. Startup stops when both are set, or when the file is missing, unreadable, empty or not a regular file. The error names the variable and the cause, and never quotes the file.Callers.
LoadDatabaseURL.REDIS_URLbefore it replaces the database.catalog.SensitiveSettingKeys, the settings stored encrypted, get a file variant.managed_by_env_varsnames the variable that supplied the value, such asSILO_SMTP_PASSWORD_FILEorREDIS_URL_FILE, so the read-only note in web admin names it too. The web app is unchanged.The provisioning document reader (
internal/provisiondoc, shared bySILO_PLUGINS_FILE,SILO_TRANSCODE_NODES_FILE, and theirfromFilereferences) uses the same file reader, so a secret file means the same value wherever it is referenced.Omnibus image.
init-configcountsDATABASE_URL_FILE,REDIS_URL_FILEandSILO_MEILISEARCH_API_KEY_FILEas set when it picks bundled services.migrate-compose-stackrefuses to run while a_FILEvariable hides a URL it has to check.Values read from files are not copied into Silo's own environment, so the child processes Silo starts don't inherit them. The backup commands still hand the database password to
pg_dumpandpg_restore, as they do for a directDATABASE_URL, since those tools need it to connect.silo secret checkreads a key from the first line of stdin, as on main, so a key pasted at a prompt is checked at Enter.silo secret check --file <path>reads a key file through the sameSECRET_KEY_FILElookup startup uses, and the startup hint for a key mismatch points at it.Validation
Go: build,
gofmt,go mod tidy -diff,go vet,make lint-changed,make lint-router-recovery,make verify-shellcheck,make verify-local-paths,make verify-bidiandmake verify-case-collisionspass.make test-go: passes except six tests that fail the same way on main on the macOS host used. Those are real-FFmpeg playback tests, and scanner and subsync tests that create non-UTF-8 file names. None is in a package this change touches.New tests:
_FILEvariable.The first two fail on main.
Live, before: a dev deployment ran the AIO image against external PostgreSQL and Redis, with only
_FILEvariables set. On main the image chose its bundled services and Silo never started (SECRET_KEY is required).Live, after: on this branch, the deployment:
SILO_SMTP_PASSWORD_FILEandREDIS_URL_FILEinmanaged_by_env_vars;silo plugins restore-holdwith onlyDATABASE_URL_FILEset;SECRET_KEY_FILE: the file does not existwhen that file was missing.Not checked live: a transcode node or proxy using the file variants, and the backup restore command. Tests and the shared reader cover them.
Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/env-secret-files/
Surface and build: server startup and the admin settings API, verified at 246c7d3e4e. Later commits merge
main(#4665, #4654) and add the review fixes (blank secret files refused,_FILEsecret whitespace preserved inReadEnvSettings,silo secret checkaligned withReadSecretFile, supplying*_FILEvariable names in length/malformed errors, early restore target checks, and unit tests); none changes the checked behavior. The review fixes in 3de6b01 changesilo secret checkand docs only; the review summary comment links their evidence.Risks
FILE__NAMEloader strips every trailing newline. A key file that ends in more than one newline therefore gives a differentSECRET_KEYthroughSECRET_KEY_FILEthan throughFILE__SECRET_KEY. The stored key check value catches this: the server refuses to start rather than misread data._FILEpath itself, as the account it runs as (PUIDin the omnibus image), whereFILE__is read by root. The file has to be readable by that account.docker-compose.ymlstill setsSECRET_KEYitself. UsingSECRET_KEY_FILEthere means replacing that line, which.env.examplenow says._FILEvariable that is set but can't be read now stopssilo backup verifyand a restore into a separate database. Before, both ran without those variables. Ignoring a secret the deployment named would skip the restore's check that it isn't writing over the live database.User manual: Silo-Server/siloserver.org#406 now lists the
_FILEvariables and the pages they touch; the variable table itself is in the open docs PR Silo-Server/siloserver.org#440.Checklist
Council review
Rounds: 2, last reviewed 02b9c36
Fixed: the
silo secret checkhint, whitespace-only_FILEvalues (refused; pluginfromFilesecrets keep their rule), the migration guard's advice and Meilisearch messages, the omnibus docs, test isolation, and small cleanups. Answered: the omnibus init not reading Silo's own.env(unchanged from main, where a direct value there was already shadowed), the bundled Meilisearch key (same rule asSILO_MEILISEARCH_API_KEY), the migration's recovery order (shared by every guard on main), and keeping the transcode node's wiring test.No visual review: nothing a user sees changes beyond the variable name inside an existing note.
AI Disclosure
claude-opus-5-5(implementation, code review),claude-sonnet-5-5(code-review cleanup finder and validation check),gpt-6.2-solandgemini-4-neon(plan review)REDIS_URLafter the swap. Gemini found an import cycle in the first design, and Opus cut the plan's scope.--keep-redis, the transcode node's warnings, a shared file reader, the docs, the migration guard and test isolation. Answered: why the backup commands fail closed, and why secrets are not copied into the environment.🤖 Generated with Claude Code
Note
Add support for reading secrets from files named by
_FILEvariablesenvutil.LookupSecretandReadSecretFilein secret.go: reads a regular file up to 1 MiB, removes one trailing LF/CRLF, rejects empty, whitespace-only, invalid UTF-8, or oversized files, and returns which variable supplied the value.DATABASE_URL_FILE,SECRET_KEY_FILE,REDIS_URL_FILE,SILO_NODE_KEY_FILE, and backup S3 keys, plus sensitive keys inReadEnvSettings(env_settings.go, bootstrap.go, backup_command.go, node_keys.go).restoreTargetEnvbefore opening the backup source, so a bad_FILEsetting fails early.silo secret checkaccepts--file <path>and returns a result after the first stdin line. The omnibus image treats_FILEvariables as external-service indicators, andmigrate-compose-stackrefuses migration whenDATABASE_URL_FILEorREDIS_URL_FILEis set._FILEvariant to nonempty values is now an error; direct values get trimmed as before, but file values bypass trim-and-blank handling before normalization. Errors now name the supplying variable.Macroscope summarized 3de6b01.