Skip to main content

CLI tool to manage proxy shadow keys

Project description

Proxy Shadow Keys

A CLI tool and local proxy service designed to intercept network requests and transparently replace "shadow keys" (e.g., shadow_my_api_key) with your real, secret keys stored securely in the macOS Keychain.

This tool allows developers to use placeholder keys in their application code or environment files, preventing accidental exposure or commits of sensitive API keys to version control.

Intentions

  • Security Details: Never hardcode real API keys in your .env files, scripts, or repositories.
  • Convenience: Use consistent placeholder keys (like shadow_stripe_secret) across your projects and let the proxy handle inserting the real sensitive values behind the scenes.
  • Fallbacks: If a shadow key isn't found in your secure vault, the proxy sends the original placeholder unchanged, preventing unexpected crashes and making debugging easy.

Project Structure

proxy-shadow-keys/
├── src/
│   └── proxy_shadow_keys/
│       ├── cli.py            # Click-based CLI commands (set, rm, start, stop, install-cert)
│       ├── interceptor.py    # mitmproxy addon that intercepts and replaces shadow keys
│       └── system_proxy.py   # Cross-platform utility to toggle system proxy settings (Windows, macOS, Linux)
├── tests/
│   ├── features/             # Behavior-Driven Development (BDD) feature specifications
│   └── step_defs/            # pytest-bdd step definitions
└── pyproject.toml            # Project configuration and dependencies

How It Works

  1. Store Keys: Use the CLI to store a real key mapping in your system's keyring (macOS Keychain, Windows Credential Locker, or Linux Secret Service).
  2. Start Proxy: The CLI starts a local mitmproxy instance in the background and configures your OS system proxy (macOS networksetup, Windows Registry, or Linux gsettings) to route traffic through it.
  3. Intercept & Replace: As your system makes HTTP/HTTPS requests, the mitmproxy addon parses request headers, JSON bodies, and URL query parameters. When it detects a string starting with shadow_, it queries the local keyring to swap the placeholder with the real API key before forwarding the request to its destination.

Requirements

  • macOS, Windows, or Linux (GNOME)
  • Python 3.9+
  • mitmproxy installed and available

Installation

The recommended way to install and run the CLI globally in an isolated environment is using pipx or uv:

# Using uv (fastest)
uv tool install proxy-shadow-keys

# Or using pipx
pipx install proxy-shadow-keys

Alternatively, you can install the package directly from source or use it in development mode:

# Clone the repository
git clone git@github.com:Tavernari/proxy-shadow-keys.git
cd proxy-shadow-keys

# Install dependencies and the CLI tool
pip install -e .

Usage

1. Certificate Installation

For the proxy to inspect encrypted HTTPS traffic, you must first install and trust the mitmproxy CA certificate. Run this command once (requires sudo privileges):

proxy-shadow-keys install-cert

2. Managing Shadow Keys

Map a placeholder shadow_ key to your real API key (stored securely via keyring):

proxy-shadow-keys set shadow_openai_key sk-proj-123456789...

To remove a mapped key:

proxy-shadow-keys rm shadow_openai_key

3. Proxy Lifecycle

Start the proxy. This will launch mitmproxy in the background and configure your local network settings to use the local proxy:

proxy-shadow-keys start

(Default port is 8080. You can optionally pass --port 8081)

When you're done, stop the proxy to restore your standard network settings:

proxy-shadow-keys stop

Testing

The project uses a BDD approach with pytest and pytest-bdd. All functionality is strictly defined in feature files before implementation.

# Install development dependencies
pip install -e ".[dev]"

# Run all tests
pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

proxy_shadow_keys-0.1.1.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

proxy_shadow_keys-0.1.1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file proxy_shadow_keys-0.1.1.tar.gz.

File metadata

  • Download URL: proxy_shadow_keys-0.1.1.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for proxy_shadow_keys-0.1.1.tar.gz
Algorithm Hash digest
SHA256 14ec09f399e3b5e2fa8da1e1438a22d05b4641701ff766215f9b2c03241b62ec
MD5 2a0a40ceda9ad4a4e118fd0a2dd5c243
BLAKE2b-256 56c3ea94c45fc81a97a6834edd350c5a41c178913f60f7482ab952e0b3e9fbe6

See more details on using hashes here.

Provenance

The following attestation bundles were made for proxy_shadow_keys-0.1.1.tar.gz:

Publisher: release.yml on Tavernari/proxy-shadow-keys

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file proxy_shadow_keys-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for proxy_shadow_keys-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f2d882f136afc1b55cf88bc5592ae8913bfd799d3ab41e29dcd3d8d212238df1
MD5 80bff775662dda0bd0c963c46f98caef
BLAKE2b-256 7a77b0678b42b5c770e6845f7192b1c5e95b2e93d8f199cc8a508d5996f2d0cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for proxy_shadow_keys-0.1.1-py3-none-any.whl:

Publisher: release.yml on Tavernari/proxy-shadow-keys

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page