Skip to content

feat(cli): add runtime credential injection command with log stream redaction - #12

Merged
LukeGus merged 5 commits into
Termix-SSH:dev-1.3.1from
CesarSanch1998:feat/inject-command
Nov 17, 2026
Merged

LukeGus merged 5 commits into
Termix-SSH:dev-1.3.1from
CesarSanch1998:feat/inject-command

Conversation

@CesarSanch1998

Copy link
Copy Markdown
Contributor

Summary

This PR introduces the termix inject command, allowing developers to securely fetch credentials stored in Termix and inject them directly into a child process's environment in memory at runtime (similar to Infisical or Vault agent injection).

Motivation

Developers often need to run scripts, CLI commands, or microservices that require credentials (API keys, database passwords, SSH private keys) stored in Termix, without:

  1. Writing secrets to disk in plaintext .env files.
  2. Leaving secrets in .bash_history or /proc/<pid>/cmdline.
  3. Manually fetching and copying credentials.

Key Security Features

  1. Zero-Disk Footprint: Credentials travel directly from Termix API over HTTPS into the child process's RAM. No temporary files or disk persistence.
  2. Real-time Log Stream Redaction (Output Masking):
    • Intercepts child process stdout and stderr streams in real time.
    • Automatically masks any injected secrets (passwords, tokens, SSH private keys) with [REDACTED_BY_TERMIX].
    • Prevents accidental credential leaks via console print, debug tracebacks, or unhandled exceptions.
  3. Multi-credential Support: Inject one or multiple credentials in a single command.
  4. Convenient Variable Mappings:
    • Injected by ID: TERMIX_<ID>_USER, TERMIX_<ID>_PASS, TERMIX_<ID>_KEY.
    • Injected by normalized credential name: e.g. a credential named Stripe API Key will be available as STRIPE_API_KEY and STRIPE_API_KEY_PASSWORD.

Syntax & Usage Examples

Basic syntax:

termix inject credential <ids...> -- <command...>
# or shorthand:
termix inject <ids...> -- <command...>

Example 1: Running a Python script with an API key

termix inject credential 4 -- python3 main.py

Example 2: Multiple credentials (e.g., DB and API keys)

termix inject 1 2 5 -- npm start

Example 3: Running a curl command without hardcoding tokens

termix inject 8 -- bash -c 'curl -X POST https://api.example.com -H "Authorization: Bearer $API_KEY"'

Verification & Testing

  • Unit tests added in test/inject.test.ts covering:
    • Environment variable name normalization (normalizeEnvName).
    • Output stream masking and redaction (maskSecrets).
  • Full test suite passed: 255 passed across 23 test files.
  • TypeScript type-check passed (tsc --noEmit).
  • ESlint and Prettier passed via pre-commit hooks.

@termix-triage-bot

termix-triage-bot Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

AI review | Looks safe to merge

Adds a termix inject command to fetch credentials and run a child process with them in the environment, optionally masking output. Contains a variable scope typo that crashes the CLI on child process exit when masking is active.

Reviewed 5340434. AI can be wrong, a maintainer still decides. Comment /termix review to run it again.

@LukeGus
LukeGus changed the base branch from main to dev-1.3.0 November 7, 2026 02:53

@LukeGus LukeGus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, the idea fits the CLI. A few things need to change before it can go in:

  1. Name based variables can overwrite the environment. A credential named Path, Home or Node Options sets PATH, HOME or NODE_OPTIONS to the password. Only set the TERMIX_<ID>_* names by default, and add an opt in flag like --names that refuses any name already in process.env.
  2. Too many names per credential. Keep one set: TERMIX_<ID>_USERNAME, TERMIX_<ID>_PASSWORD, TERMIX_<ID>_KEY (and the name based ones only behind the flag above).
  3. Drop the /plugin-api/import-export/export fallback. It pulls every host's secrets (and is audited as a full export) just to find one key. If /credentials/:id has no key, fail with a clear message.
  4. Use commander for the -- split instead of reading process.argv by hand (.passThroughOptions() with a variadic argument). As written, termix --server x inject ... or a host named inject breaks the parsing.
  5. Masking: piping stdout and stderr turns off the TTY for the child, so interactive programs, colors and prompts break, and a secret split across two chunks is not masked. Make masking opt in (--mask), inherit stdio otherwise, and keep the last maxSecretLength - 1 bytes of each chunk to mask across chunk edges.
  6. Forward signals (SIGINT, SIGTERM) to the child and exit with its code, and add a ## 1.3.0 CHANGELOG bullet plus a short section in the README command list.
  7. Please retarget nothing yourself, I moved the base to dev-1.3.0.

