|
| 1 | +# 9 Setting up Code Scanning for your repository |
| 2 | +In this lab you will: |
| 3 | + - Learn how to set up code scanning for repositories |
| 4 | + - Experience how code scanning enables you to find security vulnerabilities |
| 5 | + |
| 6 | + Good luck! 👍 |
| 7 | + |
| 8 | +This hands on lab consists of the following steps: |
| 9 | +- [Enabling GitHub Advanced Security on your repository](#enabling-github-advanced-security-on-your-repository) |
| 10 | +- [Code Scanning: What is it?](#code-scanning-what-is-it) |
| 11 | +- [Enabling the Code Scanning functionality](#enabling-the-code-scanning-functionality) |
| 12 | +- [Analyzing Code Scanning outcomes](#analyzing-code-scanning-outcomes) |
| 13 | + |
| 14 | +## Enabling GitHub Advanced Security on your repository |
| 15 | +Should GitHub Advanced Security not be enabled yet on your repository, you can enable it from the `Settings` menu on your repository, then under `Security & Analysis`, in the section `GitHub Advanced Security`, click `Enable`. Advanced Security should be enabled in order to enable Code Scanning and Secret Scanning. |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +## Code Scanning: What is it? |
| 20 | +Code scanning is a feature that you use to analyze the code in a GitHub repository to find security vulnerabilities and coding errors. Any problems identified by the analysis are shown in GitHub. |
| 21 | + |
| 22 | +You can use code scanning to find, triage, and prioritize fixes for existing problems in your code. Code scanning also prevents developers from introducing new problems. You can schedule scans for specific days and times, or trigger scans when a specific event occurs in the repository, such as a push. If code scanning finds a potential vulnerability or error in your code, GitHub displays an alert in the repository. After you fix the code that triggered the alert, GitHub closes the alert. For more information, see [Managing code scanning alerts for your repository](https://docs.github.com/en/code-security/secure-coding/managing-code-scanning-alerts-for-your-repository]). |
| 23 | + |
| 24 | +For GitHub Code Scanning documentation, please refer to: [https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/about-code-scanning](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/about-code-scanning) |
| 25 | + |
| 26 | +### Enabling the Code Scanning functionality |
| 27 | +To enable GitHub Code Scanning, please navigate to the `Settings` of your repository, click `Security & analysis` click the `Set up` drop down for the `Code Scanning` feature and choose "Advanced". |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +You'll be directed to the insert a new file that runs code scanning by using the *CodeQL Analysis* product maintained by GitHub. |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +After this step, a `codeql.yml` file is generated for you. For most projects, this workflow file will not need changes; you can simply commit it to your repository. |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +Once your changes are committed, you will see the `codeql.yml` file in the (new) directory `./github/workflows`. |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +When you click the file `codeql.yml`, you get to see the option `View runs`. |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | +From here, you can see the list of workflows with the CodeQL workflow and the run history of the CodeQL workflow. In the default CodeQL analysis workflow, code scanning is configured to analyze your code each time you either push a change to the default branch or any protected branches, or raise a pull request against the default branch. As a result, code scanning will now commence. As you can see on the below screenshot, the workflow is currently running. |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | +Reviewing any failed analysis job |
| 52 | + |
| 53 | +After some minutes, generally around 7 to 8 minutes, the workflow run will be completed and you will see the status being updated. |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | +Clicking through on the workflow run, by clicking on `Create codeql.yml`, you can see the details of the workflow run. |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +Great, now that your CodeQL workflow is completed, we can move on and discover the way your Code Scanning outcomes can be analyzed. |
| 62 | + |
| 63 | +### Analyzing Code Scanning outcomes |
| 64 | +When you navigate to the `Security` tab on your repository, and click `Code Scanning alerts`, you can see the active alerts for Code Scanning. From this view, you can view, fix, dismiss, or delete alerts for potential vulnerabilities or errors in your project's code. |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | +Each alert highlights a problem with the code and the name of the tool that identified it. You can see the line of code that triggered the alert, as well as properties of the alert, such as the severity, security severity, and the nature of the problem. Alerts also tell you when the issue was first introduced. For alerts identified by CodeQL analysis, you will also see information on how to fix the problem. |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | +For more detailed information on managing the Code Scanning alerts, refer to: [https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/managing-code-scanning-alerts-for-your-repository](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/managing-code-scanning-alerts-for-your-repository) |
0 commit comments