Skip to content

Commit 3f1be10

Browse files
isaacmbrownmyarb
andauthored
[EDI] Uploading CodeQL analysis results to GitHub (#59727)
Co-authored-by: Melanie Yarbrough <11952755+myarb@users.noreply.github.com>
1 parent 0a963ab commit 3f1be10

File tree

3 files changed

+25
-36
lines changed

3 files changed

+25
-36
lines changed

content/code-security/reference/code-scanning/sarif-files/sarif-support-for-code-scanning.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,6 @@ This is where you store details of the rules that are run during analysis. Infor
169169

170170
Each `result` object contains details for one alert in the codebase. Within the `results` object, you can reference the rule that detected the alert. For more information, see [Rules and results](#rules-and-results) above.
171171

172-
{% data reusables.code-scanning.upload-sarif-alert-limit %}
173-
174172
| Name | Required | Description |
175173
|----|----|----|
176174
| `ruleId`| {% octicon "x" aria-label="Optional" %} | The unique identifier of the rule (`reportingDescriptor.id`). For more information, see the [`reportingDescriptor` object](#reportingdescriptor-object). {% data variables.product.prodname_code_scanning_caps %} uses the rule identifier to filter results by rule on {% data variables.product.prodname_dotcom %}.

content/code-security/tutorials/customize-code-scanning/uploading-codeql-analysis-results-to-github.md

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,54 +17,45 @@ redirect_from:
1717
contentType: tutorials
1818
---
1919

20-
## About SARIF output
21-
22-
{% data variables.product.github %} creates {% data variables.product.prodname_code_scanning %} alerts in a repository using information from Static Analysis Results Interchange Format (SARIF) files. SARIF is designed to represent the output of a broad range of static analysis tools, and there are many features in the SARIF specification that are considered "optional". The results must use SARIF version 2.1.0. For more information, see [AUTOTITLE](/code-security/code-scanning/integrating-with-code-scanning/sarif-support-for-code-scanning).
23-
24-
After analyzing a {% data variables.product.prodname_codeql %} database using the {% data variables.product.prodname_codeql_cli %}, you will have a SARIF file that contains the results. For more information, see [AUTOTITLE](/code-security/codeql-cli/getting-started-with-the-codeql-cli/analyzing-your-code-with-codeql-queries). You can then use the {% data variables.product.prodname_codeql_cli %} to upload results to {% data variables.product.github %}.
20+
After analyzing a {% data variables.product.prodname_codeql %} database using the {% data variables.product.prodname_codeql_cli %}, you will have a SARIF file that contains the results. You can then use the {% data variables.product.prodname_codeql_cli %} to upload results to {% data variables.product.github %}.
2521

2622
If you used a method other than the {% data variables.product.prodname_codeql_cli %} to generate results, you can use other upload methods. For more information, see [AUTOTITLE](/code-security/code-scanning/integrating-with-code-scanning/uploading-a-sarif-file-to-github).
2723

28-
{% data reusables.code-scanning.upload-sarif-ghas %}
29-
3024
## Generating a token for authentication with {% data variables.product.github %}
3125

32-
Before you can upload your results to {% data variables.product.github %}, you will first need to generate a {% data variables.product.pat_generic %}.
26+
Before you can upload your results to {% data variables.product.github %}, you will first need to generate a {% data variables.product.pat_generic %}. See [AUTOTITLE](/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token).
3327

3428
* **{% data variables.product.pat_v1_caps %}** requires "{% data variables.product.prodname_code_scanning_caps %} alerts" **Read and write** access for the required repositories.
3529
* **{% data variables.product.pat_v2_caps %}** requires "repo" **security_events** access.
3630

37-
For more information, see [AUTOTITLE](/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token).
38-
39-
If you have installed the {% data variables.product.prodname_codeql_cli %} in a third-party CI system to create results to display in {% data variables.product.github %} as code scanning alerts, you can use a {% data variables.product.prodname_github_app %} or {% data variables.product.pat_generic %} to upload results to {% data variables.product.github %}. For more information, see [AUTOTITLE](/code-security/code-scanning/integrating-with-code-scanning/using-code-scanning-with-your-existing-ci-system#generating-a-token-for-authentication-with-github).
31+
If you have installed the {% data variables.product.prodname_codeql_cli %} in a third-party CI system, you can also use a {% data variables.product.prodname_github_app %} to upload results to {% data variables.product.github %}. See [AUTOTITLE](/code-security/code-scanning/integrating-with-code-scanning/using-code-scanning-with-your-existing-ci-system#generating-a-token-for-authentication-with-github).
4032

4133
## Uploading results to {% data variables.product.github %}
4234

43-
{% data reusables.code-scanning.upload-sarif-alert-limit %}
35+
1. {% data reusables.code-scanning.upload-sarif-alert-limit %}
36+
1. Determine the best way to pass the {% data variables.product.prodname_github_app %} or {% data variables.product.pat_generic %} you created in the previous section to the {% data variables.product.prodname_codeql_cli %}. We recommend that you review your CI system's guidance on the secure use of a secret store. The {% data variables.product.prodname_codeql_cli %} supports:
4437

45-
Before you can upload results to {% data variables.product.github %}, you must determine the best way to pass the {% data variables.product.prodname_github_app %} or {% data variables.product.pat_generic %} you created in the previous section to the {% data variables.product.prodname_codeql_cli %}. We recommend that you review your CI system's guidance on the secure use of a secret store. The {% data variables.product.prodname_codeql_cli %} supports:
38+
* Interfacing with a secret store using the `--github-auth-stdin` option (recommended).
39+
* Saving the secret in the environment variable `GITHUB_TOKEN` and running the CLI without including the `--github-auth-stdin` option.
40+
* For testing purposes you can pass the `--github-auth-stdin` command-line option and supply a temporary token via standard input.
4641

47-
* Interfacing with a secret store using the `--github-auth-stdin` option (recommended).
48-
* Saving the secret in the environment variable `GITHUB_TOKEN` and running the CLI without including the `--github-auth-stdin` option.
49-
* For testing purposes you can pass the `--github-auth-stdin` command-line option and supply a temporary token via standard input.
42+
1. When you have decided on the most secure and reliable method for your configuration, run `codeql github upload-results` on each SARIF results file and include `--github-auth-stdin` unless the token is available in the environment variable `GITHUB_TOKEN`.
5043

51-
When you have decided on the most secure and reliable method for your configuration, run `codeql github upload-results` on each SARIF results file and include `--github-auth-stdin` unless the token is available in the environment variable `GITHUB_TOKEN`.
44+
```shell
45+
# {% data variables.product.prodname_github_app %} or {% data variables.product.pat_generic %} available from a secret store
46+
<call-to-retrieve-secret> | codeql github upload-results \
47+
--repository=<repository-name> \
48+
--ref=<ref> --commit=<commit> \
49+
--sarif=<file> {% ifversion ghes %}--github-url=<URL> \
50+
{% endif %}--github-auth-stdin
5251

53-
```shell
54-
# {% data variables.product.prodname_github_app %} or {% data variables.product.pat_generic %} available from a secret store
55-
<call-to-retrieve-secret> | codeql github upload-results \
56-
--repository=<repository-name> \
57-
--ref=<ref> --commit=<commit> \
58-
--sarif=<file> {% ifversion ghes %}--github-url=<URL> \
59-
{% endif %}--github-auth-stdin
60-
61-
# {% data variables.product.prodname_github_app %} or {% data variables.product.pat_generic %} available in GITHUB_TOKEN
62-
codeql github upload-results \
63-
--repository=<repository-name> \
64-
--ref=<ref> --commit=<commit> \
65-
--sarif=<file> {% ifversion ghes %}--github-url=<URL> \
66-
{% endif %}
67-
```
52+
# {% data variables.product.prodname_github_app %} or {% data variables.product.pat_generic %} available in GITHUB_TOKEN
53+
codeql github upload-results \
54+
--repository=<repository-name> \
55+
--ref=<ref> --commit=<commit> \
56+
--sarif=<file> {% ifversion ghes %}--github-url=<URL> \
57+
{% endif %}
58+
```
6859

6960
| Option | Required | Usage |
7061
| ------ | :------: | ----- |
@@ -94,7 +85,7 @@ codeql github upload-results \
9485
{% endif %}
9586
```
9687

97-
There is no output from this command unless the upload was unsuccessful. The command prompt returns when the upload is complete and data processing has begun. On smaller codebases, you should be able to explore the {% data variables.product.prodname_code_scanning %} alerts in {% data variables.product.github %} shortly afterward. You can see alerts directly in the pull request or on the **Security** tab for branches, depending on the code you checked out. For more information, see [AUTOTITLE](/code-security/code-scanning/managing-code-scanning-alerts/triaging-code-scanning-alerts-in-pull-requests) and [AUTOTITLE](/code-security/code-scanning/managing-code-scanning-alerts/assessing-code-scanning-alerts-for-your-repository).
88+
There is no output from this command unless the upload was unsuccessful. The command prompt returns when the upload is complete and data processing has begun. On smaller codebases, you should be able to explore the {% data variables.product.prodname_code_scanning %} alerts in {% data variables.product.github %} shortly afterward. You can see alerts directly in the pull request or on the **Security** tab for branches, depending on the code you checked out.
9889

9990
## Uploading diagnostic information to {% data variables.product.github %} if the analysis fails
10091

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
You can check that the SARIF properties have the supported size for upload and that the file is compatible with code scanning. For more information, see [AUTOTITLE](/code-security/code-scanning/integrating-with-code-scanning/sarif-support-for-code-scanning#file-compatibility).
1+
Check that the SARIF properties have the supported size for upload and that the file is compatible with code scanning. For more information, see [AUTOTITLE](/code-security/code-scanning/integrating-with-code-scanning/sarif-support-for-code-scanning#file-compatibility).

0 commit comments

Comments
 (0)