Skip to content

Commit b7af619

Browse files
authored
Update manage-encrypted-secrets.md
1 parent 3b1e023 commit b7af619

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

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

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@ Secrets are encrypted environment variables you can create to store tokens, cred
22

33
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.
44

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** |
16+
| ------------------------------ | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------ | -------------------------------------------------------------------------------- |
17+
| **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+
527
## Manage encrypted secrets at organization level
628

729
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
1840

1941
You can select **Update** for more details on the configured permissions for your secret.
2042

43+
### 6.3.3 Manage Organization-Level Encrypted Secrets
44+
45+
#### Managing Organization Secrets via GitHub CLI
46+
47+
- **Create a secret for an organization:**
48+
```sh
49+
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+
2169
## Manage encrypted secrets at repository level
2270

2371
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
2674

2775
:::image type="content" source="../media/secret-repo.png" alt-text="New secret screen for repositories.":::
2876

77+
### 6.3.4 Manage Repository-Level Encrypted Secrets
78+
79+
#### Managing Repository Secrets via CLI
80+
- **List repository secrets:**
81+
```sh
82+
gh secret list --repo my-repo
83+
```
84+
- **Update a repository secret:**
85+
```sh
86+
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+
2993
## Access encrypted secrets within actions and workflows
3094

3195
### In workflows
@@ -56,3 +120,71 @@ If you need to access the encrypted secret in your action's code, the action cod
56120

57121
> [!WARNING]
58122
> 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**.
156+
157+
### 1. HashiCorp Vault
158+
```yaml
159+
- name: Fetch secret from Vault
160+
id: vault
161+
uses: hashicorp/vault-action@v2
162+
with:
163+
url: https://vault.example.com
164+
token: ${{ secrets.VAULT_TOKEN }}
165+
secret: secret/data/github/my-secret
166+
```
167+
168+
### 2. AWS Secrets Manager
169+
```yaml
170+
- name: Retrieve AWS Secret
171+
run: |
172+
SECRET_VALUE=$(aws secretsmanager get-secret-value --secret-id my-secret | jq -r .SecretString)
173+
echo "SECRET_VALUE=${SECRET_VALUE}" >> $GITHUB_ENV
174+
```
175+
176+
### 3. Azure Key Vault
177+
```yaml
178+
- name: Retrieve Azure Secret
179+
uses: Azure/get-keyvault-secrets@v1
180+
with:
181+
keyvault: "my-keyvault"
182+
secrets: "my-secret"
183+
azureCredentials: ${{ secrets.AZURE_CREDENTIALS }}
184+
```
185+
186+
### Benefits of Using Third-Party Vaults
187+
- **Centralized secret management** reduces security risks.
188+
- **Automated secret rotation** helps comply with security policies.
189+
- **Audit logs and access control** enhance security monitoring.
190+
- **Least privilege access** prevents unauthorized use of secrets.

0 commit comments

Comments
 (0)