# 供应链安全

GitHub 有助于保护供应链，从了解环境中的依赖项到了解这些依赖项中的漏洞，以及修补这些漏洞。

## 关于 GitHub 上的供应链安全性

在开发软件项目时，你可能会使用其他软件来构建和运行应用程序，例如开源库、框架或其他工具。 这些资源统称为你的“依赖项”，因为你的项目依赖它们正常运行。 你的项目可能依赖数百个此类依赖项，形成所谓的“供应链”。

你的供应链可能带来安全问题。 如果某个依赖项存在已知安全漏洞或缺陷，攻击者可能利用这些漏洞，例如插入恶意代码（“恶意软件”）、窃取敏感数据，或对项目造成其他类型的破坏。 这种威胁类型称为“供应链攻击”。 供应链中存在易受攻击的依赖项会削弱你自己项目的安全性，同时也会让用户面临风险。

保护供应链最重要的措施之一是修补易受攻击的依赖项并替换任何恶意软件。

当你在清单文件或锁定文件中指定依赖项时，可以直接将它们添加到供应链。 依赖项也可以通过可传递方式包含在内，也就是说，即使你没有指定某个特定的依赖项，但你的某个依赖项使用了它，那么你也会依赖于该依赖项。

GitHub 提供了一系列功能，可帮助你了解环境中的依赖项、了解这些依赖项中的漏洞并对其进行修补。

GitHub 上的供应链功能是：

* **依赖项关系图**
* **依赖项检查**
* **Dependabot alerts**
* **Dependabot updates**
  * **Dependabot security updates**
  * **Dependabot version updates**

依赖项关系图是供应链安全性的核心。 依赖项关系图标识了存储库或包的所有上游依赖项和公共下游依赖项。 存储库的依赖项关系图会跟踪并显示它的依赖项及其部分属性，例如漏洞信息。

以下供应链功能依赖于 GitHub 依赖关系图提供的信息。

* 依赖项审查使用依赖项关系图来标识依赖项更改，在你审查拉取请求时，可帮助你了解这些更改的安全影响。
* Dependabot 将依赖关系图提供的依赖项数据与 GitHub Advisory Database 发布的公告列表进行交叉引用，扫描您的依赖项，并在检测到潜在漏洞时生成 Dependabot alerts。
* Dependabot security updates 使用依赖关系图 Dependabot alerts 帮助你更新存储库中具有已知漏洞的依赖项。

Dependabot version updates 不要使用依赖项图，而是依赖于依赖项的语义版本控制。
Dependabot version updates 帮助你保持依赖项的更新，即使它们没有任何漏洞。

有关端到端供应链安全最佳实践指南，包括保护个人账户、代码和构建流程，请参阅 [保护端到端供应链](/zh/enterprise-server@3.21/code-security/supply-chain-security/end-to-end-supply-chain/end-to-end-supply-chain-overview)。

## 功能概述

### 什么是依赖项关系图？

若要生成依赖项关系图， GitHub 请查看清单和锁文件中声明的存储库的显式依赖项。 启用后，依赖项关系图会自动分析存储库中的所有已知包清单文件，并以此来构造一个包含已知依赖项名称和版本的关系图。

* 依赖图包含有关你的\_直接\_依赖项和\_传递\_依赖项的信息。
* 当你将提交推送到 GitHub 以更改或添加受支持的清单或锁定文件到默认分支时，以及当任何人将更改推送到你的依赖项之一的存储库时，依赖项图会自动更新。
* 依赖项图还可以包含你在项目构建时使用 GitHub Actions 提供的信息。 某些包生态系统会在生成时提取其大部分可传递依赖项，因此如果在生成时提交依赖项信息，则可获得更完整的供应链视图。
* 可以通过打开存储库的主页 GitHub并导航到 **“见解** ”选项卡来查看依赖项关系图。
* 如果至少具有对存储库的读取访问权限，则可以通过 GitHub UI 或 GitHub REST API，将存储库的依赖项关系图导出为与 SPDX 兼容的软件物料清单 (SBOM)。 有关详细信息，请参阅“[导出存储库的软件物料清单](/zh/enterprise-server@3.21/code-security/supply-chain-security/understanding-your-software-supply-chain/exporting-a-software-bill-of-materials-for-your-repository)”。

你可以使用 依赖项提交 API 从所选的包管理器或生态系统提交依赖项，即使该生态系统不支持依赖项关系图的清单或锁定文件分析。
使用 依赖项提交 API 提交到项目的依赖项将显示用于提交的检测器以及提交时间。 有关 依赖项提交 API 的详细信息，请参阅 [使用依赖项提交 API](/zh/enterprise-server@3.21/code-security/supply-chain-security/understanding-your-software-supply-chain/using-the-dependency-submission-api)。

