Skip to content

Commit ddc1a1a

Browse files
authored
Update manage-encrypted-secrets.md
1 parent 1a36bbc commit ddc1a1a

File tree

1 file changed

+74
-40
lines changed

1 file changed

+74
-40
lines changed

learn-pr/github/manage-github-actions-enterprise/includes/manage-encrypted-secrets.md

Lines changed: 74 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1-
Secrets are encrypted environment variables used to store tokens, credentials, and other types of sensitive information required by your GitHub Actions workflows and actions. Once created, these secrets are available to workflows and actions that have access to the organization, repository, or environment where they are defined.
1+
Secrets are encrypted environment variables that store tokens, credentials, and other sensitive information. Your GitHub Actions workflows and actions can use these secrets when needed. Once created, secrets become accessible to workflows and actions that have permission to access the organization, repository, or environment where the secrets are defined.
22

3-
This section introduces the tools and strategies available in GitHub Enterprise Cloud and GitHub Enterprise Server for managing encrypted secrets. You'll also learn how to access these secrets within your workflows and actions.
3+
This section explains how to manage encrypted secrets using tools and strategies in GitHub Enterprise Cloud and GitHub Enterprise Server. You'll also learn how to use these secrets within your workflows and actions.
44

55
## Manage encrypted secrets in the enterprise
66

7-
GitHub Actions enables you to securely store and use sensitive data—such as API keys, authentication tokens, passwords, and certificates—through **encrypted secrets**. These secrets are safely stored and injected into workflows, ensuring they are not exposed in logs or source code.
7+
GitHub Actions lets you securely store and use sensitive data—such as API keys, authentication tokens, passwords, and certificates—through **encrypted secrets**. These secrets are securely stored and injected into workflows. This ensures they do not appear in logs or source code.
88

9-
In an enterprise setting, effective secret management is essential for maintaining security, meeting compliance requirements, and supporting operational efficiency. GitHub supports secret management at multiple levels: **enterprise**, **organization**, **repository**, and **environment**.
9+
In an enterprise environment, effective secret management is critical. It helps maintain security, meet compliance requirements, and support operational efficiency. GitHub allows you to manage secrets at four levels: **enterprise**, **organization**, **repository**, and **environment**.
1010

1111
### Scope of encrypted secrets
1212

1313
Understanding the **scope** of secrets is essential for managing them securely in an enterprise environment.
1414

15-
| **Secret Level** | **Scope** | **Who Can Access** | **Common Use Cases** |
16-
| ------------------------------ | ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------- | ------------------------------------------------------------------------- |
17-
| **Enterprise-Level Secrets** | Available across all repositories within a GitHub Enterprise Cloud organization. | Enterprise owners, security administrators | Shared API keys or service credentials used across multiple repositories. |
18-
| **Organization-Level Secrets** | Accessible to all repositories within a specific organization. Can be restricted to selected repositories. | Organization owners, security administrators | Tokens for cloud services or shared database credentials. |
19-
| **Repository-Level Secrets** | Available only to a single repository. | Repository administrators and workflow runners | Deployment-specific API keys or database credentials. |
20-
| **Environment-Level Secrets** | Scoped to a particular deployment environment (e.g., staging, production) within a repository. | Workflow runners in the defined environment | Credentials needed for environment-specific deployments. |
15+
| **Secret Level** | **Scope** | **Who Can Access** | **Common Use Cases** |
16+
| ------------------------------ | ---------------------------------------------------------------------------------------------- | --------------------------------------------- | ---------------------------------------------------- |
17+
| **Enterprise-Level Secrets** | Apply to all repositories in a GitHub Enterprise Cloud organization. | Enterprise owners, security administrators | Share credentials across multiple repositories. |
18+
| **Organization-Level Secrets** | Apply to all repositories in an organization; optionally limit to selected repositories. | Organization owners, security administrators | Access cloud services and shared databases. |
19+
| **Repository-Level Secrets** | Apply only to a single repository. | Repository administrators, workflow runners | Secure credentials for deployment in one repository. |
20+
| **Environment-Level Secrets** | Apply to specific deployment environments within a repository (e.g., `staging`, `production`). | Workflow runners in the specified environment | Separate credentials by deployment environment. |
2121

2222
**Key considerations:**
23-
- **Enterprise secrets** are exclusive to GitHub Enterprise Cloud and offer centralized management across an organization.
24-
- **Organization secrets** support fine-grained access control by allowing restriction to specific repositories.
25-
- **Environment secrets** help prevent unintentional exposure of production credentials by limiting access to targeted workflows.
23+
24+
* **Enterprise secrets** are exclusive to GitHub Enterprise Cloud and support centralized management across an organization.
25+
* **Organization secrets** offer fine-grained access control and can be limited to specific repositories.
26+
* **Environment secrets** help prevent unintentional exposure by restricting access to workflow environments.
2627

2728
## Manage encrypted secrets at organization level
2829

