Files
codeql-action/README.md
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

177 lines
7.1 KiB
Markdown
Raw Normal View History

2020-04-29 12:47:06 +03:00
# CodeQL Action
2023-02-05 13:56:35 +02:00
This action runs GitHub's industry-leading semantic code analysis engine, [CodeQL](https://codeql.github.com/), against a repository's source code to find security vulnerabilities. It then automatically uploads the results to GitHub so they can be displayed in the repository's security tab. CodeQL runs an extensible set of [queries](https://github.com/github/codeql), which have been developed by the community and the [GitHub Security Lab](https://securitylab.github.com/) to find common vulnerabilities in your code.
2020-04-29 12:47:06 +03:00
2021-05-20 09:23:30 -07:00
For a list of recent changes, see the CodeQL Action's [changelog](CHANGELOG.md).
2020-05-06 10:55:34 +01:00
## License
This project is released under the [MIT License](LICENSE).
The underlying CodeQL CLI, used in this action, is licensed under the [GitHub CodeQL Terms and Conditions](https://securitylab.github.com/tools/codeql/license). As such, this action may be used on open source projects hosted on GitHub, and on private repositories that are owned by an organisation with GitHub Advanced Security enabled.
2020-04-29 12:47:06 +03:00
## Usage
2020-06-04 09:52:54 +01:00
This is a short walkthrough, but for more information read [configuring code scanning](https://help.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning).
To get code scanning results from CodeQL analysis on your repo you can use the following workflow as a template:
```yaml
name: "Code Scanning - Action"
on:
2021-07-16 10:08:37 +01:00
push:
branches: [main]
pull_request:
branches: [main]
schedule:
2020-10-01 16:52:44 +02:00
# ┌───────────── minute (0 - 59)
2020-10-22 18:29:58 +02:00
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ │
# * * * * *
2020-10-07 09:59:53 -07:00
- cron: '30 1 * * 0'
jobs:
CodeQL-Build:
# CodeQL runs on ubuntu-latest, windows-latest, and macos-latest
runs-on: ubuntu-latest
2021-08-09 11:40:19 -07:00
permissions:
# required for all workflows
security-events: write
# only required for workflows in private repositories
actions: read
contents: read
steps:
2020-04-29 12:47:06 +03:00
- name: Checkout repository
2022-03-30 19:42:05 +01:00
uses: actions/checkout@v3
2020-04-29 12:47:06 +03:00
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
2020-04-29 12:47:06 +03:00
# Override language selection by uncommenting this and choosing your languages
# with:
2022-11-16 18:31:04 +00:00
# languages: go, javascript, csharp, python, cpp, java, ruby
2020-04-29 12:47:06 +03:00
2022-10-26 16:34:30 -07:00
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
2020-04-29 12:47:06 +03:00
# If this step fails, then you should remove it and run the build manually (see below).
- name: Autobuild
uses: github/codeql-action/autobuild@v2
2020-04-29 12:47:06 +03:00
# ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
2020-04-29 12:47:06 +03:00
# ✏️ If the Autobuild fails above, remove it and uncomment the following
# three lines and modify them (or add more) to build your code if your
# project uses a compiled language
#- run: |
2021-08-17 15:52:11 +08:00
# make bootstrap
# make release
2020-04-29 12:47:06 +03:00
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
```
If you prefer to integrate this within an existing CI workflow, it should end up looking something like this:
```yaml
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: go, javascript
# Here is where you build your code
- run: |
2021-09-01 15:56:15 -07:00
make bootstrap
make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
```
2020-04-29 12:47:06 +03:00
2020-06-04 09:52:54 +01:00
### Configuration file
2020-06-04 09:52:54 +01:00
Use the `config-file` parameter of the `init` action to enable the configuration file. The value of `config-file` is the path to the configuration file you want to use. This example loads the configuration file `./.github/codeql/codeql-config.yml`.
```yaml
- uses: github/codeql-action/init@v2
with:
config-file: ./.github/codeql/codeql-config.yml
```
2021-01-12 12:09:22 +00:00
The configuration file can be located in a different repository. This is useful if you want to share the same configuration across multiple repositories. If the configuration file is in a private repository you can also specify an `external-repository-token` option. This should be a personal access token that has read access to any repositories containing referenced config files and queries.
```yaml
- uses: github/codeql-action/init@v2
2021-01-12 12:09:22 +00:00
with:
config-file: owner/repo/codeql-config.yml@branch
external-repository-token: ${{ secrets.EXTERNAL_REPOSITORY_TOKEN }}
```
For information on how to write a configuration file, see "[Using a custom configuration file](https://help.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#using-a-custom-configuration-file)."
2020-08-28 16:58:15 +01:00
If you only want to customise the queries used, you can specify them in your workflow instead of creating a config file, using the `queries` property of the `init` action:
```yaml
- uses: github/codeql-action/init@v2
2020-08-28 16:58:15 +01:00
with:
queries: <local-or-remote-query>,<another-query>
```
By default, this will override any queries specified in a config file. If you wish to use both sets of queries, prefix the list of queries in the workflow with `+`:
```yaml
- uses: github/codeql-action/init@v2
2020-08-28 16:58:15 +01:00
with:
queries: +<local-or-remote-query>,<another-query>
```
2023-04-10 07:56:09 +02:00
### Configuration via `config` input
2023-03-18 06:37:28 +00:00
2023-05-01 11:01:27 -07:00
You can alternatively configure CodeQL using the `config` input to the `init` Action. The value of this input must be a YAML string that follows the configuration file format documented at "[Using a custom configuration file](https://aka.ms/code-scanning-docs/config-file)."
2023-04-10 07:56:09 +02:00
2023-04-18 05:43:21 +02:00
#### Example configuration
2023-03-18 06:37:28 +00:00
2023-04-18 05:43:21 +02:00
```yaml
- uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
config: |
disable-default-queries: true
queries:
- uses: security-extended
- uses: security-and-quality
query-filters:
- include:
tags: /cwe-020/
```
2023-03-18 06:37:28 +00:00
2023-04-18 05:43:21 +02:00
#### Sharing configuration across multiple repositories
2023-05-01 11:01:27 -07:00
2023-04-18 05:43:21 +02:00
You can use Actions or environment variables to share configuration across multiple repositories and to modify configuration without needing to edit the workflow file. In the following example, `vars.CODEQL_CONF` is an [Actions configuration variable](https://docs.github.com/en/actions/learn-github-actions/variables#defining-configuration-variables-for-multiple-workflows):
2023-03-18 06:37:28 +00:00
2023-04-18 05:43:21 +02:00
```yaml
- uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
config: ${{ vars.CODEQL_CONF }}
```
2023-03-18 06:37:28 +00:00
## Troubleshooting
2023-07-06 17:14:12 +01:00
Read about [troubleshooting code scanning](https://docs.github.com/en/code-security/code-scanning/troubleshooting-code-scanning).
2023-05-25 17:03:48 +01:00
## Contributing
This project welcomes contributions. See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to build, install, and contribute.