Skip to content

Commit 9d5e6b1

Browse files
committed
Draft of exercise 04
1 parent 18445dd commit 9d5e6b1

File tree

8 files changed

+46
-91
lines changed

8 files changed

+46
-91
lines changed

Media/0401_PushProtection.png

15.6 KB
Loading

Media/0401_SecretScanning.png

10.5 KB
Loading

docs/04_make_things_secure/0401.md

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,19 @@ In addition to these manual processes, GitHub also provides automated tools for
1717

1818
## Description
1919

20-
In this task, you will improve the security of your repository using some of GitHub's built-in tools.
20+
In this task, you will enable some of GitHub's built-in tools for securing code in repositories.
2121

2222
1. Ask GitHub Copilot, "What do I need in a GitHub repository's security file?"
23-
2. Find the repository's Security policy. If there is an existing policy, make an edit and merge your change back into the main branch. Otherwise, create a policy using the template provided. GitHub Security policies are Markdown documents that indicate the preferred way to report security vulnerabilities for the repository.
23+
2. Find the repository's Security policy. If there is an existing policy, make an edit using GithUb Copilot and merge your change back into the main branch. Otherwise, create a policy using the template provided and GitHub Copilot. GitHub Security policies are Markdown documents that indicate the preferred way to report security vulnerabilities for the repository.
2424
3. Ask GitHub Copilot, "How do I enable Dependabot alerts on a GitHub repository?" Then, enable Dependabot alerts for the repository. Dependabot is an automated tool that creates a pull request when any dependencies in the code base has a known vulnerability.
2525
4. Ask GitHub Copilot, "How do I create a code scanning workflow in a GitHub repository?" After that, set up and run a Code scanning workflow for the repository using GitHub's 'CodeQL Analysis.' This workflow can run either on each pull request or on a schedule, and it checks your code for common vulnerabilities or errors.
26-
5. Ask GitHub Copilot, "How can I view the results of a CodeQL analysis in GitHub?" Then, navigate to the results.
27-
6. You should have one security issue from code scanning. Review the security issue and read up on how to correct the issue. Create a new GitHub Issue and feature branch. Then, resolve the issue, using GitHub Copilot to assist you.
26+
5. Ask GitHub Copilot, "How can I view the results of a CodeQL analysis in GitHub?" Then, navigate to the results. The next task will cover reviewing and correcting any issues you find.
27+
6. Ask GitHub Copilot, "How do I enable secret scanning on a GitHub repository?" Then, enable secret scanning and push protection on the repository.
2828

2929
## Success Criteria
3030

31-
- In GitHub, you should be able to view the 'closed' pull request which either created or updated the Security policy (SECURITY.md file).
32-
- Additionally, you should be able to view a new 'open' pull request created by Dependabot requesting an update of a dependency.
33-
- Finally, you should be able to view the results of the CodeQL Analysis in the Security tab.
31+
- The **Security** page for your GitHub repository shows that Dependabot alerts, Code scanning alerts, and Secret scanning alerts are all enabled.
32+
- You have one Dependabot alert, one Code scanning alert, and one Secret scanning alert.
3433

3534
## Learning Resources
3635

@@ -40,7 +39,7 @@ In this task, you will improve the security of your repository using some of Git
4039

4140
## Tips
4241

43-
- If you are stuck, check out the 'Security' tab of your repository on GitHub.
42+
- If you are stuck, check out the **Security** tab of your repository on GitHub.
4443

4544
## Solution
4645

@@ -70,7 +69,7 @@ In this task, you will improve the security of your repository using some of Git
7069

7170
![Select Default](../../Media/CodeQLAdvanced.png)
7271

73-
8. By choosing the advanced option, you can see the YAML for the pipeline that actually performs the code check. We don't need to make any changes here, but it's something you should be familiar with. An easy change to make in this file would be if you want to adjust the schedule of when the scan runs.
72+
8. By choosing the advanced option, you can see the YAML for the pipeline that actually performs the code check. We don't need to make any changes here, but it's something you should be familiar with. An easy change to make in this file would be if you want to adjust the schedule of when the scan runs. Use GitHub Copilot to assist you with making any change.
7473

7574
![Commit the CodeQL YAML](../../Media/CodeQLYAMLCommit.png)
7675

@@ -93,20 +92,12 @@ In this task, you will improve the security of your repository using some of Git
9392
9493
![View code scanning results](../../Media/CodeQLViewResults.png)
9594

