Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:2aronS Duel Agents Secret Isolation

From Leeroopedia
Knowledge Sources
Domains Security, Configuration
Last Updated 2026-10-27 14:00 GMT

Overview

Technique for keeping a secret credential out of structured configuration files by storing only an environment-variable reference in the config and writing the actual secret to a separate `.env` file that the tool reads at runtime, minimizing the surface where the plaintext key appears.

Description

Configuration files like `openclaw.json` are often committed to version control, shared between machines, or displayed in bug reports. If a credential is written into such a file in plaintext, it leaks. Even if the file is local-only, structured JSON configs are more likely to be inspected, copied, or backed up than a `.env` file that developers are trained to gitignore.

Secret isolation separates the credential from the config:

  • Config holds a reference — the config file contains `apiKey: "${DUEL_API_KEY}"`, an interpolation placeholder, not the actual key. This is safe to commit, display, or back up.
  • Secret lives in `.env` — the actual `DUEL_API_KEY=duel_...` is written to a separate `.env` file that the tool reads at startup via standard environment-variable loading
  • Patch construction enforces this — the function that builds the config patch hardcodes the placeholder string `${DUEL_API_KEY}` and never accepts the plaintext key into the config body; the key only flows into the `.env` merge

This pattern is the 12-Factor App config principle applied to a single tool: the config file holds structure, the `.env` file holds secrets, and the runtime resolves the reference.

Usage

Use this principle when:

  • Writing a credential into a config file that may be committed, shared, or displayed
  • The config file format supports environment-variable interpolation (e.g., `${VAR}` syntax)
  • You want to minimize the number of files that contain the plaintext secret
  • A tool reads its secrets from `.env` at runtime but its config from a structured file

Theoretical Basis

The invariant is that the plaintext key never appears in the structured config:

# Abstract algorithm (NOT real implementation)
def build_patch(key: str, proxy_url: str) -> dict:
    require_valid_key(key)
    return {
        "models": {
            "providers": {
                "duel": {
                    "baseUrl": proxy_url,
                    "apiKey": "${DUEL_API_KEY}",  # PLACEHOLDER, never plaintext
                    "api": "openai-completions",
                    ...
                }
            }
        },
        "env": {"DUEL_PROXY_URL": proxy_url}  # URL is not secret
    }

def isolate_key(config_path: str, env_path: str, key: str, proxy_url: str):
    patch = build_patch(key, proxy_url)
    write_config(config_path, deep_merge(read_config(config_path), patch))
    # Key goes ONLY to .env, never to the config file
    merge_env_file(env_path, {"DUEL_API_KEY": key, "DUEL_PROXY_URL": proxy_url})

The separation of concerns is strict: the config-writing path never receives the plaintext key, and the `.env`-writing path never receives the config structure. A reference template file (`duel-provider.json`) mirrors the patch shape with the placeholder, serving as a human-readable reference that is itself safe to commit.

Related Pages

Implemented By

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment