Zero-Disk Process Memory Injection
Learn how Ray CLI decrypts vault secrets in RAM and injects environment blocks into child processes with zero plaintext written to disk.
The core design principle of Ray Secrets is zero-disk plaintext exposure. Decrypted credentials exist exclusively in ephemeral process memory buffers and are never written to physical disk, SSD blocks, or temporary files.
1. Storage Controller Physics vs. Virtual Memory
Traditional secrets workflows rely on local .env files. While intuitive, this approach exposes credentials to non-volatile physical storage vulnerabilities:
- NAND Flash Wear-Leveling: Modern solid-state drives (SSDs) and NVMe controllers use wear-leveling algorithms in the Flash Translation Layer (FTL) to distribute write cycles evenly across physical memory cells. When an operating system unlinks or deletes a
.envfile, the controller merely marks the logical block addressing (LBA) metadata as unmapped; the raw plaintext data remains intact in physical NAND flash cells until garbage collection rewrites that block. - Commit History & Build Artifacts: Filesystem files are vulnerable to accidental git staging, container layer caching in Docker (
COPY . .), and backup snapshots. - Uncontrolled Inheritance: Shell scripts that export or source files pollute parent environment tables, leaking variables into all subsequent child subshells.
Ray Secrets addresses this physical vulnerability by eliminating filesystem writes entirely. Secrets are retrieved over authenticated TLS 1.3, decrypted exclusively in volatile DRAM, and passed directly into the operating system process creation pipeline.
2. Process Boundary Injection Mechanics
Operating systems isolate processes into private virtual address spaces managed by the CPU's Memory Management Unit (MMU) and kernel page tables. Ray CLI leverages native OS process creation APIs to inject decrypted secrets directly into the target child process.
+--------------------------------------------------------------+
| Child Process Memory |
+--------------------------------------------------------------+
| .text (Executable Machine Code) |
+--------------------------------------------------------------+
| .data / .bss (Global & Static Variables) |
+--------------------------------------------------------------+
| heap (Dynamic Allocations) |
+--------------------------------------------------------------+
| stack (Stack Frames & Local Variables) |
+--------------------------------------------------------------+
| envp [ KEY1=VAL1, KEY2=VAL2, ... ] <-- Injected in Memory |
+--------------------------------------------------------------+POSIX (Linux & macOS)
On Unix-like systems, process creation is separated into process cloning and program execution:
- Ray CLI fetches and decrypts secrets into an ephemeral in-memory dictionary.
- The CLI creates the child process using
fork(). - The child calls
execve()with an explicitenvppointer array:int execve(const char *pathname, char *const argv[], char *const envp[]); - The kernel initializes the new program image with
envploaded directly into its initial stack frame.
Windows (Win32)
On Windows, process creation is handled atomically through CreateProcessW:
- The CLI formats decrypted secrets into a double-null-terminated Unicode environment block (
KEY=VALUE\0...KEY=VALUE\0\0). - The block is passed directly to the
lpEnvironmentparameter ofCreateProcessW. - The Win32 subsystem allocates the Environment Block in the child process's Process Environment Block (PEB).
3. Process Table Security & /proc Boundaries
A critical security question in process memory injection is visibility in system process tables:
- Command Line Arguments (
argv): Never used for sensitive secrets. Command arguments passed to a program are stored in/proc/$PID/cmdlineand remain world-readable to all unprivileged users via utilities likeps auxortop. - Environment Block (
envp): Protected by OS kernel permissions. On Linux,/proc/$PID/environis restricted to mode0400(readable only by the process owner UID or processes withCAP_SYS_PTRACE). On macOS and Windows, cross-process environment reading requires administrative privileges or platform debugging entitlements.
4. Real-Time Output Stream Masking
Injecting secrets into child processes creates a risk of accidental log leakage if the child process prints sensitive variables to stdout or stderr.
Ray CLI includes an in-memory trie-based scrubbing engine:
- As secrets are resolved from the remote vault, their raw values are registered into an internal redaction trie.
- The child process's
stdoutandstderrstreams are piped through real-time masking transformers (createMaskingStream). - Any substring matching a registered secret value is automatically replaced with
***before streaming to terminal consoles or CI log aggregators.
To disable output masking for local debugging, pass the --no-mask flag.
5. Subprocess Tree Lifecycle & Signal Forwarding
To ensure that injected processes do not linger as orphaned daemons in memory:
- Signal Forwarding: Ray CLI intercepts OS process signals (
SIGINT,SIGTERM,SIGHUP,SIGQUIT) and immediately propagates them to the child process PID. - Process Subtree Termination: Upon process termination, Ray CLI initiates a tree-kill sequence to terminate all child subprocesses and worker threads, ensuring no orphaned background processes continue holding decrypted secrets in memory.
6. Ephemeral Filesystem Mount Sandbox for Legacy Tooling
While direct memory injection works for modern applications, certain compilers, static code generators, or legacy enterprise CLI utilities require a physical file path on disk (e.g. --config path/to/.env).
For these edge cases, Ray CLI provides an explicit sandboxed fallback via --mount:
ray run --mount .env -- npm run build:legacy| Flag / Option | Type | Description |
|---|---|---|
--mount <path> | string | Write secrets temporarily to an ephemeral in-memory or filesystem file path during process execution |
When --mount is specified, Ray CLI enforces strict defensive controls:
- Workspace Containment: Validates that the requested mount path resides strictly within the workspace root, rejecting directory traversal attempts (
../). - Restricted POSIX File Mode: Writes the file with mode
0600(read and write permissions restricted strictly to the current user). - Automatic Gitignore Protection: Automatically verifies and appends the mounted path to
.gitignoreto prevent version control commits. - Collision Backup: If a target file already exists, Ray CLI requires the
--forceflag, backing up the original file to a timestamped archive in.ray/tmp/. - Synchronous Exit Cleanup: Registers synchronous process exit and signal hooks (
cleanupMountSync). When the command finishes or receives a termination signal, the temporary file is unlinked immediately, and any backed-up file is restored.
7. Security Guarantees Matrix
| Security Boundary | Protection Mechanism | Plaintext Exposure |
|---|---|---|
| At Rest | AES-256-GCM authenticated encryption in remote vault | Zero plaintext |
| In Transit | TLS 1.3 authenticated REST & WebSocket streaming | Zero plaintext |
| On Physical Disk | Ephemeral process memory injection (zero disk I/O) | 0 Bytes on Disk |
| Process Boundary | Kernel MMU private virtual memory isolation (POSIX execve / Win32 PEB) | Isolated to child PID |
| Console Output | In-memory trie-based real-time stream scrubber | Automatically redacted (***) |
| Legacy Mount | Mode 0600 restricted file with synchronous exit traps | Ephemeral (unlinked on exit) |
Ready to eliminate plaintext secrets?
Create a workspace to organize environments, invite your team, and generate scoped Service Tokens for CI/CD.