关于 Cloud Security & Container Hardening
面向云、容器、Kubernetes 和基础设施即代码安全评估的 Claude 技能,覆盖 AWS、Azure 和 GCP。它结合配置审查与扫描指导、合规映射,并以攻击路径组织发现项。
主要功能
- 01AWS、Azure 和 GCP 安全审查
- 02Docker 与 Kubernetes 加固
- 03Terraform 和 CloudFormation 扫描
- 04云合规框架映射
- 05容器镜像扫描指导
- 06按攻击路径整理发现项
适用场景
- 01审计云身份与存储设置
- 02审查 Dockerfile 或 Kubernetes 清单
- 03扫描 Terraform 或 CloudFormation 文件
- 04将云安全发现映射到合规控制
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ masriyan/ claude-code-cybersecurity-skill --skill cloud-security-&-container-hardening安装后在 Claude Code 中输入/cloud-security-&-container-hardening确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
examples/example_usage.mdscripts/iac_scanner.pycloud_auditor.py详细介绍
云安全与容器加固
目的
帮助 Claude 执行 AWS、Azure 和 GCP 云安全评估、容器和 Kubernetes 安全加固、基础设施即代码(Terraform、CloudFormation、Kubernetes 清单)扫描,以及依据 CIS 基准和主要框架生成云合规报告。
激活条件
当用户询问以下内容时,将激活此技能:
- 审计 AWS IAM、S3、安全组或云服务
- 审查 Azure RBAC、存储、NSG 或 Key Vault 配置
- 评估 GCP IAM、Cloud Storage 或 GKE 安全性
- 扫描 Terraform 文件、CloudFormation 模板或 Kubernetes 清单
- 加固 Docker 容器或审查 Dockerfile
- Kubernetes RBAC、Pod 安全或网络策略
- 云合规性(CIS、SOC2、PCI-DSS、HIPAA)
- 容器镜像漏洞扫描
- 云架构安全审查
- IaC 安全扫描(tfsec、Checkov、Terrascan)
先决条件
pip install pyyaml boto3 requests
推荐的云安全工具:
AWS CLI— AWS 审计与管理ScoutSuite— 多云安全审计Prowler— AWS/Azure/GCP 安全评估Checkov— IaC 静态分析tfsec— Terraform 安全扫描器Trivy— 容器和 IaC 漏洞扫描器kube-bench— CIS Kubernetes 基准Falco— 容器运行时安全
核心能力
1. AWS 安全审计
当用户要求审计 AWS 安全性时:
使用 CLI 快速检查 AWS 安全性:
# IAM: Find users without MFA
aws iam get-account-summary
aws iam list-users | jq '.Users[].UserName' | xargs -I{} aws iam list-mfa-devices --user-name {}
# Find overly permissive policies
aws iam list-policies --scope Local --only-attached | jq '.Policies[].PolicyName'
# S3: Find public buckets
aws s3api list-buckets --query 'Buckets[].Name' | xargs -I{} aws s3api get-bucket-acl --bucket {}
aws s3api list-buckets --query 'Buckets[].Name' | xargs -I{} aws s3api get-bucket-policy-status --bucket {}
# Security groups: Find wide-open rules
aws ec2 describe-security-groups --filters "Name=ip-permission.cidr,Values=0.0.0.0/0" \
--query 'SecurityGroups[*].{ID:GroupId,Name:GroupName,Rules:IpPermissions}'
# CloudTrail: Verify logging
aws cloudtrail describe-trails
aws cloudtrail get-trail-status --name [trail-name]
# Root account check
aws iam get-account-summary --query 'SummaryMap.AccountMFAEnabled'
AWS IAM 安全检查清单:
Identity & Access Management:
[ ] Root account has MFA enabled
[ ] Root account has no access keys
[ ] All IAM users have MFA enabled
[ ] No IAM users with AdministratorAccess unless necessary
[ ] All IAM users have individual credentials (no shared)
[ ] Password policy: min 14 chars, complexity, rotation ≤90 days
[ ] Access keys rotated every 90 days
[ ] Unused credentials disabled (>90 days no use)
[ ] No inline policies; use managed policies
S3 Security:
[ ] Block Public Access enabled at account level
[ ] No buckets with public READ ACL
[ ] Server-side encryption enabled (SSE-S3 or SSE-KMS)
[ ] Versioning enabled for critical buckets
[ ] MFA Delete enabled for critical buckets
[ ] Access logging enabled
[ ] Bucket policies use HTTPS-only conditions
Networking:
[ ] No security groups with 0.0.0.0/0 → port 22 (SSH)
[ ] No security groups with 0.0.0.0/0 → port 3389 (RDP)
[ ] VPC Flow Logs enabled
[ ] No default VPC in use for production workloads
[ ] Private subnets for database and application tiers
Monitoring & Detection:
[ ] CloudTrail enabled in all regions
[ ] CloudTrail log file integrity validation enabled
[ ] GuardDuty enabled
[ ] Security Hub enabled and findings reviewed
[ ] Config rules configured for compliance
[ ] CloudWatch alarms for: root login, failed auth, security group changes
AWS 严重发现项模板:
**CRITICAL: S3 Bucket Publicly Readable**
Bucket: example-data-prod
Finding: GetBucketAcl returns AllUsers:READ
Risk: All objects publicly readable — potential data breach
Fix: aws s3api put-bucket-acl --bucket example-data-prod --acl private
Enable: aws s3api put-public-access-block --bucket example-data-prod \
--public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true
**HIGH: Security Group Allows SSH from Internet**
Group: sg-0abc123 (web-servers)
Rule: Inbound TCP 22 from 0.0.0.0/0
Risk: SSH brute-force, CVE exploitation
Fix: Change source from 0.0.0.0/0 to your VPN/bastion host IP
2. Azure 安全审计
当用户要求审计 Azure 时:
# Login and set subscription
az login
az account set --subscription [subscription-id]
# Check RBAC assignments
az role assignment list --all --include-inherited \
--query "[?roleDefinitionName=='Owner' || roleDefinitionName=='Contributor'].{Name:principalName,Role:roleDefinitionName}"
# Storage account public access
az storage account list --query "[?allowBlobPublicAccess==true].name"
# NSG rules allowing any source
az network nsg list --query "[*].{NSG:name}" | jq '.[].NSG' | xargs -I{} \
az network nsg rule list --nsg-name {} --resource-group [rg] \
--query "[?sourceAddressPrefix=='*'].{Rule:name,Port:destinationPortRange}"
# Key Vault access policies
az keyvault list --query "[*].name" | xargs -I{} az keyvault show --name {} \
--query 'properties.accessPolicies'
Azure 安全检查清单:
Identity:
[ ] Global Administrator role has MFA
[ ] No more than 3-5 Global Administrators
[ ] Privileged Identity Management (PIM) for elevated roles
[ ] Guest accounts reviewed quarterly
[ ] Legacy authentication blocked (Conditional Access)
Storage:
[ ] No public blob containers (allowBlobPublicAccess = false)
[ ] Secure transfer required (HTTPS only)
[ ] Storage accounts use private endpoints
[ ] Storage logs enabled (read/write/delete)
[ ] Customer-managed keys for sensitive data
Networking:
[ ] NSGs restrict management ports (22, 3389) from internet
[ ] Azure DDoS Protection enabled
[ ] Network Watcher flow logs enabled
Monitoring:
[ ] Azure Monitor Diagnostic Settings for all resources
[ ] Security Center (Defender for Cloud) enabled
[ ] Log Analytics Workspace connected
[ ] Alerts for privileged role assignments
3. 容器安全(Docker)
当用户要求审查 Dockerfile 或容器安全性时:
Claude 会直接读取并分析 Dockerfile:
Dockerfile 安全审查:
# BEFORE (insecure)
FROM ubuntu:latest # ← Never use latest
RUN apt-get install -y curl # ← Install what you need during build
COPY . . # ← Copies everything including .env files
RUN chmod 777 /app # ← World-writable is dangerous
CMD ["./app"] # ← Runs as root by default
EXPOSE 0-65535 # ← Never expose all ports
# AFTER (secure)
FROM ubuntu:24.04 AS builder # Pin specific version
RUN apt-get update && apt-get install -y --no-install-recommends curl \
&& rm -rf /var/lib/apt/lists/* # Clean up after install
WORKDIR /app
FROM ubuntu:24.04 AS runtime # Multi-stage: minimal runtime image
WORKDIR /app
COPY --from=builder /app/bin/myapp ./ # Only copy what's needed
RUN groupadd -r appgroup && useradd -r -g appgroup appuser
RUN chown -R appuser:appgroup /app
USER appuser # Non-root user
EXPOSE 8080 # Only expose necessary port
HEALTHCHECK --interval=30s --timeout=3s \
CMD curl -f http://localhost:8080/health || exit 1
CMD ["./myapp"]
Dockerfile 审计检查清单:
[ ] Base image version pinned (not latest)
[ ] Multi-stage build used to minimize final image
[ ] Runs as non-root user (USER instruction)
[ ] No COPY . . (copies .env, secrets)
[ ] .dockerignore exists and excludes .env, *.key, secrets/
[ ] Package caches cleaned after installation (rm -rf /var/lib/apt/lists/*)
[ ] No RUN commands with passwords, tokens, or secrets
[ ] HEALTHCHECK defined
[ ] Only necessary ports EXPOSE'd
[ ] Read-only filesystem where possible
[ ] No setuid/setgid binaries in final image
容器镜像扫描:
# Scan with Trivy
trivy image myapp:latest --severity HIGH,CRITICAL
trivy image myapp:latest --format json --output scan-results.json
# Docker bench security (runtime checks)
docker run --rm --net host --pid host --userns host --cap-add audit_control \
-v /etc:/etc:ro -v /usr/bin/containerd:/usr/bin/containerd:ro \
-v /usr/bin/runc:/usr/bin/runc:ro \
-v /usr/lib/systemd:/usr/lib/systemd:ro \
-v /var/lib:/var/lib:ro -v /var/run/docker.sock:/var/run/docker.sock:ro \
docker/docker-bench-security
4. Kubernetes 安全
当用户要求审计 Kubernetes 安全性时:
# Run CIS Kubernetes Benchmark
docker run --pid=host -v /etc:/etc:ro -v /var/lib:/var/lib:ro \
-v /usr/bin/kubelet:/usr/bin/kubelet:ro \
aquasec/kube-bench:latest
# Check for privileged pods
kubectl get pods --all-namespaces -o json | \
jq '.items[] | select(.spec.containers[].securityContext.privileged==true) |
.metadata.name + " in " + .metadata.namespace'
# Check RBAC for overly permissive ClusterRoles
kubectl get clusterrolebindings -o json | \
jq '.items[] | select(.roleRef.name=="cluster-admin") | .subjects[]?'
# Check for pods running as root
kubectl get pods --all-namespaces -o json | \
jq '.items[] | select(.spec.securityContext.runAsUser==0 or
.spec.containers[].securityContext.runAsUser==0) | .metadata.name'
安全 Pod 规范模板:
apiVersion: v1
kind: Pod
metadata:
name: secure-app
spec:
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
fsGroup: 2000
seccompProfile:
type: RuntimeDefault
automountServiceAccountToken: false # Disable unless needed
containers:
- name: app
image: myapp:v1.2.3@sha256:abc123 # Pin by digest
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsNonRoot: true
capabilities:
drop:
- ALL # Drop ALL capabilities
add:
- NET_BIND_SERVICE # Add back only what's needed
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi" # Always set limits
cpu: "500m"
volumeMounts:
- name: tmp
mountPath: /tmp # Writable volume for /tmp if needed
volumes:
- name: tmp
emptyDir: {}
Kubernetes 安全检查清单:
RBAC:
[ ] No wildcards (*) in ClusterRole rules
[ ] cluster-admin role not assigned to service accounts
[ ] Each workload uses a dedicated service account
[ ] ServiceAccount token auto-mount disabled by default
Pod Security:
[ ] All pods have securityContext defined
[ ] runAsNonRoot: true for all containers
[ ] allowPrivilegeEscalation: false
[ ] readOnlyRootFilesystem: true where possible
[ ] capabilities: drop: [ALL]
[ ] No hostPID, hostIPC, hostNetwork
[ ] No privileged: true
Networking:
[ ] Default deny NetworkPolicy in all namespaces
[ ] Only required pod-to-pod communication allowed
[ ] Egress restricted (not just ingress)
Secrets Management:
[ ] No secrets in environment variables (use mounted secrets or vault)
[ ] No secrets in ConfigMaps
[ ] External secrets management (Vault, AWS SSM, Azure Key Vault)
[ ] ETCD encryption at rest enabled
Image Security:
[ ] All images from private registry (not Docker Hub public)
[ ] Image digest pinning (not mutable tags)
[ ] Admission controller (OPA, Kyverno) enforcing policy
[ ] Image scanning in CI/CD pipeline
5. IaC 安全扫描
当用户要求扫描 Terraform 或 CloudFormation 时:
Claude 会直接读取 IaC 文件并识别问题:
常见 Terraform 配置错误:
# INSECURE: S3 bucket with public access
resource "aws_s3_bucket" "bad" {
bucket = "my-bucket"
acl = "public-read" # ← PUBLIC READ!
}
# SECURE: S3 bucket with all public access blocked
resource "aws_s3_bucket" "good" {
bucket = "my-bucket"
}
resource "aws_s3_bucket_public_access_block" "good" {
bucket = aws_s3_bucket.good.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
# INSECURE: Security group allows all inbound
resource "aws_security_group_rule" "bad" {
type = "ingress"
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"] # ← OPEN TO INTERNET!
}
自动化 IaC 扫描:
# Checkov (Terraform, CloudFormation, K8s, Dockerfile)
checkov -d ./terraform/ --framework terraform --output json > checkov-results.json
checkov -d ./k8s-manifests/ --framework kubernetes
# tfsec (Terraform focused)
tfsec ./terraform/ --format json --out tfsec-results.json
# Trivy (IaC, container, filesystem)
trivy config ./terraform/
trivy config ./k8s-manifests/
# Use iac_scanner.py
python scripts/iac_scanner.py --path ./terraform/ --output findings.json
python scripts/iac_scanner.py --path ./k8s-manifests/ --type kubernetes --output k8s_audit.json
合规框架映射
| 发现项 | CIS AWS | SOC2 | PCI-DSS | HIPAA |
|---|---|---|---|---|
| 未强制启用 MFA | 1.10, 1.14 | CC6.1 | 8.3.2 | 164.312(d) |
| S3 存储桶公开 | 2.1.5 | CC6.7 | 3.4 | 164.312(a)(2)(iv) |
| CloudTrail 已禁用 | 3.1, 3.2 | CC7.2 | 10.2 | 164.312(b) |
| SSH 对互联网开放 | 5.2 | CC6.6 | 1.2.1 | 164.312(e)(1) |
| 使用根账户 | 1.7 | CC6.1 | 7.1.1 | 164.308(a)(1) |
脚本参考
iac_scanner.py
python scripts/iac_scanner.py --path ./terraform/ --output findings.json
python scripts/iac_scanner.py --path ./k8s-manifests/ --type kubernetes --output k8s_audit.json
技能集成
| 条件 | 相邻技能 |
|---|---|
| 通过侦察发现云资产 | ← 技能 01(侦察与 OSINT) |
| 用于 CSOC 警报的云漏洞 | → 技能 11(CSOC 自动化) |
| 实施云加固建议 | → 技能 15(蓝队防御) |
参考资料
- 云 CIS 基准
- AWS Well-Architected 安全支柱
- Azure Security Benchmark v3
- GCP 安全最佳实践
- CIS Kubernetes 基准
- Checkov 文档
- Prowler 文档
v3.0 增强(2026 年更新)
以攻击路径为导向的云安全:
- 身份即边界 — 枚举权限提升路径(权限过宽的角色、
iam:PassRole、通配符操作、跨账户信任、与 CI/CD 的 OIDC 联合)。从攻击路径(CNAPP/CSPM 风格)的角度思考,而不是孤立的错误配置。 - 实例元数据 — 在 AWS 上要求使用 IMDSv2,并将跳数限制设为 1;验证 Azure/GCP 的元数据防护是否能抵御 SSRF(关联技能 09)。
- Kubernetes 2026 — Pod Security Admission(baseline/restricted)、工作负载身份(EKS Pod Identity / GKE Workload Identity / AKS)、不向默认 SA 授予 cluster-admin、默认拒绝的网络策略,以及准入控制(OPA/Gatekeeper、Kyverno)。
- CI/CD 与供应链 — 流水线中的密钥、对云的 OIDC 信任、制品签名(Sigstore/cosign)、SLSA 来源证明,以及 Terraform 状态文件暴露。
- 运行时 — 使用 eBPF 运行时检测(Falco/Tetragon)检测容器逃逸和加密货币挖矿;将发现映射到 MITRE ATT&CK for Cloud/Containers。
精确性规则: 将每项发现报告为错误配置 → 可触达的身份/数据 → 影响范围,并提供准确的 CLI/IaC 修复方案。