96-
12. Select the alert and then choose "Show more" to view details on the security issue. It turns out that an attacker could traverse to an arbitrary directory based on the way the MP&P staff wrote this function. In order to correct the function and prevent a directory traversal attack, replace `WriteToDirectory()` with the following code:
97-
98-
```csharp
99-
public static void WriteToDirectory(ZipArchiveEntry entry, string destDirectory)
100-
{
101-
string destFileName = Path.GetFullPath(Path.Combine(destDirectory, entry.FullName));
102-
string fullDestDirPath = Path.GetFullPath(destDirectory + Path.DirectorySeparatorChar);
103-
if (!destFileName.StartsWith(fullDestDirPath)) {
104-
throw new System.InvalidOperationException("Entry is outside the target dir: " + destFileName);
105-
}
106-
entry.ExtractToFile(destFileName);
107-
}
108-
```
109-
110-
Commit the code and create a pull request to the main branch. You should then see a CodeQL scan for the pull request, and after it succeeds, complete the pull request. Then, return to the code scanning results view and confirm that no issues remain on the list.
95+
12. Return to the **Settings** menu and select **Code security and analysis**. Navigate to the bottom of the page and select the **Enable** button for Secret scanning.
96+
97+
![Enable secret scanning](../../Media/0401_SecretScanning.png)
98+
99+
Once you have enabled secret scanning, you will be able to enable a second option for Push protection.
100+
101+
![Enable push protection](../../Media/0401_PushProtection.png)
111102

112103
</details>

docs/04_make_things_secure/0402.md

Lines changed: 20 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,24 @@ nav_order: 2
55
parent: 'Exercise 04: Make things secure'
66
---
77

8-
# Task 02 - Fix issues GitHub Advanced Security found (20 minutes)
9-
108
## Introduction
119

12-
The Munson's Pickles and Preserves Team Messaging System is up and running! They even have a proper Git Flow to protect against unintended changes to the main branch, and are recording application telemetry into App Insights. Before we are truly production-ready, though, there is one topic we have to cover: security.
13-
14-
One good DevOps practice is to enable protections against code-level vulnerabilities, and GitHub provides a number of useful features in this area. First, there are Issues, which allow developers or users to open 'tickets' indicating bugs to be fixed or potential vulnerabilities. If your organization prefers security flaws to be reported in a location other than GitHub, you have the option to provide a custom Security policy which describes the process for reporting.
15-
16-
In addition to these manual processes, GitHub also provides automated tools for scanning code for common errors. In this task, you will utilize the built-in Dependabot, which provides alerts if your repository contains libraries, packages, or external dependencies with known vulnerabilities. You will also set up a workflow with CodeQL, which can scan your source code for common coding errors or basic security flaws. This will help to ensure that the Team Messaging System contains code without any known vulnerabilities.
10+
Now that the Munson's Pickles and Preserves team has GitHub Advanced Security in place, they would like your assistance in resolving the issues the tool has found. They see a variety of issues, from vulnerable dependencies to secrets exposed in code, and even coding practices that may be dangerous.
1711

1812
## Description
1913

2014
In this task, you will improve the security of your repository using some of GitHub's built-in tools.
2115

22-
1. Ask GitHub Copilot, "What do I need in a GitHub repository's security file?"
23-
2. Find the repository's Security policy. If there is an existing policy, make an edit and merge your change back into the main branch. Otherwise, create a policy using the template provided. GitHub Security policies are Markdown documents that indicate the preferred way to report security vulnerabilities for the repository.
24-
3. Ask GitHub Copilot, "How do I enable Dependabot alerts on a GitHub repository?" Then, enable Dependabot alerts for the repository. Dependabot is an automated tool that creates a pull request when any dependencies in the code base has a known vulnerability.
25-
4. Ask GitHub Copilot, "How do I create a code scanning workflow in a GitHub repository?" After that, set up and run a Code scanning workflow for the repository using GitHub's 'CodeQL Analysis.' This workflow can run either on each pull request or on a schedule, and it checks your code for common vulnerabilities or errors.
26-
5. Ask GitHub Copilot, "How can I view the results of a CodeQL analysis in GitHub?" Then, navigate to the results.
27-
6. You should have one security issue from code scanning. Review the security issue and read up on how to correct the issue. Create a new GitHub Issue and feature branch. Then, resolve the issue, using GitHub Copilot to assist you.
16+
1. You should have one security issue from code scanning. Review the security issue and read up on how to correct the issue. Create a new GitHub Issue from the code scanning alert.
17+
2. You should have one security issue from secret scanning. Create a separate GitHub Issue from the security alert. In reviewing this alert, one of the developers informs you that this secret is part of a local configuration file and that file should not be checked into source control at all.
18+
3. You should have one Dependabot alert due to a vulnerable version of a library. Try to use Dependabot to fix this package version and create a new pull request with the change. If it does not work, create a GitHub Issue for this Dependabot alert.
19+
4. Create a new feature branch. Then, use GitHub Copilot to assist you in resolving all of the outstanding security issues.
20+
5. Create a pull request, closing out the issues that you've resolved. Use GitHub Copilot Enterprise to generate a meaningful pull request message and have another learner review your code changes. Merge your code into the main branch of your repository.
2821

