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
+132Lines changed: 132 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,28 @@ Secrets are encrypted environment variables you can create to store tokens, cred
2
2
3
3
In this section, you'll explore the different tools and strategies available in GitHub Enterprise Cloud and GitHub Enterprise Server in order to manage the use of encrypted secrets. We'll also explain how to access encrypted secrets in your workflows and actions.
4
4
5
+
## 6.3 Manage Encrypted Secrets in the Enterprise
6
+
7
+
GitHub Actions provides a way to securely store and use sensitive information like API keys, authentication tokens, passwords, and certificates using **encrypted secrets**. These secrets are securely stored and injected into workflows, ensuring they are never exposed in logs or code repositories.
8
+
9
+
In an enterprise environment, managing secrets effectively is crucial for security, compliance, and operational efficiency. Secrets in GitHub are managed at different scopes, including **enterprise, organization, repository, and environment levels**.
10
+
11
+
### 6.3.1 Identify the Scope of Encrypted Secrets
12
+
13
+
Understanding the **scope** of secrets is key to managing them securely in an enterprise environment.
14
+
15
+
|**Secret Level**|**Scope**|**Who Can Access?**|**Use Cases**|
|**Enterprise-Level Secrets**| Available across all repositories within a GitHub Enterprise Cloud organization. | Enterprise owners, security administrators | Standard API keys, shared service credentials used across multiple repositories. |
18
+
|**Organization-Level Secrets**| Available to all repositories within a specific organization. Can be limited to selected repositories. | Organization owners, security administrators | Shared tokens for accessing cloud services, database credentials. |
19
+
|**Repository-Level Secrets**| Limited to a single repository. | Repository admins and workflow runners. | Repository-specific database credentials, API keys for deployment. |
20
+
|**Environment-Level Secrets**| Scoped to a specific deployment environment within a repository (e.g., `staging`, `production`). | Workflow runners executing in the defined environment. | Secrets required for deployments in different environments. |
21
+
22
+
**Key Considerations:**
23
+
-**Enterprise Secrets** are only available in GitHub Enterprise Cloud, providing a centralized way to manage organization-wide secrets.
24
+
-**Organization Secrets** can be scoped to selected repositories to enforce the **principle of least privilege**.
25
+
-**Environment Secrets** help prevent accidental exposure of production credentials by limiting access based on workflow environments.
26
+
5
27
## Manage encrypted secrets at organization level
6
28
7
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.
@@ -18,6 +40,32 @@ The access policy appears underneath the secret in the secret list once it's sav
18
40
19
41
You can select **Update** for more details on the configured permissions for your secret.
gh secret set SECRET_NAME --org my-org --body "super-secret-value"
50
+
```
51
+
-**List all organization secrets:**
52
+
```sh
53
+
gh secret list --org my-org
54
+
```
55
+
-**Update an existing secret:**
56
+
```sh
57
+
gh secret set SECRET_NAME --org my-org --body "new-secret-value"
58
+
```
59
+
-**Delete a secret:**
60
+
```sh
61
+
gh secret delete SECRET_NAME --org my-org
62
+
```
63
+
64
+
#### Security Considerations for Organization Secrets
65
+
-**Restrict secrets to specific repositories** instead of allowing all repositories to use them.
66
+
-**Use role-based access control (RBAC)** to ensure only necessary personnel can update secrets.
67
+
-**Monitor access logs** to detect unauthorized usage.
68
+
21
69
## Manage encrypted secrets at repository level
22
70
23
71
If you need an encrypted secret to be scoped to a specific repository, GitHub Enterprise Cloud and GitHub Enterprise Server also let you create secrets at repository level.
@@ -26,6 +74,22 @@ To create a secret at repository level, go to your repository **Settings** and f
26
74
27
75
:::image type="content" source="../media/secret-repo.png" alt-text="New secret screen for repositories.":::
gh secret set SECRET_NAME --repo my-repo --body "new-secret-value"
87
+
```
88
+
-**Delete a repository secret:**
89
+
```sh
90
+
gh secret delete SECRET_NAME --repo my-repo
91
+
```
92
+
29
93
## Access encrypted secrets within actions and workflows
30
94
31
95
### In workflows
@@ -56,3 +120,71 @@ If you need to access the encrypted secret in your action's code, the action cod
56
120
57
121
> [!WARNING]
58
122
> When authoring your own actions, make sure not to include any encrypted secrets in your action's source code, because actions are sharable units of work. If your action needs to use encrypted secrets or other user-supplied inputs, it's best to use the core module from the [Actions Toolkit](https://github.com/actions/toolkit).
123
+
124
+
### 6.3.2 Access Encrypted Secrets Within Actions and Workflows
125
+
126
+
#### Example: Using a Secret in a Workflow
127
+
128
+
```yaml
129
+
name: Deploy Application
130
+
131
+
on:
132
+
push:
133
+
branches:
134
+
- main
135
+
136
+
jobs:
137
+
deploy:
138
+
runs-on: ubuntu-latest
139
+
steps:
140
+
- name: Checkout repository
141
+
uses: actions/checkout@v3
142
+
143
+
- name: Use secret in a script
144
+
run: echo "Deploying with API_KEY=${{ secrets.DEPLOYMENT_KEY }}"
145
+
```
146
+
147
+
#### Best Practices for Using Secrets in Workflows
148
+
- **Do not print secrets** in logs using `echo ${{ secrets.SECRET_NAME }}`.
149
+
- **Use secrets within script commands**, rather than assigning them to environment variables.
150
+
- **Limit access** by defining secrets at the **lowest necessary level**.
151
+
- **Rotate secrets periodically** and update workflows accordingly.
152
+
153
+
## 6.3.5 Describe How to Use 3rd Party Vaults
154
+
155
+
Many enterprises integrate GitHub Actions with external secret management solutions like **HashiCorp Vault, AWS Secrets Manager, and Azure Key Vault**.
0 commit comments