Skip to main content

Выпуск GitHub AE сейчас ограничен.

Настройка code scanning

You can configure code scanning for a repository to find security vulnerabilities in your code.

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

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 is available for organization-owned repositories in GitHub AE. This is a GitHub Advanced Security feature (free during the beta release). For more information, see "About GitHub Advanced Security."

About code scanning

Code scanning helps you catch vulnerabilities in the code in your repository. With CodeQL code scanning, you can select custom or built-in query suites for use in your analysis, set a specific scan schedule, choose which events trigger a scan, and more.

You can also configure code scanning with third-party tools. For more information, see "Configuring code scanning using third-party actions."

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

Your repository is eligible for code scanning if:

  • it uses CodeQL-supported languages or you plan to generate code scanning results with a third-party tool.
  • GitHub Actions are enabled.
  • GitHub Advanced Security is enabled.

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 using the CodeQL action

  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" and "CodeQL code scanning for compiled languages."

  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."

For information on bulk enablement, see "Configuring code scanning with CodeQL at scale."

Next steps

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