有关依赖项关系图的详细信息，请参阅 [依赖项关系图](/zh/enterprise-server@3.21/code-security/supply-chain-security/understanding-your-software-supply-chain/about-the-dependency-graph)。

### 什么是依赖项审查？

依赖项审查可帮助审阅者和参与者了解每个拉取请求中的依赖项更改及其安全性影响。

* 依赖项审查会在拉取请求中告知你已经添加、移除或更新了哪些依赖项。 你可以使用发布日期、依赖项的受欢迎程度和漏洞信息来帮助决定是否接受更改。
* 你可以通过在“**已更改文件**”选项卡上显示丰富差异来查看拉取请求的依赖审查。

有关依赖项评审的详细信息，请参阅“[依赖项审查](/zh/enterprise-server@3.21/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review)”。

### 什么是 Dependabot？

Dependabot 通过通知你依赖项中的任何安全漏洞并自动打开拉取请求来升级你的依赖项，使你的依赖项保持最新。
Dependabot 拉取请求将在触发Dependabot警报时，指向下一个可用的安全版本，或者在新版本发布时指向最新版本。

术语“Dependabot”包含以下功能：

* Dependabot alerts：在 **<svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-shield" aria-label="shield" role="img"><path d="M7.467.133a1.748 1.748 0 0 1 1.066 0l5.25 1.68A1.75 1.75 0 0 1 15 3.48V7c0 1.566-.32 3.182-1.303 4.682-.983 1.498-2.585 2.813-5.032 3.855a1.697 1.697 0 0 1-1.33 0c-2.447-1.042-4.049-2.357-5.032-3.855C1.32 10.182 1 8.566 1 7V3.48a1.75 1.75 0 0 1 1.217-1.667Zm.61 1.429a.25.25 0 0 0-.153 0l-5.25 1.68a.25.25 0 0 0-.174.238V7c0 1.358.275 2.666 1.057 3.86.784 1.194 2.121 2.34 4.366 3.297a.196.196 0 0 0 .154 0c2.245-.956 3.582-2.104 4.366-3.298C13.225 9.666 13.5 8.36 13.5 7V3.48a.251.251 0 0 0-.174-.237l-5.25-1.68ZM8.75 4.75v3a.75.75 0 0 1-1.5 0v-3a.75.75 0 0 1 1.5 0ZM9 10.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path></svg> Security** 存储库的选项卡上以及存储库的依赖项关系图中显示通知。 该警报包括指向项目中受影响的文件的链接，以及有关修复的版本的信息。
* Dependabot updates：
  * Dependabot security updates：触发警报时触发更新，将依赖项升级到安全版本。
  * Dependabot version updates：计划更新，使依赖项保持与最新版本同步。

Dependabot security updates 和 Dependabot version updates 需要 GitHub Actions 在 GitHub Enterprise Server 上运行。
Dependabot alerts 不需要 GitHub Actions。 有关详细信息，请参阅“[为企业启用 Dependabot](/zh/enterprise-server@3.21/admin/configuration/configuring-github-connect/enabling-dependabot-for-your-enterprise)”。

Dependabot security updates 可以修复 GitHub Actions 中有漏洞的依赖项。 启用安全更新后，Dependabot 将自动提出拉取请求，以将工作流中使用的存在漏洞的 GitHub Actions 更新到最低的已修补版本。 有关详细信息，请参阅 [Dependabot 安全更新](/zh/enterprise-server@3.21/code-security/dependabot/dependabot-security-updates/about-dependabot-security-updates)。

#### 什么是 Dependabot 警报？

Dependabot alerts 根据依赖关系图和包含已知漏洞公告的GitHub Advisory Database，突出显示受新发现漏洞影响的存储库。

* Dependabot 执行扫描以检测不安全的依赖项并在以下情况下发送 Dependabot alerts ：
  * 每小时从 GitHub.com 同步新的咨询数据到您的实例。 有关详细信息，请参阅“[在 GitHub Advisory Database 中浏览安全公告](/zh/enterprise-server@3.21/code-security/security-advisories/working-with-global-security-advisories-from-the-github-advisory-database/browsing-security-advisories-in-the-github-advisory-database)”。
  * 存储库的依赖项关系图更改