29-
Creating encrypted secrets at organization level to store sensitive information is a great way to ensure the security of this information, while minimizing management overhead in your enterprise.
30+
Creating encrypted secrets at the organization level helps secure sensitive information while reducing the effort required to manage secrets across multiple repositories.
3031

3132
For example, some developers writing workflows in your GitHub organization need the credentials to deploy code to production in some of their workflows. In order to avoid sharing this sensitive piece of information, you could create an encrypted secret containing the credentials at organization level. This way the credentials can be used in the workflows without being exposed.
3233

@@ -60,54 +61,68 @@ You can select **Update** for more details on the configured permissions for you
6061
```
6162

6263
#### Security considerations for organization secrets
63-
6464
- **Restrict secrets to specific repositories** rather than granting access to all repositories by default.
6565
- **Implement role-based access control (RBAC)** to ensure only authorized team members can create, update, or delete secrets.
6666
- **Monitor access logs regularly** to identify and respond to unauthorized usage or suspicious activity.
6767

68-
## Manage encrypted secrets at the repository level
69-
If you need to scope a secret to a specific repository, GitHub Enterprise Cloud and GitHub Enterprise Server support creating secrets at the repository level.
70-
71-
To create a repository-level secret:
68+
## Manage Encrypted Secrets at the Repository Level
69+
To scope a secret to a specific repository, use GitHub Enterprise Cloud or GitHub Enterprise Server.
7270

73-
1. Navigate to the repository’s **Settings**.
74-
2. In the sidebar, select **Secrets and variables > Actions > New repository secret**.
75-
3. Enter a name and value for the secret.
71+
### Create a Repository-Level Secret
72+
1. **Navigate** to the repository’s **Settings**.
73+
2. **Select** **Secrets and variables > Actions**, then **New repository secret**.
74+
3. **Enter** a name and value for the secret.
7675

7776
:::image type="content" source="../media/secret-repo.png" alt-text="New secret screen for repositories." border="false":::
7877

7978
### Manage Repository-Level Encrypted Secrets via CLI
80-
- **List repository secrets:**
79+
80+
* **List repository secrets:**
81+
8182
```sh
8283
gh secret list --repo my-repo
8384
```
84-
- **Update a repository secret:**
85+
86+
* **Update a repository secret:**
87+
8588
```sh
8689
gh secret set SECRET_NAME --repo my-repo --body "new-secret-value"
8790
```
88-
- **Delete a repository secret:**
91+
92+
* **Delete a repository secret:**
93+
8994
```sh
9095
gh secret delete SECRET_NAME --repo my-repo
9196
```
9297

93-
## Access encrypted secrets within actions and workflows
9498

95-
### In workflows
99+
## Access Encrypted Secrets Within Actions and Workflows
100+
101+
### In Workflows
96102

97-
To access an encrypted secret in a workflow, you must use the `secrets` context in your workflow file. For example:
103+
Access secrets using the `secrets` context. Use either `with` to pass the secret as an input, or `env` to set it as an environment variable.
98104

99105
```yml
100106
steps:
101107
- name: Hello world action
102-
with: # Set the secret as an input
108+
uses: actions/hello-world@v1
109+
with:
110+
# Pass the secret as an input to the action
103111
super_secret: ${{ secrets.SuperSecret }}
104-
env: # Or as an environment variable
112+
env:
113+
# Set the secret as an environment variable
105114
super_secret: ${{ secrets.SuperSecret }}
106115
```
107116
108-
### In actions
117+
- **Use `with`:**
118+
**Pass** the secret as an input parameter to the action. This method is commonly used when the action explicitly defines inputs in its `action.yml`.
119+
120+
- **Use `env`:**
121+
**Expose** the secret as an environment variable to the step. This is useful when the command in the step or a script inside the action expects an environment variable.
122+
123+
### In Actions
109124

110-
To access an encrypted secret in an action, you must specify the secret as an `input` parameter in the `action.yml` metadata file. For example:
125+
To use secrets inside a custom action, define them as inputs in the `action.yml` metadata file and access them as environment variables in the action code.
111126

112127
```yml
113128
inputs:
@@ -116,10 +131,20 @@ inputs:
116131
required: true
117132
```
118133

119-
If you need to access the encrypted secret in your action's code, the action code could read the value of the input using the `$SUPER_SECRET` environment variable.
134+
```js
135+
// Access the input using the Actions Toolkit
136+
const core = require('@actions/core');
137+
const token = core.getInput('super_secret');
138+
```
139+
140+
- **Define in `action.yml`:**
141+
**Specify** the secret as a required or optional input.
142+
143+
- **Access in code:**
144+
**Read** the secret using the [Actions Toolkit](https://github.com/actions/toolkit) (recommended) or by referencing environment variables if set.
120145

121146
> [!WARNING]
122-
> When creating custom actions, avoid including encrypted secrets directly in the source code, as actions are designed to be shared. To handle secrets or user-supplied inputs securely, use the core module from the [Actions Toolkit](https://github.com/actions/toolkit).
147+
> Avoid hardcoding secrets in the action source code. To securely manage inputs and secrets, **use the Actions Toolkit** for handling values within your code logic.
123148

124149
## Configure security hardening for GitHub Actions
125150

@@ -159,13 +184,16 @@ For example, using `github.event.pull_request.title` as an environment variable
159184

160185
:::image type="content" source="../media/manage-encrypted-secrets_workflow.png" alt-text="Screenshot showing a GitHub Actions workflow execution related to encrypted secrets." border="false":::
161186

162-
3. *Leverage workflow templates to implement code scanning*: If you click on the **Actions** tab of any repository, you will be able to select the **New Workflow** button on the left side of the pane. On the **Choose a workflow** page, you'll find a **Security** section where you can select workflow templates to add to your repository. The CodeQL scanner, in particular, can be configured to run on specific events. You can configure it to trigger on an appropriate event to scan a branch's files & flag exposures (CWE's) in actions used within workflows; including vulnerabilities such as script injection.
187+
3. **Leverage workflow templates to implement code scanning**:
188+
**Navigate** to the repository’s **Actions** tab and select the **New Workflow** button on the left pane. On the **Choose a workflow** page, **locate** the **Security** section to access and apply workflow templates.
189+
190+
**Configure** the CodeQL scanner to run on specific events, enabling it to scan a branch's files and flag exposures (CWEs) in actions used within workflows, including vulnerabilities such as script injection.
163191

164192
:::image type="content" source="../media/manage-encrypted-secrets_newworkflow.png" alt-text="Screenshot showing the creation of a new GitHub Actions workflow for managing encrypted secrets." border="false":::
165193

166194
:::image type="content" source="../media/manage-encrypted-secrets_codeql.png" alt-text="Screenshot showing CodeQL configuration related to managing encrypted secrets." border="false":::
167195

168-
4. *Restrict permissions for tokens*: Make sure to always apply the `rule of least privilege` to any created token. In other words, ensure the token is assigned the minimum privileges to achieve the task for which it was created.
196+
4. *Restrict permissions for tokens*: Ensure you always apply the `rule of least privilege` to any created token. In other words, ensure the token is assigned the minimum privileges to achieve the task for which it was created.
169197

170198
### Best practices for securely using third-party actions
171199

@@ -190,9 +218,15 @@ Follow these best practices to safely incorporate third-party actions into your
190218
3. **Audit the action’s source code**
191219
Review the action’s source to confirm it handles data securely and does not include unexpected or malicious behavior.
192220

193-
### Indicators of a trustworthy third-party action
221+
### Indicators of a Trustworthy Third-Party Action
222+
223+
Use trusted actions to reduce risk in your workflows.
224+
225+
- **Look for the Verified badge:**
226+
Trustworthy actions appear in the GitHub Marketplace and display a **Verified creator** badge next to the title. This means the creator has been verified by GitHub.
194227

195-
You should have situational awareness of indicators of a trustworthy third-party action to be better able to manage risk. The action should appear on the Github Marketplace. When you view the action's entry in the GitHub Marketplace, ensure that it shows the 'Verified creator' badge to the right of the title (highlighted red in the image below). This indicates that the vendor has been verified by GitHub. In addition, the `action.yml` file defining the action should be well documented.
228+
- **Check documentation:**
229+
The `action.yml` file should be well documented and clearly describe how the action works.
196230

197231
:::image type="content" source="../media/manage-encrypted-secrets_marketplace.png" alt-text="Screenshot showing the GitHub Marketplace interface for managing encrypted secrets." border="false":::
198232

@@ -202,7 +236,7 @@ Enable Dependabot version updates to automatically keep your GitHub Actions depe
202236

203237
### Potential impact of a compromised runner
204238

205-
The following sections describe possible attack vectors that could be exploited if a runner is compromised.
239+
This section describe possible attack vectors that could be exploited if a runner is compromised.
206240

207241
#### Exfiltration of data from a runner
208242

@@ -277,7 +311,7 @@ Avoid using classic personal access tokens in workflows. These tokens grant broa
277311
If you must use a personal token, create a **fine-grained PAT** tied to a dedicated organizational account. Restrict its access to only the specific repositories required by the workflow.
278312
Note: This approach is difficult to scale and is best avoided in favor of deploy keys or GitHub Apps.
279313

280-
:::image type="content" source="../media/manage-encrypted-secrets\_personalaccesstoken.png" alt-text="Screenshot showing a button to generate new GitHub personal access token." border="false":::
314+
:::image type="content" source="../media/manage-encrypted-secrets_personalaccesstoken.png" alt-text="Screenshot showing a button to generate new GitHub personal access token." border="false":::
281315

282316
5. **SSH keys on personal accounts**
283317

0 commit comments

Comments
 (0)