Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions .env.example

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
# Node environment variable files
.env
.env*
!.env.example
!.env.test

# caches
Expand Down
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,35 @@ The minor bump marks the coming transport-default change (native-api first,
with availability-aware fallback; not in these previews yet). Preview builds
publish `0.2.0-next.<run_number>` to `@next`; `@latest` stays on 0.1.10.

### Added

- **Password files** (#672): `--cdb-password-file` / `CENTRS_CDB_PASSWORD_FILE`
and `--password-file` / `CENTRS_PASSWORD_FILE` read the CDB key and the
target password from a file, such as a container's `/run/secrets/<name>`,
on the CLI, `centrs mcp` and the library (`cdbPasswordFile`,
`passwordFile`). The CDB key file is read on each encrypted-CDB load, so
rotating or deleting it takes effect at the next call. A file that cannot
give a password is `cdb/password-unavailable` or `auth/password-unavailable`;
an unneeded CDB key file is not read, and a missing one is only the
`cdb/password-not-needed` warning. ssh (execute, sftp/scp, terminal) sends
no password, so it reads no password file. Value and file in one tier is
`usage/conflicting-flags`. `meta.settings` reports `{kind:"file", key}`.
Only flags and the process environment may name a file: `settings set`
refuses the keys and the `centrs.env` loader drops them.

### Changed

- **A working-directory `.env` no longer reaches centrs** (#666). Bun
auto-loads `.env`, `.env.local` and `.env.<mode>` into `process.env` and
reads its own startup settings from them; when it did, the CLI and
`centrs mcp` entries now re-launch once under `bun --no-env-file` with the
launch environment, and print `settings/dotenv-ignored` on stderr naming
the `CENTRS_*` keys ignored. On Linux the launch environment is exact;
elsewhere a key a `.env` file names is dropped even if the shell exported
it, except the Windows system variables (`PATHEXT`, `SYSTEMROOT`, `WINDIR`,
`COMSPEC`). A dropped `HOME` falls back to `os.homedir()`, and a named
`PATH` is reset to the system default. `.env.example` is gone.

- **Error codes:** RouterOS's `no such …` answers now split by meaning
(#659, CHR 7.25.1 and 7.24.6). A missing item in a menu that exists
(native `no such item`, a bare REST HTTP 404, `/execute`'s
Expand Down
8 changes: 8 additions & 0 deletions GLOSSARY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -861,3 +861,11 @@ pids
EOPNOTSUPP # operating-system error: the requested operation is not supported
ENOSYS # operating-system error: the requested function is not implemented
NTFS # Windows filesystem supporting the hard links used by the CDB lock
# Dotenv guard (#666): environment variables the OS always sets, kept on re-launch
SYSTEMROOT # Windows system directory variable
WINDIR # Windows directory variable
PATHEXT # Windows executable extensions variable
COMSPEC # Windows command interpreter variable
Wbem # Windows Management Instrumentation directory in the default Windows PATH
NONBLOCK # O_NONBLOCK open flag: a password file never blocks on a FIFO
mkfifo # POSIX command that makes a named pipe (FIFO), used in tests
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ CLI/MCP add, set and remove operations and `discover --save` reload and retry.
Close WinBox before mutating the same file: external writers do not take the
centrs lock.
Encrypted-CDB reads and writes work with `--cdb-password` /
`CENTRS_CDB_PASSWORD`; writes decrypt, mutate and re-encrypt with a fresh salt.
`CENTRS_CDB_PASSWORD`, or a file holding the password with
`--cdb-password-file` / `CENTRS_CDB_PASSWORD_FILE` (a container's
`/run/secrets/<name>`); writes decrypt, mutate and re-encrypt with a fresh salt.
A target password can come from a file the same way (`--password-file` /
`CENTRS_PASSWORD_FILE`).
`devices init --encrypt` creates an encrypted registry, and `devices encrypt`
explicitly converts an existing open CDB. Conversion retains existing backups
and warns that plaintext copies remain. The manual WinBox round-trip is still
Expand Down
11 changes: 7 additions & 4 deletions commands/devices/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,11 @@ can edit it too. Precedence is per-field: args → env → device record →

Start encrypted with `devices init --encrypt`, or start open for a lab and run
`devices encrypt` when moving to production. Both require a non-empty
`--cdb-password` / `CENTRS_CDB_PASSWORD`. A password alone does not change the
mode of initialization or ordinary writes. The library exports
`--cdb-password` / `CENTRS_CDB_PASSWORD`, or a file holding it
(`--cdb-password-file` / `CENTRS_CDB_PASSWORD_FILE`, #672). A password alone,
or a file alone, does not change the mode of initialization or ordinary writes:
with an open CDB the file is not read, and a missing one is only the
`cdb/password-not-needed` warning. The library exports
`initCdb({ encrypt: true, cdbPassword, cdbFile })` and
`encryptCdb({ cdbPassword, cdbFile })`; both use the shared settings precedence.

Expand Down Expand Up @@ -575,8 +578,8 @@ warning still applies to them. Without the snapshot, a forgotten password cannot
be recovered.

`init` and `encrypt` act on the CDB file, not on records: they accept only
`--cdb-file`, `--cdb-password`, `--format`/`--json`, plus `--encrypt` (`init`)
or `--no-backup` (`encrypt`). Any other flag is `input/invalid-command`
`--cdb-file`, `--cdb-password`, `--cdb-password-file`, `--format`/`--json`,
plus `--encrypt` (`init`) or `--no-backup` (`encrypt`). Any other flag is `input/invalid-command`
instead of being silently ignored. `devices init --help` and
`devices encrypt --help` show only those accepted flags; the same metadata
generates their sections in [`docs/CLI.md`](../../docs/CLI.md).
Expand Down
10 changes: 8 additions & 2 deletions commands/mcp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ If `centrs` is already installed on `PATH`, the equivalent command is:
}
```

Use `CENTRS_CDB_PASSWORD` to read or write an encrypted CDB. The write layer
Use `CENTRS_CDB_PASSWORD` to read or write an encrypted CDB, or
`CENTRS_CDB_PASSWORD_FILE` (`--cdb-password-file`) to name a file that holds
it, such as `/run/secrets/<name>`. Then the password is in neither argv nor
the environment, and the file is read on every CDB load: rotating it takes
effect at the next call, and deleting it makes calls fail with
`cdb/password-unavailable` while the server keeps running. The write layer
decrypts under the loaded password, mutates the record set, and re-encrypts with
a fresh salt before the atomic rename. Prefer an unencrypted throwaway CDB for
bench harnesses and CI.
Expand Down Expand Up @@ -168,7 +173,8 @@ MCP server applies it as a hard allowlist:
- **CDB source** follows the constitution: default
`~/.config/tikoci/winbox.cdb`, overridden by `CENTRS_CDB_FILE` / `--cdb-file`,
or a freshly created CDB the operator hands the server at start. An encrypted
CDB is decrypted with `--cdb-password` (or `CENTRS_CDB_PASSWORD`). With no CDB,
CDB is decrypted with `--cdb-password` (or `CENTRS_CDB_PASSWORD`), or with
the file `--cdb-password-file` (or `CENTRS_CDB_PASSWORD_FILE`) names. With no CDB,
the server still serves `centrs_explain` (offline); CDB mutations require a
loadable CDB file.
- **Credentials live in the CDB and are never returned by MCP.** `centrs_devices
Expand Down
30 changes: 30 additions & 0 deletions commands/retrieve/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,36 @@ Exit 1, `transport/connection-refused`. `meta.via="rest-api"`, and
nowhere. `meta.validation` has no `result`; its device stage is `skipped` with
`reason: "not reached: transport/connection-refused"` (GH#435).

### 16d. The CDB key from a file (#672)

`$KEY_FILE` holds the password of the encrypted CDB `$ENC_CDB`, as a
container's `/run/secrets/<name>` does. One trailing newline is ignored.

```bash
centrs retrieve $R /system/resource --cdb-file $ENC_CDB --cdb-password-file $KEY_FILE --json
CENTRS_CDB_PASSWORD_FILE=$KEY_FILE centrs retrieve $R /system/resource --cdb-file $ENC_CDB --json
```

Both succeed with the record's credentials (`meta.settings.password.kind="cdb"`).
The key appears nowhere in the envelope. The file is read on each CDB load, so
after it is deleted the next call fails with `cdb/password-unavailable`.
Giving `--cdb-password` too is `usage/conflicting-flags`. With an open CDB the
file is not read: the run succeeds with a `cdb/password-not-needed` warning
that says whether the file exists.

### 16e. The router password from a file (#672)

```bash
centrs retrieve $R /system/resource --username $U --password-file $PW_FILE --json
```

`ok: true`; `meta.settings.password={kind:"file",key:"--password-file"}`. Like
`--password` and `CENTRS_PASSWORD`, a password file outranks every CDB record,
and a missing one is `auth/password-unavailable`, never a fall back to the
record. So set `CENTRS_PASSWORD_FILE` per invocation, or keep router
passwords in the CDB; in a container-wide environment it replaces every
record's password.

### 16c. The gate passed, then a later step failed (GH#435)

```bash
Expand Down
27 changes: 27 additions & 0 deletions commands/settings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ matters for what `get`/`set`/`print`/`reset` accept:
| --- | --- | --- |
| `CENTRS_PASSWORD`, `CENTRS_USERNAME` | Default credentials belong to the `__default__` CDB record, which routes through the `devices` write layer and is redacted from structured output (constitution: identity and CDB). A parallel copy in a plaintext file is a second source of truth for the same secret, one that is never redacted. | `centrs devices add __default__ --user … --password …` |
| `CENTRS_CDB_PASSWORD` | This is the CDB's own decryption password. Storing it beside an *encrypted* CDB in a plaintext sibling file defeats the encryption. Security-sensitive surface per `SECURITY.md`. | Pass `--cdb-password` per invocation, export the env var in the calling shell, or use `Bun.secret()` once available — never persist to `centrs.env`. |
| `CENTRS_PASSWORD_FILE`, `CENTRS_CDB_PASSWORD_FILE` | A path, not a secret, but only a flag or the process environment may name one (#672). A `centrs.env` line, or a cloned workspace's file, could otherwise point it at `~/.ssh/id_ed25519` and send that file as a password. The `centrs.env` loader drops these keys too. | `--password-file` / `--cdb-password-file` per invocation, or the launching environment (a container's env, an MCP server's launch config). |
| `CENTRS_SKIP_ENV_FILE` | Self-referential: it means "don't load `centrs.env`." Writing it *into* `centrs.env` is a no-op by construction (a file that says "ignore me" is never read to find out). | Export it in the shell or pass `--skip-env-file` per call. |
| `CENTRS_RUN_FAST_INTEGRATION` | A CI/test signal, not a user preference. | N/A — set by `bun run test:integration`, never by a human. |

Expand Down Expand Up @@ -225,6 +226,32 @@ canonical `CENTRS_FORMAT=` line. It is **user-global only** — the single XDG
path above; there is no project-local config file discovered from the working
directory.

**A working-directory `.env` is not read** (#666). Bun loads `.env`,
`.env.local` and `.env.<mode>` from the working directory into `process.env`
for any script it runs, and reads some of its own settings from them at
startup (`BUN_CONFIG_VERBOSE_FETCH` would print a REST Basic credential).
So when Bun loaded one, the CLI and `centrs mcp` entries re-launch once
under `bun --no-env-file` with the environment centrs was started with, and
print `warning [settings/dotenv-ignored]` on stderr naming the `CENTRS_*`
keys ignored (never their values). A cloned repo therefore cannot turn on
`CENTRS_INSECURE`, point `CENTRS_CDB_FILE`, a `*_FILE` key or
`XDG_CONFIG_HOME` somewhere, or switch on Bun's fetch logging. On Linux the
child gets exactly the exec-time environment (`/proc/self/environ`), and the
re-launch happens only when Bun changed it. Elsewhere, every key a Bun `.env`
file names is dropped except the Windows system variables (`PATHEXT`,
`SYSTEMROOT`, `WINDIR`, `COMSPEC`), which Windows always sets. A shell
export of a dropped key is lost too, which fails safe. That includes `HOME`:
it picks `centrs.env`, and a Windows shell often has none, so a dropped
`HOME` falls back to the account's home directory (`os.homedir()`). A named
`PATH` is reset to the system default (the OS's own `bin` and `sbin`
directories, or the `SYSTEMROOT` directories with OpenSSH on Windows): a service may start
Bun with no `PATH`, and the file must not pick which `ssh` runs. Bun also
allows a line break between a key and its `=`, so names are matched across
lines.
The shebang stays `env bun` (no `env -S bun --no-env-file`): BusyBox `env`
(Alpine, `oven/bun:alpine`) has no `-S`. A library caller passes its own
`env`.

**The `config` precedence layer** — `src/resolver/config-file.ts` resolves
`${XDG_CONFIG_HOME:-~/.config}/tikoci/centrs.env` (injectable `env` map,
mirroring `defaultCdbPath`) and `loadEnvFileDefaults()` parses it into a flat
Expand Down
5 changes: 4 additions & 1 deletion commands/terminal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ omits `BatchMode=yes` (`interactive: true` in `sshCommonOptions`), so the host
`ssh` can prompt on the inherited TTY for an encrypted key's passphrase or a
password. centrs does not forward `--password` to ssh — OpenSSH accepts no
password on the argv — so password auth is satisfied by that interactive prompt,
not by the centrs-resolved credential.
not by the centrs-resolved credential. For the same reason the ssh terminal
reads no password source: `--password-file` and `CENTRS_PASSWORD_FILE` are
mac-telnet only, so an image-wide file that is missing cannot stop a key or
agent login.

Resolved by the sftp transfer client (`src/protocols/sftp.ts`), so they are no
longer open for the file path: **host-key verification** rides the unified
Expand Down
Loading
Loading