Skip to main content
Мы публикуем частые обновления нашей документации, и перевод этой страницы может все еще выполняться. Актуальные сведения см. в документации на английском языке.
В настоящее время GitHub AE находится в ограниченном выпуске.

Настройка проверки кода для репозитория

Вы можете настроить code scanning для репозитория для поиска уязвимостей безопасности в коде.

Кто может использовать эту функцию

People with admin permissions to a repository, or the security manager role for the repository, can configure code scanning for that repository. People with write permissions to a repository can also configure code scanning, but only by creating a workflow file or manually uploading a SARIF file.

Code scanning доступен для принадлежащих организации репозиториев в GitHub AE. Это функция входит в состав GitHub Advanced Security (на этапе бета-версии предоставляется бесплатно). Дополнительные сведения см. в разделе Сведения о GitHub Advanced Security.

Options for configuring code scanning

You decide how to generate code scanning alerts, and which tools to use, at a repository level. GitHub AE provides fully integrated support for CodeQL analysis, and also supports analysis using third-party tools. For more information, see the following bullets and "About code scanning."

If you run code scanning using multiple configurations, an alert will sometimes have multiple analysis origins. If an alert has multiple analysis origins, you can view the status of the alert for each analysis origin on the alert page. For more information, see "About code scanning alerts."

Note: This article describes the features available with the version of the CodeQL action and associated CodeQL CLI bundle included in the initial release of this version of GitHub AE. If your enterprise uses a more recent version of the CodeQL action, see the GitHub Enterprise Cloud version of this article for information on the latest features.

Prerequisites

Before configuring code scanning for a repository, you must ensure that there is at least one self-hosted GitHub Actions runner available to the repository.

Enterprise owners, organization and repository administrators can add self-hosted runners. For more information, see "About self-hosted runners" and "Adding self-hosted runners."

Configuring code scanning manually

  1. On your enterprise, navigate to the main page of the repository.

  2. Under the repository name, click Security. If you cannot see the "Security" tab, select the dropdown menu, and then click Security. Screenshot of a repository header showing the tabs. The "Security" tab is highlighted by a dark orange outline.

  3. To the right of "Code scanning alerts", click Set up code scanning. If "code scanning alerts" is missing, you need to ask an organization owner or repository administrator to enable GitHub Advanced Security. For more information, see "Managing security and analysis settings for your organization" or "Managing security and analysis settings for your repository."

  4. Under "Get started with code scanning", click Set up this workflow on the CodeQL analysis workflow or on a third-party workflow.

    Workflows are only displayed if they are relevant for the programming languages detected in the repository. The CodeQL analysis workflow is always displayed, but the "Set up this workflow" button is only enabled if CodeQL analysis supports the languages present in the repository.

  5. To customize how code scanning scans your code, edit the workflow.

    Generally, you can commit the CodeQL analysis workflow without making any changes to it. However, many of the third-party workflows require additional configuration, so read the comments in the workflow before committing.

    For more information, see "Customizing code scanning."

  6. Click Commit changes... to display the commit changes form.

    Screenshot of the form to create a new file. To the right of the file name, a green button, labeled "Commit changes...", is outlined in dark orange.

  7. In the commit message field, type a commit message.

  8. Choose whether you'd like to commit directly to the default branch, or create a new branch and start a pull request.

  9. Click Commit new file or Propose new file.

In the suggested CodeQL analysis workflow, code scanning is configured to analyze your code each time you either push a change to the default branch or any protected branches, or raise a pull request against the default branch. As a result, code scanning will now commence.

The on:pull_request and on:push triggers for code scanning are each useful for different purposes. For more information, see "Customizing code scanning."

Bulk configuration of code scanning

You can configure code scanning in many repositories at once using a script. If you'd like to use a script to raise pull requests that add a GitHub Actions workflow to multiple repositories, see the jhutchings1/Create-ActionsPRs repository for an example using PowerShell, or nickliffen/ghas-enablement for teams who do not have PowerShell and instead would like to use NodeJS.

Viewing the logging output from code scanning

After configuring code scanning for your repository, you can watch the output of the actions as they run.

  1. Under your repository name, click Actions. Actions tab in the main repository navigation

    You'll see a list that includes an entry for running the code scanning workflow. The text of the entry is the title you gave your commit message.

    Screenshot of the "All workflows" page. In the list of workflow runs is a run labeled "Create .github/workflows/codeql.yml."

  2. Click the entry for the run of the code scanning workflow.

  3. Click the job name on the left. For example, Analyze (LANGUAGE).

    Screenshot of the log output for the "Analyze (go)" job. In the left sidebar, under the "Jobs" heading, "Analyze (go)" is listed.

  4. Review the logging output from the actions in this workflow as they run.

  5. Once all jobs are complete, you can view the details of any code scanning alerts that were identified. For more information, see "Managing code scanning alerts for your repository."

Understanding the pull request checks

Each code scanning workflow you set to run on pull requests always has at least two entries listed in the checks section of a pull request. There is one entry for each of the analysis jobs in the workflow, and a final one for the results of the analysis.

The names of the code scanning analysis checks take the form: "TOOL NAME / JOB NAME (TRIGGER)." For example, for CodeQL, analysis of C++ code has the entry "CodeQL / Analyze (cpp) (pull_request)." You can click Details on a code scanning analysis entry to see logging data. This allows you to debug a problem if the analysis job failed. For example, for code scanning analysis of compiled languages, this can happen if the action can't build the code.

Screenshot showing an example of code scanning pull request checks. Failure of CodeQL analysis for C++ is shown with a red cross.

When the code scanning jobs complete, GitHub works out whether any alerts were added by the pull request and adds the "Code scanning results / TOOL NAME" entry to the list of checks. After code scanning has been performed at least once, you can click Details to view the results of the analysis.

Next steps

After configuring code scanning, and allowing its actions to complete, you can: