Skip to main content

为您的设备配置代码扫描

可以在没有托管运行程序的情况下code scanning为企业 Code scanning 允许用户扫描代码中是否存在漏洞和错误。

谁可以使用此功能?

Code scanning 可用于以下存储库类型:

  • GitHub.com 上的公共存储库
  • GitHub Team、GitHub Enterprise Cloud 或 GitHub Enterprise Server 上的组织拥有的存储库,已启用 GitHub Code Security

关于 code scanning

Code scanning 是一项功能,可用于分析 GitHub 仓库中的代码,以查找安全漏洞和编码错误。 分析标识的任何问题都显示在存储库中。

可以将 code scanning 配置为运行 CodeQL 分析和第三方分析。 Code scanning 还支持本机使用 GitHub Actions 或外部使用现有的 CI/CD 基础结构运行分析。 下面的项目符号汇总了当您配置 你的 GitHub Enterprise Server 实例 使用操作来允许 code scanning 时可供用户使用的选项。

检查许可证是否包括 Advanced Security

可通过查看企业设置来确定企业是否具有 Advanced Security 产品许可证。 有关详细信息,请参阅“为您的企业启用GitHub Advanced Security产品”。

先决条件 code scanning

GitHub Code Security 或 GitHub Advanced Security 的许可证,(请参阅 GitHub Advanced Security 许可证计费

运行code scanning使用GitHub Actions

预配自托管式运行器

GitHub可以使用GitHub Actions工作流运行code scanning。 首先,你需要在环境中预配一个或多个自托管 GitHub Actions 运行器。 你可以在仓库、组织或企业帐户级别预配自托管运行器。 请参阅“自托管运行程序”和“添加自托管的运行器”。

必须确保 Git 位于用于运行 CodeQL 操作的任何自承载运行程序上的 PATH 变量中。

注意

如果使用 CodeQLcode scanning 分析企业中Python编写的代码,则必须确保自承载运行程序已安装Python 3。

预配运行器规模集

您可以使用 Actions Runner Controller 来为 GitHub Enterprise Server 实例创建专用运行程序缩放集。 请参阅“使用 Actions Runner Controller 部署运行程序规模集”。

预配操作 code scanning

如果要使用操作以运行code scanning在GitHub Enterprise Server上,那么操作必须可在您的设备上获得。

操作 CodeQL 包含在安装 GitHub Enterprise Server中。 如果 GitHub Enterprise Server3.20 和你的 GitHub Actions 运行程序都可以访问互联网,该操作将自动下载 CodeQL2.23.9 执行分析所需的捆绑包。 或者,可以使用同步工具将最新发布的CodeQL分析捆绑包版本提供到本地。 请参阅下面有关无互联网访问的服务器上配置 CodeQL 分析的内容。

通过设置GitHub Connect,还可以向用户提供code scanning的第三方操作。 请参阅下面的“为您的设备配置代码扫描”。

在未访问 Internet 的服务器上配置 CodeQL 分析

如果您希望在未连接到 Internet 的服务器上运行GitHub Enterprise Server,并想允许用户为其存储库启用CodeQLcode scanning,则必须使用CodeQL动作同步工具将CodeQL分析包复制到您的服务器上。 该工具及其用法的详细信息在 https://github.com/github/codeql-action-sync-tool 提供。

如果配置 CodeQL 操作同步工具,则可以使用它来同步操作的最新版本 CodeQL 和相关 CodeQL 分析捆绑包。 这些与 GitHub Enterprise Server 兼容。

配置GitHub Connect以同步GitHub Actions

  1. 如果要从 GitHub.com 按需下载操作工作流,则需要启用 GitHub Connect。 请参阅“为 GitHub.com 启用 GitHub Connect”。
  2. 还需要启用 GitHub Actions。 请参阅“GitHub Actions for GitHub Enterprise Server 使用入门”。
  3. 下一步是通过GitHub Connect配置对GitHub.com操作的访问权限。 请参阅“使用 GitHub Connect 启用对 GitHub.com操作的自动访问”。
  4. 将自托管运行器添加到仓库、组织或企业帐户。 请参阅“添加自托管的运行器”。

使用CodeQL CLI运行代码扫描

如果不想使用 GitHub Actions,则应使用 CodeQL CLI 运行 code scanning。

CodeQL CLI这是一种命令行工具,可用于分析任何计算机上的代码库,包括第三方 CI/CD 系统。 请参阅“在现有 CI 系统上使用代码扫描”。