Build the Secured Pipeline · the finished project
← Previous: Git · Course map · Next: Security →
Tip
This repo is the finished template for the CI/CD project. Treat it as your cheat sheet.
It is your devsecops-capstone repo at the end of the CI/CD project: everything from the Git project, plus .github/workflows/pipeline.yml with all four parts in it (skeleton, build and test, three Trivy scans, OIDC deploy job). The commit history shows the pipeline growing one push at a time on a pipeline branch, then merged.
| Section | 7 of 10 · Automation |
| Time | About 60 minutes, 6 phases |
| Runs on | GitHub Actions, your capstone repo, and an AWS account for the deploy role |
| Deliverable | A pipeline that gates every change on tests and scans, deploys through a short-lived role with no stored keys, and is a required check on main |
Note
The pipeline runs on this template repo. Open the Actions tab to see build, test and the three scans run against this code. There is no AWS account behind it, so ACCOUNT_ID is still a placeholder and the deploy job stops at a step called Deploy skipped: set up AWS first. In your repo, once you replace ACCOUNT_ID (Phase 5), the pipeline runs and deploys on every push and pull request.
Drawn in Excalidraw. To edit it, open assets/diagram.excalidraw at excalidraw.com.
devsecops-capstone/ (this template repo)
├── .github/workflows/pipeline.yml NEW: the finished pipeline
├── .gitignore from the Git project
├── app/ from the Git project (the Docker app)
├── infra/ from the Git project (the Terraform network)
├── docs/example-README.md your README.md, unchanged since the Git project
└── reference/
└── github-deploy-trust.json the trust policy you write at ~/github-deploy-trust.json
reference/ holds a file that lives outside your repo in the walkthrough (in your home folder). It is here so you can check it.
Every change goes branch, push, PR, merge. Main is protected, so you use the pipeline's own process to build the pipeline.
cd ~/devsecops-capstone && git switch -c pipeline && mkdir -p .github/workflows
code .github/workflows/pipeline.yml| Phase | What you add to pipeline.yml |
Commit message |
|---|---|---|
| 1 · Skeleton | on: push (main), pull_request, checkout, echo "Pipeline is running" |
Add pipeline skeleton |
| 2 · Build and test | setup-python 3.12, pip install -r app/requirements.txt, pytest app/, docker build -t myapi:${{ github.sha }} app/ |
Build and test in the pipeline |
| 3 · Security gates | Trivy fs app/ (exit-code 1, blocks), Trivy config infra/ (exit-code 0), Trivy image (exit-code 0) |
Add security scans as pipeline gates |
| 5 · Deploy job | deploy: with needs: build, id-token: write, configure-aws-credentials (OIDC), placeholder echo |
Add OIDC deploy job |
After each push, watch the Actions tab. Reading the log is half the skill.
| Scan | exit-code |
Why |
|---|---|---|
Dependencies + secrets in app/ |
1 |
A HIGH finding fails the build |
IaC in infra/ |
0 |
Reports only, for now. The Security section fixes the serious ones and turns it into a gate |
| Container image | 0 |
Reports only, for now |
- IAM, Identity providers:
token.actions.githubusercontent.com, audiencests.amazonaws.com(skip if it exists from CI/CD Unit 5). - Get your owner and repo IDs:
curl -s https://api.github.com/repos/yourname/devsecops-capstone | python3 -c "import sys, json; r = json.load(sys.stdin); print('Owner ID:', r['owner']['id']); print('Repo ID: ', r['id'])"- Fill in
reference/github-deploy-trust.json(ACCOUNT_ID,yournametwice,OWNER_ID,REPO_ID), save it as~/github-deploy-trust.json, then:
aws iam create-role --role-name github-deploy --assume-role-policy-document file://$HOME/github-deploy-trust.json --query Role.Arn --output textThe role has no permissions yet, on purpose. The capstone builds the real, least-privilege deploy role.
Replace ACCOUNT_ID in the DEPLOY_ROLE line before you push. Until you do, the deploy job skips the AWS steps and says what is missing. needs: build is the gate: if anything upstream is red, deploy never runs.
Merge the pipeline PR. Then Settings, Branches, the main rule, Require status checks to pass: search for and select build. From now on the merge button stays grey until the pipeline is green.
- Every push runs build, test, three scans, and a gated deploy
- The dependency scan fails the build on HIGH findings, and the other two only report
- The deploy role is assumed through OIDC, with no stored keys
-
mainwill not merge a PR whose pipeline is red
| Mistake | What happens | The fix |
|---|---|---|
Forgetting to replace ACCOUNT_ID |
The deploy job stops at Deploy skipped: set up AWS first | Put your account number in the trust policy and the DEPLOY_ROLE line |
Missing permissions: id-token: write |
OIDC cannot get a token | It sits on the deploy job |
| Trust policy subject typo | Not authorized to perform sts:AssumeRoleWithWebIdentity |
Print the IDs again and compare, character by character |
| Committing straight to main | Rejected: main is protected | Branch, push, PR, merge |
Caution
This project uses aquasecurity/trivy-action@v0.36.0, a version tag. In March 2026 attackers moved almost every trivy-action tag to code that stole secrets. The Security section pins every action to a full commit SHA, and the capstone explains why. Do the Security section before you trust a tag again.
- GitHub Actions: workflows, jobs, steps, triggers and marketplace actions
- Security gates: scanners as pipeline steps, with deliberate fail-or-report decisions
- OIDC: short-lived cloud credentials instead of stored secrets
- Enforcement: required checks that make the pipeline mandatory
TechTwoForty · CI/CD · 7 of 10
← Previous: Git ·
Course map ·
Next: Security →