Tests for 1, 4 and 5 would be great.

@CesarSanch1998

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review, @LukeGus! All requested changes have been addressed:

  1. Explicit ID Variable Format: Injected variables by default are strictly TERMIX_<ID>_USERNAME, TERMIX_<ID>_PASSWORD, and TERMIX_<ID>_KEY. Redundant aliases were removed.
  2. Friendly Name Gating & Protection: Friendly name injection (STRIPE_API_KEY, etc.) now requires the --names flag. It aborts with a descriptive UsageError if a name collides with an existing process.env variable or another credential.
  3. Removed Export Fallback: Dropped the /plugin-api/import-export/export call; missing keys on /credentials/:id now fail cleanly with a clear error.
  4. Native Commander Parsing: Converted to native Commander .passThroughOptions() with positional args, preserving global options like --server.
  5. Opt-in Masking & Buffer Window: Stream masking is now opt-in via --mask (retaining raw interactive TTY and colors by default). Masking uses StreamMasker sliding window buffer to guarantee secrets split across stream chunks are redacted.
  6. Process Lifecycle: Implemented SIGINT/SIGTERM forwarding and child exit code propagation.
  7. Docs & Tests:Added entries to CHANGELOG.md under ## 1.3.0, updated README.md, rebased onto dev-1.3.0, and expanded the test suite to 11 unit tests covering all edge cases.

@LukeGus LukeGus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the command and the masking tests look good. One thing blocks it: program.enablePositionalOptions() in src/index.ts changes every command. Global flags are now only accepted before the subcommand, so termix hosts list --json and termix hosts list --url ... fail with unknown option. On dev-1.3.0 both work.

Please keep global options working after any subcommand. One way: drop enablePositionalOptions() and passThroughOptions(), use .allowUnknownOption() on inject, and read the command to run from process.argv after the first --. Add a test that termix hosts list --json still parses.

Also, bad input like a missing -- or an invalid id should exit with the usage code, not the internal error code.

@github-actions
github-actions Bot deleted the branch Termix-SSH:dev-1.3.0 November 8, 2026 19:30
@CesarSanch1998
CesarSanch1998 changed the base branch from dev-1.3.0 to main November 9, 2026 03:22
- enforce TERMIX_<ID>_USERNAME, TERMIX_<ID>_PASSWORD, TERMIX_<ID>_KEY
- gate friendly env names behind --names with process.env collision checks
- remove export fallback endpoint
- use native commander passThroughOptions with positional args
- make stream masking optional via --mask and implement sliding window buffer
- forward SIGINT/SIGTERM and propagate child exit code
- update CHANGELOG.md, README.md, and add unit tests
@CesarSanch1998
CesarSanch1998 changed the base branch from main to dev-1.3.1 November 13, 2026 14:49

@LukeGus LukeGus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is a nice addition. A few changes before it can go in:

  1. In the close handler, a child killed by any signal other than SIGINT or SIGTERM (SIGKILL, SIGHUP, an OOM kill) exits 0. Exit with 128 plus the signal number (os.constants.signals[signal]) so scripts see the failure.
  2. Two credentials whose names normalize to the same variable (like 'Stripe API Key' and 'stripe-api-key') silently overwrite each other. Please refuse with a clear error, or skip the name based variables for those and say so on stderr.
  3. Masking works per chunk, so a secret split across two stdout chunks can print unmasked. Keep the last (longest secret length - 1) bytes back between chunks before masking, and flush them on close. A test for a secret split over two writes would cover it.
  4. Add a short section on inject to the README's command list and to the CLI docs page in Termix-SSH/Docs if you can, so people find it.

