跳到正文
Skillpedia
部署与云(DevOps)35k · #8052

implementing-hashicorp-vault-dynamic-secrets

它能做什么

这个工具可以配置 HashiCorp Vault,让它为数据库和 AWS 服务生成临时密码和访问密钥。这样你就不必使用长期不变的静态密码,因为生成的凭据会自动过期。

适用场景

  • ✓你想停止在配置文件中使用静态密码时。
  • ✓你需要快速过期的数据库或 AWS 凭据时。
  • ✓为了符合定期更换密码的安全规定时。

技能链接

https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/implementing-hashicorp-vault-dynamic-secrets/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/implementing-hashicorp-vault-dynamic-secrets/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“为 PostgreSQL 数据库配置 HashiCorp Vault 的动态密钥。”

每周 5 个新技能,1 分钟读完。

工作原理

Vault 会连接到你的数据库或 AWS,按需创建临时凭据。这些凭据在过期或不再需要时会被自动撤销。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Implementing HashiCorp Vault Dynamic Secrets

When to Use

  • Applications use static database credentials stored in configuration files or environment variables
  • AWS IAM access keys are long-lived and shared across services
  • Need to eliminate credential sprawl by generating short-lived, per-request secrets
  • Compliance requirements mandate credential rotation (PCI-DSS Requirement 8, NIST 800-53 IA-5)
  • Implementing zero-trust secret management where credentials are never stored at rest
  • Migrating from manual credential management to automated secrets lifecycle

Do not use for storing static secrets that cannot be dynamically generated (use Vault's KV secrets engine instead); dynamic secrets are for credentials that can be programmatically created and revoked on target systems.

Prerequisites

  • HashiCorp Vault 1.15+ (Community or Enterprise edition)
  • Vault server initialized and unsealed with auto-unseal configured (AWS KMS, Azure Key Vault, or Transit)
  • Target database systems with admin credentials for Vault to create/revoke dynamic accounts
  • AWS IAM account with permissions to create/delete IAM users and access keys
  • Network connectivity from Vault to all target systems
  • Vault policies and authentication methods configured for consuming applications

Workflow

Step 1: Deploy and Configure Vault Server

Initialize Vault with production-grade configuration:

# vault-config.hcl - Production Vault server configuration
storage "raft" {
  path    = "/opt/vault/data"
  node_id = "vault-1"

  retry_join {
    leader_api_addr = "https://vault-2.corp.local:8200"
  }
  retry_join {
    leader_api_addr = "https://vault-3.corp.local:8200"
  }
}

listener "tcp" {
  address       = "0.0.0.0:8200"
  tls_cert_file = "/opt/vault/tls/vault-cert.pem"
  tls_key_file  = "/opt/vault/tls/vault-key.pem"
}

seal "awskms" {
  region     = "us-east-1"
  kms_key_id = "alias/vault-unseal-key"
}

api_addr      = "https://vault-1.corp.local:8200"
cluster_addr  = "https://vault-1.corp.local:8201"

telemetry {
  prometheus_retention_time = "24h"
  disable_hostname          = true
}

ui = true
# Initialize Vault cluster
vault operator init -key-shares=5 -key-threshold=3

# Enable audit logging
vault audit enable file file_path=/var/log/vault/audit.log

# Enable AppRole authentication for applications
vault auth enable approle

# Create policy for database secret consumers
vault policy write db-consumer - <<EOF
# Allow reading dynamic database credentials
path "database/creds/app-readonly" {
  capabilities = ["read"]
}
path "database/creds/app-readwrite" {
  capabilities = ["read"]
}

# Allow renewing and revoking own leases
path "sys/leases/renew" {
  capabilities = ["update"]
}
path "sys/leases/revoke" {
  capabilities = ["update"]
}

# Allow reading own token info
path "auth/token/lookup-self" {
  capabilities = ["read"]
}
EOF

# Create AppRole for application
vault write auth/approle/role/webapp \
    token_policies="db-consumer" \
    token_ttl=1h \
    token_max_ttl=4h \
    secret_id_ttl=720h \
    secret_id_num_uses=0

Step 2: Configure Database Secrets Engine

Set up dynamic credential generation for PostgreSQL and MySQL:

# Enable the database secrets engine
vault secrets enable database

# Configure PostgreSQL connection
vault write database/config/production-postgres \
    plugin_name=postgresql-database-plugin \
    allowed_roles="app-readonly,app-readwrite,app-admin" \
    connection_url="postgresql://{{username}}:{{password}}@db-primary.corp.local:5432/appdb?sslmode=verify-full" \
    username="vault_admin" \
    password="$VAULT_DB_PASSWORD" \
    password_authentication="scram-sha-256"

# Rotate the root credentials so Vault manages them exclusively
vault write -force database/rotate-root/production-postgres

# Create read-only role (TTL: 1 hour, max 24 hours)
vault write database/roles/app-readonly \
    db_name=production-postgres \
    creation_statements="CREATE ROLE \"{{name}}\" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}'; \
        GRANT SELECT ON ALL TABLES IN SCHEMA public TO \"{{name}}\"; \
        ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO \"{{name}}\";" \
    revocation_statements="REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA public FROM \"{{name}}\"; \
        DROP ROLE IF EXISTS \"{{name}}\";" \
    default_ttl="1h" \
    max_ttl="24h"

# Create read-write role (TTL: 30 minutes, max 8 hours)

…
常见问题

什么是“动态密钥”?

这是 Vault 自动生成和管理的凭据(比如密码或访问密钥)。它们的有效期有限,使用后或过期后会被撤销。

为什么要用动态密钥,而不是静态密钥?

静态密码一旦泄露就会带来安全风险。动态密钥有效期很短,而且每次使用都是专门生成的,因此降低了风险,也让未授权访问更难实现。

如果应用需要持续访问怎么办?

应用可以在旧凭据过期之前申请新的动态凭据,这样既能保持访问,又不需要使用静态密码。

详情

作者的原始描述

Configures HashiCorp Vault dynamic secrets engines for database credentials, AWS IAM keys, and PKI certificates, with automatic generation, lease management, and rotation to eliminate static secrets in application configuration. Use when eliminating long-lived static credentials, configuring a Vault secrets engine, generating ephemeral database or cloud credentials, or automating credential rotati

repo: mukul975/Anthropic-Cybersecurity-Skills

热度

GitHub 星标
35k
排名
#8052
许可证
Apache-2.0
更新时间
2026/8/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能