grock / course-secure-repository-supply-chain

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Secure your repository's supply chain

Secure your supply chain, understand dependencies in your environment, know about vulnerabilities in those dependencies and patch them.

Welcome

GitHub helps you secure your supply chain, from understanding the dependencies in your environment, to knowing about vulnerabilities in those dependencies and patching them.

  • Who this is for: Developers, DevOps Engineers, Site Reliability Engineers, Security experts
  • What you'll learn: How to view repository dependencies, view Dependabot alerts, and enable Dependabot security and version updates
  • What you'll build: Repository dependencies, Dependabot alerts, pull requests to fix dependencies and version updates
  • Prerequisites: None
  • Timing: This course is four steps long and can be completed in under an hour

How to start this course

  1. Right-click Start course and open the link in a new tab.
    start-course
  2. In the new tab, follow the prompts to create a new repository.
    • For owner, choose your personal account or an organization to host the repository.
    • We recommend creating a public repository—private repositories will use Actions minutes. Create a new repository
  3. After your new repository is created, wait about 20 seconds, then refresh the page. Follow the step-by-step instructions in the new repository's README.

Step 1: Review and add dependencies using dependency graph

Welcome to "Secure your repository's supply chain"! 👋

What's the big deal about securing your repository's supply chain?: With the accelerated use of open source, most projects depend on hundreds of open-source dependencies. This poses a security problem: what if the dependencies you're using are vulnerable? You could be putting your users at risk of a supply chain attack. One of the most important things you can do to protect your supply chain is to patch your vulnerable dependencies and replace any malware.

GitHub offers a range of features to help you understand the dependencies in your environment, know about vulnerabilities in those dependencies, and patch them. The supply chain features on GitHub are:

  • Dependency graph
  • Dependency review
  • Dependabot alerts
  • Dependabot updates
    • Dependabot security updates
    • Dependabot version updates

What is a dependency graph: The dependency graph is a summary of the manifest and lock files stored in a repository and any dependencies that are submitted for the repository using the dependency submission API (beta). For each repository, it shows:

  • Dependencies, the ecosystems and packages it depends on
  • Dependents, the repositories and packages that depend on it

⌨️ Activity: Verify that dependency graph is enabled

We recommend opening another browser tab to work through the following activities so you can keep these instructions open for reference.

  1. Navigate to the Settings tab.
  2. Click Code security and analysis.
  3. Verify/enable Dependency graph. (If the repo is private, you will enable it here. If the repo is public, it will be enabled by default)

⌨️ Activity: Add a new dependency and view your dependency graph

  1. Navigate to the Code tab and locate the code/src/AttendeeSite folder.
  2. Add the following content to the package-lock.json file after the third to last }
    ,
     "follow-redirects": {
       "version": "1.14.1",
       "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.1.tgz",
       "integrity": "sha512-HWqDgT7ZEkqRzBvc2s64vSZ/hfOceEol3ac/7tKwzuvEyWx3/4UegXh5oBOIotkGsObyk3xznnSRVADBgWSQVg=="
     }
    
  3. Navigate to the Insights tab.
  4. Click Dependency graph.
  5. Review all new dependencies on the Dependencies hub.
  6. Search for follow-redirects and review the new dependency you just added. Screen Shot 2022-10-17 at 3 37 36 PM

Wait about 20 seconds then refresh this page for the next step

Step 2: Enable and view Dependabot alerts

Nice work! 🎉 You added and viewed a dependency with dependency graph!

Given how many dependencies our repository is using, maintaining them needs to become an automated task. Keeping our code secure is a top priority, so one thing we need to do is set up a way to be notified when a dependency we are using is vulnerable or malware. We can do this by enabling Dependabot alerts!

What are Dependabot alerts?: Dependabot alerts tell you that your code depends on a package that is insecure. These Dependabot alerts reference the GitHub Advisory Database, which contains a list of known security vulnerabilities and malware, grouped in two categories: GitHub reviewed advisories and unreviewed advisories.

If your code depends on a package that has a security vulnerability, this can cause a range of problems for your project or the people who use it. You should upgrade to a secure version of the package as soon as possible. If your code uses malware, you need to replace the package with a secure alternative.

Let's try this out with our newly added follow-redirects dependency!

⌨️ Activity: View security advisories in the GitHub Advisory Database

  1. Navigate to the GitHub Advisory Database.
  2. Type or paste follow-redirects into the search box.
  3. Click on any of the advisories that were found.
  4. Note the packages, impact, patches, workaround, and references for the advisory.

