Skip to content

cm8421/keygate

Repository files navigation

Keygate

Keygate — Zero-Trust Credential Gateway for AI Agents. Securely expose API credentials to AI through the MCP protocol and local proxy — passwords never enter the LLM context.

Core Features

  • 🔐 AES-256-GCM Encryption: Industry-grade encryption standard, keys stored in OS Keychain
  • 🤖 MCP Server: Seamless integration with Claude Code and other AI Agents
  • 🔄 Proxy Mode: Local reverse proxy automatically replaces credentials, AI only sees aliases
  • 🖥️ CLI Tool: Complete command-line password management interface
  • 🔌 Plugin System: Support for custom Provider plugins
  • 📝 Audit Logs: Complete password access audit trail

Quick Start

One-Click Install (Recommended)

curl -fsSL https://raw.githubusercontent.com/cm8421/keygate/main/scripts/install.sh | bash

After installation, the service will start automatically and be configured for auto-start on boot.

Manual Install

# Install dependencies
npm install

# Build
npm run build

# Initialize vault
kg init

# Install auto-start service
kg service install

# Configure Providers
kg setup

Configure Providers

# Interactive wizard (recommended)
kg setup

# Or manual add
kg add deepseek.com --provider deepseek --alias "pm-deepseek" -p "sk-api-key"

Manage Service

# Check status
kg status

# Start/stop service
kg service start
kg service stop

# View logs
kg service logs -f

# Upgrade
kg upgrade

Architecture Overview

Keygate Architecture

Core Security Guarantee: AI Agent only holds the alias (e.g., pm-deepseek), real credentials are automatically replaced at the Proxy layer and never enter the LLM context.

MCP Server Integration

Keygate acts as an MCP Server, collaborating with Claude Code and other AI Agents.

Available Tools

Tool Description Sensitive
list_passwords List password entries (metadata only) No
get_password Get proxy config (alias + proxy URL) No

Usage Example

Say to Claude Code:

"Help me call the DeepSeek API"

Claude Code automatically:

  1. Calls list_passwords to find entries
  2. Calls get_password({domain: "deepseek.com"})
  3. Receives response:
    {
      "success": true,
      "alias": "pm-deepseek",
      "proxyUrl": "http://localhost:3198/deepseek",
      "message": "Set SDK baseURL to proxy URL, apiKey to alias"
    }
  4. Configure SDK:
    const client = new DeepSeek({
      baseURL: 'http://localhost:3198/deepseek',
      apiKey: 'pm-deepseek'
    });
  5. Proxy automatically replaces alias → real credential → forwards to DeepSeek API

Configure MCP

In Claude Code's MCP configuration:

{
  "mcpServers": {
    "keygate": {
      "command": "node",
      "args": ["/path/to/keygate/dist/mcp/server.js"]
    }
  }
}

Config file location: ~/.claude.json

CLI Usage

Initialize

kg init

Add Password

# Interactive input
kg add deepseek.com -n "DeepSeek" -u "user@example.com"

# Pass password directly
kg add deepseek.com -n "DeepSeek" -p "sk-api-key"

# Configure proxy mode
kg add deepseek.com \
  --name "DeepSeek" \
  --alias "pm-deepseek" \
  --password "sk-api-key" \
  --upstream "https://api.deepseek.com" \
  --proxy-path "/deepseek"

List Passwords

# List all
kg list

# Search
kg list -s "github"

# Filter by tag
kg list --tag "work"

Get Password

# Get password (hidden by default)
kg get deepseek.com

# Show password
kg get deepseek.com --show

Delete Password

# Interactive confirmation
kg delete <entry-id>

# Force delete
kg delete <entry-id> -f

Start Proxy

kg proxy
# [proxy] credential proxy listening on http://127.0.0.1:3198

View Logs

kg proxy-logs
kg proxy-logs --tail 100
kg proxy-logs --filter "502"

Provider Presets

Built-in configurations for 9 mainstream AI providers, ready to use out of the box:

Provider Domain Proxy Path
DeepSeek deepseek.com /deepseek
Zhipu GLM open.bigmodel.cn /zhipu, /zhipu-coding
Qwen dashscope.aliyuncs.com /qwen, /qwen-coding
Kimi api.moonshot.ai /moonshot, /moonshot-coding
Doubao ark.cn-beijing.volces.com /doubao
MiniMax api.minimaxi.com /minimax, /minimax-coding
StepFun api.stepfun.com /stepfun

Plugin System

Support for custom Provider plugins. Create ~/.keygate/plugins/custom.mjs:

export default {
  proxyPath: '/custom',
  resolveUpstream(path) {
    return 'https://api.custom-provider.com';
  },
  injectCredential(headers, credential) {
    headers['X-API-Key'] = credential;
  }
};

Security Design

Credential Isolation

Component What It Sees
AI Agent alias (e.g., pm-deepseek) + proxy URL
Proxy Server Real credential (in memory, not logged)
Upstream API Real credential
LLM Context alias (meaningless string)

Encryption Scheme

Property Value
Algorithm AES-256-GCM
Key Source 32 bytes random key
Key Storage OS Keychain (keytar)
IV Length 96 bits (12 bytes)
Auth Tag 128 bits (16 bytes)

Rate Limiting

  • Window: 60 seconds
  • Max failures: 10 per window
  • Exceeded response: HTTP 429

Audit Logs

All requests logged to SQLite:

  • Timestamp
  • Method/Path
  • Alias
  • Status code
  • Routing layer (plugin/preset/database)
  • Latency

Development

Run Tests

npm test                    # Run all tests
npm run test:unit           # Unit tests
npm run test:integration    # Integration tests
npm run test:proxy          # Proxy server tests
npm run test:mcp            # MCP server tests

Type Check

npm run typecheck

Development Mode

npm run dev  # Watch mode compilation

Project Structure

src/
├── core/
│   ├── crypto.ts        # AES-256-GCM encryption
│   ├── store.ts         # SQLite storage
│   ├── vault.ts         # Vault logic
│   ├── keychain.ts      # OS Keychain wrapper
│   └── session.ts       # Session Token management
├── mcp/
│   ├── server.ts        # MCP server
│   └── tools/           # MCP tool implementations
├── proxy/
│   ├── server.ts        # Proxy server
│   ├── plugin-loader.ts # Plugin loader
│   └── request-log.ts   # Request logging
├── providers/
│   └── index.ts         # Provider Presets
├── utils/
│   └── header-parser.ts # HTTP Header parsing
├── types/               # TypeScript type definitions
├── cli.ts               # CLI entry
└── index.ts             # Exports

Documentation Index

Document Description
USER_GUIDE_EN.md User Guide
API_REFERENCE_EN.md API Reference
TROUBLESHOOTING_EN.md Troubleshooting Guide
PLUGIN_DEVELOPMENT.md Plugin Development Guide (AI Coding)

License

MIT

About

面向 AI Agent 的零信任凭证网关 - 让 AI 安全访问 API,密码永不进入 LLM 上下文

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors