Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,36 @@ jobs:
permissions:
id-token: write
contents: read
env:
# Phase 5: replace ACCOUNT_ID with your 12-digit AWS account number.
DEPLOY_ROLE: arn:aws:iam::ACCOUNT_ID:role/github-deploy
steps:
- uses: actions/checkout@v4

# Until ACCOUNT_ID is replaced (like on the template repo), this step
# says what to set up and the two steps after it skip.
- name: "Deploy skipped: set up AWS first"
if: contains(env.DEPLOY_ROLE, 'ACCOUNT_ID')
run: |
echo "::notice title=Deploy skipped: set up AWS first::Every gate passed. Make the github-deploy role, then replace ACCOUNT_ID in DEPLOY_ROLE to deploy. The run summary lists the steps."
cat >> "$GITHUB_STEP_SUMMARY" <<'EOF'
## Deploy skipped: the deploy role is not filled in yet

Every gate in the build job passed. To let the deploy job sign in to AWS:

1. **Phase 4:** make the `github-deploy` role, trusted through OIDC.
2. **Phase 5:** in `.github/workflows/pipeline.yml`, replace `ACCOUNT_ID` in the `DEPLOY_ROLE` line with your 12-digit AWS account number.

Push that change and this job signs in to AWS with no stored keys.
EOF

- name: Configure AWS credentials (OIDC)
if: ${{ !contains(env.DEPLOY_ROLE, 'ACCOUNT_ID') }}
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::ACCOUNT_ID:role/github-deploy
role-to-assume: ${{ env.DEPLOY_ROLE }}
aws-region: eu-west-2

- name: Deploy
if: ${{ !contains(env.DEPLOY_ROLE, 'ACCOUNT_ID') }}
run: echo "push image to ECR + update service here"
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
| **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` |

> [!WARNING]
> **GitHub Actions is switched off on this template repo.** There is no AWS account behind it, so the deploy job could never sign in. In **your** repo the pipeline runs on every push and pull request.
> [!NOTE]
> [![CI/CD Pipeline](https://github.com/wjpearce-github/TechTwoForty-CICD/actions/workflows/pipeline.yml/badge.svg)](https://github.com/wjpearce-github/TechTwoForty-CICD/actions/workflows/pipeline.yml)
>
> **The pipeline runs on this template repo.** Open the [Actions tab](https://github.com/wjpearce-github/TechTwoForty-CICD/actions) 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.

## The big picture

Expand Down Expand Up @@ -89,7 +91,7 @@ aws iam create-role --role-name github-deploy --assume-role-policy-document file
The role has **no permissions** yet, on purpose. The capstone builds the real, least-privilege deploy role.

### Phase 5 · The deploy job
Replace `ACCOUNT_ID` in the `role-to-assume` line before you push. `needs: build` is the gate: if anything upstream is red, deploy never runs.
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.

### Phase 6 · Close the gate
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.
Expand All @@ -105,7 +107,7 @@ Merge the pipeline PR. Then Settings, Branches, the `main` rule, **Require statu

| Mistake | What happens | The fix |
|---|---|---|
| Forgetting to replace `ACCOUNT_ID` | The credentials step fails | Put your account number in both places |
| 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 |
Expand Down
Loading