Hands-on demo – Creating encrypted secrets in GitHub Actions
GitHub provides the ability to create encrypted secrets at both the repository and organization levels. These secrets are secure variables that can be used in workflows to manage sensitive data like API keys, tokens, and credentials.
1. Creating Secrets for a Repository
Steps to Add Repository Secrets
Navigate to your GitHub repository.
Click Settings > Secrets and variables > Actions.
Click New repository secret.
Provide a Name and Value (the secret) and click Add secret.
Example: Repository Secrets
Name:
MY_API_KEYValue:
super-secret-api-key
2. Creating Secrets for an Organization
Steps to Add Organization Secrets
Navigate to your GitHub organization.
Click Settings > Secrets and variables > Actions.
Click New organization secret.
Provide a Name and Value and click Add secret.
Example: Organization Secrets
Name:
ORG_API_KEYValue:
organization-wide-api-key
Using Secrets in GitHub Actions
Secrets created at either the repository or organization level can be accessed securely in workflows using the $GITHUB_SECRETS_NAME syntax.
Using Repository Secrets in Workflows
Example: Using Repository Secrets
xxxxxxxxxx161nameDeploy to Production2on3 push4 branches5main6jobs7 deploy8 runs-onubuntu-latest9 steps10nameCheckout Repository11 usesactions/checkout@v312nameDeploy Application13 run./deploy.sh14 env15 DATABASE_URL$ secrets.DATABASE_URL 16 API_KEY$ secrets.MY_API_KEY Using Organization Secrets in Workflows
Example: Using Organization Secrets
xxxxxxxxxx161nameDeploy to Production (Organization)2on3 push4 branches5main6jobs7 deploy8 runs-onubuntu-latest9 steps10nameCheckout Repository11 usesactions/checkout@v312nameDeploy Application13 run./deploy.sh14 env15 DATABASE_URL$ secrets.ORG_DATABASE_URL 16 API_KEY$ secrets.ORG_API_KEY Best Practices for Using Secrets
Scope Secrets: Restrict secrets to specific repositories or workflows for security.
Secret Rotation: Regularly update and rotate secrets to maintain security.
Use Environment Variables: Keep secrets in environment variables within your workflow for enhanced security.
Summary
By using encrypted secrets for both repositories and organizations, you ensure secure access to sensitive data in GitHub Actions workflows.






















Leave a Reply