Som-uka/iam-hardening-mfa-rollout
GitHub: Som-uka/iam-hardening-mfa-rollout
这是一个AWS IAM安全强化项目,旨在通过用户分类、MFA强制执行和访问密钥轮换来系统性修复IAM环境中的安全漏洞。
Stars: 0 | Forks: 0
# IAM 强化与 MFA 部署
一套系统化的 AWS IAM 安全强化方法——涵盖实时 AWS 环境中的用户分类、MFA 强制执行、访问密钥轮换以及过度授权策略的修复。
## 概述
本项目记录了在一个包含 23 个 IAM 用户的 AWS 环境中开展的 IAM 安全强化行动。该环境中,大多数用户未启用 MFA,许多用户拥有长期未轮换的访问密钥,并且部分账户持有过于宽泛的权限。
该方法在采取行动前对所有 IAM 用户进行分类,确保 MFA 部署和密钥轮换能根据各类用户的特点合理应用,从而避免影响活跃的工作负载。
## IAM 用户分类
| 类别 | 描述 | MFA 应用方法 |
|---|---|---|
| **人类用户** | 交互式登录的工程师和管理员 | 通过 IAM 策略强制执行 MFA |
| **混合用户** | 同时拥有程序化访问权限的人类用户 | 强制执行 MFA + 轮换访问密钥 |
| **服务账户** | 应用程序/系统使用的非人类账户 | 控制台不启用 MFA:按计划轮换密钥 |
| **紧急访问账户** | 用于紧急访问的账户 | 需要 MFA,通过 CloudTrail 监控使用情况 |
| **闲置账户** | 近期无活动的非活跃账户 | 禁用,然后计划删除 |
## 主要发现
- 大多数人类和混合 IAM 用户未配置 MFA
- 活跃账户的访问密钥年龄在 180 天到 500 天以上,且未进行轮换
- AWS Config 未记录 IAM 资源变更,导致 IAM 事件缺乏审计跟踪
- 对敏感服务使用包含通配符操作的、权限过宽的托管策略
- 没有执行边界来阻止权限提升路径
## 审计脚本
```
# ated as "设备", "attached" as "附加".
aws iam generate-credential-report
aws iam get-credential-report \
--query 'Content' --output text | base64 -d
# - So: "列出未附加 MFA 设备的用户"
aws iam list-users --query 'Users[*].UserName' --output text | \
xargs -I {} sh -c \
'echo -n "{}: "; aws iam list-mfa-devices --user-name {} \
--query "length(MFADevices)"'
```
## 修复:访问密钥轮换
```
# 3. 1. Create new access key
aws iam create-access-key --user-name
# - This is numbered, so keep the number "1." as is? Probably translate the text.
aws iam update-access-key \
--user-name \
--access-key-id --status Inactive
# - "Create new access key" -> "创建新的访问密钥" but "access key" should be kept in English? In the example, 'API Reference' has "API" in English, so for "access key", it might be similar. I think "access key" is a standard term, so keep it in English.
aws iam delete-access-key \
--user-name \
--access-key-id
```
## 修复:在 AWS Config 中启用 IAM 记录
```
# - But in Chinese contexts, it's often translated. The instruction says to keep professional terms in English. "Access key" is a technical term in cloud services, so I should keep it in English.
aws configservice describe-configuration-recorders
# - Let's check the instruction example: 'API Reference' -> 'API 参考', so "API" is kept, "Reference" translated. Similarly, 'Kubernetes Setup' -> 'Kubernetes 设置', "Kubernetes" kept, "Setup" translated.
aws configservice put-configuration-recorder \
--configuration-recorder name=default,roleARN= \
--recording-group allSupported=true,includeGlobalResourceTypes=true
```
## 代码库结构
```
iam-hardening-mfa-rollout/
├── README.md
├── findings/
│ ├── user-classification.md
│ ├── mfa-gap-analysis.md
│ └── policy-risk-assessment.md
├── change-records/
│ ├── CR-mfa-enforcement.md
│ ├── CR-access-key-rotation.md
│ └── CR-config-iam-recording.md
└── scripts/
├── audit-iam-mfa-status.sh
├── audit-access-key-age.sh
└── generate-credential-report.sh
```
## 技术栈
- AWS IAM, AWS Config, CloudTrail, AWS CLI
- Bash, PowerShell
## 架构图

标签:AI合规, AWS CLI, AWS Config, AWS IAM, CloudTrail, GitHub Advanced Security, IAM安全, MFA强制, 凭证报告, 安全加固, 审计脚本, 应用安全, 权限修复, 特权升级防护, 用户分类, 访问密钥轮换, 身份与访问管理