This demo will integrate with Codacy. Codacy is a static analysis tool that helps developers improve code quality and security. Codacy integrates with GitHub and other source code management systems to provide automated code review and analysis. Codacy can be used to enforce code quality standards, identify security vulnerabilities, and track code quality metrics over time.
Codacy is a third-party tool that requires a subscription. It provides support for more languages than CodeQL. There are many such services as this, this is just an example for this course.
IMPORTANT: Only complete this setup if you have not already created this repo in a previous demo.
-
Ensure you have a GitHub Advanced Security license. Check with you administrator if you are unsure.
-
Clone the public repo,
https://github.com/ewg-atmosera/buffer-overflow-cpp
, to your local computer.git clone https://github.com/ewg-atmosera/buffer-overflow-cpp
-
Create a new repo in your GitHub account named
buffer-overflow-cpp
, and push the clone repo to it.git remote add explore-codeql <YOUR GIT REPO URL>
git push explore-codeql main
-
Click the
Actions
tab for thebuffer-overflow-cpp
repo. -
In the upper-left, click the
New workflow
button. -
In the
Search workflows
, typecodacy
, then hitEnter
. -
One workflow should appear,
Codacy Analysis
. Click theConfigure
button. -
Add
workflow_dispatch:
to theon
section. -
Review the configuration. You will observe and
output
option set to "results.sarif", and aformat
of "sarif". Thesarif
format is a standard format for static analysis results that can be consumed by many tools.Third-party code scanning tools are initiated with a GitHub Action or a GitHub App based on an event in GitHub, like a pull request. The results are formatted as SARIF and uploaded to the GitHub Security Alerts tab. Alerts are then aggregated per tool and GitHub is able to track and suppress duplicate alerts.
-
In the configuration file you will observe the following line.
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
To call Codacy, you will need to add a secret named CODACY_PROJECT_TOKEN
to the repo. To set the project token you will need to generate one on the Codacy website.
-
At the top of the repo page, click the
Settings
tab. -
In the left-side menu, click
Secrets and variables
, then clickActions
. -
Click the
New repository secret
button. -
In the
Name
field, typeCODACY_PROJECT_TOKEN
, and copy the token from Codacy into theSecret
field. Then, click theAdd secret
button. -
Click on the
Actions
tab, then click theCodacy Analysis
workflow. -
Manually run the workflow by clicking the
Run workflow
button and select the main branch. Review the result. Note the upload sarif task. -
Review the code scanning alerts. You will see the alerts from Codacy in the
Security
tab. -
While CodeQL is a powerful tool, it is limited to the languages it supports. Codacy supports many more languages, so it can be used to analyze code that CodeQL cannot. Also, Codacy provides a different set of rules and checks than CodeQL, so it can be used to complement CodeQL analysis.