Secrets Management in Workflows
You'll learn how to securely store and access sensitive credentials in GitHub Actions workflows without exposing them in your code.
Why Secrets Matter
Hardcoding passwords, API keys, or tokens directly in workflow files is like writing your house key's hiding spot on your front door. Anyone with repository access can see them, and they're permanently stored in Git history. GitHub secrets solve this by encrypting sensitive values and injecting them only when workflows run.
How GitHub Secrets Work
Think of secrets as a secure vault attached to your repository. You store sensitive data once through the GitHub UI (Settings → Secrets and variables → Actions), and GitHub encrypts it. When your workflow runs, you reference these secrets using the secrets context, and GitHub temporarily provides the decrypted value—never displaying it in logs.
Using Secrets in Workflows
Reference secrets using the ${{ secrets.SECRET_NAME }} syntax:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Deploy to production
run: |
echo "Deploying with credentials..."
deploy-tool --token ${{ secrets.DEPLOY_TOKEN }}
env:
DATABASE_PASSWORD: ${{ secrets.DB_PASSWORD }}
API_KEY: ${{ secrets.API_KEY }}
GitHub automatically masks secret values in logs, replacing them with *** to prevent accidental exposure. Secrets can be defined at repository, environment, or organization levels, with environment secrets providing additional access controls.
Security Best Practices
Never echo or print secrets directly. Avoid passing them as command-line arguments where possible—prefer environment variables. Regularly rotate secrets and use environment-specific secrets for different deployment stages.
Key Takeaway: GitHub Actions secrets provide encrypted storage for sensitive data, accessible only during workflow execution through the secrets context, keeping credentials out of your codebase and logs.