How to Handle Secrets and Credentials in CI/CD Part 4 โ Step 2: Reference the Secrets in Your Workflow
๐ How to Handle Secrets and Credentials in CI/CD Part 4
โ๏ธ Step 2: Reference the Secrets in Your Workflow
Your GitHub Actions workflow could look like this: name: Build and Push Docker Image
on: push: branches: - main
jobs: build: runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Log in to container registry
uses: docker/login-action@v3
with:
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Build Docker image
run: docker build -t myapp:${{ github.sha }} .
- name: Push Docker image
run: |
docker tag myapp:${{ github.sha }} \
https://lnkd.in/gmnRvp-R github.sha }}
docker push \
https://lnkd.in/gmnRvp-R github.sha }}
Notice what’s not in the workflow:
๐ซ Actual username
๐ซ Actual password
๐ซ API key
The workflow only contains references such as:
${{ secrets.REGISTRY_PASSWORD }}
GitHub retrieves the stored value when the workflow runs.
๐ฆ Think of It Like a Bank Vault
The workflow says:
“I need the registry credential.” GitHub checks that the workflow has access.
๐ The credential is retrieved.
๐ณ Docker authenticates to the registry.
๐ฆ The image is pushed.
The credential itself doesn’t need to be committed to Git.
๐ก๏ธ Step 3: Protect Production Secrets
Development and production shouldn’t automatically share the same credentials. GitHub Environments can help separate them. For example:
๐งช development
๐ญ staging
๐ production
Your production environment can have its own secrets and additional protection rules. A production deployment might therefore require:
๐จโ๐ป Code merged
โฌ๏ธ
๐งช Automated tests passed
โฌ๏ธ
๐ Production environment authorized
โฌ๏ธ
๐ Production credential accessed
โฌ๏ธ
๐ Deployment executed
This helps prevent every workflow from automatically gaining access to sensitive production credentials.
To be contd. ยป>Part 5
#Kubernetes #KubernetesNetworking #DevOps #SRE #CloudComputing #AWS #Azure #CNI #Calico #Cilium #Ingress #ServiceMesh #LinuxNetworking #NetworkEngineering #DevSecOps #CloudNative
