You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: learn-pr/github/manage-github-actions-enterprise/includes/manage-encrypted-secrets.md
+74-40Lines changed: 74 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff 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.
2
2
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.
4
4
5
5
## Manage encrypted secrets in the enterprise
6
6
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.
8
8
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**.
10
10
11
11
### Scope of encrypted secrets
12
12
13
13
Understanding the **scope** of secrets is essential for managing them securely in an enterprise environment.
14
14
15
-
|**Secret Level**|**Scope**|**Who Can Access**|**Common Use Cases**|
|**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**|
|**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.|
21
21
22
22
**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.
26
27
27
28
## Manage encrypted secrets at organization level
28
29
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.
30
31
31
32
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.
32
33
@@ -60,54 +61,68 @@ You can select **Update** for more details on the configured permissions for you
60
61
```
61
62
62
63
#### Security considerations for organization secrets
63
-
64
64
-**Restrict secrets to specific repositories** rather than granting access to all repositories by default.
65
65
-**Implement role-based access control (RBAC)** to ensure only authorized team members can create, update, or delete secrets.
66
66
-**Monitor access logs regularly** to identify and respond to unauthorized usage or suspicious activity.
67
67
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.
72
70
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.
76
75
77
76
:::image type="content" source="../media/secret-repo.png" alt-text="New secret screen for repositories." border="false":::
78
77
79
78
### Manage Repository-Level Encrypted Secrets via CLI
80
-
-**List repository secrets:**
79
+
80
+
***List repository secrets:**
81
+
81
82
```sh
82
83
gh secret list --repo my-repo
83
84
```
84
-
-**Update a repository secret:**
85
+
86
+
***Update a repository secret:**
87
+
85
88
```sh
86
89
gh secret set SECRET_NAME --repo my-repo --body "new-secret-value"
87
90
```
88
-
-**Delete a repository secret:**
91
+
92
+
***Delete a repository secret:**
93
+
89
94
```sh
90
95
gh secret delete SECRET_NAME --repo my-repo
91
96
```
92
97
93
-
## Access encrypted secrets within actions and workflows
94
98
95
-
### In workflows
99
+
## Access Encrypted Secrets Within Actions and Workflows
100
+
101
+
### In Workflows
96
102
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.
98
104
99
105
```yml
100
106
steps:
101
107
- 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
103
111
super_secret: ${{ secrets.SuperSecret }}
104
-
env: # Or as an environment variable
112
+
env:
113
+
# Set the secret as an environment variable
105
114
super_secret: ${{ secrets.SuperSecret }}
106
115
```
107
116
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
109
124
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.
111
126
112
127
```yml
113
128
inputs:
@@ -116,10 +131,20 @@ inputs:
116
131
required: true
117
132
```
118
133
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.
120
145
121
146
> [!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.
123
148
124
149
## Configure security hardening for GitHub Actions
125
150
@@ -159,13 +184,16 @@ For example, using `github.event.pull_request.title` as an environment variable
159
184
160
185
:::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":::
161
186
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.
163
191
164
192
:::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":::
165
193
166
194
:::image type="content" source="../media/manage-encrypted-secrets_codeql.png" alt-text="Screenshot showing CodeQL configuration related to managing encrypted secrets." border="false":::
167
195
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.
169
197
170
198
### Best practices for securely using third-party actions
171
199
@@ -190,9 +218,15 @@ Follow these best practices to safely incorporate third-party actions into your
190
218
3. **Audit the action’s source code**
191
219
Review the action’s source to confirm it handles data securely and does not include unexpected or malicious behavior.
192
220
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.
194
227
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.
196
230
197
231
:::image type="content" source="../media/manage-encrypted-secrets_marketplace.png" alt-text="Screenshot showing the GitHub Marketplace interface for managing encrypted secrets." border="false":::
198
232
@@ -202,7 +236,7 @@ Enable Dependabot version updates to automatically keep your GitHub Actions depe
202
236
203
237
### Potential impact of a compromised runner
204
238
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.
206
240
207
241
#### Exfiltration of data from a runner
208
242
@@ -277,7 +311,7 @@ Avoid using classic personal access tokens in workflows. These tokens grant broa
277
311
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.
278
312
Note: This approach is difficult to scale and is best avoided in favor of deploy keys or GitHub Apps.
279
313
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":::
0 commit comments