mcpField
T
threat-modeling-with-aws-security-agent

threat-modeling-with-aws-security-agent

github.com/aws安全3.3k1.6k 次安装1 天前更新
代码仓库

关于 threat-modeling-with-aws-security-agent

该技能使用 STRIDE 方法,将需求和设计文档与源代码对照,识别安全态势变化。它面向在 AWS Security Agent 中审查威胁模型的开发团队,无需先运行扫描。

主要功能

  1. 01对照需求与设计文档审查代码
  2. 02使用 STRIDE 分类威胁
  3. 03创建并轮询威胁建模任务
  4. 04生成包含影响与建议的报告

适用场景

  1. 01评估设计变更带来的安全风险
  2. 02根据需求和设计文档识别威胁

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/aws/agent-toolkit-for-aws --skill threat-modeling-with-aws-security-agent

安装后在 Claude Code 中输入/threat-modeling-with-aws-security-agent确认已加载。

详细介绍

AWS Security Agent——威胁模型审查

使用 STRIDE 方法分析规范文档(requirements.md、design.md),并与源代码对照,以识别安全态势变化。无需事先扫描。

本地状态

读取 .security-agent/config.json 获取 agent_space_id 和 region。如果缺少这些值,先内联运行 setup-security-agent 工作流。

解析所需值
占位符解析方式
<id>(Agent 空间)config.agent_space_id
<region>config.region(默认值为 us-east-1)
<account>aws sts get-caller-identity --query Account --output text
<role-arn>arn:aws:iam::<account>:role/SecurityAgentScanRole
<bucket>security-agent-scans-<account>-<region>

工作流

  1. 预检查。 读取配置,验证 Agent 空间,解析所需值。

  2. 收集规范文件。 找出用户正在处理的 requirements.md 和/或 design.md。使用绝对路径。如果不清楚要审查哪些文件,请询问用户。

  3. 压缩工作区(排除项与代码扫描相同):

    cd <absolute-workspace-path>
    zip -r /tmp/source.zip . \
      -x ".git/*" -x ".security-agent/*" -x "node_modules/*" \
      -x "__pycache__/*" -x ".venv/*" -x "venv/*" \
      -x "dist/*" -x "build/*" -x "target/*" \
      -x ".mypy_cache/*" -x ".pytest_cache/*" -x ".tox/*" \
      -x ".next/*" -x "cdk.out/*" -x ".DS_Store" -x "*.pyc"
    
  4. 上传源代码 zip 文件:

    SCAN_ID="tm-$(date +%s)-$(openssl rand -hex 3)"
    WORKSPACE_ID=$(printf '%s' "$(pwd)" | md5sum | cut -c1-12)
    aws s3 cp /tmp/source.zip s3://<bucket>/security-scans/source/${WORKSPACE_ID}/source.zip --expected-bucket-owner <account>
    
  5. 上传规范文件:

    aws s3 cp /path/to/requirements.md s3://<bucket>/security-scans/threat-models/${SCAN_ID}/specs/requirements.md --expected-bucket-owner <account>
    aws s3 cp /path/to/design.md s3://<bucket>/security-scans/threat-models/${SCAN_ID}/specs/design.md --expected-bucket-owner <account>
    
  6. 创建威胁模型:

    aws securityagent create-threat-model --agent-space-id <id> --title <title> \
      --service-role <role-arn> \
      --assets sourceCode=[{s3Location=s3://<bucket>/security-scans/source/${WORKSPACE_ID}/source.zip}] \
      --scope-docs '[{"s3Location":"s3://<bucket>/security-scans/threat-models/'${SCAN_ID}'/specs/requirements.md"},{"s3Location":"s3://<bucket>/security-scans/threat-models/'${SCAN_ID}'/specs/design.md"}]'
    

    记录 threatModelId。

  7. 启动威胁模型任务:

    aws securityagent start-threat-model-job --agent-space-id <id> --threat-model-id <tm-id>
    

    记录 threatJobId。

  8. 将信息持久化到 scans.json,并设置 scan_type: "THREAT_MODEL"。

  9. 告知用户:“威胁模型审查已启动。运行时间因工作区大小而异。我每 2 分钟检查一次——回复‘停止轮询’即可选择退出。”

  10. 每 2 分钟轮询一次:

    aws securityagent batch-get-threat-model-jobs --agent-space-id <id> --threat-model-job-ids <tj-id>
    

    仅在状态发生变化时回复。

  11. 状态为 COMPLETED 时 → 获取威胁:

    aws securityagent list-threats --agent-space-id <id> --threat-job-id <tj-id>
    

    如果存在 nextToken,使用 --next-token 分页。

发现结果展示

每项威胁包括:statement、severity、stride 类别、threatImpact、recommendation、impactedAssets。

🟣 CRITICAL: {statement}
   STRIDE: {stride}
   Impact: {threatImpact}
   Assets: {impactedAssets}
   Recommendation: {recommendation}

🔴 HIGH: {statement}
   ...

将完整报告写入 .security-agent/findings-{scan_id}.md。指出任何相较于先前设计构成回归的威胁。


规则

  • 威胁模型审查独立进行——无需事先扫描
  • 每 2 分钟轮询一次,不要更频繁
  • 至少需要一个规范文件
  • 工作区和规范文件均使用绝对路径
  • 标题:threat-model-<feature-name>(不含空格)

评论

支持 Markdown