ToolypetMCP
intermediate3 minutescross hub

API Key Rotation Workflow

Generate new API keys, create HMAC signatures for validation, and hash old keys for audit logging.

api-keyrotationhmacsecurity

Cuándo usar esta receta

Structured API key rotation with audit trail. Ensures new keys work before decommissioning old ones, and maintains security logs without storing raw secrets.

Pasos

1

Generate new API key

Indicación:Generate a new 512-bit API key in base64 format for rotation
2

Validate new key with HMAC

Indicación:Create HMAC-SHA256 signature of a test payload using the new key to verify it works
3

Hash old key for audit trail

Indicación:SHA-256 hash the old API key for audit log storage (never store raw keys in logs)
4

Create audit event ID

Indicación:Generate a UUID v4 as the rotation event ID for tracking

Preguntas frecuentes

How often should API keys be rotated?

Every 90 days for production keys, immediately on team member departure, and instantly if a key is potentially compromised.

Why hash old keys for audit logs?

You need to identify which key was used without storing the actual secret. A SHA-256 hash lets you match against known keys without exposure risk.

Recetas relacionadas