Skip to main content

Rekey

Zero-downtime API key rotation for developers and agents, using a dual-key (overlap) flow.

CLI / MCP ──► Orchestrator ──► Provider Adapter  (create / verify / revoke)
                         └───► Destination Updaters (write only)

Dual-key flow

  1. Create a new key — the old key stays valid
  2. Verify it (pre-flight)
  3. Update every destination
  4. Verify again
  5. Revoke the old key (or let it expire)

The old key is never revoked unless steps 1–4 succeed. If something fails before any destination is written, the new key is revoked. If it fails mid-update, nothing is revoked and the report lists which destinations already hold the new key.

Bootstrap Modes (How keys are acquired)

Rekey supports three bootstrap mechanisms to mint or rotate keys, all adhering to the exact same dual-key interface:

Mode How keys are minted Best Used When Supported Providers
api Direct REST API calls with admin credential Fully automated pipelines, server environments, or CI/CD OpenAI (Admin key), GitHub (App private key)
cli Official vendor CLI subprocess (redacted output) Tooling already has a logged-in CLI on dev machines Stripe (stripe login)
oauth RFC 8628 Device Flow (browser delegation + token store) Developer machines where human authentication is preferred over long-lived root keys GitHub (OAuth Apps)
assisted User pastes rotated key into hidden prompt Fallback when automated endpoints do not exist Any

Choose the mode in rekey.yaml via provider.mode: api | cli | oauth.

OAuth Flow Example (GitHub)

When using mode: oauth:

  1. Rekey initiates RFC 8628 Device Flow and presents a short user code:
    [OAuth] Complete authentication in your browser:
      URL:  https://github.com/login/device
      Code: WDWN-ABCD
    
  2. Your browser opens automatically; confirm the device.
  3. Rekey securely stores the refresh & access token in ~/.config/rekey/oauth_tokens.json (0600 permissions).
  4. Rekey completes the dual-key flow: verifies /user, syncs destinations, and lets old tokens expire.

Install & run

pip install -e ".[mcp,dev]"
cp rekey.example.yaml rekey.yaml        # edit ids; no secrets in this file
export OPENAI_ADMIN_KEY=...             # credentials come from env vars only

rekey list
rekey rotate openai-prod                # dry run (default)
rekey rotate openai-prod --execute

MCP server

REKEY_CONFIG=./rekey.yaml rekey-mcp

Add to your MCP client config (e.g. mcp_config.json):

{
  "mcpServers": {
    "rekey": {
      "command": "/abs/path/to/rekey/.venv/bin/rekey-mcp",
      "env": { "REKEY_CONFIG": "/abs/path/to/rekey/rekey.yaml" }
    }
  }
}

Provider credentials (e.g. OPENAI_ADMIN_KEY) must be in the server's environment — never pass them through the agent. Works with MCP SDK 1.x (FastMCP) and 2.x (MCPServer).

Tools: list_targets, rotate_key(target, dry_run=True). Responses contain only masked values and fingerprints — agents never see a secret. Assisted mode is refused over MCP.

Destinations & Environment Targeting

Rekey supports pushing rotated keys to multiple destinations and environments simultaneously:

Destination Environment Field Example Config
Local .env path (file-based) path: .env.production
GitHub Actions environment (optional) environment: production (updates environment secret) or omit for repo secret
Vercel targets (optional list) targets: [production, preview] or [production] (default)
destinations:
  - type: env_file
    path: .env.production
    variable: OPENAI_API_KEY

  - type: github_actions
    owner: myorg
    repo: my-app
    secret_name: OPENAI_API_KEY
    environment: production          # targets GitHub Environment

  - type: vercel
    project: my-nextjs-app
    env_name: OPENAI_API_KEY
    targets: [production, preview]   # updates multiple Vercel environments

Layout

src/rekey/
  adapters/      base.py openai.py github.py stripe.py assisted.py
  destinations/  base.py env_file.py github_actions.py
  orchestrator/  rotator.py
  mcp/           server.py
  cli.py config.py state.py secrets.py runner.py
tests/

Tests

pytest

Metadata

Release files for rekey-cli 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rekey-cli 0.1.0
File Size Uploaded Provenance
rekey_cli-0.1.0.tar.gz 26.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for rekey-cli 0.1.0
File Interpreter ABI Platform
rekey_cli-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 64.4 kB

Release files / rekey_cli-0.1.0.tar.gz

Download URL rekey_cli-0.1.0.tar.gz
Size 26.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e221558687e7d7ef43d03d55049d3fcba98b0319e370a1024a38f9fe1bc35cdd
BLAKE2b-256 checksum
How to use checksums
83510752a23f182f8fc48bb58ddd36db34cb3190fac3989123c2e39ebf1d58ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / rekey_cli-0.1.0-py3-none-any.whl

Download URL rekey_cli-0.1.0-py3-none-any.whl
Size 38.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c454a3754f072e5ad5a7f11e09013454aa4139ab8e6bbdbcd561f30caf836a98
BLAKE2b-256 checksum
How to use checksums
2c58d5173a29d0eb78203f1a76b9568375dff804b66d7c2f01393ba436ce589e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for rekey-cli 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page