Skip to content

Read passwords from files: CENTRS_CDB_PASSWORD_FILE, CENTRS_PASSWORD_FILE and --*-file (container /run/secrets) #672

Done

Description

@mobileskyfi

Why

RouterOS /app (7.23+) delivers secrets as files: an app-level secrets: entry, listed under a service, appears at /run/secrets/<name>. Docker and Podman secrets work the same way. That is safer than an env value. On RouterOS, an expanded [secret:…] env value is copied into the derived /container entry's env, where a read,!sensitive user can see it and a plain /export prints it (the #542 territory). A file stays out of RouterOS config and export.

Today centrs accepts the CDB key only from --cdb-password or CENTRS_CDB_PASSWORD, and a target password only from the flag, the env or the CDB. devices add/set adds --password-stdin (#582). Inside a container, that leaves two bad choices: plumb the secret into env, or have every agent run CENTRS_CDB_PASSWORD=$(cat /run/secrets/…) centrs ….

Measured for tikoci/app-t3code#47 (research, PR tikoci/app-t3code#73, CHR 7.25.2 x86, centrs 0.2.0-next):

  • centrs devices init --encrypt keyed from /run/secrets/routeros_pw creates /data/.config/tikoci/winbox.cdb (0600, no plaintext). __default__ is admin with an empty password, plus a gateway record. retrieve then works with every source cdb, and fails closed without the key (cdb/password-required).
  • A router-side /user/add name=t3code group=<ro> password=[/file/get …/secret-routeros_pw contents] turns the same generated value into a dedicated account. centrs read through the CDB as that user, and RouterOS refused a write. So one file served as both the CDB key and the account password.

The only missing piece is getting the key to each centrs process without env. This scheme isn't app-t3code-specific: any centrs in a RouterOS /app or Docker container has /run/secrets.

Proposal

  1. CENTRS_CDB_PASSWORD_FILE / --cdb-password-file <path>: read the CDB key from a file, stripping one trailing newline (as --password-stdin does). Also for centrs mcp.
  2. CENTRS_PASSWORD_FILE / --password-file <path> for the target password, for parity. app-t3code may not use it, but the pair should match.
  3. devices add|set --password-file <path>: the record password from a file. Optionally remove the file after a successful write, for T3 Code's secret cards: T3 delivers a value the user typed to an owner-only file that lasts about 24 h. An agent could then devices add <router> --user u --password-file <path>, and the plaintext wouldn't outlive the import. T3's multi-field cards write one file per field, so a whole-record-from-file form is a possible follow-up, not part of this.

Rules to settle (constitution)

  • Setting both X and X_FILE (or the flag and its file form) is a usage error, not a silent precedence.
  • meta.settings reports the source as a file (the env key or the flag), never the contents. Errors name the path, not the value.
  • centrs.env still never carries credentials. Whether it may carry a *_FILE path (a pointer, not a secret) is a decision to make here.
  • The constitution's credential rules (the CDB is the credential store; CENTRS_CDB_PASSWORD never comes from centrs.env or a file) give way for an explicit path the caller names. The reason for the old rule, a decrypt password persisted beside the CDB, doesn't apply to /run/secrets.

Filed from app-t3code#47 at the owner's request.

Activity

  1. mobileskyfi commented on Nov 25, 2026

    @mobileskyfi
    ContributorAuthor

    Correction to item 3, from the review of tikoci/app-t3code#73 (checked against T3 v0.1.12 apps/server/src/secrets/SecretRequests.ts). T3 writes a card's typed value to its plaintext secret store first, then moves it to an owner-only file under <T3 state>/secrets/files. It sweeps those files by mtime at startup and then hourly. So --password-file with remove-after shortens how long the plaintext stays on the container's persistent volume; it doesn't avoid it. Items 1 and 2 (/run/secrets) are unaffected.

  2. mobileskyfi commented on Nov 25, 2026

    @mobileskyfi
    ContributorAuthor

    Triage. Reviewer: claude-code/claude-opus-5-5 · head 3cf57ae (main) · session t3code thread c4f35b6a-f56e-4cad-b640-9060ce54d101

    Fit. This is option (a) of #603, which the Auth and secrets theme already plans. The theme's long-term shape is three sources per secret: a value, a file, and later a password command or keychain helper. Built as below, #672 needs no rework when the command form lands. It goes on the current track so app-t3code can try it in a next release.

    Scope, as settled with the maintainer:

    1. Keep. --cdb-password-file / CENTRS_CDB_PASSWORD_FILE, including centrs mcp.
    2. Keep. --password-file / CENTRS_PASSWORD_FILE for the target password.
    3. Dropped. devices add|set --password-stdin < <path> already reads a record password from a file (devices set/add record password needs a non-argv channel (env/stdin) #582). Removing the file after import only shortens how long the plaintext stays on disk, since T3 has already stored the value; that cleanup is T3 Code's job. centrs never deletes a file the caller gave it, which would also fail on a read-only /run/secrets mount.

    Implementation rules:

    • One resolver. CENTRS_CDB_PASSWORD is read separately today in src/devices.ts, src/mcp/config.ts, src/resolver/selection.ts, src/resolver/cdb.ts and src/resolver/settings.ts. Resolve value-or-file once and return { value, source }, shared by CLI, MCP and the library. The later _COMMAND form then becomes one more case in it.
    • Conflicts. Value, file and (later) command are one choice per secret. Setting more than one, as flag or env, is usage/conflicting-flags.
    • Read on each CDB load, not at process start. mcp/config.ts currently keeps the password for the life of the process. Reading per load lets rotating or deleting the file take effect at the next call, which is MCP/CDB: unlock-password channel for hosts that don't pass env (password command or file, fetched per load) #603's lock behaviour.
    • Errors. A missing, unreadable or empty file is cdb/password-unavailable (MCP/CDB: unlock-password channel for hosts that don't pass env (password command or file, fetched per load) #603's code); no source configured stays cdb/password-required. Errors name the path, never the contents. On MCP the fix text tells the operator to configure the server's password source and never invites the agent to ask the user for the password.
    • Trailing newline. Strip it with the same helper --password-stdin uses (readPasswordStdin), so the two can't drift apart.
    • meta.settings reports { kind: "file", key } (the env key or the flag). It may show the path and never shows the value.
    • No *_FILE in centrs.env or any workspace file. Only a flag or the process environment may name the path. Otherwise a cloned workspace could point CENTRS_PASSWORD_FILE at ~/.ssh/id_ed25519 and, through its own CDB record, send that file to a host it chose. In a container, /app YAML environment: carries the path, which is enough. Add the *_FILE keys to the list settings refuses to write and to the keys the centrs.env reader ignores, next to CENTRS_CDB_PASSWORD. This rule is also why Read passwords from files: CENTRS_CDB_PASSWORD_FILE, CENTRS_PASSWORD_FILE and --*-file (container /run/secrets) #672 can go ahead of the theme's workspace gate.
    • No file-permission check. Modes on /run/secrets vary, and on RouterOS they don't mean anything, so a group- or world-readable file is accepted without a warning.

    Docs. Using one generated value as both the CDB key and the RouterOS account password suits app-t3code, but centrs docs shouldn't present it as the recommended pattern.

    Acceptance. examples.md entries for both forms. A unit test proves file contents never appear in an envelope. CHR integration runs retrieve keyed from a file. #603's stdio MCP checks run on an encrypted throwaway fixture: no password in argv or env; deleting the file makes the next call return cdb/password-unavailable without crashing.

    Matrix change: tikoci/centrs PR on branch docs/matrix-672-password-files.

  3. added
    from-app-t3code
    hardening
    on Nov 25, 2026
  4. mobileskyfi commented on Nov 25, 2026

    @mobileskyfi
    ContributorAuthor

    Alignment review from the app-t3code side, against the triage above. Reviewer: claude-code/claude-opus-5-5, cross-checked with tikoci/app-t3code#73 at a41224e, which now matches this scope.

    Agreed as triaged: items 1 and 2, dropping item 3 (--password-stdin < <file> covers the import; app-t3code's recipe or T3's sweep deletes the file), one resolver, the conflict rule, re-reading on each CDB load, cdb/password-unavailable, no permission check, and not documenting one value for both the CDB key and a router password as the recommended pattern. In a RouterOS container, the /app YAML environment: and the image ENV are process environment, so the "flag or process env only" rule works for app-t3code.

    Three things to settle before building:

    1. Installed centrs reads CENTRS_* from the working directory's .env (Bun auto-load) #666 undercuts the "process environment only" rule. The installed centrs is #!/usr/bin/env bun (still true at 3cf57ae), and Bun loads the working directory's .env into process.env. So a cloned workspace's .env with CENTRS_PASSWORD_FILE=~/.ssh/id_ed25519 looks like process environment to centrs. That is the exact ~/.ssh case the triage uses to keep *_FILE out of centrs.env and workspace files. Suggest making Installed centrs reads CENTRS_* from the working directory's .env (Bun auto-load) #666 a prerequisite of Read passwords from files: CENTRS_CDB_PASSWORD_FILE, CENTRS_PASSWORD_FILE and --*-file (container /run/secrets) #672, or fixing them together; how the auto-load gets turned off is Installed centrs reads CENTRS_* from the working directory's .env (Bun auto-load) #666's call. In app-t3code, agents work inside cloned repos all the time, so this is the usual case, not an edge case.
    2. A missing key file when no key is needed. app-t3code has a rule that every YAML environment: key is also an image ENV default. So CENTRS_CDB_PASSWORD_FILE=/run/secrets/<name> would be set on every run, including Docker without that secret and a first start before any CDB exists. If centrs returns cdb/password-unavailable whenever the variable is set and the file is missing, plain use breaks there. Suggestion: it's an error only when the key is actually needed (loading an encrypted CDB, or init --encrypt); otherwise a warning, like today's unused---cdb-password warning. Either way, app-t3code needs to know which behavior to design for.
    3. CENTRS_PASSWORD_FILE in a container env replaces every record's password. The env tier outranks CDB records (args → env → record → __default__), as CENTRS_PASSWORD does today. That's correct behavior, but a container that sets it globally makes the CDB's per-router passwords useless. Worth one sentence in the examples.md entry: set it per invocation, or keep router passwords in the CDB. app-t3code won't set it in the container env (recorded in test(ci): green the windows-latest unit tier — SO_REUSEPORT skip + null-sink/basename portability (#69) #73).

    app-t3code's open choice of one app secret or two (CDB key and account password) is on our side and doesn't affect this issue.

  5. added a commit that references this issue on Nov 26, 2026
  6. mobileskyfi commented on Nov 26, 2026

    @mobileskyfi
    ContributorAuthor

    Settling the three points from the app-t3code review. Reviewer: claude-code/claude-opus-5-5 · head ccee2ff (PR #673) · session t3code thread c4f35b6a-f56e-4cad-b640-9060ce54d101

    1. Installed centrs reads CENTRS_* from the working directory's .env (Bun auto-load) #666 is a prerequisite. The "flag or process environment only" rule doesn't hold while Bun loads a cloned repo's .env into process.env. Installed centrs reads CENTRS_* from the working directory's .env (Bun auto-load) #666 lands first, or in the same PR as this. The matrix track item (PR docs(matrix): put password files (#672) on the current track #673) now says so. I've added a note on Installed centrs reads CENTRS_* from the working directory's .env (Bun auto-load) #666 about env -S in a container base image.

    2. A key file that is missing when no key is needed is a warning, not an error. The file is read only when a key is actually needed:

      • loading an encrypted CDB;
      • devices init --encrypt;
      • devices add-encryption.
      Case Result
      Key needed, file missing, unreadable or empty cdb/password-unavailable
      Key not needed (open CDB, no CDB yet, or no CDB-backed work), file missing warning, no error
      Key not needed, file present the existing cdb/password-not-needed warning, as for an unused --cdb-password

      For the missing-file warning, either reuse cdb/password-not-needed with the path in its context or add a sibling code; that's the implementer's choice, recorded in the errors catalog either way. A file alone never converts an open CDB, the same rule as for a password value today. This makes an image-wide CENTRS_CDB_PASSWORD_FILE default safe on plain Docker and on a first start.

    3. CENTRS_PASSWORD_FILE outranks CDB records. This follows the normal order (args → env → record → __default__), as CENTRS_PASSWORD does today. If it is set but the file is missing, resolving a target password is an error (usage/cdb/password-unavailable, whichever the shared resolver settles on). It never quietly falls back to the record. The examples.md entry says to set it per invocation, or to keep router passwords in the CDB, and not to set it in a container-wide env.

    Acceptance gains two checks: a set-but-missing CENTRS_CDB_PASSWORD_FILE with an open or absent CDB gives a warning and ok:true; and a working-directory .env that sets CENTRS_PASSWORD_FILE has no effect (covered by #666's test).

  7. mobileskyfi commented on Nov 26, 2026

    @mobileskyfi
    ContributorAuthor

    Maintainer confirmed points 1–3 above. One addition for app-t3code, on point 3: the maintainer leans toward app-t3code using its own environment names for router credentials (not CENTRS_*), with its t3app init writing them into the CDB's __default__ record. Router credentials then live in the CDB like any other, and nothing in the container environment outranks the records. This is app-t3code's design and doesn't change this issue's scope.

    On #666 (the prerequisite): the proposed env -S shebang fails on BusyBox (v1.36 to v1.38, Alpine and oven/bun:alpine), so #666 now suggests filtering the .env keys inside centrs instead. Details on #666.

    Reviewer: claude-code/claude-opus-5-5 · session t3code thread c4f35b6a-f56e-4cad-b640-9060ce54d101

  8. added 3 commits that reference this issue on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    from-app-t3codehardening

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions