Observação: o CodeQL runner está sendo preterido. No GitHub Enterprise Server 3.0 e superior, você pode instalar a CodeQL CLI versão 2.6.3 para substituir o CodeQL runner.
Para obter mais informações, confira a reprovação do executor do CodeQL. Para obter informações sobre como migrar para a CodeQL CLI, confira "Como migrar do executor do CodeQL para a CLI do CodeQL".
Note: Your site administrator must enable code scanning for your GitHub Enterprise Server instance before you can use this feature. For more information, see "Configuring code scanning for your appliance."
About the CodeQL runner
The CodeQL runner is a tool you can use to run code scanning on code that you're processing in a third-party continuous integration (CI) system. Code scanning é um recurso que você usa para analisar o código em um repositório de GitHub para localizar vulnerabilidades de segurança e erros de codificação. Quaisquer problemas identificados pela análise são exibidos em GitHub Enterprise Server. For information, see "About code scanning with CodeQL."
In many cases it is easier to set up CodeQL code scanning using the CodeQL CLI directly in your CI system.
Alternatively, you can use GitHub Actions to run code scanning within GitHub Enterprise Server. For information, see "Setting up code scanning for a repository."
The CodeQL runner is a command-line tool that runs CodeQL analysis on a checkout of a GitHub repository. You add the runner to your third-party system, then call the runner to analyze code and upload the results to GitHub Enterprise Server. These results are displayed as code scanning alerts in the repository.
Note:
- The CodeQL runner is available to customers with an Advanced Security license.
Downloading the CodeQL runner
You can download the CodeQL runner from https://HOSTNAME/github/codeql-action/releases. On some operating systems, you may need to change permissions for the downloaded file before you can run it.
On Linux:
chmod +x codeql-runner-linux
On macOS:
chmod +x codeql-runner-macos
sudo xattr -d com.apple.quarantine codeql-runner-macos
On Windows, the codeql-runner-win.exe
file usually requires no change to permissions.
Adding the CodeQL runner to your CI system
Once you download the CodeQL runner and verify that it can be executed, you should make the runner available to each CI server that you intend to use for code scanning. For example, you might configure each server to copy the runner from a central, internal location. Alternatively, you could use the REST API to get the runner directly from GitHub, for example:
wget https://HOSTNAME/github/codeql-action/releases/latest/download/codeql-runner-linux
chmod +x codeql-runner-linux
In addition to this, each CI server also needs:
- A GitHub App or personal access token for the CodeQL runner to use. You must use an access token with the
repo
scope, or a GitHub App with thesecurity_events
write permission, andmetadata
andcontents
read permissions. For information, see "Building GitHub Apps" and "Creating a personal access token." - Access to the CodeQL bundle associated with this release of the CodeQL runner. This package contains queries and libraries needed for CodeQL analysis, plus the CodeQL CLI, which is used internally by the runner. For information, see "CodeQL CLI."
The options for providing access to the CodeQL bundle are:
- Allow the CI servers access to https://HOSTNAME/github/codeql-action so that the CodeQL runner can download the bundle automatically.
- Manually download/extract the bundle, store it with other central resources, and use the
flag to specify the location of the bundle in calls to initialize the CodeQL runner.--codeql-path
Calling the CodeQL runner
You should call the CodeQL runner from the checkout location of the repository you want to analyze. The two main commands are:
init
required to initialize the runner and create a CodeQL database for each language to be analyzed. These databases are populated and analyzed by subsequent commands.analyze
required to populate the CodeQL databases, analyze them, and upload results to GitHub Enterprise Server.
For both commands, you must specify the URL of GitHub Enterprise Server, the repository OWNER/NAME, and the GitHub Apps or personal access token to use for authentication. You also need to specify the location of the CodeQL bundle, unless the CI server has access to download it directly from the github/codeql-action
repository.
You can configure where the CodeQL runner stores the CodeQL bundle for future analysis on a server using the --tools-dir
--temp-dir
To view the command-line reference for the runner, use the -h
flag. For example, to list all commands run: codeql-runner-OS -h
, or to list all the flags available for the init
command run: codeql-runner-OS init -h
(where OS
varies according to the executable that you are using). For more information, see "Configuring code scanning in your CI system."
Observações:
-
O upload do SARIF dá suporte a um máximo de 5.000 resultados por upload. Todos os resultados acima desse limite são ignorados. Se uma ferramenta gerar muitos resultados, você deverá atualizar a configuração para se concentrar nos resultados referentes � s regras ou � s consultas mais importantes.
-
Para cada upload, o upload do SARIF dá suporte a, no máximo, 10 MB para o arquivo SARIF compactado em
gzip
. Todos os uploads acima desse limite são rejeitados. Se o arquivo SARIF for muito grande porque contém muitos resultados, você deverá atualizar a configuração para se concentrar nos resultados das regras ou consultas mais importantes.
Basic example
This example runs CodeQL analysis on a Linux CI server for the octo-org/example-repo
repository hosted on https://github.example.com
. The process is very simple because the repository contains only languages that can be analyzed by CodeQL directly, without being built (that is, Go, JavaScript, Python, and TypeScript).
In this example, the server has access to download the CodeQL bundle directly from the github/codeql-action
repository, so there is no need to use the --codeql-path
flag.
-
Check out the repository to analyze.
-
Move into the directory where the repository is checked out.
-
Initialize the CodeQL runner and create CodeQL databases for the languages detected.
$ echo "$TOKEN" | /path/to-runner/codeql-runner-linux init --repository octo-org/example-repo --github-url https://github.example.com --github-auth-stdin > Cleaning temp directory /srv/checkout/example-repo/codeql-runner > ... > Created CodeQL database at /srv/checkout/example-repo/codeql-runner/codeql_databases/javascript.
-
Preencha os bancos de dados do CodeQL, analise-os e carregue os resultados no GitHub Enterprise Server. Os resultados serão exibidos na guia Segurança do repositório.
$ echo "$TOKEN" | /path/to-runner/codeql-runner-linux analyze --repository octo-org/example-repo --github-url https://github.example.com --github-auth-stdin --commit 5b6a3078b31dc346e5ce7b86837d6abbe7a18bbd --ref refs/heads/my-branch > Finalizing database creation > ... > POST /repos/octo-org/example-repo/code-scanning/sarifs - 202 in 786ms > Successfully uploaded results
-
Para carregar os resultados da code scanning como verificações de solicitação de pull, especifique a solicitação de pull usando o sinalizador
. Recomendamos configurar o CodeQL runner para que ele seja executado no evento de webhook--ref
pull_request
.$ echo "$TOKEN" | /path/to-runner/codeql-runner-linux analyze --repository octo-org/example-repo --github-url https://github.example.com --github-auth-stdin --commit 1dc7a1346e5ce7b86835b68bbda3078b37d6abbe --ref refs/pull/123/merge > Finalizing database creation > ... > POST /repos/octo-org/example-repo/code-scanning/sarifs - 202 in 786ms > Successfully uploaded results
Para obter mais informações sobre como ver alertas da code scanning, confira "Como fazer a triagem de alertas da verificação de código em solicitações de pull" e "Como gerenciar alertas da verificação de código para seu repositório".
Compiled language example
This example is similar to the previous example, however this time the repository has code in C/C++, C#, or Java. To create a CodeQL database for these languages, the CLI needs to monitor the build. At the end of the initialization process, the runner reports the command you need to set up the environment before building the code. You need to run this command, before calling the normal CI build process, and then running the analyze
command.
-
Check out the repository to analyze.
-
Move into the directory where the repository is checked out.
-
Initialize the CodeQL runner and create CodeQL databases for the languages detected.
$ echo "$TOKEN" | /path/to-runner/codeql-runner-linux init --repository octo-org/example-repo-2 --github-url https://github.example.com --github-auth-stdin > Cleaning temp directory /srv/checkout/example-repo-2/codeql-runner > ... > CodeQL environment output to "/srv/checkout/example-repo-2/codeql-runner/codeql-env.json" and "/srv/checkout/example-repo-2/codeql-runner/codeql-env.sh". Please export these variables to future processes so that CodeQL can monitor the build, for example by running ". /srv/checkout/example-repo-2/codeql-runner/codeql-env.sh".
-
Source the script generated by the
init
action to set up the environment to monitor the build. Note the leading dot and space in the following code snippet.$ . /srv/checkout/example-repo-2/codeql-runner/codeql-env.sh
-
Build the code. On macOS, you need to prefix the build command with the environment variable
$CODEQL_RUNNER
. For more information, see "Troubleshooting CodeQL runner in your CI system." -
Preencha os bancos de dados do CodeQL, analise-os e carregue os resultados no GitHub Enterprise Server. Os resultados serão exibidos na guia Segurança do repositório.
$ echo "$TOKEN" | /path/to-runner/codeql-runner-linux analyze --repository octo-org/example-repo --github-url https://github.example.com --github-auth-stdin --commit 5b6a3078b31dc346e5ce7b86837d6abbe7a18bbd --ref refs/heads/my-branch > Finalizing database creation > ... > POST /repos/octo-org/example-repo/code-scanning/sarifs - 202 in 786ms > Successfully uploaded results
-
Para carregar os resultados da code scanning como verificações de solicitação de pull, especifique a solicitação de pull usando o sinalizador
. Recomendamos configurar o CodeQL runner para que ele seja executado no evento de webhook--ref
pull_request
.$ echo "$TOKEN" | /path/to-runner/codeql-runner-linux analyze --repository octo-org/example-repo --github-url https://github.example.com --github-auth-stdin --commit 1dc7a1346e5ce7b86835b68bbda3078b37d6abbe --ref refs/pull/123/merge > Finalizing database creation > ... > POST /repos/octo-org/example-repo/code-scanning/sarifs - 202 in 786ms > Successfully uploaded results
Para obter mais informações sobre como ver alertas da code scanning, confira "Como fazer a triagem de alertas da verificação de código em solicitações de pull" e "Como gerenciar alertas da verificação de código para seu repositório".
Note: If you use a containerized build, you need to run the CodeQL runner in the container where your build task takes place.