|
| 1 | +## Step 1: Enable Secret Protection |
| 2 | + |
| 3 | +If you check your email, you probably just got an alert from GitHub with the subject "Possible valid secrets detected". Oh no! 😮 |
| 4 | + |
| 5 | +Don't worry! We put some expired credentials in the exercise on purpose since public repositories get secret protection for free. Nice! 🕵️ |
| 6 | + |
| 7 | +In this step, you will enable secret protection on your repository. After it is enabled, you will add a new credential to see how secret protection identifies the credential and alerts you. |
| 8 | + |
| 9 | +> [!WARNING] |
| 10 | +> If your repository is private, you will need [GitHub Advanced Security](https://docs.github.com/en/enterprise-cloud@latest/get-started/learning-about-github/about-github-advanced-security) to continue. We recommend [changing this exercise repository to public](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/managing-repository-settings/setting-repository-visibility) to enable it. |
| 11 | +
|
| 12 | +### What is a secret? |
| 13 | + |
| 14 | +In our context, a secret (or credential) is a plain-text string, or a pair of strings, that authorizes access to a service. Examples could be AWS secret access keys/ID's, Google API keys, or GitHub Personal Access Tokens (PATs). |
| 15 | + |
| 16 | +The GitHub Docs provides a list of [all supported patterns](https://docs.github.com/en/code-security/secret-scanning/secret-scanning-patterns#supported-secrets). |
| 17 | + |
| 18 | +### What is secret protection? |
| 19 | + |
| 20 | +Secret protection is a powerful tool which allows teams to identify these plain-text credentials, remove them, and create rules to prevent them from being written to GitHub in the first place. |
| 21 | + |
| 22 | +Secret protection is available **for free for public repositories** on all plans. Enterprises that need secret protection capabilities for private repositories should review [GitHub Advanced Security](https://github.com/security/advanced-security). Not only does it include secret protection, it also provides advanced static analysis, software composition analysis (SCA), and enterprise tools to manage your entire AppSec pipeline and reduce your risk profile. |
| 23 | + |
| 24 | +### :keyboard: Activity: Configure secret protection |
| 25 | + |
| 26 | +1. In the header of your repository, open **Settings** in a new browser tab. |
| 27 | + |
| 28 | +1. In the left navigation, under the **Security** section, select **Advanced Security**. |
| 29 | + |
| 30 | +1. Scroll down past the **Code Scanning** and **Dependabot** sections until you find the **Secret Protection** section. |
| 31 | + |
| 32 | + > 💡 **Tip:** We also have exercises about [code scanning](https://github.com/skills/introduction-to-codeql) and [supply chain protection](https://github.com/skills/secure-repository-supply-chain)! |
| 33 | +
|
| 34 | +1. Adjust the default configuration to match the below. |
| 35 | + |
| 36 | + - **Secret Protection:** `enabled` |
| 37 | + - **Push Protection:** `disabled` |
| 38 | + |
| 39 | + <img width="400" alt="Secret protection configuration settings" src="https://github.com/user-attachments/assets/7b999e54-dbf4-400d-8730-17b96bc06de1" /> |
| 40 | + |
| 41 | +### :keyboard: Activity: Commit a sensitive file |
| 42 | + |
| 43 | +Now let's (accidentally) commit a sensitive file to see how it works. Don't worry, these are inactive credentials. |
| 44 | + |
| 45 | +1. In the header of your repository, click the **Code** tab. |
| 46 | + |
| 47 | +1. Above the list of files, click the **Add file** dropdown and select **Create new file**. |
| 48 | + |
| 49 | + <img width="350" alt="New file button" src="https://github.com/user-attachments/assets/8f3f8da8-1471-485a-9df5-8c03ecba2d8e"/> |
| 50 | + |
| 51 | +1. Enter the file name `credentials.yml` and copy following **inactive** example credentials into it. |
| 52 | + |
| 53 | + <img width="400" alt="New file button" src="https://github.com/user-attachments/assets/40f5ce62-936c-4d71-8c51-02c724d5aac0"/> |
| 54 | + |
| 55 | + ```yaml |
| 56 | + default: |
| 57 | + aws_access_key_id: AKIAQYLPMN5HNM4OZ56B |
| 58 | + aws_secret_access_key: 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 |
| 59 | + mongodb: mongodb+srv://svc-admin:[email protected] |
| 60 | + output: json |
| 61 | + region: us-east-2 |
| 62 | + ``` |
| 63 | +
|
| 64 | +1. In the top right, use the **Commit changes...** button to commit directly to the `main` branch. |
| 65 | + |
| 66 | + > ❗️ **Important:** Committing to your default branch is not usually a recommended practice. We only do this to simplify the exercise. |
| 67 | + |
| 68 | +1. With our credentials file (accidentally) shared, Mona should quickly notice it and prepare the next step. |
0 commit comments