* Dependabot alerts 显示在存储库的 **<svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-shield" aria-label="shield" role="img"><path d="M7.467.133a1.748 1.748 0 0 1 1.066 0l5.25 1.68A1.75 1.75 0 0 1 15 3.48V7c0 1.566-.32 3.182-1.303 4.682-.983 1.498-2.585 2.813-5.032 3.855a1.697 1.697 0 0 1-1.33 0c-2.447-1.042-4.049-2.357-5.032-3.855C1.32 10.182 1 8.566 1 7V3.48a1.75 1.75 0 0 1 1.217-1.667Zm.61 1.429a.25.25 0 0 0-.153 0l-5.25 1.68a.25.25 0 0 0-.174.238V7c0 1.358.275 2.666 1.057 3.86.784 1.194 2.121 2.34 4.366 3.297a.196.196 0 0 0 .154 0c2.245-.956 3.582-2.104 4.366-3.298C13.225 9.666 13.5 8.36 13.5 7V3.48a.251.251 0 0 0-.174-.237l-5.25-1.68ZM8.75 4.75v3a.75.75 0 0 1-1.5 0v-3a.75.75 0 0 1 1.5 0ZM9 10.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path></svg> Security** 选项卡上，并且出现在存储库的依赖图中。 该警报包括指向项目中受影响的文件的链接，以及有关修复的版本的信息。

有关详细信息，请参阅“[Dependabot alerts](/zh/enterprise-server@3.21/code-security/dependabot/dependabot-alerts/about-dependabot-alerts)”。

#### 什么是 Dependabot 更新？

有两种类型的 Dependabot updates： Dependabot\_安全更新\_ 和 *版本* 更新。               Dependabot 在上述两种情况下都会生成自动拉取请求以更新你的依赖项，但有几点不同。

Dependabot security updates：

* 由 Dependabot 警报触发
* 将依赖项更新到可修复已知漏洞的最低版本
* 支持用于依赖项关系图支持的生态系统
* 不需要配置文件，但可使用配置文件来替代默认行为

Dependabot version updates：

* 需要配置文件
* 按配置的计划运行
* 将依赖项更新到与配置匹配的最新版本
* 支持用于不同类别的生态系统

有关 Dependabot updates 的更多信息，请参阅 [Dependabot 安全更新](/zh/enterprise-server@3.21/code-security/dependabot/dependabot-security-updates/about-dependabot-security-updates) 和 [Dependabot 版本更新](/zh/enterprise-server@3.21/code-security/dependabot/dependabot-version-updates/about-dependabot-version-updates)。

### 什么是不可变发行版？

存储库可以启用不可变版本，以防止发布后更改发布的资产和关联的 Git 标记。 这可以通过阻止攻击者将漏洞注入到你使用的版本中来降低供应链攻击的风险。 这也意味着依赖特定版本的项目不太可能中断。

创建不可变版本会自动为发布生成证明。 可以使用此认证来确保发布及其制品与已发布的信息匹配。

### 什么是工件声明？

软件提供程序可以为使用 GitHub Actions 构建的软件生成证明。 证明是经过加密签名的声明，用于确立构建的来源（用于构建的软件源代码和工作流运行）或相关的软件物料清单 (SBOM)。

可以通过验证依赖项的证明来提高供应链安全性。 尽管证明不能保证安全性，但它们提供了有关软件生成位置和方式的信息，因此可以更确信依赖项未被篡改。 可以使用 Kubernetes 准入控制器之类的工具来限制部署，以防止部署未经验证的构建。

当你使用 GitHub Actions 为组织的自有构建生成证明时，构建工件会自动上传到 linked artifacts page。 此平台允许查看所有链接项目的存储和部署记录，以便找到用于基于部署上下文生成项目或筛选安全警报的源代码和工作流运行。

## 功能可用性

* **依赖项图和 Dependabot alerts：** 默认情况下未启用。 这两项功能由企业所有者在企业级别进行配置。 有关详细信息，请参阅 [为企业启用依赖项关系图](/zh/enterprise-server@3.21/admin/code-security/managing-supply-chain-security-for-your-enterprise/enabling-the-dependency-graph-for-your-enterprise) 和 [为企业启用 Dependabot](/zh/enterprise-server@3.21/admin/configuration/configuring-github-connect/enabling-dependabot-for-your-enterprise)。

* **依赖项评审：** 当为实例启用依赖关系图，并且为组织或存储库启用 GitHub Code Security or GitHub Advanced Security 时可用。 有关详细信息，请参阅“[关于GitHub高级安全性](/zh/enterprise-server@3.21/get-started/learning-about-github/about-github-advanced-security)”。

* **Dependabot security updates：** 默认情况下未启用。 可以为使用Dependabot security updates和依赖项关系图的任何存储库启用Dependabot alerts。 有关启用安全更新的信息，请参阅 [配置 Dependabot 安全更新](/zh/enterprise-server@3.21/code-security/dependabot/dependabot-security-updates/configuring-dependabot-security-updates)。

* **Dependabot version updates：** 默认情况下未启用。 对存储库具有写入权限的人员可以启用 Dependabot version updates。 有关启用版本更新的信息，请参阅 [配置 Dependabot 版本更新](/zh/enterprise-server@3.21/code-security/dependabot/dependabot-version-updates/configuring-dependabot-version-updates)。