你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

配置 Microsoft Security DevOps GitHub 操作

Microsoft Security DevOps 是一个命令行应用程序,它将静态分析工具集成到开发生命周期中。 Security DevOps 安装、配置和运行最新版本的静态分析工具(例如 SDL、安全性和合规性工具)。 Security DevOps 是数据驱动的,具有可移植配置,可实现跨多个环境的确定性执行。

Microsoft Security DevOps 使用以下开源工具:

名称 语言 许可证
反恶意软件 Windows 中来自 Microsoft Defender for Endpoint 的反恶意软件防护,它会扫描恶意软件并在发现恶意软件时中断构建。 默认情况下,此工具在 Windows 最新代理上扫描。 非开放源代码
Bandit Python Apache 许可证 2.0
BinSkim 二进制 - Windows、ELF MIT 许可证
Checkov Terraform、Terraform 计划、CloudFormation、AWS SAM、Kubernetes、Helm 图表、Kustomize、Dockerfile、无服务器、Bicep、OpenAPI、ARM Apache 许可证 2.0
ESlint JavaScript MIT 许可证
模板分析器 ARM 模板、Bicep MIT 许可证
Terrascan Terraform (HCL2)、Kubernetes (JSON/YAML)、Helm v3、Kustomize、Dockerfiles、CloudFormation Apache 许可证 2.0
Trivy 容器映像、基础结构即代码 (IaC) Apache 许可证 2.0

先决条件

配置 Microsoft Security DevOps GitHub 操作

设置 GitHub 操作:

  1. 登录 GitHub

  2. 选择要在为其配置 GitHub 操作的存储库。

  3. 选择“操作”。

    显示“操作”按钮所在位置的屏幕截图。

  4. 选择“新建工作流”。

  5. 在“GitHub Actions 入门”页上,选择“自己设置工作流”

    显示选择“新建工作流”按钮的位置的屏幕截图。

  6. 在文本框中,输入工作流文件的名称。 例如 msdevopssec.yml

    显示输入新工作流名称的位置的屏幕截图。

  7. 将以下示例操作工作流复制并粘贴到“编辑新文件”选项卡中。

    name: MSDO
    on:
      push:
        branches:
          - master
    
    jobs:
      sample:
        name: Microsoft Security DevOps
    
        # MSDO runs on windows-latest.
        # ubuntu-latest also supported
        runs-on: windows-latest
    
        permissions:
          contents: read
          id-token: write
          actions: read
          security-events: write
    
        steps:
    
          # Checkout your code repository to scan
        - uses: actions/checkout@v3
    
          # Run analyzers
        - name: Run Microsoft Security DevOps Analysis
          uses: microsoft/security-devops-action@latest
          id: msdo
        # with:
          # config: string. Optional. A file path to an MSDO configuration file ('*.gdnconfig').
          # policy: 'GitHub' | 'microsoft' | 'none'. Optional. The name of a well-known Microsoft policy. If no configuration file or list of tools is provided, the policy may instruct MSDO which tools to run. Default: GitHub.
          # categories: string. Optional. A comma-separated list of analyzer categories to run. Values: 'code', 'artifacts', 'IaC', 'containers'. Example: 'IaC, containers'. Defaults to all.
          # languages: string. Optional. A comma-separated list of languages to analyze. Example: 'javascript,typescript'. Defaults to all.
          # tools: string. Optional. A comma-separated list of analyzer tools to run. Values: 'bandit', 'binskim', 'checkov', 'eslint', 'templateanalyzer', 'terrascan', 'trivy'.
    
          # Upload alerts to the Security tab
        - name: Upload alerts to Security tab
          uses: github/codeql-action/upload-sarif@v2
          with:
            sarif_file: ${{ steps.msdo.outputs.sarifFile }}
    
          # Upload alerts file as a workflow artifact
        - name: Upload alerts file as a workflow artifact
          uses: actions/upload-artifact@v3
          with:  
            name: alerts
            path: ${{ steps.msdo.outputs.sarifFile }}
    

    注意

    有关其他工具配置选项和说明,请参阅 Microsoft Security DevOps wiki

  8. 选择“开始提交”

    显示选择“开始提交”的位置的屏幕截图。

  9. 选择“提交新文件”。

    显示如何提交新文件的屏幕截图。

    完成此过程可能需要一分钟。

  10. 选择“操作”并验证新操作是否正在运行。

    屏幕截图显示要导航到哪个位置来查看新操作是否正在运行。

查看扫描结果

查看扫描结果:

  1. 登录 GitHub

  2. 导航到“安全性”>“代码扫描警报”>“工具”。

  3. 从下拉菜单中,选择“按工具筛选”。

代码扫描结果将按 GitHub 中的特定 MSDO 工具筛选。 这些代码扫描结果也会拉取到 Defender for Cloud 建议中。

了解更多

详细了解 Defender for Cloud 中的 DevOps 安全性

了解如何将 GitHub 组织连接到 Defender for Cloud