Notice the list of advisories for our dependency! This can look scary but it's actually a good thing. It means that our dependency is actively being maintained and patches are being pushed to remove the vulnerability. If we had Dependabot alerts enabled, we could receive alerts when we need to update a dependency and act promptly to secure them.

Let's enable Dependabot alerts on our repository!

⌨️ Activity: Enable Dependabot alerts

  1. Navigate to the Settings tab.
  2. Click Code security and analysis.
  3. Click Enable Dependabot alerts (Wait about 60 seconds and then click the Security tab at the top of the repository).
  4. Review each of the four Dependabot alerts under the Vulnerability alerts section.

Dependabot has alerted us of four vulnerabilities that need to be updated from the dependencies that we are using. Dependabot helps us address these vulnerabilities by creating pull requests for each one as we select and review the alert.

Let's see how this would work by using Dependabot to create a pull request for one of the alerts!

⌨️ Activity: Create a pull request based on a Dependabot alert

  1. Select the Prototype Pollution in minimist alert under the Dependabot alerts section and click on the alert.
  2. Click the Create Dependabot security update button (This will create a pull request for the fix and could take ~2 minutes).
  3. Click the Review security update button. The pull request will be displayed.
    • You can view the pull request and Files changed tab to review the update.
  4. Navigate back to the Conversation tab and click the Merge pull request button.
  5. Click Confirm merge.

Wait about 20 seconds then refresh this page for the next step.

Step 3: Enable and trigger Dependabot security updates

Nice work enabling, viewing, and creating Dependabot alerts ✨

Enabling Dependabot alerts on our repository was a great step toward improving our code security, but we still had to manually select an alert and then manually select the option to create the pull request. It would be nice to further improve the automation and maintenance of our dependencies! Well, with Dependabot security updates, we can do just that.

What are Dependabot security updates?: When enabled, Dependabot will detect and fix vulnerable dependencies for you by opening pull requests automatically to resolve Dependabot alerts when they arise.

We manually created the pull request for the Prototype Pollution in minimist alert, but let's now enable Dependabot security updates to automate this process with the next alert!

⌨️ Activity: Enable and trigger Dependabot security updates

  1. Navigate to the Settings tab, select Code security and analysis, and enable the Dependabot security updates.
  2. Navigate to the Pull requests repository tab and select the newly created pull request titled Bump axios from 0.21.1 to 0.21.2 in /code/src/AttendeeSite.
    • You may need to wait 30-60 seconds.
  3. Click the Merge pull request button.
  4. Click Confirm merge.

Wait about 20 seconds then refresh this page for the next step.

Step 4: Enable and trigger Dependabot version updates

Nicely done! 🥳

You now have automated the process for Dependabot to alert and create pull requests to update your dependencies! At this point, you only need to review the pull request and then merge it to stay on top of your security alerts.

The security updates feature helps automate the process to resolve alerts, but what about just keeping up-to-date with version updates? We can have the same automation to update our dependencies for updated versions using the Dependabot version updates feature.

What are Dependabot version updates?: In addition to security alerts, Dependabot can also take the effort out of maintaining your dependencies. You can use it to ensure that your repository automatically keeps up with the latest releases of the packages and applications it depends on. Just like security alerts, Dependabot will identify an outdated dependency and create a pull request to update the manifest to the latest version of the dependency.

Let's see how this works!

⌨️ Activity: Enable and trigger Dependabot version updates

  1. Navigate to the Settings tab, select Code security and analysis, and enable the Dependabot version updates.
    • A new file editor opens with pre-poplulated contents. The file is called dependabot.yml.
  2. Add nuget to the package-ecosystem.
  3. Change the directory to /code/. (The dependabot.yml file should look like this) Screen Shot 2022-09-27 at 6 52 45 AM
  4. Click Commit changes directly to the main branch.

Wait about 20 seconds then refresh this page for the next step.

Finish

Congratulations friend, you've completed this course!

celebrate

Here's a recap of all the tasks you've accomplished in your repository:

  • You've learned how to view and use dependency graph.
  • You've learned how to enable and use Dependabot alerts.
  • You've learned how to enable and use Dependabot secuirty updates.
  • You've learned how to enable and use Dependabot version updates.

Additional learning and resources

What's next?


Get help: Post in our discussion boardReview the GitHub status page

© 2022 GitHub • Code of ConductMIT License

About

License:MIT License


Languages

Language:C# 98.3%Language:JavaScript 1.7%