๐Ÿ” 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

How to Handle Secrets and Credentials in CI/CD