performing-service-account-credential-rotation
跨 Active Directory、云平台和应用程序数据库自动化服务账户凭据轮换,消除陈旧密钥并降低泄露风险。
Best use case
performing-service-account-credential-rotation is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
跨 Active Directory、云平台和应用程序数据库自动化服务账户凭据轮换,消除陈旧密钥并降低泄露风险。
Teams using performing-service-account-credential-rotation should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/performing-service-account-credential-rotation/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How performing-service-account-credential-rotation Compares
| Feature / Agent | performing-service-account-credential-rotation | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
跨 Active Directory、云平台和应用程序数据库自动化服务账户凭据轮换,消除陈旧密钥并降低泄露风险。
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 执行服务账户凭据轮换
## 概述
服务账户是应用程序、守护进程、CI/CD 流水线和自动化流程用于向系统和 API 认证的非人类身份。这些账户通常具有较高权限,其凭据(密码、API 密钥、证书、令牌)往往长期有效且在团队间共享,使其成为攻击者的主要目标。凭据轮换是按计划系统性替换这些密钥、将新凭据传播到所有依赖系统,并在轮换后验证服务连续性的流程。
## 前置条件
- 跨 AD、云和应用程序的所有服务账户清单
- 密钥管理平台(HashiCorp Vault、AWS Secrets Manager、Azure Key Vault 或 CyberArk)
- 服务依赖映射(哪些服务使用哪些凭据)
- 轮换窗口的变更管理流程
- 轮换后的服务健康监控
## 核心概念
### 服务账户类型
| 类型 | 平台 | 凭据 | 轮换方法 |
|------|------|------|---------|
| Active Directory 服务账户 | Windows/AD | 密码 | gMSA(自动)或 PAM 管理 |
| AWS IAM 用户 | AWS | 访问密钥/Secret 密钥 | AWS Secrets Manager 轮换 Lambda |
| GCP 服务账户 | GCP | JSON 密钥文件 | 通过 IAM API 进行密钥轮换 |
| Azure 服务主体 | Azure | 客户端密钥/证书 | Key Vault + 轮换策略 |
| 数据库服务账户 | SQL/Oracle/Postgres | 密码 | Vault 动态密钥 |
| API 密钥 | SaaS 应用程序 | API 令牌 | 应用特定 API |
### 组托管服务账户(gMSA)
Windows gMSA 由 Active Directory 提供自动密码管理:
- AD 每 30 天自动轮换密码
- 密码为 240 字节,加密随机生成
- 多台服务器可同时使用同一 gMSA
- 无管理员知晓或管理密码
- 消除 Windows 服务的手动轮换需求
### 轮换架构
```
密钥管理器 / Vault
│
├── 轮换触发(计划或按需)
│
├── 生成新凭据
│
├── 在源系统更新凭据(AD、云 IAM、数据库)
│
├── 在所有消费方更新凭据:
│ ├── 应用程序配置
│ ├── CI/CD 流水线密钥
│ ├── Kubernetes 密钥
│ └── 其他依赖服务
│
├── 验证服务健康:
│ ├── 健康检查端点
│ ├── 认证测试
│ └── 功能冒烟测试
│
└── 撤销旧凭据(宽限期后)
```
## 实施步骤
### 步骤 1:发现和盘点服务账户
枚举所有服务账户及其依赖关系:
```powershell
# Active Directory:查找所有服务账户
Get-ADServiceAccount -Filter * -Properties *
Get-ADUser -Filter {ServicePrincipalName -ne "$null"} -Properties ServicePrincipalName,PasswordLastSet,LastLogonDate
# 查找密码超过 90 天的账户
$threshold = (Get-Date).AddDays(-90)
Get-ADUser -Filter {PasswordLastSet -lt $threshold -and Enabled -eq $true} -Properties PasswordLastSet,ServicePrincipalName |
Where-Object {$_.ServicePrincipalName} |
Select-Object Name, PasswordLastSet, ServicePrincipalName
```
### 步骤 2:为 Windows 服务实施 gMSA
```powershell
# 创建 KDS 根密钥(一次性,全域范围)
Add-KdsRootKey -EffectiveImmediately
# 创建 gMSA 账户
New-ADServiceAccount -Name "svc-webapp-gmsa" `
-DNSHostName "svc-webapp-gmsa.corp.example.com" `
-PrincipalsAllowedToRetrieveManagedPassword "WebServerGroup" `
-KerberosEncryptionType AES128,AES256
# 在目标服务器上安装
Install-ADServiceAccount -Identity "svc-webapp-gmsa"
# 测试账户
Test-ADServiceAccount -Identity "svc-webapp-gmsa"
# 配置 IIS 应用程序池使用 gMSA
# 将标识设置为:CORP\svc-webapp-gmsa$
```
### 步骤 3:使用 Secrets Manager 轮换 AWS 访问密钥
```python
import boto3
import json
def rotate_iam_access_key(secret_arn, iam_username):
"""通过 Secrets Manager 轮换 IAM 用户的访问密钥。"""
iam = boto3.client("iam")
sm = boto3.client("secretsmanager")
# 创建新访问密钥
new_key = iam.create_access_key(UserName=iam_username)
new_access_key = new_key["AccessKey"]["AccessKeyId"]
new_secret_key = new_key["AccessKey"]["SecretAccessKey"]
# 在 Secrets Manager 中存储新凭据
sm.put_secret_value(
SecretId=secret_arn,
SecretString=json.dumps({
"accessKeyId": new_access_key,
"secretAccessKey": new_secret_key,
"username": iam_username,
})
)
# 列出旧访问密钥并停用
keys = iam.list_access_keys(UserName=iam_username)
for key in keys["AccessKeyMetadata"]:
if key["AccessKeyId"] != new_access_key and key["Status"] == "Active":
iam.update_access_key(
UserName=iam_username,
AccessKeyId=key["AccessKeyId"],
Status="Inactive"
)
return {"new_key_id": new_access_key, "old_keys_deactivated": True}
```
### 步骤 4:使用 Vault 进行数据库凭据轮换
```python
import hvac
def configure_vault_database_rotation(vault_url, vault_token, db_config):
"""配置 HashiCorp Vault 实现数据库凭据自动轮换。"""
client = hvac.Client(url=vault_url, token=vault_token)
# 启用数据库密钥引擎
client.sys.enable_secrets_engine(
backend_type="database",
path="database"
)
# 配置数据库连接
client.secrets.database.configure(
name=db_config["name"],
plugin_name="postgresql-database-plugin",
connection_url=f"postgresql://{{{{username}}}}:{{{{password}}}}@"
f"{db_config['host']}:{db_config['port']}/{db_config['database']}",
allowed_roles=[db_config["role_name"]],
username=db_config["admin_user"],
password=db_config["admin_password"],
)
# 创建动态凭据角色
client.secrets.database.create_role(
name=db_config["role_name"],
db_name=db_config["name"],
creation_statements=[
"CREATE ROLE \"{{name}}\" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}';",
f"GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO \"{{{{name}}}}\";"
],
default_ttl="1h",
max_ttl="24h",
)
return {"status": "configured", "role": db_config["role_name"]}
```
### 步骤 5:轮换后验证
每次轮换后,验证服务连续性:
```python
import requests
import time
def verify_service_health(service_endpoints, max_retries=3, delay=10):
"""检查凭据轮换后服务是否正常。"""
results = []
for endpoint in service_endpoints:
for attempt in range(max_retries):
try:
response = requests.get(
endpoint["health_url"],
timeout=10,
headers=endpoint.get("headers", {})
)
healthy = response.status_code == 200
results.append({
"service": endpoint["name"],
"status": "healthy" if healthy else f"unhealthy ({response.status_code})",
"attempt": attempt + 1,
})
if healthy:
break
except requests.RequestException as e:
results.append({
"service": endpoint["name"],
"status": f"error: {str(e)}",
"attempt": attempt + 1,
})
if attempt < max_retries - 1:
time.sleep(delay)
return results
```
## 验证清单
- [ ] 完整的服务账户清单及依赖映射
- [ ] 为所有符合条件的 Windows 服务账户实施 gMSA
- [ ] 通过密钥管理器轮换云访问密钥(AWS、GCP、Azure)
- [ ] 通过动态密钥(Vault)或轮换策略管理数据库凭据
- [ ] 定义轮换计划(根据风险级别为 30-90 天)
- [ ] 轮换后健康检查自动化
- [ ] 为轮换失败配置告警
- [ ] 宽限期后撤销旧凭据
- [ ] 轮换事件已记录且可审计
- [ ] 回滚流程已记录并测试
## 参考资料
- [Google Cloud 服务账户密钥轮换](https://cloud.google.com/iam/docs/key-rotation)
- [AWS Secrets Manager 轮换](https://docs.aws.amazon.com/secretsmanager/latest/userguide/rotating-secrets.html)
- [Microsoft gMSA 文档](https://learn.microsoft.com/en-us/windows-server/security/group-managed-service-accounts/group-managed-service-accounts-overview)
- [HashiCorp Vault 数据库密钥引擎](https://developer.hashicorp.com/vault/docs/secrets/databases)Related Skills
performing-yara-rule-development-for-detection
通过识别可执行文件中的唯一字节模式、字符串和行为指标,开发精准的 YARA 恶意软件检测规则,同时将误报率降至最低。
performing-wireless-security-assessment-with-kismet
使用 Kismet 通过被动射频监控进行无线网络安全评估,检测流氓接入点(Rogue AP)、隐藏 SSID、弱加密和未授权客户端。
performing-wireless-network-penetration-test
执行无线网络渗透测试,通过捕获握手包、破解 WPA2/WPA3 密钥、检测流氓接入点以及使用 Aircrack-ng 和相关工具测试无线网络分段,评估 WiFi 安全性。
performing-windows-artifact-analysis-with-eric-zimmerman-tools
使用 Eric Zimmerman 的开源 EZ Tools 套件(包括 KAPE、MFTECmd、PECmd、LECmd、JLECmd 和 Timeline Explorer)执行全面的 Windows 取证制品分析,解析注册表 hive、预取文件、事件日志和文件系统元数据。
performing-wifi-password-cracking-with-aircrack
在授权无线安全评估中捕获 WPA/WPA2 握手包,并使用 aircrack-ng、hashcat 和字典攻击进行离线密码破解, 以评估密码短语强度和无线网络安全状况。
performing-web-cache-poisoning-attack
在授权安全测试期间,通过未纳入缓存键的头部和参数毒化缓存响应,利用 Web 缓存机制向其他用户投递恶意内容。
performing-web-cache-deception-attack
通过利用 CDN 缓存层与源服务器之间的路径规范化差异,执行 Web 缓存欺骗攻击,从而缓存并获取敏感的已认证内容。
performing-web-application-vulnerability-triage
使用 OWASP 风险评级方法论对 DAST/SAST 扫描器的 Web 应用程序漏洞发现进行分类,区分真阳性和假阳性,并确定修复优先级。
performing-web-application-scanning-with-nikto
Nikto 是一款开源 Web 服务器和 Web 应用程序扫描器,可针对超过 7,000 个潜在危险文件/程序进行测试,检查超过 1,250 个服务器的过期版本,并识别超过 270 个服务器的版本特定问题。
performing-web-application-penetration-test
遵循 OWASP Web 安全测试指南(WSTG)方法论,对 Web 应用程序执行系统化安全测试,识别认证、授权、 输入验证、会话管理和业务逻辑中的漏洞。测试人员以 Burp Suite 作为主要拦截代理,结合手动测试技术 发现自动化扫描器遗漏的缺陷。适用于 Web 应用渗透测试、OWASP 测试、应用安全评估或 Web 漏洞测试等请求场景。
performing-web-application-firewall-bypass
使用编码技术、HTTP 方法操控、参数污染和载荷混淆绕过 Web 应用防火墙保护,将 SQL 注入、XSS 及其他攻击载荷穿透 WAF 检测规则。
performing-vulnerability-scanning-with-nessus
使用 Tenable Nessus 执行认证和未认证漏洞扫描,识别网络基础设施、服务器和应用程序中的已知漏洞、 错误配置、默认凭据和缺失补丁。扫描器将发现与 CVE 数据库和 CVSS 评分关联,生成优先级修复指导。 适用于漏洞扫描、Nessus 评估、补丁合规检查或自动化漏洞检测等请求场景。