2922
## Success Criteria
3023

31-
- In GitHub, you should be able to view the 'closed' pull request which either created or updated the Security policy (SECURITY.md file).
32-
- Additionally, you should be able to view a new 'open' pull request created by Dependabot requesting an update of a dependency.
33-
- Finally, you should be able to view the results of the CodeQL Analysis in the Security tab.
24+
- In GitHub, you should be able to view the 'closed' pull request with your changes.
25+
- The **Security** tab shows no outstanding alerts for Dependabot, Code scanning, or Secret scanning.
3426

3527
## Learning Resources
3628

@@ -40,60 +32,20 @@ In this task, you will improve the security of your repository using some of Git
4032

4133
## Tips
4234

43-
- If you are stuck, check out the 'Security' tab of your repository on GitHub.
35+
- If you are stuck, review the details provided for each of the vulnerability alerts. This may include sample code to cause and fix a security issue, as well as links to additional resources.
4436

4537
## Solution
4638

4739
<details markdown="block">
4840
<summary>Expand this section to view the solution</summary>
4941

50-
1. Select **Settings** in your repo, then **Code security and analysis**. Select **Enable** on "Dependabot alerts" and "Dependabot security updates."
51-
52-
![Enabled Dependabot alerts and security updates](../../Media/EnableDependabot.png)
53-
54-
**Note** This will also automatically enable "Dependency graph."
55-
2. Navigate to [https://github.com/electron/electron/blob/main/SECURITY.md](https://github.com/electron/electron/blob/main/SECURITY.md) for information about security policies. This is an example of a sample security policy that you could use for this exercise.
56-
3. In your GitHub repo, select **Security**, **Policy**, and **Start setup**
57-
58-
![Start the security policy setup](../../Media/StartSecurityPolicySetup.png)
59-
60-
4. Paste the security policy into the Markdown file (you can overwrite what is there now) and update it for the Munson's Pickles and Preserves Team Messaging System and the GitHub repo your code is in. Then, commit the changes to the main branch.
61-
62-
![Commit the updated security policy](../../Media/CommitSecurityPolicy.png)
63-
64-
5. Next, we need to enable CodeQL. Select **Settings** and then **Code security and analysis**.
65-
6. Scroll down if needed and select **Set up** in "Code scanning" for "CodeQL analysis."
66-
67-
![Setup CodeQL analysis](../../Media/CodeQLAnalysisSetup.png)
68-
69-
7. If you select "Default", the code scan will immediately be run. For this exercise, select **Advanced**.
70-
71-
![Select Default](../../Media/CodeQLAdvanced.png)
72-
73-
8. By choosing the advanced option, you can see the YAML for the pipeline that actually performs the code check. We don't need to make any changes here, but it's something you should be familiar with. An easy change to make in this file would be if you want to adjust the schedule of when the scan runs.
74-
75-
![Commit the CodeQL YAML](../../Media/CodeQLYAMLCommit.png)
76-
77-
After you've reviewed the YAML, commit the change to main.
78-
79-
![Commit the change](../../Media/CodeQLCommitChange.png)
80-
81-
9. After you've committed the change, select **Actions** and you should see your CodeQL Scan workflow running.
82-
83-
![CodeQL scan running](../../Media/CodeQLScanRunning.png)
84-
85-
10. After about 5 minutes, you should see the workflow has completed.
86-
87-
![Workflow complete](../../Media/CodeQLWorkflowComplete.png)
88-
89-
11. After it's complete, go back to **Settings** and **Code security and analysis**. Then, select the ellipsis **...** next to the "Set up" menu. From the ellipsis dropdown, explore each of the first two options: "View last scan log" and "View Code Scanning alerts." You will find one High-risk vulnerability around arbitrary file access during archive extraction.
90-
91-
{: .note }
92-
> This page will still show "Set up" because we chose the Advanced option instead of Basic.
93-
94-
![View code scanning results](../../Media/CodeQLViewResults.png)
42+
1. Select **Security** in your repo, then **Code scanning**. Select the 'Arbitrary file access during archive extraction ("Zip Slip")' code issue. Select **Create issue** to create a GitHub issue around this code scanning alert.
43+
2. After creating an issue for the code scanning alert, navigate back to **Security** and then select **Secret scanning**. TODO: continue this!
44+
3. After creating an issue for the secret scanning alert, navigate back to the **Security** page and then select **Dependabot**. Select the 'Improper Handling of Exceptional Conditions in Newtonsoft.Json' alert. Then, select **Create Dependabot security update** to have Dependabot try to fix this issue. TODO: continue this!
45+
4. Create a new feature branch and give it a name like 'security-fixes'. Fetch changes from your machine and then check out and pull the new branch using the Git command line, Visual Studio Code, or your tool of choice.
46+
5. In GitHub, navigate back to the **Security** page and then select **Code scanning**. Select the code issue once again. Choose "Show more" to view details on the security issue. It turns out that an attacker could traverse to an arbitrary directory based on the way the MP&P staff wrote this function. In order to correct the function and prevent a directory traversal attack, update the `WriteToDirectory()` function. You can highlight the function, strike `Ctrl+i` or `Command+i`, and use a prompt like "Please update this function to prevent a directory traversal attack."
9547

96-
12. Select the alert and then choose "Show more" to view details on the security issue. It turns out that an attacker could traverse to an arbitrary directory based on the way the MP&P staff wrote this function. In order to correct the function and prevent a directory traversal attack, replace `WriteToDirectory()` with the following code:
48+
For comparison, the following code will not be vulnerable to a directory traversal attack:
9749

9850
```csharp
9951
public static void WriteToDirectory(ZipArchiveEntry entry, string destDirectory)
@@ -107,6 +59,10 @@ In this task, you will improve the security of your repository using some of Git
10759
}
10860
```
10961

110-
Commit the code and create a pull request to the main branch. You should then see a CodeQL scan for the pull request, and after it succeeds, complete the pull request. Then, return to the code scanning results view and confirm that no issues remain on the list.
62+
6. TODO: notes on correcting the secret scan alert
63+
7. TODO: dependabot alert work needed?
64+
8. Commit the code changes you have made, using GitHub Copilot to assist with creating a commit message. Include in your commit messages any issues you have resolved. Then, create a pull request to the main branch. Use GitHub Copilot Enterprise to create a relevant pull request message.
65+
9. Assign another learner as a reviewer for the pull request. Ensure that the other learner completes the code review and approves your changes.
66+
10. You should see a CodeQL scan for the pull request. Assuming that it succeeds and the other learner has approved your changes, complete the pull request. Then, return to the **Security** page and confirm that no issues remain on any of the three lists.
11167

11268
</details>

docs/04_make_things_secure/0403.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ parent: 'Exercise 04: Make things secure'
99

1010
## Introduction
1111

12-
To wrap up the DevOps journey, Munson's Pickles and Preserves would like to understand what is happening in their deployed environments. By the time users complain about a problem, it is already too late. It is also imperative to know not only about the performance of the site, but also the impact--positive or negative--a feature has had on the users. Please take a moment to review the articles in the **Learning Resources** section to gain a better understanding of the importance of monitoring, as well as Application Insights, one of the tools available in Azure to make monitoring easy.
12+
To reach the next step of their DevOps journey, Munson's Pickles and Preserves would like to understand what is happening in their deployed environments. By the time users complain about a problem, it is already too late. It is also imperative to know not only about the performance of the site, but also the impact--positive or negative--a feature has had on the users. Please take a moment to review the articles in the **Learning Resources** section to gain a better understanding of the importance of monitoring, as well as Application Insights, one of the tools available in Azure to make monitoring easy.
1313

1414
## Description
1515

index.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ For running this lab you will need:
2727
* An AAD tenant where you are a global admin. and an Azure subscription in that same tenant.
2828
* M365 E5 licenses (or a trial for these licenses configured) in that same tenant.
2929

30-
**[MCAPS non-prod subscriptions](https://dev.azure.com/OneCommercial/NoCode/_wiki/wikis/NoCode.wiki/12/Hybrid-Subscription) are the most convenient way for you to meet all these prerequisites**, and the lab activities assume that you have configured an external subscription via [https://aka.ms/MCAPSNewAzureSub](https://aka.ms/MCAPSNewAzureSub).
30+
**[MCAPS non-prod subscriptions](https://dev.azure.com/OneCommercial/NoCode/_wiki/wikis/NoCode.wiki/12/Hybrid-Subscription) are the most convenient way for you to meet all these prerequisites**, and the lab activities assume that you have configured an external subscription via [https://aka.ms/MCAPSNewAzureSub](https://aka.ms/MCAPSNewAzureSub). Note that this must be an **external** MCAPS subscription and not a hybrid subscription.
31+
32+
{: .note }
33+
> If you requested an external MCAPS subscription prior to April of 2024, you might have an obsolete MCAPS subscription. In that case, you will need to delete the subscription, delete the tenant, and re-request the external MCAPS subscription in the new system **before** beginning these labs. The link above will allow you to request a subscription in the new system. Obsolete external MCAPS subscriptions will be eliminated in September of 2024.

0 commit comments

Comments
 (0)