|
| 1 | +# Securing the Development Pipeline |
| 2 | + |
| 3 | +| [← Introduction & Your First Workflow][walkthrough-previous] | [Next: Running Tests →][walkthrough-next] | |
| 4 | +|:-----------------------------------|------------------------------------------:| |
| 5 | + |
| 6 | +In the previous exercise you created your first GitHub Actions workflow — a manually triggered "Hello World." Before building out CI/CD, let's explore security. Ensuring code security is imperative in today's environment, and GitHub provides tools that automate this for you — many of which are powered by GitHub Actions under the hood. |
| 7 | + |
| 8 | +When we think about how we create code today, there are three main areas to secure: |
| 9 | + |
| 10 | +- The **code we write** — which may contain vulnerabilities |
| 11 | +- The **libraries we use** — which may have known security issues |
| 12 | +- The **credentials we manage** — which may accidentally leak into source code |
| 13 | + |
| 14 | +[GitHub Advanced Security][advanced-security] provides a suite of tools covering each of these areas. Let's explore and enable them on our repository. |
| 15 | + |
| 16 | +## Scenario |
| 17 | + |
| 18 | +Security is important in every application. By detecting potential vulnerabilities early, teams can make updates before incidents occur. The shelter wants to ensure insecure code and libraries are detected as early as possible. You'll enable Dependabot, secret scanning, and code scanning to meet these needs. |
| 19 | + |
| 20 | +## Background |
| 21 | + |
| 22 | +[GitHub Advanced Security][advanced-security-docs] is a set of security features available directly in GitHub. The three pillars are: |
| 23 | + |
| 24 | +- **Code scanning** analyzes your source code for security vulnerabilities using [CodeQL][about-code-scanning], GitHub's semantic code analysis engine. When enabled, it runs as a GitHub Actions workflow — the same automation platform you used in the previous exercise. Every push and pull request triggers the analysis automatically. |
| 25 | +- **Dependabot** monitors your project's dependencies for known vulnerabilities and can automatically create [pull requests][about-prs] to update insecure packages to safe versions. |
| 26 | +- **Secret scanning** detects tokens, keys, and other credentials that have been committed to your repository, and can block pushes that contain [supported secrets][supported-secrets]. |
| 27 | + |
| 28 | +> [!NOTE] |
| 29 | +> Code scanning is built on [GitHub Actions][github-actions]. When you enable CodeQL's default setup, GitHub creates and manages a workflow for you behind the scenes. You'll see this connection more clearly when you navigate to the **Actions** tab after enabling it. This is a great example of how Actions powers automation across the GitHub platform — not just CI/CD pipelines you write yourself. |
| 30 | +
|
| 31 | +## Configure Dependabot |
| 32 | + |
| 33 | +Most projects depend on open source and external libraries. While modern development would be impossible without them, we always need to ensure the dependencies we use are secure. [Dependabot][dependabot-quickstart] monitors your repository's dependencies and raises alerts — or even creates pull requests — to update insecure packages. |
| 34 | + |
| 35 | +Public repositories on GitHub automatically have Dependabot alerts enabled. Let's configure Dependabot to also create PRs that update insecure library versions automatically. |
| 36 | + |
| 37 | +1. Navigate to your repository on GitHub. |
| 38 | +2. Select **Settings** > **Code security** (under **Security** in the sidebar). |
| 39 | +3. Locate the **Dependabot** section. |
| 40 | + |
| 41 | +  |
| 42 | + |
| 43 | +4. Select **Enable** next to **Dependabot security updates** to configure Dependabot to create PRs to resolve alerts. |
| 44 | + |
| 45 | +You've now enabled Dependabot alerts and security updates! When an insecure library is detected, you'll receive an alert, and Dependabot will create a pull request to update to a secure version. |
| 46 | + |
| 47 | +> [!TIP] |
| 48 | +> Dependabot doesn't just alert you — it can automatically create pull requests that bump library versions to secure ones. When you pair this with a CI pipeline that runs tests on every PR (which you'll build in the [next exercise][walkthrough-next]), those Dependabot PRs are automatically tested before merging. This creates a powerful feedback loop: vulnerabilities are detected, fixes are proposed, and your tests verify the update won't break anything — all without manual intervention. |
| 49 | +
|
| 50 | +> [!IMPORTANT] |
| 51 | +> After enabling Dependabot security updates you may notice new pull requests created for potentially outdated packages. For this workshop you can ignore these pull requests. |
| 52 | +
|
| 53 | +## Enable secret scanning |
| 54 | + |
| 55 | +Many developers have accidentally checked in code containing tokens or credentials. Regardless of the reason, even seemingly innocuous tokens can create a security issue. [Secret scanning][about-secret-scanning] detects tokens in your source code and raises alerts. With push protection enabled, pushes containing supported secrets are blocked before they reach your repository. |
| 56 | + |
| 57 | +1. On the same **Code security** settings page, locate the **Secret scanning** section. |
| 58 | +2. Next to **Receive alerts on GitHub for detected secrets, keys or other tokens**, select **Enable**. |
| 59 | +3. Next to **Push protection**, select **Enable** to block pushes containing a [supported secret][supported-secrets]. |
| 60 | + |
| 61 | +  |
| 62 | + |
| 63 | +You've now enabled secret scanning and push protection — helping prevent credentials from reaching your repository. |
| 64 | + |
| 65 | +## Enable code scanning |
| 66 | + |
| 67 | +There is a direct relationship between the amount of code an organization writes and its potential attack surface. [Code scanning][about-code-scanning] analyzes your source code for known vulnerabilities. When an issue is detected on a pull request, a comment is added highlighting the affected line with contextual information for the developer. |
| 68 | + |
| 69 | +Let's enable code scanning with the default CodeQL setup. This runs automatically whenever code is pushed to `main` or a pull request targets `main`, and on a regular schedule to catch newly discovered vulnerabilities. |
| 70 | + |
| 71 | +1. On the same **Code security** settings page, locate the **Code scanning** section. |
| 72 | +2. Next to **CodeQL analysis**, select **Set up** > **Default**. |
| 73 | + |
| 74 | +  |
| 75 | + |
| 76 | +3. On the **CodeQL default configuration** dialog, select **Enable CodeQL**. |
| 77 | + |
| 78 | +  |
| 79 | + |
| 80 | +> [!IMPORTANT] |
| 81 | +> Your list of languages may be different from what's shown in the screenshot. |
| 82 | +
|
| 83 | +A background process starts and configures a CodeQL analysis workflow for your repository. |
| 84 | + |
| 85 | +> [!TIP] |
| 86 | +> After enabling CodeQL, navigate to the **Actions** tab in your repository. You'll see a new **CodeQL** workflow listed alongside the **Hello World** workflow you created earlier. This is the Actions workflow that GitHub created automatically to run code scanning — proof that Actions isn't just for CI/CD, but powers many of GitHub's built-in features. |
| 87 | +
|
| 88 | +## Summary and next steps |
| 89 | + |
| 90 | +You've enabled GitHub Advanced Security for your repository: |
| 91 | + |
| 92 | +- **Dependabot** monitors dependencies for known vulnerabilities and creates PRs to update them. |
| 93 | +- **Secret scanning** detects leaked credentials and blocks pushes containing supported secrets. |
| 94 | +- **Code scanning** analyzes your source code using CodeQL, running as a GitHub Actions workflow on every push and PR. |
| 95 | + |
| 96 | +These tools run automatically in the background, catching security issues before they reach production. Now that you've seen how GitHub uses Actions internally for security automation, it's time to build your own CI workflow. Next, we'll [automate testing][walkthrough-next] for the shelter's application. |
| 97 | + |
| 98 | +### Resources |
| 99 | + |
| 100 | +- [About GitHub Advanced Security][advanced-security-docs] |
| 101 | +- [About code scanning with CodeQL][about-code-scanning] |
| 102 | +- [Dependabot quickstart guide][dependabot-quickstart] |
| 103 | +- [About secret scanning][about-secret-scanning] |
| 104 | +- [GitHub Skills: Secure your repository's supply chain][skills-supply-chain] |
| 105 | +- [GitHub Skills: Secure code game][skills-secure-code] |
| 106 | + |
| 107 | +| [← Introduction & Your First Workflow][walkthrough-previous] | [Next: Running Tests →][walkthrough-next] | |
| 108 | +|:-----------------------------------|------------------------------------------:| |
| 109 | + |
| 110 | +[about-code-scanning]: https://docs.github.com/code-security/code-scanning/introduction-to-code-scanning/about-code-scanning |
| 111 | +[about-prs]: https://docs.github.com/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests |
| 112 | +[about-secret-scanning]: https://docs.github.com/code-security/secret-scanning/introduction/about-secret-scanning |
| 113 | +[advanced-security]: https://github.com/features/security |
| 114 | +[advanced-security-docs]: https://docs.github.com/get-started/learning-about-github/about-github-advanced-security |
| 115 | +[dependabot-quickstart]: https://docs.github.com/code-security/getting-started/dependabot-quickstart-guide |
| 116 | +[github-actions]: https://github.com/features/actions |
| 117 | +[supported-secrets]: https://docs.github.com/code-security/secret-scanning/introduction/supported-secret-scanning-patterns |
| 118 | +[skills-supply-chain]: https://github.com/skills/secure-repository-supply-chain |
| 119 | +[skills-secure-code]: https://github.com/skills/secure-code-game |
| 120 | +[walkthrough-previous]: 1-introduction.md |
| 121 | +[walkthrough-next]: 3-running-tests.md |
0 commit comments