{"meta":{"title":"为设备配置代码扫描","intro":"你可以为企业启用、配置和禁用 code scanning。 用户使用 Code scanning 可以扫描代码以发现漏洞和错误。","product":"安全性和代码质量","breadcrumbs":[{"href":"/zh/enterprise-server@3.20/code-security","title":"安全性和代码质量"},{"href":"/zh/enterprise-server@3.20/code-security/how-tos","title":"How-tos"},{"href":"/zh/enterprise-server@3.20/code-security/how-tos/secure-at-scale","title":"大规模保护"},{"href":"/zh/enterprise-server@3.20/code-security/how-tos/secure-at-scale/configure-enterprise-security","title":"配置企业安全性"},{"href":"/zh/enterprise-server@3.20/code-security/how-tos/secure-at-scale/configure-enterprise-security/configure-specific-tools","title":"配置特定工具"},{"href":"/zh/enterprise-server@3.20/code-security/how-tos/secure-at-scale/configure-enterprise-security/configure-specific-tools/configuring-code-scanning-for-your-appliance","title":"配置代码扫描"}],"documentType":"article"},"body":"# 为设备配置代码扫描\n\n你可以为企业启用、配置和禁用 code scanning。 用户使用 Code scanning 可以扫描代码以发现漏洞和错误。\n\n<!--The CodeQL CLI man pages include a link to a section in this article. If you rename this article,\nmake sure that you also update the MS short link: https://aka.ms/code-scanning-docs/configuring-ghes.-->\n\n## 关于 code scanning\n\nCode scanning 是一项功能，可用于分析 GitHub 仓库中的代码，以查找安全漏洞和编码错误。 分析标识的任何问题都显示在存储库中。\n\n您可以配置 code scanning 以运行 CodeQL 分析和第三方分析。 Code scanning 还支持使用 GitHub Actions 在本机运行分析，或使用现有 CI/CD 基础结构在外部运行分析。 下方要点总结了当你配置 你的 GitHub Enterprise Server 实例 以允许使用操作运行 code scanning 时用户可用的选项。\n\n* CodeQL\\*\\*\\*\\*：将 GitHub Actions 与任一默认设置配合使用（请参阅“[配置代码扫描的默认设置](/zh/enterprise-server@3.20/code-security/code-scanning/enabling-code-scanning/configuring-default-setup-for-code-scanning)”）或与高级设置配合使用（请参阅“[配置代码扫描的高级设置](/zh/enterprise-server@3.20/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/configuring-advanced-setup-for-code-scanning#configuring-advanced-setup-for-code-scanning-with-codeql)”），或在第三方持续集成 (CI) 系统中运行 CodeQL 分析（请参阅“[在现有 CI 系统上使用代码扫描](/zh/enterprise-server@3.20/code-security/code-scanning/integrating-with-code-scanning/using-code-scanning-with-your-existing-ci-system)”）。\n* 第三方：使用 GitHub Actions 或第三方工具并将结果上传至 GitHub（请参阅 [将 SARIF 文件上传到 GitHub](/zh/enterprise-server@3.20/code-security/code-scanning/integrating-with-code-scanning/uploading-a-sarif-file-to-github)）\\*\\*\\*\\*。\n\n## 检查你的许可证是否包含 Advanced Security\n\n可通过查看企业设置来确定企业是否具有 Advanced Security 产品许可证。 有关详细信息，请参阅“[为企业启用 GitHub Advanced Security 产品](/zh/enterprise-server@3.20/admin/code-security/managing-github-advanced-security-for-your-enterprise/enabling-github-advanced-security-for-your-enterprise#checking-whether-your-license-includes-github-advanced-security)”。\n\n## code scanning 的前提条件\n\n* GitHub Code Security 或 GitHub Advanced Security 的许可证（请参阅 [GitHub Advanced Security 许可证计费](/zh/enterprise-server@3.20/billing/managing-billing-for-your-products/managing-billing-for-github-advanced-security/about-billing-for-github-advanced-security)）\n\n* 在管理控制台中启用的 Code scanning（请参阅“[为企业启用 GitHub Advanced Security 产品](/zh/enterprise-server@3.20/admin/code-security/managing-github-advanced-security-for-your-enterprise/enabling-github-advanced-security-for-your-enterprise)”）\n\n* 用于运行 code scanning 分析的 VM 或容器。\n\n<!-- Anchor to maintain the CodeQL CLI manual pages link: https://aka.ms/code-scanning-docs/configuring-ghes -->\n\n<a name=\"running-code-scanning-using-github-actions\"></a>\n\n## 使用 code scanning 运行 GitHub Actions\n\n### 预配自托管式运行器\n\nGitHub 可以使用 code scanning 工作流运行 GitHub Actions。 首先，您需要在环境中预配一个或多个自托管的 GitHub Actions 运行器。 你可以在仓库、组织或企业帐户级别预配自托管运行器。 请参阅“[自托管运行程序](/zh/enterprise-server@3.20/actions/hosting-your-own-runners/managing-self-hosted-runners/about-self-hosted-runners)”和“[添加自托管的运行器](/zh/enterprise-server@3.20/actions/hosting-your-own-runners/managing-self-hosted-runners/adding-self-hosted-runners)”。\n\n您必须确保 Git 在用于运行 CodeQL 操作的任何自托管运行器上的 PATH 变量中。\n\n> \\[!NOTE]\n> 如果在企业中使用 CodeQL code scanning 分析用 Python 编写的代码，则必须确保自托管运行器已安装 Python 3。\n\n### 预配运行器规模集\n\n可以使用 Actions Runner Controller 为GitHub Enterprise Server 实例创建专用运行器规模集。 请参阅“[使用 Actions Runner Controller 部署运行程序规模集](/zh/enterprise-server@3.20/actions/hosting-your-own-runners/managing-self-hosted-runners-with-actions-runner-controller/deploying-runner-scale-sets-with-actions-runner-controller#using-arc-with-dependabot-and-code-scanning)”。\n\n### 预配 code scanning 的操作\n\n如果您要使用操作在 code scanning 上运行 GitHub Enterprise Server，操作必须在您的设备上可用。\n\nCodeQL 操作包含在您安装的 GitHub Enterprise Server 中。 如果 GitHub Enterprise Server 3.20 和 GitHub Actions 运行器均可访问 Internet，则操作将自动下载执行分析所需的 CodeQL 2.23.9 捆绑包。 或者，你也可以使用同步工具使最新发布版本的 CodeQL 分析包在本地可用。 请参阅下面的“[在没有互联网接入的服务器上配置 CodeQL 分析](#configuring-codeql-analysis-on-a-server-without-internet-access)”。\n\n您也可以通过设置 code scanning，使第三方操作可供 GitHub Connect 的用户使用。 请参阅下面的“[为设备配置代码扫描](/zh/enterprise-server@3.20/admin/code-security/managing-github-advanced-security-for-your-enterprise/configuring-code-scanning-for-your-appliance#configuring-github-connect-to-sync-github-actions)”。\n\n### 在没有互联网接入的服务器上配置 CodeQL 分析\n\n如果您在上面运行 GitHub Enterprise Server 的服务器未连接到互联网，但您要允许用户对其仓库启用 CodeQL code scanning，则您必须使用 CodeQL 操作同步工具将 CodeQL 分析包从 GitHub.com 复制到您的服务器。 该工具及其用法的详细信息在 [https://github.com/github/codeql-action-sync-tool](https://github.com/github/codeql-action-sync-tool/) 提供。\n\n如果配置 CodeQL 操作同步工具，可以使用它来同步最新发布的 CodeQL 操作和相关的 CodeQL 分析包。 这些与 GitHub Enterprise Server 兼容。\n\n### 配置 GitHub Connect 以同步 GitHub Actions\n\n1. 如果要从 GitHub.com 下载按需操作工作流程，则需要启用 GitHub Connect。 请参阅“[为 GitHub.com 启用 GitHub Connect](/zh/enterprise-server@3.20/admin/configuration/configuring-github-connect/managing-github-connect#enabling-github-connect)”。\n2. 还需要启用 GitHub Actions。 请参阅“[GitHub Actions for GitHub Enterprise Server 使用入门](/zh/enterprise-server@3.20/admin/github-actions/getting-started-with-github-actions-for-your-enterprise/getting-started-with-github-actions-for-github-enterprise-server)”。\n3. 下一步是使用 GitHub.com 配置对 GitHub Connect 上的操作的访问权限。 请参阅“[使用 GitHub Connect 启用对 GitHub.com操作的自动访问](/zh/enterprise-server@3.20/admin/github-actions/managing-access-to-actions-from-githubcom/enabling-automatic-access-to-githubcom-actions-using-github-connect)”。\n4. 将自托管运行器添加到仓库、组织或企业帐户。 请参阅“[添加自托管的运行器](/zh/enterprise-server@3.20/actions/hosting-your-own-runners/managing-self-hosted-runners/adding-self-hosted-runners)”。\n\n## 使用 CodeQL CLI 运行代码扫描\n\n如果不想使用 GitHub Actions，应该使用 code scanning 运行 CodeQL CLI。\n\nCodeQL CLI 是一个命令行工具，可用于分析任何计算机上的代码库，包括第三方 CI/CD 系统。 请参阅“[在现有 CI 系统上使用代码扫描](/zh/enterprise-server@3.20/code-security/code-scanning/integrating-with-code-scanning/using-code-scanning-with-your-existing-ci-system)”。"}