Skip to content

Commit 0e6d563

Browse files
authored
Merge pull request github#17611 from github/repo-sync
repo sync
2 parents 6711a49 + 2b8aa8c commit 0e6d563

File tree

1 file changed

+38
-31
lines changed

1 file changed

+38
-31
lines changed

content/code-security/code-scanning/using-codeql-code-scanning-with-your-existing-ci-system/configuring-codeql-cli-in-your-ci-system.md

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ You can display the command-line help for any command using the <nobr>`--help`</
6161
- For a pull request, check out either the head commit of the pull request, or check out a {% data variables.product.prodname_dotcom %}-generated merge commit of the pull request.
6262
2. Set up the environment for the codebase, making sure that any dependencies are available. For more information, see [Creating databases for non-compiled languages](https://codeql.github.com/docs/codeql-cli/creating-codeql-databases/#creating-databases-for-non-compiled-languages) and [Creating databases for compiled languages](https://codeql.github.com/docs/codeql-cli/creating-codeql-databases/#creating-databases-for-compiled-languages) in the documentation for the {% data variables.product.prodname_codeql_cli %}.
6363
3. Find the build command, if any, for the codebase. Typically this is available in a configuration file in the CI system.
64-
4. Run `codeql database create` from the checkout root of your repository and build the codebase.
64+
4. Run `codeql database create` from the checkout root of your repository and build the codebase.
6565
{% ifversion fpt or ghes > 3.1 or ghae or ghec %}
6666
```shell
6767
# Single supported language - create one CodeQL databsae
68-
codeql database create &lt;database&gt; --command&lt;build&gt; --language=&lt;language-identifier&gt;
68+
codeql database create &lt;database&gt; --command&lt;build&gt; --language=&lt;language-identifier&gt;
6969

7070
# Multiple supported languages - create one CodeQL database per language
7171
codeql database create &lt;database&gt; --command&lt;build&gt; \
72-
--db-cluster --language=&lt;language-identifier&gt;,&lt;language-identifier&gt;
72+
--db-cluster --language=&lt;language-identifier&gt;,&lt;language-identifier&gt;
7373
```
7474
{% else %}
7575
```shell
@@ -106,7 +106,7 @@ $ codeql database create /codeql-dbs/example-repo --language=javascript \
106106
in /checkouts/example-repo.
107107
> [build-stdout] Single-threaded extraction.
108108
> [build-stdout] Extracting
109-
...
109+
...
110110
> Finalizing database at /codeql-dbs/example-repo.
111111
> Successfully created database at /codeql-dbs/example-repo.
112112
```
@@ -146,16 +146,11 @@ $
146146
147147
## Analyzing a {% data variables.product.prodname_codeql %} database
148148
149-
1. Create a {% data variables.product.prodname_codeql %} database (see above).{% if codeql-packs %}
150-
2. Optional, run `codeql pack download` to download any {% data variables.product.prodname_codeql %} packs (beta) that you want to run during analysis. For more information, see "[Downloading and using {% data variables.product.prodname_codeql %} query packs](#downloading-and-using-codeql-query-packs)" below.
151-
```shell
152-
codeql pack download &lt;packs&gt;
153-
```
154-
{% endif %}
155-
3. Run `codeql database analyze` on the database and specify which {% if codeql-packs %}packs and/or {% endif %}queries to use.
149+
1. Create a {% data variables.product.prodname_codeql %} database (see above).
150+
2. Run `codeql database analyze` on the database and specify which {% if codeql-packs %}packs and/or {% endif %}queries to use.
156151
```shell
157152
codeql database analyze &lt;database&gt; --format=&lt;format&gt; \
158-
--output=&lt;output&gt; {% if codeql-packs %}&lt;packs,queries&gt;{% else %} &lt;queries&gt;{% endif %}
153+
--output=&lt;output&gt; {% if codeql-packs %}--download &lt;packs,queries&gt;{% else %}&lt;queries&gt;{% endif %}
159154
```
160155

161156
{% ifversion fpt or ghes > 3.1 or ghae or ghec %}
@@ -179,7 +174,8 @@ codeql database analyze &lt;database&gt; --format=&lt;format&gt; \
179174
| <nobr>`--output`</nobr> | {% octicon "check-circle-fill" aria-label="Required" %} | Specify where to save the SARIF results file.{% ifversion fpt or ghes > 3.1 or ghae or ghec %}
180175
| <nobr>`--sarif-category`<nobr> | {% octicon "question" aria-label="Required with multiple results sets" %} | Optional for single database analysis. Required to define the language when you analyze multiple databases for a single commit in a repository. Specify a category to include in the SARIF results file for this analysis. A category is used to distinguish multiple analyses for the same tool and commit, but performed on different languages or different parts of the code.|{% endif %}{% ifversion fpt or ghes > 3.3 or ghae or ghec %}
181176
| <nobr>`--sarif-add-query-help`</nobr> | | Optional. Use if you want to include any available markdown-rendered query help for custom queries used in your analysis. Any query help for custom queries included in the SARIF output will be displayed in the code scanning UI if the relevant query generates an alert. For more information, see [Analyzing databases with the {% data variables.product.prodname_codeql_cli %}](https://codeql.github.com/docs/codeql-cli/analyzing-databases-with-the-codeql-cli/#including-query-help-for-custom-codeql-queries-in-sarif-files) in the documentation for the {% data variables.product.prodname_codeql_cli %}.{% endif %}{% if codeql-packs %}
182-
| `<packs>` | | Optional. Use if you have downloaded CodeQL query packs and want to run the default queries or query suites specified in the packs. For more information, see "[Downloading and using {% data variables.product.prodname_codeql %} packs](#downloading-and-using-codeql-query-packs)."{% endif %}
177+
| `<packs>` | | Optional. Use if you want to include CodeQL query packs in your analysis. For more information, see "[Downloading and using {% data variables.product.prodname_codeql %} packs](#downloading-and-using-codeql-query-packs)."
178+
| <nobr>`--download`</nobr> | | Optional. Use if some of your CodeQL query packs are not yet on disk and need to be downloaded before running queries.{% endif %}
183179
| <nobr>`--threads`</nobr> | | Optional. Use if you want to use more than one thread to run queries. The default value is `1`. You can specify more threads to speed up query execution. To set the number of threads to the number of logical processors, specify `0`.
184180
| <nobr>`--verbose`</nobr> | | Optional. Use to get more detailed information about the analysis process{% ifversion fpt or ghes > 3.1 or ghae or ghec %} and diagnostic data from the database creation process{% endif %}.
185181
@@ -192,13 +188,12 @@ This example analyzes a {% data variables.product.prodname_codeql %} database st
192188
193189
```
194190
$ codeql database analyze /codeql-dbs/example-repo \
195-
javascript-code-scanning.qls {% ifversion fpt or ghes > 3.1 or ghae or ghec %}--sarif-category=javascript{% endif %}
191+
javascript-code-scanning.qls {% ifversion fpt or ghes > 3.1 or ghae or ghec %}--sarif-category=javascript \{% endif %}
196192
--format={% ifversion fpt or ghae or ghec %}sarif-latest{% else %}sarifv2.1.0{% endif %} --output=/temp/example-repo-js.sarif
197193
198194
> Running queries.
199-
> Compiling query plan for /codeql-home/codeql/qlpacks/
200-
codeql-javascript/AngularJS/DisablingSce.ql.
201-
...
195+
> Compiling query plan for /codeql-home/codeql/qlpacks/codeql-javascript/AngularJS/DisablingSce.ql.
196+
...
202197
> Shutting down query evaluator.
203198
> Interpreting results.
204199
```
@@ -251,38 +246,50 @@ There is no output from this command unless the upload was unsuccessful. The com
251246
252247
The {% data variables.product.prodname_codeql_cli %} bundle includes queries that are maintained by {% data variables.product.company_short %} experts, security researchers, and community contributors. If you want to run queries developed by other organizations, {% data variables.product.prodname_codeql %} query packs provide an efficient and reliable way to download and run queries. For more information, see "[About code scanning with CodeQL](/code-security/secure-coding/automatically-scanning-your-code-for-vulnerabilities-and-errors/about-code-scanning-with-codeql#about-codeql-queries)."
253248
254-
Before you can use a {% data variables.product.prodname_codeql %} pack to analyze a database, you must download any packages you require from the {% data variables.product.company_short %} {% data variables.product.prodname_container_registry %} by running `codeql pack download` and specifying the packages you want to download. If a package is not publicly available, you will need to use a {% data variables.product.prodname_github_app %} or personal access token to authenticate. For more information and an example, see "[Uploading results to {% data variables.product.product_name %}](#uploading-results-to-github)" above.
255-
256-
```shell
257-
codeql pack download &lt;scope/name@version&gt;,...
258-
```
249+
Before you can use a {% data variables.product.prodname_codeql %} pack to analyze a database, you must download any packages you require from the {% data variables.product.company_short %} {% data variables.product.prodname_container_registry %}. This can be done either by using the `--download` flag as part of the `codeql database analyze` command. If a package is not publicly available, you will need to use a {% data variables.product.prodname_github_app %} or personal access token to authenticate. For more information and an example, see "[Uploading results to {% data variables.product.product_name %}](#uploading-results-to-github)" above.
259250
260251
| Option | Required | Usage |
261252
|--------|:--------:|-----|
262-
| <nobr>`<scope/name@version>`</nobr> | {% octicon "check-circle-fill" aria-label="Required" %} | Specify the scope and name of one or more CodeQL query packs to download using a comma-separated list. Optionally, include the version to download and unzip. By default the latest version of this pack is downloaded. |
253+
| <nobr>`<scope/name@version:path>`</nobr> | {% octicon "check-circle-fill" aria-label="Required" %} | Specify the scope and name of one or more CodeQL query packs to download using a comma-separated list. Optionally, include the version to download and unzip. By default the latest version of this pack is downloaded. Optionally, include a path to a query, directory, or query suite to run. If no path is included, then run the default queries of this pack. |
263254
| <nobr>`--github-auth-stdin`</nobr> | | Optional. Pass the {% data variables.product.prodname_github_app %} or personal access token created for authentication with {% data variables.product.company_short %}'s REST API to the CLI via standard input. This is not needed if the command has access to a `GITHUB_TOKEN` environment variable set with this token.
264255
265256
### Basic example
266257
267-
This example runs two commands to download the latest version of the `octo-org/security-queries` pack and then analyze the database `/codeql-dbs/example-repo`.
258+
This example runs the `codeql database analyze` command with the `--download` option to:
259+
260+
1. Download the latest version of the `octo-org/security-queries` pack.
261+
2. Download a version of the `octo-org/optional-security-queries` pack that is *compatible* with version 1.0.1 (in this case, it is version 1.0.2). For more information on semver compatibility, see [npm's semantic version range documentation](https://github.com/npm/node-semver#ranges).
262+
3. Run all the default queries in `octo-org/security-queries`.
263+
4. Run only the query `queries/csrf.ql` from `octo-org/optional-security-queries`
268264
269265
```
270-
$ echo $OCTO-ORG_ACCESS_TOKEN | codeql pack download octo-org/security-queries
266+
$ echo $OCTO-ORG_ACCESS_TOKEN | codeql database analyze --download /codeql-dbs/example-repo \
267+
octo-org/security-queries \
268+
octo-org/optional-security-queries@~1.0.1:queries/csrf.ql \
269+
--format=sarif-latest --output=/temp/example-repo-js.sarif
271270
272271
> Download location: /Users/mona/.codeql/packages
273272
> Installed fresh octo-org/security-queries@1.0.0
274-
275-
$ codeql database analyze /codeql-dbs/example-repo octo-org/security-queries \
276-
--format=sarif-latest --output=/temp/example-repo-js.sarif
277-
273+
> Installed fresh octo-org/optional-security-queries@1.0.2
278274
> Running queries.
279275
> Compiling query plan for /Users/mona/.codeql/packages/octo-org/security-queries/1.0.0/potential-sql-injection.ql.
280-
> [1/1] Found in cache: /Users/mona/.codeql/packages/octo-org/security-queries/1.0.0/potential-sql-injection.ql.
276+
> [1/2] Found in cache: /Users/mona/.codeql/packages/octo-org/security-queries/1.0.0/potential-sql-injection.ql.
281277
> Starting evaluation of octo-org/security-queries/query1.ql.
282-
> [1/1 eval 394ms] Evaluation done; writing results to docto-org/security-queries/query1.bqrs.
278+
> Compiling query plan for /Users/mona/.codeql/packages/octo-org/optional-security-queries/1.0.2/queries/csrf.ql.
279+
> [2/2] Found in cache: /Users/mona/.codeql/packages/octo-org/optional-security-queries/1.0.2/queries/csrf.ql.
280+
> Starting evaluation of octo-org/optional-security-queries/queries/csrf.ql.
281+
> [2/2 eval 694ms] Evaluation done; writing results to octo-org/security-queries/query1.bqrs.
283282
> Shutting down query evaluator.
284283
> Interpreting results.
285284
```
285+
286+
### Direct download of {% data variables.product.prodname_codeql %} packs
287+
288+
If you want to download a {% data variables.product.prodname_codeql %} pack without running it immediately, then you can use the `codeql pack download` command. This is useful if you want to avoid accessing the internet when running {% data variables.product.prodname_codeql %} queries. When you run the {% data variables.product.prodname_codeql %} analysis, you can specify packs, versions, and paths in the same way as in the previous example:
289+
290+
```shell
291+
echo $OCTO-ORG_ACCESS_TOKEN | codeql pack download &lt;scope/name@version:path&gt; &lt;scope/name@version:path&gt; ...
292+
```
286293
{% endif %}
287294
288295
{% ifversion fpt or ghes > 3.1 or ghae or ghec %}

0 commit comments

Comments
 (0)