implementing-api-key-security-controls
Implements secure API key generation, storage, rotation, and revocation controls to protect API authentication credentials from leakage, brute force, and abuse.
Skill by pinkpixel-dev
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/pinkpixel-dev-implementing-api-key-security-controls
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: backend, security
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions: not checked yet.
What's inside
- Skill name
implementing-api-key-security-controls- Description
- Implements secure API key generation, storage, rotation, and revocation controls to protect API authentication credentials from leakage, brute force, and abuse. The engineer designs API key formats with sufficient entropy, implements secure hashing for storage, enforces per-key scoping and rate limiting, monitors for leaked keys in public repositories, and builds key rotation workflows. Activates for requests involving API key management, API key security, key rotation policy, or API credential protection.
- License
- Apache-2.0
- Instructions
- 376 lines in SKILL.md · view on GitHub
Before installing
- Ships executable scripts
Files (4)
- LICENSE
- SKILL.md
- api-reference.md · references/
- agent.py · scripts/
SKILL.md (first lines)
# Implementing API Key Security Controls
## When to Use
- Designing secure API key generation with sufficient entropy and identifiable prefixes for leak detection
- Implementing server-side API key hashing (never storing keys in plaintext) with SHA-256 or bcrypt
- Building key rotation workflows that allow zero-downtime key replacement for API consumers
- Configuring per-key scoping to limit each API key to specific endpoints, IP ranges, and rate limits
- Setting up automated monitoring for API key leakage in GitHub repos, logs, and client-side code
**Do not use** API keys as the sole authentication mechanism for user-facing applications. API keys are best suited for server-to-server communication and developer access.
## Prerequisites
- Secure random number generator (os.urandom, secrets module) for key generation
- Database with proper encryption at rest for storing hashed API keys
- Redis or similar store for key-to-metadata caching and rate limiting
- Secret scanning tools (GitHub secret scanning, truffleHog, gitleaks)
- Monitoring and alerting infrastructure for key usage anomalies
## Workflow
### Step 1: Secure API Key Generation
```python
import secrets
import hashlib
import hmac
import time
import json
from datetime import datetime, timedelta
class APIKeyManager:
"""Manages secure API key lifecycle: generation, storage, validation, rotation."""
# Key format: prefix_base64random (e.g., sk_live_a1b2c3d4e5f6...)
# Prefix identifies the key type and environment for leak detection
KEY_PREFIXES = {
"live_secret": "sk_live_",
"test_secret": "sk_test_",
"live_public": "pk_live_",
"test_public": "pk_test_",
}
def __init__(self, db_connection, redis_connection):
self.db = db_connection
self.redis = redis_connection
def generate_key(self, key_type="live_secret", owner_id=None, scopes=None,
rate_limit=None, ip_allowlist=None, expires_days=365):
"""Generate a new API key with metadata."""
prefix = self.KEY_PREFIXES.get(key_type, "sk_live_")
# Generate 32 bytes (256 bits) of randomness
random_bytes = secrets.token_bytes(32)
key_body = secrets.token_urlsafe(32) # Base64url-encoded
# Full API key that the client receives (shown only once)
full_key = f"{prefix}{key_body}"
# Hash the key for storage (never store the raw key)
key_hash = hashlib.sha256(full_key.encode()).hexdigest()
# Create a short key ID for reference (first 8 chars)
key_id = f"{prefix}{key_body[:8]}..."
# Store the hashed key with metadata
key_metadata = {
"key_hash": key_hash,
"key_id": key_id,
"key_type": key_type,
"owner_id": owner_id,
"scopes": scopes or ["read"],
"rate_limit": rate_limit or {"requests": 1000, "window": 3600},
"ip_allowlist": ip_allowlist or [],
"created_at": datetime.utcnow().isoformat(),
"expires_at": (datetime.utcnow() + timedelta(days=expires_days)).isoformat(),
"last_used": None,
"is_active": True,
"usage_count": 0,
}
# Store in database
self.db.execute(
"INSERT INTO api_keys (key_hash, key_id, metadata) VALUES (?, ?, ?)",
(key_hash, key_id, json.dumps(key_metadata))
)
# Cache in Redis for fast validation
self.redis.setex(
f"apikey:{key_hash}",
86400, # 24-hour cache TTL
json.dumps(key_metadata)
)
return {
"api_key": full_key, # Show to user ONCE
"key_id": key_id, # For reference/management
"scopes": key_metadata["scopes"],
"expires_at": key_metadata["expires_at"],
}
def validate_key(self, api_key):
"""Validate an API key and return its metadata."""
key_hash = hashlib.sha256(api_key.encode()).hexdigest()
# Check Redis cache first
cached = self.redis.get(f"apikey:{key_hash}")
if cached:
metadata = json.loads(cached)
else:
# Fall back to database
row = self.db.execute(
"SELECT metadata FROM api_keys WHERE key_hash = ?",
(key_hash,)
).fetchone()
if not row:
return None, "invalid_key"
metadata = json.loads(row[0])
# Refresh cacheFrom pinkpixel-dev/skills-collection-2, Apache-2.0.
More from pinkpixel-dev/skills-collection-2
- 0.459score
implementing-alert-fatigue-reduction
pinkpixel-dev
Implements strategies to reduce SOC alert fatigue by tuning detection rules, consolidating duplicate alerts, implementing risk-based alerting, and measuring…
SkillDFreshness: D★ 4Claude Code +9 - 0.459score
implementing-application-whitelisting-with-applocker
pinkpixel-dev
Implements application whitelisting using Windows AppLocker to restrict unauthorized software execution on endpoints, reducing attack surface from malware…
SkillDFreshness: D★ 4Claude Code +9 - 0.459score
implementing-attack-surface-management
pinkpixel-dev
Implements external attack surface management (EASM) using Shodan, Censys, and ProjectDiscovery tools (subfinder, httpx, nuclei) for asset discovery…
SkillDFreshness: D★ 4Claude Code +9 - 0.459score
implementing-aws-nitro-enclave-security
pinkpixel-dev
Implements AWS Nitro Enclave-based confidential computing environments with cryptographic attestation, KMS policy integration using PCR-based condition keys…
SkillDFreshness: D★ 4Claude Code +9 - 0.456score
implementing-aws-macie-for-data-classification
pinkpixel-dev
Implement Amazon Macie to automatically discover, classify, and protect sensitive data in S3 buckets using machine learning and pattern matching for PII…
SkillDFreshness: D★ 4Claude Code +9 - 0.456score
implementing-attack-path-analysis-with-xm-cyber
pinkpixel-dev
Deploy XM Cyber's continuous exposure management platform to map attack paths, identify choke points, and prioritize the 2% of exposures that threaten…
SkillDFreshness: D★ 4Claude Code +9 - 0.456score
implementing-aes-encryption-for-data-at-rest
pinkpixel-dev
AES (Advanced Encryption Standard) is a symmetric block cipher standardized by NIST (FIPS 197) used to protect classified and sensitive data.
SkillDFreshness: D★ 4Claude Code +9 - 0.456score
implementing-aws-config-rules-for-compliance
pinkpixel-dev
Implementing AWS Config rules for continuous compliance monitoring of AWS resources, deploying managed and custom rules aligned to CIS and PCI DSS frameworks…
SkillDFreshness: D★ 4Claude Code +9 - 0.456score
implementing-aws-iam-permission-boundaries
pinkpixel-dev
Configure IAM permission boundaries in AWS to delegate role creation to developers while enforcing maximum privilege limits set by the security team.
SkillDFreshness: D★ 4Claude Code +9 - 0.456score
implementing-anti-phishing-training-program
pinkpixel-dev
Security awareness training is the human layer of phishing defense.
SkillDFreshness: D★ 4Claude Code +9 - 0.456score
implementing-aqua-security-for-container-scanning
pinkpixel-dev
Deploy Aqua Security's Trivy scanner to detect vulnerabilities, misconfigurations, secrets, and license issues in container images across CI/CD pipelines and…
SkillDFreshness: D★ 4Claude Code +9 - 0.455score
implementing-anti-ransomware-group-policy
pinkpixel-dev
Configures Windows Group Policy Objects (GPO) to prevent ransomware execution and limit its spread.
SkillDFreshness: D★ 4Claude Code +9
Signals
- Stars
- 4
- Forks
- 4
- Open issues
- 0
- Last commit (this folder)
- Mar 29, 2026 (7 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- Apache-2.0
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
Same skill elsewhere
Copies of this SKILL.md published by others; search shows only one of them.
More from pinkpixel-dev
- 0.534score
adhd
pinkpixel-dev
Parallel divergent ideation for coding agents.
SkillCFreshness: C★ 9Claude Code +9 - 0.470score
3d-web-experience
pinkpixel-dev
You bring the third dimension to the web.
SkillDFreshness: D★ 9Claude Code +9 - 0.459score
implementing-aws-nitro-enclave-security
pinkpixel-dev
Implements AWS Nitro Enclave-based confidential computing environments with cryptographic attestation, KMS policy integration using PCR-based condition keys…
SkillDFreshness: D★ 4Claude Code +9 - 0.459score
implementing-attack-surface-management
pinkpixel-dev
Implements external attack surface management (EASM) using Shodan, Censys, and ProjectDiscovery tools (subfinder, httpx, nuclei) for asset discovery…
SkillDFreshness: D★ 4Claude Code +9 - 0.459score
implementing-application-whitelisting-with-applocker
pinkpixel-dev
Implements application whitelisting using Windows AppLocker to restrict unauthorized software execution on endpoints, reducing attack surface from malware…
SkillDFreshness: D★ 4Claude Code +9 - 0.459score
implementing-alert-fatigue-reduction
pinkpixel-dev
Implements strategies to reduce SOC alert fatigue by tuning detection rules, consolidating duplicate alerts, implementing risk-based alerting, and measuring…
SkillDFreshness: D★ 4Claude Code +9
Cite this page
implementing-api-key-security-controls skill. Agent Mart. https://agentmart.dev/skills/pinkpixel-dev-implementing-api-key-security-controls (last updated 2026-10-24)