Skip to main content

配置依赖项审查

可以使用依赖项评审来捕获漏洞,以避免将其添加到项目中。

关于依赖项评审

依赖项审查帮助您了解依赖项变化以及这些变化在每个拉取请求中的安全影响。 它提供了一个易于理解的依赖项变化可视化效果,多差异显示在拉取请求的“更改的文件”选项卡上。 依赖项审查告知您:

  • 哪些依赖项连同发行日期一起添加、删除或更新。
  • 有多少项目使用这些组件。
  • 这些依赖项的漏洞数据。

有关详细信息,请参阅“关于依赖项审查”和“审查拉取请求中的依赖项更改”。

关于配置依赖项审查

依赖项审查包含在公共存储库的 GitHub Enterprise Cloud 中。 若要在组织拥有的专用存储库中使用依赖项审查,必须具有 GitHub Advanced Security 许可证并启用依赖项关系图。

Repository administrators can enable or disable the dependency graph for private repositories.

You can also enable or disable the dependency graph for all repositories owned by your user account or organization. For more information, see "Configuring the dependency graph."

  1. On GitHub.com, navigate to the main page of the repository.

  2. 在存储库名称下,单击 “设置”。 “存储库设置”按钮

  3. In the "Security" section of the sidebar, click Code security and analysis.

  4. Read the message about granting GitHub Enterprise Cloud read-only access to the repository data to enable the dependency graph, then next to "Dependency Graph", click Enable. "Enable" button for the dependency graph You can disable the dependency graph at any time by clicking Disable next to "Dependency Graph" on the settings page for "Code security and analysis."

  5. 如果尚未启用“GitHub Advanced Security”,请单击此功能旁边的“启用”。 GitHub 高级安全功能的屏幕截图,其中突出显示了“启用”按钮

关于配置 dependency review action

dependency review action 扫描拉取请求中的依赖项更改,如果有任何新的依赖项存在已知漏洞,则会引发错误。 API 终结点支持此操作,该终结点比较两个修订之间的依赖关系,并报告任何差异。

有关操作和 API 终结点的详细信息,请参阅 API 文档中的“关于依赖项审查”和“依赖项审查”。

可用配置选项如下。

选项必选使用情况
fail-on-severity可选定义严重性级别(lowmoderatehighcritical)的阈值。
对于引入指定严重性级别或更高级别的漏洞的任何拉取请求,该操作都将失败。

提示:allow-licensesdeny-licenses 选项互斥。

配置 dependency review action

可以通过两种方法配置 dependency review action:

  • 在工作流文件中内联配置选项。
  • 在工作流文件中引用配置文件。

请注意,所有示例使用操作 (v3) 的短版本号,而不是 semver 版本号(例如,v3.0.8)。 这可确保使用操作的最新次要版本。

使用内联配置设置 dependency review action

  1. 将新的 YAML 工作流添加到 .github/workflows 文件夹。

    YAML
    name: 'Dependency Review'
    on: [pull_request]
    
    permissions:
      contents: read
    
    jobs:
      dependency-review:
       runs-on: ubuntu-latest
         steps:
           - name: 'Checkout Repository'
             uses: actions/checkout@v3
           - name: Dependency Review
             uses: actions/dependency-review-action@v3
  2. 指定您的设置。

    此 dependency review action 示例文件说明了如何使用可用的配置选项。

    YAML
    name: 'Dependency Review'
    on: [pull_request]
    
    permissions:
      contents: read
    
    jobs:
      dependency-review:
      runs-on: ubuntu-latest
        steps:
          - name: 'Checkout Repository'
            uses: actions/checkout@v3
          - name: Dependency Review
            uses: actions/dependency-review-action@v3
            with:
            # Possible values: "critical", "high", "moderate", "low" 
            fail-on-severity: critical
    
            # You can only include one of these two options: `allow-licenses` and `deny-licences`
            # ([String]). Only allow these licenses (optional)
            # Possible values: Any `spdx_id` value(s) from https://docs.github.com/en/rest/licenses 
            allow-licenses: GPL-3.0, BSD-3-Clause, MIT
            # ([String]). Block the pull request on these licenses (optional)
            # Possible values: Any  `spdx_id` value(s) from https://docs.github.com/en/rest/licenses 
            deny-licenses: LGPL-2.0, BSD-2-Clause
    
            # ([String]). Skip these GitHub Advisory Database IDs during detection (optional)
            # Possible values: Any valid GitHub Advisory Database ID from https://github.com/advisories  
            allow-ghsas: GHSA-abcd-1234-5679, GHSA-efgh-1234-5679
    
            # ([String]). Block pull requests that introduce vulnerabilities in the scopes that match this list (optional)
            # Possible values: "development", "runtime", "unknown"
            fail-on-scopes: development, runtime
    

使用配置文件设置 dependency review action

  1. 将新的 YAML 工作流添加到 .github/workflows 文件夹,并使用 config-file 指定正在使用配置文件。

    YAML
    name: 'Dependency Review'
    on: [pull_request]
    
    permissions:
     contents: read
    
    jobs:
      dependency-review:
        runs-on: ubuntu-latest
        steps:
          - name: 'Checkout Repository'
            uses: actions/checkout@v3
          - name: Dependency Review
            uses: actions/dependency-review-action@v3
            with:
             # ([String]). Representing a path to a configuration file local to the repository or in an external repository.
             # Possible values: An absolute path to a local file or an external file.
             config-file: './.github/dependency-review-config.yml'   
             # Syntax for an external file: OWNER/REPOSITORY/FILENAME@BRANCH
             config-file: 'github/octorepo/dependency-review-config.yml@main'
    
             # ([Token]) Use if your configuration file resides in a private external repository.
             # Possible values: Any GitHub token with read access to the private external repository.  
             external-repo-token: 'ghp_123456789abcde'
  2. 在指定路径中创建配置文件。

    此 YAML 示例文件说明了如何使用可用的配置选项。

    YAML
      # Possible values: "critical", "high", "moderate", "low" 
      fail-on-severity: critical
    
      # You can only include one of these two options: `allow-licenses` and `deny-licences`
      # ([String]). Only allow these licenses (optional)
      # Possible values: Any `spdx_id` value(s) from https://docs.github.com/en/rest/licenses 
      allow-licenses: 
        - GPL-3.0
        - BSD-3-Clause
        - MIT
       # ([String]). Block the pull request on these licenses (optional)
       # Possible values: Any  `spdx_id` value(s) from https://docs.github.com/en/rest/licenses 
      deny-licenses: 
        - LGPL-2.0
        - BSD-2-Clause
    
       # ([String]). Skip these GitHub Advisory Database IDs during detection (optional)
       # Possible values: Any valid GitHub Advisory Database ID from https://github.com/advisories  
      allow-ghsas: 
        - GHSA-abcd-1234-5679 
        - GHSA-efgh-1234-5679
    
       # ([String]). Block pull requests that introduce vulnerabilities in the scopes that match this list (optional)
       # Possible values: "development", "runtime", "unknown"
      fail-on-scopes: 
        - development 
        - runtime
    

    有关配置选项的更多详细信息,请参阅 dependency-review-action