@LukeGus LukeGus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @CesarSanch1998. Your last round covered the name clashes and split secrets. I added the 128 plus signal exit code, kept multi byte characters whole across chunks, merged dev-1.3.1 and wrote the docs section.

@LukeGus
LukeGus merged commit 17f205d into Termix-SSH:dev-1.3.1 Nov 17, 2026
5 checks passed
termix-ci Bot added a commit that referenced this pull request Nov 18, 2026
* fix: update zod and override minimatch for audit advisories

* chore: harden workflows, pin actions and add Dependabot for actions

* chore: run installs without scripts and lint the lockfile

* chore: drop overwrite mode, release as draft then publish

* feat: attest build provenance for release binaries

* feat: api-keys create takes read and full scopes and --never-expires

* fix: drop the npm cache from the release job that holds the App key

* fix: pin postject and build the binary without a shell

* chore: run CI on free GitHub runners

* chore: update dependencies (#28)

* chore: update dependencies

* chore: keep typescript below 7 until the tooling supports it

* fix: keep the original error as cause when rethrowing

* feat: users disable/enable, invite links and access-review commands

* feat(cli): add runtime credential injection command with log stream redaction (#12)

* feat(cli): add inject command for runtime credential injection with stream redaction

* feat(cli): address review feedback for inject command

- enforce TERMIX_<ID>_USERNAME, TERMIX_<ID>_PASSWORD, TERMIX_<ID>_KEY
- gate friendly env names behind --names with process.env collision checks
- remove export fallback endpoint
- use native commander passThroughOptions with positional args
- make stream masking optional via --mask and implement sliding window buffer
- forward SIGINT/SIGTERM and propagate child exit code
- update CHANGELOG.md, README.md, and add unit tests

* fix(cli): allow global options after subcommands and return exit code 2 on inject usage errors

* fix: exit 128 plus signal when the child is killed, keep split utf-8 whole

---------

Co-authored-by: LukeGus <bugattiguy527@gmail.com>

* chore: bring in main

---------

Co-authored-by: LukeGus <bugattiguy527@gmail.com>
Co-authored-by: Luke Gustafson <88517757+LukeGus@users.noreply.github.com>
Co-authored-by: CesarSanch1998 <100056699+CesarSanch1998@users.noreply.github.com>
termix-ci Bot added a commit that referenced this pull request Nov 18, 2026
* fix: update zod and override minimatch for audit advisories

* chore: harden workflows, pin actions and add Dependabot for actions

* chore: run installs without scripts and lint the lockfile

* chore: drop overwrite mode, release as draft then publish

* feat: attest build provenance for release binaries

* feat: api-keys create takes read and full scopes and --never-expires

* fix: drop the npm cache from the release job that holds the App key

* fix: pin postject and build the binary without a shell

* chore: run CI on free GitHub runners

* chore: update dependencies (#28)

* chore: update dependencies

* chore: keep typescript below 7 until the tooling supports it

* fix: keep the original error as cause when rethrowing

* feat: users disable/enable, invite links and access-review commands

* feat(cli): add runtime credential injection command with log stream redaction (#12)

* feat(cli): add inject command for runtime credential injection with stream redaction

* feat(cli): address review feedback for inject command

- enforce TERMIX_<ID>_USERNAME, TERMIX_<ID>_PASSWORD, TERMIX_<ID>_KEY
- gate friendly env names behind --names with process.env collision checks
- remove export fallback endpoint
- use native commander passThroughOptions with positional args
- make stream masking optional via --mask and implement sliding window buffer
- forward SIGINT/SIGTERM and propagate child exit code
- update CHANGELOG.md, README.md, and add unit tests

* fix(cli): allow global options after subcommands and return exit code 2 on inject usage errors

* fix: exit 128 plus signal when the child is killed, keep split utf-8 whole

---------

Co-authored-by: LukeGus <bugattiguy527@gmail.com>

* chore: bring in main

* fix: build the windows binary in bash so the asset name reaches npm

---------

Co-authored-by: LukeGus <bugattiguy527@gmail.com>
Co-authored-by: Luke Gustafson <88517757+LukeGus@users.noreply.github.com>
Co-authored-by: CesarSanch1998 <100056699+CesarSanch1998@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants