Terminal prompt logo for Ali Haidry — alihaidry.dev~/AHAli Haidryalihaidry.dev
Phase 4 of 6Published

CI/CD and DevSecOps

CI/CD here is a gate before it is a conveyor belt. Every promotion is a pull request, and a change reaches a pod only after it has passed the checks.

GitHub ActionsOIDCTrivySemgrepCheckovUpdated Nov 2026

Goal

What this phase delivers

A delivery path with no stored cloud credentials: four parallel quality and security jobs on every pull request, images built in ACR Tasks and scanned by digest, the digest committed to the GitOps repository, and production behind an approval and a manual sync.

  • Quality and security gatesbackend, semgrep, frontend and iac jobs run in parallel on every pull request.Done
  • Build in the cloud, scan by digestACR Tasks builds the images; Trivy scans repo@digest, the exact bytes that will run.Done
  • Promotion by pull requestfeature, develop, staging and main map to the three environments.Done
  • Approval gate for prodA GitHub environment needs a reviewer, then a manual Argo CD sync.Done
  • Rehearsed rollbackrollback.yml restores the previous values with one commit.Done

Steps and commands

Run these in dev first. Every step has a check that proves it worked, so you are never guessing.

  1. Open a pull request and read the checks

    The four jobs run in parallel: backend (tests, Bandit, pip-audit), semgrep, frontend (lint, build, npm audit) and iac (Terraform validate, Checkov, Trivy config scan).

    $ gh pr create --fill
    $ gh pr checks
    Check: all four jobs are green before a merge is possible.
  2. Let the build job do its work

    On a push, the job logs in to Azure with OIDC, builds both images in ACR Tasks, resolves each digest and scans repo@digest with Trivy.

    $ gh run view
    $ az acr repository show-tags -n paktechacr --repository paktech-chat-api -o table
    Check: the new tag exists in the registry and the Trivy step passed.
  3. Watch the gitops job commit the digest

    The job commits the new digest to the GitOps repository. For dev and staging, Argo CD syncs automatically.

    $ kubectl -n paktech-chat-dev get pods -w
    $ kubectl get applications -n argocd
    Check: new pods start before the old ones stop, and the application is Synced.
  4. Approve and promote to prod

    The gitops job waits at the prod environment gate. After approval, read the two-line digest diff in Argo CD and sync by hand.

    # GitHub: approve the pending prod deployment
    # Argo CD: App Diff -> read the digest change -> Sync
    Check: the prod application is OutOfSync until you sync, then Healthy with the new digest.
  5. Rehearse the rollback

    Run the manual rollback workflow for dev with one step back, then roll forward again.

    # Actions -> rollback.yml -> Run workflow (environment dev, steps_back 1)
    Check: a commit restores the previous tag, new pods start before old ones stop, and the app keeps working.

Workflow

The path from a push to a running pod, with the gate where prod waits for a human.

  1. STEP 1PushPull request
  2. STEP 2ChecksFour parallel jobs
  3. STEP 3BuildACR Tasks, OIDC
  4. STEP 4ScanTrivy by digest
  5. STEP 5GitOps commitDigest to Git
  6. STEP 6Argo CDAuto, or manual in prod

Rollback: Run rollback.yml. It restores the previous values file in the GitOps repository, and Argo CD redeploys the old image. Argo CD polls every 3 minutes, so use a hard refresh to speed it up.

Diagram

The pipeline from git push to a running pod
Figure: the pipeline from git push to a running pod.
A green pipeline run: four checks in parallel, then build and gitops
Figure: a green run. Four checks in parallel, then build and gitops.
The prod approval gate: gitops waits for a reviewer
Figure: the production approval gate.

Issues met

These are real, from the run. The surprises are the useful part.

The Trivy scan blocked the first image
Cause
python-jose 3.3.0, CVE-2024-33663 (critical, algorithm confusion in the JWT library). The base image had zero findings; the vulnerable code was my dependency.
Fix
Merged the Dependabot bump to 3.5.0 after its checks passed, re-scanned, and verified a fresh login and chat on the new library.
backend failed because black would reformat a file
Cause
CI installed an unpinned, newer black than pre-commit uses.
Fix
Pinned black, isort and bandit to the pre-commit versions.
Bandit passed locally but failed in CI
Cause
Local Python 3.14 breaks Bandit 1.7.8, so it scanned zero files and looked clean. CI runs 3.11.
Fix
Reviewed the two real findings and added targeted nosec comments with rule numbers.
The Trivy step exited 1 with no message
Cause
The install script wrote to a read-only path and curl -s hid the error; then the pinned release asset returned 404 after the 2026 Trivy ecosystem supply-chain compromise.
Fix
Stopped piping an install script from main. Download a pinned release by URL and verify a hard-coded SHA-256 before running it.
GITOPS_TOKEN was visible on screen
Cause
It was created as a repository variable, which is plain text.
Fix
Deleted it, revoked the token and saved a new one under Secrets.

Trade-offs

Where images are built
I chose: ACR Tasks, not the runner

Why: Nothing is built on the runner, the image never leaves Azure on the way to the registry, and the digest comes straight from ACR.

It costs: Build logs live in two places and the build depends on ACR Tasks being available.

Production deployment
I chose: Approval plus a manual sync

Why: Two deliberate human steps for the environment that matters, with a readable two-line diff in between.

It costs: Slower releases and a person who has to be there.

Tag or digest
I chose: Digest everywhere

Why: A tag can be moved after it was scanned; a digest cannot. The scan, the commit and the running pod refer to the same bytes.

It costs: Less readable than tags, so the pipeline records both.

Interview questions

Why scan by digest instead of tag?
A tag is mutable. Scanning repo@digest guarantees the bytes you scanned are the bytes you deploy.
How does GitHub Actions deploy to Azure with no stored secret?
It requests a short-lived OIDC token for the workflow run, and Azure trusts it through a federated credential limited to the repository, branch or environment.
Tell me about a security gate that worked.
The first image the pipeline scanned was blocked for a critical JWT library CVE in a dependency of mine. I merged the upgrade after its checks, the scan passed, and I verified login. A scanner that has never failed a build is an unproven control.