{"meta":{"title":"配置 Dependabot 安全更新","intro":"可以使用 Dependabot security updates 或手动拉取请求轻松更新易受攻击的依赖项。","product":"安全性和代码质量","breadcrumbs":[{"href":"/zh/code-security","title":"安全性和代码质量"},{"href":"/zh/code-security/how-tos","title":"How-tos"},{"href":"/zh/code-security/how-tos/secure-your-supply-chain","title":"保护供应链"},{"href":"/zh/code-security/how-tos/secure-your-supply-chain/secure-your-dependencies","title":"保护依赖项"},{"href":"/zh/code-security/how-tos/secure-your-supply-chain/secure-your-dependencies/configuring-dependabot-security-updates","title":"配置安全更新"}],"documentType":"article"},"body":"# 配置 Dependabot 安全更新\n\n可以使用 Dependabot security updates 或手动拉取请求轻松更新易受攻击的依赖项。\n\n<!--Marketing-LINK: From home page \"Learn more about Dependabot\".-->\n\n## 管理 Dependabot security updates 存储库\n\n可以启用或禁用 Dependabot security updates 个人帐户或组织拥有的所有符合条件的存储库。 有关详细信息，请参阅“[管理安全和分析功能](/zh/account-and-profile/setting-up-and-managing-your-personal-account-on-github/managing-personal-account-settings/managing-security-and-analysis-settings-for-your-personal-account)”或“[管理组织的安全和分析设置](/zh/organizations/keeping-your-organization-secure/managing-security-settings-for-your-organization/managing-security-and-analysis-settings-for-your-organization)”。\n\n还可以为单个存储库启用或禁用 Dependabot security updates 。\n\n### 为 Dependabot security updates 单个存储库启用或禁用\n\n1. 在 GitHub 上，导航到存储库的主页面。\n2. 在仓库名称下，单击 <svg version=\"1.1\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" class=\"octicon octicon-gear\" aria-label=\"gear\" role=\"img\"><path d=\"M8 0a8.2 8.2 0 0 1 .701.031C9.444.095 9.99.645 10.16 1.29l.288 1.107c.018.066.079.158.212.224.231.114.454.243.668.386.123.082.233.09.299.071l1.103-.303c.644-.176 1.392.021 1.82.63.27.385.506.792.704 1.218.315.675.111 1.422-.364 1.891l-.814.806c-.049.048-.098.147-.088.294.016.257.016.515 0 .772-.01.147.038.246.088.294l.814.806c.475.469.679 1.216.364 1.891a7.977 7.977 0 0 1-.704 1.217c-.428.61-1.176.807-1.82.63l-1.102-.302c-.067-.019-.177-.011-.3.071a5.909 5.909 0 0 1-.668.386c-.133.066-.194.158-.211.224l-.29 1.106c-.168.646-.715 1.196-1.458 1.26a8.006 8.006 0 0 1-1.402 0c-.743-.064-1.289-.614-1.458-1.26l-.289-1.106c-.018-.066-.079-.158-.212-.224a5.738 5.738 0 0 1-.668-.386c-.123-.082-.233-.09-.299-.071l-1.103.303c-.644.176-1.392-.021-1.82-.63a8.12 8.12 0 0 1-.704-1.218c-.315-.675-.111-1.422.363-1.891l.815-.806c.05-.048.098-.147.088-.294a6.214 6.214 0 0 1 0-.772c.01-.147-.038-.246-.088-.294l-.815-.806C.635 6.045.431 5.298.746 4.623a7.92 7.92 0 0 1 .704-1.217c.428-.61 1.176-.807 1.82-.63l1.102.302c.067.019.177.011.3-.071.214-.143.437-.272.668-.386.133-.066.194-.158.211-.224l.29-1.106C6.009.645 6.556.095 7.299.03 7.53.01 7.764 0 8 0Zm-.571 1.525c-.036.003-.108.036-.137.146l-.289 1.105c-.147.561-.549.967-.998 1.189-.173.086-.34.183-.5.29-.417.278-.97.423-1.529.27l-1.103-.303c-.109-.03-.175.016-.195.045-.22.312-.412.644-.573.99-.014.031-.021.11.059.19l.815.806c.411.406.562.957.53 1.456a4.709 4.709 0 0 0 0 .582c.032.499-.119 1.05-.53 1.456l-.815.806c-.081.08-.073.159-.059.19.162.346.353.677.573.989.02.03.085.076.195.046l1.102-.303c.56-.153 1.113-.008 1.53.27.161.107.328.204.501.29.447.222.85.629.997 1.189l.289 1.105c.029.109.101.143.137.146a6.6 6.6 0 0 0 1.142 0c.036-.003.108-.036.137-.146l.289-1.105c.147-.561.549-.967.998-1.189.173-.086.34-.183.5-.29.417-.278.97-.423 1.529-.27l1.103.303c.109.029.175-.016.195-.045.22-.313.411-.644.573-.99.014-.031.021-.11-.059-.19l-.815-.806c-.411-.406-.562-.957-.53-1.456a4.709 4.709 0 0 0 0-.582c-.032-.499.119-1.05.53-1.456l.815-.806c.081-.08.073-.159.059-.19a6.464 6.464 0 0 0-.573-.989c-.02-.03-.085-.076-.195-.046l-1.102.303c-.56.153-1.113.008-1.53-.27a4.44 4.44 0 0 0-.501-.29c-.447-.222-.85-.629-.997-1.189l-.289-1.105c-.029-.11-.101-.143-.137-.146a6.6 6.6 0 0 0-1.142 0ZM11 8a3 3 0 1 1-6 0 3 3 0 0 1 6 0ZM9.5 8a1.5 1.5 0 1 0-3.001.001A1.5 1.5 0 0 0 9.5 8Z\"></path></svg>“Settings”\\*\\*\\*\\*。 如果看不到“设置”选项卡，请选择“<svg version=\"1.1\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" class=\"octicon octicon-kebab-horizontal\" aria-label=\"kebab horizontal icon\" role=\"img\"><path d=\"M8 9a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3ZM1.5 9a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Zm13 0a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z\"></path></svg>”下拉菜单，然后单击“设置”。\n\n   ![存储库标头的屏幕截图，其中显示了选项卡。 “设置”选项卡以深橙色边框突出显示。](/assets/images/help/repository/repo-actions-settings.png)\n3. 在边栏的“Security”部分中，单击“<svg version=\"1.1\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" class=\"octicon octicon-codescan\" aria-label=\"codescan\" role=\"img\"><path d=\"M8.47 4.97a.75.75 0 0 0 0 1.06L9.94 7.5 8.47 8.97a.75.75 0 1 0 1.06 1.06l2-2a.75.75 0 0 0 0-1.06l-2-2a.75.75 0 0 0-1.06 0ZM6.53 6.03a.75.75 0 0 0-1.06-1.06l-2 2a.75.75 0 0 0 0 1.06l2 2a.75.75 0 1 0 1.06-1.06L5.06 7.5l1.47-1.47Z\"></path><path d=\"M12.246 13.307a7.501 7.501 0 1 1 1.06-1.06l2.474 2.473a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215ZM1.5 7.5a6.002 6.002 0 0 0 3.608 5.504 6.002 6.002 0 0 0 6.486-1.117.748.748 0 0 1 .292-.293A6 6 0 1 0 1.5 7.5Z\"></path></svg> Advanced Security”\\*\\*\\*\\*。\n4. 在“安全更新”Dependabot 右侧，单击“ **启用** ”以启用该功能或 **禁用** 该功能。\n   对于公共存储库，如果始终启用该功能，则会禁用该按钮。\n\n## 将Dependabot security updates组成为单个拉取请求\n\n若要使用分组的安全更新，你必须先启用以下功能：\n\n* **依赖项关系图**。 有关详细信息，请参阅“[启用依赖项关系图](/zh/code-security/supply-chain-security/understanding-your-software-supply-chain/configuring-the-dependency-graph)”。\n\n***\n\n```\n          Dependabot alerts\n          **。 有关详细信息，请参阅“[AUTOTITLE](/code-security/dependabot/dependabot-alerts/configuring-dependabot-alerts)”。\n```\n\n***\n\n```\n          Dependabot security updates\n          **。 有关详细信息，请参阅“[AUTOTITLE](/code-security/dependabot/dependabot-security-updates/configuring-dependabot-security-updates)”。\n```\n\n> \\[!NOTE]\n> 首次启用分组安全更新后， Dependabot 将立即尝试创建分组拉取请求。 你可能会注意到 Dependabot 关闭旧的拉取请求并打开新请求。\n\n可以通过以下一种或两种方式为 Dependabot security updates 启用分组拉取请求。\n\n* 若要跨目录和按生态系统将尽可能多的可用安全更新分组在一起，请在仓库的“Advanced Security”设置中，或在组织的“ Advanced Security”下的“Global settings”中启用分组。\n* 如需更精细地控制分组（例如按包名称、开发/生产依赖项、SemVer 级别或每个生态系统的多个目录进行分组），请在仓库中的 `dependabot.yml` 配置文件中添加配置选项。\n\n> \\[!NOTE]\n> 如果已在 `dependabot.yml` 文件中为 Dependabot security updates 配置了组规则，则所有可用更新都将根据指定的规则进行分组。 如果还启用了组织或存储库级别的分组安全更新设置，则 Dependabot 只会跨那些未在 `dependabot.yml` 中配置的目录进行分组。\n\n### 为单个存储库启用或禁用Dependabot security updates分组\n\n1. 在 GitHub 上，导航到存储库的主页面。\n2. 在仓库名称下，单击 <svg version=\"1.1\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" class=\"octicon octicon-gear\" aria-label=\"gear\" role=\"img\"><path d=\"M8 0a8.2 8.2 0 0 1 .701.031C9.444.095 9.99.645 10.16 1.29l.288 1.107c.018.066.079.158.212.224.231.114.454.243.668.386.123.082.233.09.299.071l1.103-.303c.644-.176 1.392.021 1.82.63.27.385.506.792.704 1.218.315.675.111 1.422-.364 1.891l-.814.806c-.049.048-.098.147-.088.294.016.257.016.515 0 .772-.01.147.038.246.088.294l.814.806c.475.469.679 1.216.364 1.891a7.977 7.977 0 0 1-.704 1.217c-.428.61-1.176.807-1.82.63l-1.102-.302c-.067-.019-.177-.011-.3.071a5.909 5.909 0 0 1-.668.386c-.133.066-.194.158-.211.224l-.29 1.106c-.168.646-.715 1.196-1.458 1.26a8.006 8.006 0 0 1-1.402 0c-.743-.064-1.289-.614-1.458-1.26l-.289-1.106c-.018-.066-.079-.158-.212-.224a5.738 5.738 0 0 1-.668-.386c-.123-.082-.233-.09-.299-.071l-1.103.303c-.644.176-1.392-.021-1.82-.63a8.12 8.12 0 0 1-.704-1.218c-.315-.675-.111-1.422.363-1.891l.815-.806c.05-.048.098-.147.088-.294a6.214 6.214 0 0 1 0-.772c.01-.147-.038-.246-.088-.294l-.815-.806C.635 6.045.431 5.298.746 4.623a7.92 7.92 0 0 1 .704-1.217c.428-.61 1.176-.807 1.82-.63l1.102.302c.067.019.177.011.3-.071.214-.143.437-.272.668-.386.133-.066.194-.158.211-.224l.29-1.106C6.009.645 6.556.095 7.299.03 7.53.01 7.764 0 8 0Zm-.571 1.525c-.036.003-.108.036-.137.146l-.289 1.105c-.147.561-.549.967-.998 1.189-.173.086-.34.183-.5.29-.417.278-.97.423-1.529.27l-1.103-.303c-.109-.03-.175.016-.195.045-.22.312-.412.644-.573.99-.014.031-.021.11.059.19l.815.806c.411.406.562.957.53 1.456a4.709 4.709 0 0 0 0 .582c.032.499-.119 1.05-.53 1.456l-.815.806c-.081.08-.073.159-.059.19.162.346.353.677.573.989.02.03.085.076.195.046l1.102-.303c.56-.153 1.113-.008 1.53.27.161.107.328.204.501.29.447.222.85.629.997 1.189l.289 1.105c.029.109.101.143.137.146a6.6 6.6 0 0 0 1.142 0c.036-.003.108-.036.137-.146l.289-1.105c.147-.561.549-.967.998-1.189.173-.086.34-.183.5-.29.417-.278.97-.423 1.529-.27l1.103.303c.109.029.175-.016.195-.045.22-.313.411-.644.573-.99.014-.031.021-.11-.059-.19l-.815-.806c-.411-.406-.562-.957-.53-1.456a4.709 4.709 0 0 0 0-.582c-.032-.499.119-1.05.53-1.456l.815-.806c.081-.08.073-.159.059-.19a6.464 6.464 0 0 0-.573-.989c-.02-.03-.085-.076-.195-.046l-1.102.303c-.56.153-1.113.008-1.53-.27a4.44 4.44 0 0 0-.501-.29c-.447-.222-.85-.629-.997-1.189l-.289-1.105c-.029-.11-.101-.143-.137-.146a6.6 6.6 0 0 0-1.142 0ZM11 8a3 3 0 1 1-6 0 3 3 0 0 1 6 0ZM9.5 8a1.5 1.5 0 1 0-3.001.001A1.5 1.5 0 0 0 9.5 8Z\"></path></svg>“Settings”\\*\\*\\*\\*。 如果看不到“设置”选项卡，请选择“<svg version=\"1.1\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" class=\"octicon octicon-kebab-horizontal\" aria-label=\"kebab horizontal icon\" role=\"img\"><path d=\"M8 9a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3ZM1.5 9a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Zm13 0a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z\"></path></svg>”下拉菜单，然后单击“设置”。\n\n   ![存储库标头的屏幕截图，其中显示了选项卡。 “设置”选项卡以深橙色边框突出显示。](/assets/images/help/repository/repo-actions-settings.png)\n3. 在边栏的“Security”部分中，单击“<svg version=\"1.1\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" class=\"octicon octicon-codescan\" aria-label=\"codescan\" role=\"img\"><path d=\"M8.47 4.97a.75.75 0 0 0 0 1.06L9.94 7.5 8.47 8.97a.75.75 0 1 0 1.06 1.06l2-2a.75.75 0 0 0 0-1.06l-2-2a.75.75 0 0 0-1.06 0ZM6.53 6.03a.75.75 0 0 0-1.06-1.06l-2 2a.75.75 0 0 0 0 1.06l2 2a.75.75 0 1 0 1.06-1.06L5.06 7.5l1.47-1.47Z\"></path><path d=\"M12.246 13.307a7.501 7.501 0 1 1 1.06-1.06l2.474 2.473a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215ZM1.5 7.5a6.002 6.002 0 0 0 3.608 5.504 6.002 6.002 0 0 0 6.486-1.117.748.748 0 0 1 .292-.293A6 6 0 1 0 1.5 7.5Z\"></path></svg> Advanced Security”\\*\\*\\*\\*。\n4.\n\n```\n          Dependabot\n```\n\n```\n          在“分组安全更新”右侧的“启用”下，单击“**启用**”以启用该功能或**禁用**该功能。\n```\n\n### 为组织启用或禁用“分组”Dependabot security updates\n\n```\n           可以启用分组 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)”。\n```\n\n## 使用配置文件重写默认行为\n\n可以通过将`dependabot.yml`文件添加到存储库来替代Dependabot security updates的默认行为。\n`dependabot.yml`文件可以更精细地控制分组，并覆盖Dependabot security updates设置的默认行为。\n\n将 `groups` 选项与 `applies-to: security-updates` 按键结合使用，以创建（每个包管理器的）依赖项集，从而使 Dependabot 能够打开单个拉取请求以同时更新多个依赖项。 可以按包名称（`patterns` 和 `exclude-patterns` 密钥）、依赖项类型（`dependency-type` 密钥）和 SemVer（`update-types` 密钥）来定义组。\n\nDependabot 按组在 `dependabot.yml` 文件中出现的顺序创建组。 如果依赖项更新可以属于多个组，则只会将它分配给与之匹配的第一个组。\n\n如果只需要\\_安全\\_更新并且想要排除\\_版本\\_更新，可以将 `open-pull-requests-limit` 设置为 `0`，以防止给定 `package-ecosystem` 的版本更新。\n\n有关可用于安全更新的配置选项的详细信息，请参阅 [自定义 Dependabot 安全更新的拉取请求](/zh/code-security/dependabot/dependabot-security-updates/customizing-dependabot-security-prs)。\n\n```yaml copy\n# Example configuration file that:\n#  - Has a private registry\n#  - Ignores lodash dependency\n#  - Disables version-updates\n#  - Defines a group by package name, for security updates for golang dependencies\n\nversion: 2\nregistries:\n  example:\n    type: npm-registry\n    url: https://example.com\n    token: ${{secrets.NPM_TOKEN}}\nupdates:\n  - package-ecosystem: \"npm\"\n    directory: \"/src/npm-project\"\n    schedule:\n      interval: \"daily\"\n    # For Lodash, ignore all updates\n    ignore:\n      - dependency-name: \"lodash\"\n    # Disable version updates for npm dependencies\n    open-pull-requests-limit: 0\n    registries:\n      - example\n  - package-ecosystem: \"gomod\"\n    directories:\n      - \"**/*\"\n    schedule:\n      interval: \"weekly\"\n    open-pull-requests-limit: 0\n    groups:\n      golang:\n        applies-to: security-updates\n        patterns:\n          - \"golang.org*\"\n```\n\n> \\[!NOTE]\n> 为了让 Dependabot 使用此配置进行安全更新，`directory` 必须是清单文件的路径，或者 `directories` 必须包含与清单文件位置相匹配的路径或 glob 模式，并且不应指定 `target-branch`。\n\n## 延伸阅读\n\n* [关于 Dependabot 警报](/zh/code-security/dependabot/dependabot-alerts/about-dependabot-alerts)\n* [配置 Dependabot 警报](/zh/code-security/dependabot/dependabot-alerts/configuring-dependabot-alerts)\n* [依赖项关系图支持的包生态系统](/zh/code-security/supply-chain-security/understanding-your-software-supply-chain/dependency-graph-supported-package-ecosystems#supported-package-ecosystems)"}