Skip to main content

配置 Dependabot 安全更新

可以使用 Dependabot security updates 或手动拉取请求轻松更新易受攻击的依赖项。

谁可以使用此功能?

Users with write access

注意

站点管理员必须先为 你的 GitHub Enterprise Server 实例设置 Dependabot updates,然后你才能使用此功能。 有关详细信息,请参阅 为企业启用 Dependabot.

如果企业所有者在企业级别设置了策略,你可能无法启用或禁用 Dependabot updates。 有关详细信息,请参阅“强制实施企业的代码安全性和分析策略”。

管理 Dependabot security updates 存储库

可以启用或禁用 Dependabot security updates 个人帐户或组织拥有的所有符合条件的存储库。 有关详细信息,请参阅“管理安全和分析功能”或“管理组织的安全和分析设置”。

还可以为单个存储库启用或禁用 Dependabot security updates 。

为 Dependabot security updates 单个存储库启用或禁用

  1. 在 GitHub 上,导航到存储库的主页面。

  2. 在仓库名称下,单击 “Settings”****。 如果看不到“设置”选项卡,请选择“”下拉菜单,然后单击“设置”。

    存储库标头的屏幕截图,其中显示了选项卡。 “设置”选项卡以深橙色边框突出显示。

  3. 在边栏的“Security”部分中,单击“ Advanced Security”****。

  4. 在“安全更新”Dependabot 右侧,单击“ 启用 ”以启用该功能或 禁用 该功能。

将Dependabot security updates组成为单个拉取请求

若要使用分组的安全更新,你必须先启用以下功能:

  •         **依赖项关系图**。 有关详细信息,请参阅“[AUTOTITLE](/code-security/supply-chain-security/understanding-your-software-supply-chain/configuring-the-dependency-graph)”。
    
  •         **
            Dependabot alerts
            **。 有关详细信息,请参阅“[AUTOTITLE](/code-security/dependabot/dependabot-alerts/configuring-dependabot-alerts)”。
    
  •         **
            Dependabot security updates
            **。 有关详细信息,请参阅“[AUTOTITLE](/code-security/dependabot/dependabot-security-updates/configuring-dependabot-security-updates)”。
    

注意

首次启用分组安全更新后, Dependabot 将立即尝试创建分组拉取请求。 你可能会注意到 Dependabot 关闭旧的拉取请求并打开新请求。

可以通过以下一种或两种方式为 Dependabot security updates 启用分组拉取请求。

  • 若要跨目录和按生态系统将尽可能多的可用安全更新分组在一起,请在仓库的“Advanced Security”设置中,或在组织的“ Advanced Security”下的“Global settings”中启用分组。
  • 如需更精细地控制分组(例如按包名称、开发/生产依赖项、SemVer 级别或每个生态系统的多个目录进行分组),请在仓库中的 dependabot.yml 配置文件中添加配置选项。

注意

如果已在 dependabot.yml 文件中为 Dependabot security updates 配置了组规则,则所有可用更新都将根据指定的规则进行分组。 如果还启用了组织或存储库级别的分组安全更新设置,则 Dependabot 只会跨那些未在 dependabot.yml 中配置的目录进行分组。

为单个存储库启用或禁用Dependabot security updates分组

  1. 在 GitHub 上,导航到存储库的主页面。

  2. 在仓库名称下,单击 “Settings”****。 如果看不到“设置”选项卡,请选择“”下拉菜单,然后单击“设置”。

    存储库标头的屏幕截图,其中显示了选项卡。 “设置”选项卡以深橙色边框突出显示。

  3. 在边栏的“Security”部分中,单击“ Advanced Security”****。

          Dependabot
          在“分组安全更新”右侧的“启用”下,单击“**启用**”以启用该功能或**禁用**该功能。

为组织启用或禁用“分组”Dependabot security updates

           可以启用分组 Dependabot security updates 到单个拉取请求中。 有关详细信息,请参阅“[AUTOTITLE](/code-security/securing-your-organization/enabling-security-features-in-your-organization/configuring-global-security-settings-for-your-organization#grouping-dependabot-security-updates)”。

使用配置文件重写默认行为

可以通过将dependabot.yml文件添加到存储库来替代Dependabot security updates的默认行为。 dependabot.yml文件可以更精细地控制分组,并覆盖Dependabot security updates设置的默认行为。

groups 选项与 applies-to: security-updates 按键结合使用,以创建(每个包管理器的)依赖项集,从而使 Dependabot 能够打开单个拉取请求以同时更新多个依赖项。 可以按包名称(patternsexclude-patterns 密钥)、依赖项类型(dependency-type 密钥)和 SemVer(update-types 密钥)来定义组。

Dependabot 按组在 dependabot.yml 文件中出现的顺序创建组。 如果依赖项更新可以属于多个组,则只会将它分配给与之匹配的第一个组。

如果只需要_安全_更新并且想要排除_版本_更新,可以将 open-pull-requests-limit 设置为 0,以防止给定 package-ecosystem 的版本更新。

有关可用于安全更新的配置选项的详细信息,请参阅 自定义 Dependabot 安全更新的拉取请求

YAML
# Example configuration file that:
#  - Has a private registry
#  - Ignores lodash dependency
#  - Disables version-updates
#  - Defines a group by package name, for security updates for golang dependencies

version: 2
registries:
  example:
    type: npm-registry
    url: https://example.com
    token: ${{secrets.NPM_TOKEN}}
updates:
  - package-ecosystem: "npm"
    directory: "/src/npm-project"
    schedule:
      interval: "daily"
    # For Lodash, ignore all updates
    ignore:
      - dependency-name: "lodash"
    # Disable version updates for npm dependencies
    open-pull-requests-limit: 0
    registries:
      - example
  - package-ecosystem: "gomod"
    directories:
      - "**/*"
    schedule:
      interval: "weekly"
    open-pull-requests-limit: 0
    groups:
      golang:
        applies-to: security-updates
        patterns:
          - "golang.org*"

注意

为了让 Dependabot 使用此配置进行安全更新,directory 必须是清单文件的路径,或者 directories 必须包含与清单文件位置相匹配的路径或 glob 模式,并且不应指定 target-branch

延伸阅读

  •         [AUTOTITLE](/code-security/dependabot/dependabot-alerts/about-dependabot-alerts)
    
  •         [AUTOTITLE](/code-security/dependabot/dependabot-alerts/configuring-dependabot-alerts)
    
  •         [AUTOTITLE](/code-security/supply-chain-security/understanding-your-software-supply-chain/dependency-graph-supported-package-ecosystems#supported-package-ecosystems)