diff --git a/README.md b/README.md index a2546ab..48d21f0 100644 --- a/README.md +++ b/README.md @@ -156,12 +156,14 @@ compose.yaml Local Postgres + Kafka ## Docs - [docs/](docs/) — planning pack and lab notes + - [Lab 48 planning pack index](docs/lab48/README.md) — every Lab 48 deliverable, file and status - [Architecture](docs/architecture.md) - [AI usage plan](docs/ai-usage-plan.md) - [Environment strategy](docs/environment-strategy.md) - [GitHub Actions plan](docs/github-actions-plan.md) - [Terraform / Ansible plan](docs/terraform-ansible-plan.md) - [Backlog](docs/backlog.md) + - [ADRs](docs/adrs/) · [NFRs](docs/nfrs.md) · [Risk register](docs/risk-register.md) · [Team roles](docs/team-roles.md) - [Lab 49 backend notes](docs/lab49/README.md) · [Lab 50 frontend + persistence notes](docs/lab50/README.md) - [Lab 51 CI/CD runbook](docs/capstone-cicd-runbook.md) - [Lab 51 security and observability](docs/lab51/security-and-observability.md) — roles, endpoint matrix, negative tests, health diff --git a/defense/README.md b/defense/README.md index 2070c6f..e57fced 100644 --- a/defense/README.md +++ b/defense/README.md @@ -1,3 +1,20 @@ # Defense packet (Lab 52) -Placeholder for the Lab 52 demo and defense materials (slides, demo script, evidence index, Q&A, retrospective). Fill this folder during Lab 52 — linked from the root README so the path exists now. +Notes for the Thu/Fri Oct 22-23 defense. No PDF in this folder. Slides get built from `final-presentation-outline.md`. + +| File | What it is | +| --- | --- | +| [evidence-index.md](evidence-index.md) | Claim to file, commit, run, or digest | +| [demo-script.md](demo-script.md) | ~11 min speaker / operator script | +| [demo-walkthrough.sh](demo-walkthrough.sh) | The demo curls with check marks. `bash defense/demo-walkthrough.sh` from the repo root | +| [technical-q-and-a.md](technical-q-and-a.md) | Short answers with evidence | +| [retrospective.md](retrospective.md) | Blameless retro, five actions | +| [self-assessment.md](self-assessment.md) | Outcome, evidence, status | +| [final-presentation-outline.md](final-presentation-outline.md) | 11 slides | +| [feedback-log.md](feedback-log.md) | Empty until the panel | +| [notes/demo-commands.md](notes/demo-commands.md) | Start the stack and every demo command by hand | +| [notes/demo-recording-guide.md](notes/demo-recording-guide.md) | How to record the backup video | +| [notes/walkthrough-run.txt](notes/walkthrough-run.txt) | Saved green run of the script, Oct 22 | +| [notes/](notes/) | How to start, fallback, failure runs, deploy gap | + +Do not open `backend/src/main/resources/application-local.yml` on the projector. It has the local signing key. diff --git a/defense/demo-script.md b/defense/demo-script.md new file mode 100644 index 0000000..5a4ce2c --- /dev/null +++ b/defense/demo-script.md @@ -0,0 +1,58 @@ +# Demo script — Northstar CRM + +**Total:** about 11 minutes, plus questions after. +**Fixtures:** `CUS-1001` Amina Khan, `CUS-1002` Ravi Singh, correlation `lab-request-001`. +**Roles:** Speaker: TBD / Operator: TBD. +**Where:** UI http://localhost:4200 and API http://localhost:8081. Stack notes: `defense/notes/demo-validation.md`. + +If the laptop API dies, say the failover line in `defense/notes/fallback-pack.md` and stop clicking. + +## Pre-seed (before they walk in) + +| # | Confirm | What we know | +| --- | --- | --- | +| 1 | Amina (`CUS-1001`) searchable | API GET returned Amina Khan, ACTIVE. UI search was not clicked in this session. | +| 2 | Ravi (`CUS-1002`) searchable | API GET returned Ravi Singh, PROSPECT. | +| 3 | Agent login works | Login as `agent` returned 200, `expiresIn` 900. Do not mint the token early. It dies in 15 minutes. Password is the local one in `README.md`. Do not put it on a slide. | +| 4 | Kafka console bookmarked | Command in `defense/notes/demo-validation.md`. Binary path checked on `crm-kafka`. | +| 5 | SQL ready | `docker exec crm-postgres psql -U crm -d crm` works. Query is in the validation notes. | +| 6 | Fallback pack open | `defense/notes/fallback-pack.md`. No screenshot folder. | + +Also: the lookup list has two extra local customers (`CUS-1003`, `CUS-1004`). Search Amina. Do not scroll the full list on the projector. + +Sign in as **agent** for the whole demo. The close button will be hidden. The 403 is a curl. + +## Timed beats + +From 5:15 to 9:15 the operator can run `bash defense/demo-walkthrough.sh` from the repo root instead of typing curls. It asks for the agent password (from `README.md`, it does not show), never prints the token, and puts a check mark on each step. Raw commands are in `defense/notes/demo-commands.md`. A saved green run is in `defense/notes/walkthrough-run.txt`. + +| Time | Speaker | Operator | Evidence | +| --- | --- | --- | --- | +| 0:00 | Agents need one place to find a customer and write down the call. That is the slice. Success is CAP-12: save a note for Amina, keep it in Postgres, publish one event. | Show the home screen, or the title slide if the UI is not up yet. | E02, E01 | +| 0:45 | Angular talks to Spring. Spring checks the JWT, writes Postgres, then Kafka. We deploy image digests, not a rebuild. | If a diagram slide exists, leave it up. Otherwise stay on the sign-in page. | E01, E10, E12 | +| 1:20 | Sign in as the agent. The token stays in memory. A refresh logs you out. The page is not the security check. | Open http://localhost:4200/login. Username `agent`. Password from `README.md`. Click **Sign in**. Expect the header `agent (AGENT)` and the home heading "What would you like to do?" | E18, E21 | +| 2:20 | Look up Amina. She is the seeded active customer, `CUS-1001`. | Click **Look up a customer**. Search `Amina`. Click **Search**. Open **Profile** on the `CUS-1001` row. Expect name Amina Khan, id `CUS-1001`, status ACTIVE. | E04, E27 | +| 3:20 | An agent does not get a Close button. The line on the page is only a hint. The API is what blocks it. We will show the 403 at the end so we do not close Ravi by mistake. | Point at `Only an ADMIN can close a customer.` (`data-testid="close-requires-admin"`). Do not hunt for a button. | E19, E21 | +| 4:00 | Record a note. The app sends correlation `lab-request-001` on API calls. | Click **Record an interaction**. Type `NOTE` if it is not already selected. Summary: `Resolved login question`. Click create. Expect the detail page for a new id, customer `CUS-1001`. | E03, E09 | +| 5:15 | The row is in Postgres. That is the source of truth. | Script step 4 (steps 1-3 are health, seed rows, sign-in; press Enter through them). Or run the SQL in `demo-validation.md` for `lab-request-001`. Expect `CUS-1001`, `NOTE`, that correlation, visible true. | E04, E11 | +| 6:15 | After commit we publish `CustomerInteractionRecorded` on `crm.customer.interactions.v1`. The summary is not in the event. | In the backend terminal, find `Publishing` and `Applied` with `correlationId=lab-request-001`. If the terminal is not on screen, script step 5 runs the kafka-console-consumer. Point at `correlationId` and `customerId`. | E10, E09 | +| 7:15 | Bad input does not get a stack trace. It gets Problem Details. The form's dropdown cannot send a bad type, so this one is a curl. | Script step 6. It sends `POST /api/v1/interactions` type `TEXT`, header `X-Correlation-Id: lab-request-001`. Expect **400**, `detail` `Validation failed`, `errors` mentioning CALL, EMAIL, NOTE, or MEETING. | E05, `defense/notes/failure-experiments.md` | +| 8:15 | Same agent, close Ravi. The UI hid the button. The API still says no. | Script step 7. It sends `DELETE /api/v1/customers/CUS-1002` with the agent token and `X-Correlation-Id: lab-request-001`. Expect **403**, `detail` `Your role does not allow this action.`, and the correlation echoed. Then it reads Ravi back and shows `Ravi is still PROSPECT`. | E19, E20 | +| 9:15 | Optional if you are ahead: `CUS-9999` is not a customer. | Script step 8, `GET /api/v1/customers/CUS-9999`. Expect **404** `Unknown customer: CUS-9999`. Step 9 (fake token, **401**) follows. Skip both if you are past 9:30. | E02 | +| 9:30 | CI on main run 39777251733 (merge of PR #25, `ebda5ed`) passed. Frontend 56 tests, backend 99. Images were pushed by digest. Trivy wrote reports and did not fail the job. CodeQL passes on main now. | Open the Actions run. Read the two digest lines. Do not open a kubeconfig. | E23, E31, E35, E39 | +| 10:20 | We have not deployed. The class fixes are on `feature/k3s-class-deploy`, not main. Rollback is a new deploy of the previous digests, or `kubectl rollout undo` after a real rollout. Neither has been run. | Show `defense/notes/deployment-gap.md` or the rollback section of `docs/capstone-cicd-runbook.md`. | E06, E33, E37, E38 | +| 10:50 | What we can stand behind is the slice, the tests, and the digests. What we cannot stand behind is a running cluster. Next step is the student namespace, then smoke `CUS-1001`. | Stop. Leave the profile or the Actions tab up for questions. `unset TOKEN`. | E07, E08 | + +## Controlled failure + +The 8:15 beat is the one we keep if we have to cut. 403, correlation echoed, Ravi unchanged. + +If that call fails because the API is down, read the saved 403 body in `defense/notes/walkthrough-run.txt` (step 7, Oct 22) or `defense/notes/failure-experiments.md` (Oct 21). Say it was captured on this laptop, not on the cluster. + +## If you are long at 7:00 + +Drop the architecture sentence you already said, drop `CUS-9999`, and keep sign-in, Amina, the note, the 403, and the digest. Do not drop the 403. + +## Close, if they ask "one more week" + +Get the kubeconfig, deploy the class overlay, smoke CUS-1001, and only then practice rollback. Until that smoke line exists, the deploy slide stays a plan. diff --git a/defense/demo-walkthrough.sh b/defense/demo-walkthrough.sh new file mode 100755 index 0000000..271b45e --- /dev/null +++ b/defense/demo-walkthrough.sh @@ -0,0 +1,130 @@ +#!/usr/bin/env bash +# Northstar CRM demo walkthrough. Press Enter to move between steps. +# Usage, from the repo root: bash defense/demo-walkthrough.sh +# Run it AFTER you saved the note in the UI. +# Nothing here changes data except the 400/403 attempts, which the API rejects. + +API="${API:-http://localhost:8081}" +CID="lab-request-001" +AUTO="${AUTO:-0}" # AUTO=1 skips the pauses (for testing) + +bold=$(tput bold 2>/dev/null); dim=$(tput dim 2>/dev/null) +green=$(tput setaf 2 2>/dev/null); red=$(tput setaf 1 2>/dev/null) +blue=$(tput setaf 4 2>/dev/null); reset=$(tput sgr0 2>/dev/null) + +step() { echo; echo "${bold}${blue}== $1 ==${reset}"; echo "$2"; } +show() { echo "${dim}\$ $1${reset}"; } +ok() { echo "${green}✔ $1${reset}"; } +bad() { echo "${red}✘ $1${reset}"; } +pause() { [ "$AUTO" = "1" ] && return; echo; read -r -p "${dim}Press Enter to continue...${reset}" _; } +pretty(){ python3 -m json.tool 2>/dev/null || cat; } +psqlq() { docker exec crm-postgres psql -U crm -d crm -At -c "$1"; } + +# call METHOD PATH [JSON]: prints status + pretty body, sets $STATUS and $BODY +call() { + local method="$1" path="$2" data="$3" + local args=(-sS -o /tmp/demo_body.$$ -w '%{http_code}' -X "$method" "$API$path" + -H "X-Correlation-Id: $CID") + [ -n "$TOKEN" ] && args+=(-H "Authorization: Bearer $TOKEN") + [ -n "$data" ] && args+=(-H 'Content-Type: application/json' -d "$data") + STATUS=$(curl "${args[@]}") + BODY=$(cat /tmp/demo_body.$$); rm -f /tmp/demo_body.$$ + echo "HTTP ${bold}$STATUS${reset}" + [ -n "$BODY" ] && echo "$BODY" | pretty +} + +trap 'unset TOKEN' EXIT + +# --------------------------------------------------------------- +step "1. Is the app up?" "Checking the API's readiness endpoint." +show "curl $API/actuator/health/readiness" +if curl -sS "$API/actuator/health/readiness" | grep -q '"UP"'; then + ok "API is up" +else + bad "API is not answering. Start the backend first (see defense/notes/demo-commands.md)."; exit 1 +fi +pause + +# --------------------------------------------------------------- +step "2. Our two test customers" "Amina should be ACTIVE, Ravi should be PROSPECT." +show "SELECT public_id, full_name, status FROM customer ..." +docker exec crm-postgres psql -U crm -d crm -c \ + "SELECT public_id, full_name, status FROM customer WHERE public_id IN ('CUS-1001','CUS-1002') ORDER BY public_id;" +SEEDS=$(psqlq "SELECT string_agg(public_id || '=' || status, ',' ORDER BY public_id) FROM customer WHERE public_id IN ('CUS-1001','CUS-1002');") +[ "$SEEDS" = "CUS-1001=ACTIVE,CUS-1002=PROSPECT" ] && ok "Amina is ACTIVE, Ravi is PROSPECT" || bad "Seed rows look wrong: $SEEDS" +pause + +# --------------------------------------------------------------- +step "3. Sign in as the agent" "The token stays in this shell only. It is never printed." +if [ -z "$DEMO_PASSWORD" ]; then + read -r -s -p "agent password: " DEMO_PASSWORD; echo +fi +show "POST $API/api/v1/auth/login (user: agent)" +TOKEN=$(curl -sS -X POST "$API/api/v1/auth/login" -H 'Content-Type: application/json' \ + -d "{\"username\":\"agent\",\"password\":\"$DEMO_PASSWORD\"}" \ + | python3 -c 'import json,sys; print(json.load(sys.stdin).get("accessToken",""))' 2>/dev/null) +unset DEMO_PASSWORD +if [ -n "$TOKEN" ]; then ok "Signed in as agent (token good for 15 minutes)"; else bad "Login failed"; exit 1; fi +pause + +# --------------------------------------------------------------- +step "4. The note is in Postgres" "Postgres is the source of truth. Looking for correlation $CID." +show "SELECT ... FROM customer_interaction WHERE correlation_id = '$CID'" +docker exec crm-postgres psql -U crm -d crm -c \ + "SELECT c.public_id, i.interaction_type, i.correlation_id, i.deleted_at IS NULL AS visible + FROM customer_interaction i JOIN customer c ON c.customer_id = i.customer_id + WHERE i.correlation_id = '$CID' ORDER BY i.created_at DESC LIMIT 3;" +NOTES=$(psqlq "SELECT count(*) FROM customer_interaction i JOIN customer c ON c.customer_id = i.customer_id + WHERE i.correlation_id = '$CID' AND c.public_id = 'CUS-1001' AND i.interaction_type = 'NOTE' AND i.deleted_at IS NULL;") +[ "${NOTES:-0}" -gt 0 ] && ok "Found a visible NOTE for CUS-1001" || bad "No visible NOTE for CUS-1001 yet. Save one in the UI first." +pause + +# --------------------------------------------------------------- +step "5. The event went out on Kafka" "After the save, we publish CustomerInteractionRecorded. The summary is NOT in the event." +show "kafka-console-consumer --topic crm.customer.interactions.v1" +docker exec crm-kafka /opt/kafka/bin/kafka-console-consumer.sh \ + --bootstrap-server localhost:9092 --topic crm.customer.interactions.v1 \ + --from-beginning --timeout-ms 8000 2>/dev/null | grep "$CID" | grep 'CUS-1001' | tail -1 > /tmp/demo_event.$$ +if [ -s /tmp/demo_event.$$ ]; then pretty < /tmp/demo_event.$$; ok "Event found for CUS-1001"; else bad "No event found for $CID"; fi +rm -f /tmp/demo_event.$$ +pause + +# --------------------------------------------------------------- +step "6. Bad input gets a clean error" "Sending a type of TEXT, which isn't allowed. Expect 400, not a stack trace." +show "POST $API/api/v1/interactions {interactionType: TEXT}" +call POST /api/v1/interactions \ + "{\"customerId\":\"CUS-1001\",\"interactionType\":\"TEXT\",\"summary\":\"bad type\",\"correlationId\":\"$CID\"}" +[ "$STATUS" = "400" ] && ok "Rejected with 400" || bad "Expected 400, got $STATUS" +pause + +# --------------------------------------------------------------- +step "7. An agent tries to close Ravi" "The UI already hides the Close button. This goes straight at the API. Expect 403." +show "DELETE $API/api/v1/customers/CUS-1002 (as agent)" +call DELETE /api/v1/customers/CUS-1002 +[ "$STATUS" = "403" ] && ok "Blocked with 403" || bad "Expected 403, got $STATUS" +echo +echo "And Ravi didn't change:" +show "GET $API/api/v1/customers/CUS-1002" +call GET /api/v1/customers/CUS-1002 >/dev/null +RAVI=$(echo "$BODY" | python3 -c 'import json,sys; print(json.load(sys.stdin).get("status",""))' 2>/dev/null) +[ "$RAVI" = "PROSPECT" ] && ok "Ravi is still PROSPECT" || bad "Ravi status is '$RAVI'" +pause + +# --------------------------------------------------------------- +step "8. Unknown customer" "Optional. Expect 404." +show "GET $API/api/v1/customers/CUS-9999" +call GET /api/v1/customers/CUS-9999 +[ "$STATUS" = "404" ] && ok "404 as expected" || bad "Expected 404, got $STATUS" + +pause + +# --------------------------------------------------------------- +step "9. A fake token" "No real sign-in, no access. Expect 401." +show "GET $API/api/v1/customers/CUS-1001 (Authorization: Bearer not-a-real-jwt)" +REAL="$TOKEN"; TOKEN="not-a-real-jwt" +call GET /api/v1/customers/CUS-1001 +TOKEN="$REAL"; unset REAL +[ "$STATUS" = "401" ] && ok "Rejected with 401" || bad "Expected 401, got $STATUS" + +echo +ok "Demo done. Token cleared." diff --git a/defense/evidence-index.md b/defense/evidence-index.md new file mode 100644 index 0000000..dd00302 --- /dev/null +++ b/defense/evidence-index.md @@ -0,0 +1,98 @@ +# Evidence index + +Paths are from the repo root. Checked 2026-10-21 while writing this pack. CI rows refreshed 2026-10-22. +`main` is `ebda5ed` (PR #25, merged 2026-10-22 12:18Z / 8:18 AM ET). It includes PRs #23-#26. +This branch is `defense/lab52-pack` (Lab 48 docs, then that `main` merged in). + +Every slide in `defense/final-presentation-outline.md` uses an ID from this table. + +## Minimum rows from the lab guide + +| ID | Claim | Artifact | Lab | Scrubbed? | +| --- | --- | --- | --- | --- | +| E01 | C4-style context (one file, not a `docs/architecture/` folder) | `docs/architecture.md` | 48 | Y | +| E02 | CAP-12 acceptance | `docs/backlog.md` (status: done) | 48 | Y | +| E03 | Interaction API | `docs/lab49/backend-demo.md`, `backend/src/test/java/com/northstar/crm/api/InteractionApiIT.java` | 49 | Y | +| E04 | UI to PostgreSQL | `docs/lab50/frontend-persistence-demo.md` (2026-10-20 browser note; auth steps in that file are old). Seed rows: `backend/src/main/resources/db/migration/V1__crm_schema.sql` | 50 | Y | +| E05 | JWT deny (401 / 403) | `docs/lab51/security-and-observability.md`, `backend/src/test/java/com/northstar/crm/security/SecurityIT.java` (17 tests), `defense/notes/failure-experiments.md` | 51 | Y | +| E06 | Rollback | `docs/capstone-cicd-runbook.md` section "Rollback". Not executed. Class steps: `feature/k3s-class-deploy` `docs/lab51/class-cluster-deploy.md` (not merged) | 51 | Y | +| E07 | NFRs | `docs/nfrs.md` | 48 | Y | +| E08 | Risk register | `docs/risk-register.md` (names an owner per line) | 48 | Y | +| E09 | Correlation `lab-request-001` | `frontend/src/app/core/correlation.interceptor.ts` (`LAB_CORRELATION_ID`). Header constant: `X-Correlation-Id` in `backend/src/main/java/com/northstar/crm/observability/CorrelationId.java` | 49-51 | Y | + +There is no `docs/architecture/` directory. E01 is the single architecture file plus the three ADRs below. + +## Planning + +| ID | Claim | Artifact | Lab | Scrubbed? | +| --- | --- | --- | --- | --- | +| E10 | Events after commit, no outbox | `docs/adrs/001-event-contract.md` | 48 | Y | +| E11 | PostgreSQL 16, Flyway, not Oracle | `docs/adrs/002-postgresql.md`, migrations `V1` `V2` `V3` under `backend/src/main/resources/db/migration/` | 48 | Y | +| E12 | Build once, deploy digests | `docs/adrs/003-github-actions-digest-promotion.md` | 48 | Y | +| E13 | Team roles | `docs/team-roles.md`. Brandon's piece is still "TBD" in that file | 48 | Y | +| E14 | AI usage plan | `docs/ai-usage-plan.md`. The "Must verify" boxes are still unchecked | 48 | Y | +| E15 | Four environments, approvals | `docs/environment-strategy.md`. Namespaces are placeholders | 48 | Y | +| E16 | Lab 48 index | `docs/lab48/README.md` | 48 | Y | + +## Security + +| ID | Claim | Artifact | Lab | Scrubbed? | +| --- | --- | --- | --- | --- | +| E17 | HS256, 15 min TTL, startup refuses a short or missing key | `backend/src/main/resources/application.yml` (`ttl` default `15m`), `SecurityConfig.jwtSigningKey` (32 byte minimum), `TokenService` | 51 | Y | +| E18 | Login and roles | `POST /api/v1/auth/login`. Users `agent` (AGENT) and `admin` (AGENT+ADMIN) in `application.yml`. BCrypt: `DemoUserDirectory` | 51 | Y | +| E19 | API is the boundary. Close/reopen needs ADMIN | `SecurityConfig` (`DELETE /api/v1/customers/**` is ADMIN). `CustomerService.update` throws if status moves to or from `CLOSED` without ADMIN. Commit `8e573e9` | 51 | Y | +| E20 | 401 vs 403 body | `ProblemDetailAuthHandlers` (fixed sentences, plus `correlationId`). Live probes in `defense/notes/failure-experiments.md` | 51 | Y | +| E21 | Angular keeps the token in memory. Guards are UX | `frontend/src/app/core/auth/auth-session.service.ts`, `auth.guard.ts`. Close button hidden for agents in `customer-detail-page.component.ts` | 51 | Y | + +## Tests and the laptop + +| ID | Claim | Artifact | Lab | Scrubbed? | +| --- | --- | --- | --- | --- | +| E22 | Backend verify, this machine, 2026-10-21 17:48 ET | `mvn -B clean verify` in `backend/`. `Tests run: 99, Failures: 0, Errors: 0, Skipped: 0`. `SecurityIT`: 17. BUILD SUCCESS. Docker Desktop 29.8.0, Java 21.0.12.1 | 49-51 | Y | +| E23 | CI counts on main | Capstone CI run [39777251733](https://github.com/WillCraig/CapstoneProjectBoot/actions/runs/39777251733) on `ebda5ed`. Backend job: `Tests run: 99` (`SecurityIT` 17). Frontend job: `TOTAL: 56 SUCCESS`. Earlier run 39649860445 on `0235018` had 99 and 43 | 51 | Y | +| E24 | Frontend unit tests, this machine, 2026-10-22 8:28 AM ET | `npm ci` then `npx ng test --watch=false --browsers=ChromeHeadless` on this branch. `TOTAL: 56 SUCCESS` (Chrome Headless 156, Node 26.8.1). Was 43 on Oct 21, before PRs #23-#26 | 50 | Y | +| E25 | Selenium happy path exists, not in CI | `frontend/e2e/crm-happy-path.e2e.mjs`, `frontend/e2e/README.md`. Last recorded pass: `reports/local-test-run-2026-10-21.md` (1 test, pass). Not re-run for this pack | 50 | Y | +| E26 | Local smoke, earlier the same day | `reports/local-test-run-2026-10-21.md` quotes `Smoke passed for CUS-1001 with correlation lab-request-001`. Script: `scripts/smoke-crm.sh`. Not re-run for this pack | 51 | Y | +| E27 | Seed customers on the laptop DB | 2026-10-21 query on the already-running `crm-postgres`: `CUS-1001` Amina Khan ACTIVE, `CUS-1002` Ravi Singh PROSPECT. Two extra local rows (`CUS-1003`, `CUS-1004`) are not in Flyway | 50 | Y | +| E28 | Duplicates | `V2__processed_event.sql`. `InteractionEventConsumerIT.duplicateDelivery_appliesOnlyOnce` | 49 | Y | +| E29 | Kafka down after commit | `defense/notes/failure-experiments.md` (isolated stack, 2026-10-21 17:52 ET) | 49 | Y | + +## CI, images, deploy + +| ID | Claim | Artifact | Lab | Scrubbed? | +| --- | --- | --- | --- | --- | +| E30 | PR jobs: frontend, backend, Trivy fs, images | `.github/workflows/capstone-ci.yml`. Trivy steps set `exit-code: "0"`. Images push only when `github.event_name == 'push'` | 51 | Y | +| E31 | Digests from run 39777251733 | `ghcr.io/willcraig/capstone-crm-backend@sha256:ae571851d8c74da1d3f279d421a3576b9d9e4520523a1411b4a48f3e55c9581d` and `ghcr.io/willcraig/capstone-crm-frontend@sha256:fa7e4cf7c53c36b83a867709ad8f72e2d983312c2e255c905fbe634f029a0ca1`. Copied from that run's "Record image IDs and registry digests" log | 51 | Y | +| E32 | JAR checksum from the same run (unchanged since 39649860445) | `3b260400cb99baef70f248018dc2e106333ff51cd87c715f6e6c17447810f7c7 crm-backend-0.0.1-SNAPSHOT.jar` (package-once job) | 51 | Y | +| E33 | Manual deploy workflow, dry-run default, never run | `.github/workflows/capstone-deploy.yml` (`dry_run` default `true`). `gh run list --workflow capstone-deploy.yml` returned no runs | 51 | Y | +| E34 | Branch protection does not require the CI jobs | `GET /repos/WillCraig/CapstoneProjectBoot/branches/main/protection` on 2026-10-21: `required_status_checks` is null. One approving review is required (`required_approving_review_count` 1) | 51 | Y | +| E35 | CodeQL passes on main | `.github/workflows/codeql.yml`. Run [39777251809](https://github.com/WillCraig/CapstoneProjectBoot/actions/runs/39777251809) on `ebda5ed` passed and logged `Successfully uploaded results`. Every CodeQL run since 2026-10-21 23:27Z passes. Before that it failed at upload, e.g. run [39670104483](https://github.com/WillCraig/CapstoneProjectBoot/actions/runs/39670104483): `Code scanning is not enabled for this repository.` | 51 | Y | +| E36 | Repo visibility at check time | `gh repo view` on 2026-10-21 returned `visibility: PUBLIC`. Still PUBLIC on 2026-10-22. When it changed was not looked up | 51 | Y | +| E37 | Class cluster work is not on main | Branch `feature/k3s-class-deploy`, 4 commits ahead of `0235018`: `f679691` numeric UID 10001, `060e886` class overlay + `scripts/deploy-class.sh`, `078e15a` deploy workflow class target, `2c121c3` `docs/lab51/class-cluster-deploy.md` | 51 | Y | +| E38 | No kubeconfig here | `~/.kube/config` absent. `kubectl config current-context` -> `current-context is not set`. Student number not confirmed | 51 | Y | +| E39 | Trivy does not fail the build | `exit-code: "0"` in E30. Runbook baseline (2026-10-20, not re-counted today): 44 fixable HIGH/CRITICAL on the backend image, 53 on the frontend. `docs/capstone-cicd-runbook.md` | 51 | Y | +| E40 | Merged UI PRs | #23 confetti, #24 show/hide password, #26 accessibility, #25 responsive layout. All on `main` at `ebda5ed`, and in this branch | 50 | Y | +| E41 | How to start and fall back | `README.md` "Run it locally". `defense/notes/demo-validation.md`, `defense/notes/fallback-pack.md`, `defense/notes/deployment-gap.md` | 52 | Y | +| E42 | Demo failures in one script | `defense/demo-walkthrough.sh` (health, seeds, sign-in, row, event, 400, 403, 404, 401). Green run on this laptop 2026-10-22: `defense/notes/walkthrough-run.txt`. Commands by hand: `defense/notes/demo-commands.md`. Recording steps: `defense/notes/demo-recording-guide.md` | 52 | Y | + +GHCR package visibility was not checked. `gh api /users/WillCraig/packages` returned 403 (`read:packages` is not on this token). + +## Non-claims / limitations + +We will not say these are done: + +- A cluster deploy. Capstone Deploy has no runs. `~/.kube/config` is not on this machine. The class overlay is not merged. +- A rollback. The commands are written. Nothing has been rolled back. +- CodeQL findings. The check passes now (E35). We have not read the alert list. +- Trivy as a gate. It uploads a report and exits 0. A green CI run does not mean zero highs. +- Selenium in CI. It is a local script. The Oct 21 note says it passed once. We did not re-run it for this pack. +- Browser click-through today. API reads of Amina and Ravi were done. The Angular pages were not driven. +- OpenShift. The brief names it. We ship k3s manifests. `docs/architecture.md` says ask the instructor. +- Required CI checks. Protection requires a review. It does not require the Capstone CI jobs. +- GitHub Environments, reviewers, and deploy secrets. Named in the runbook. Not verified as created. +- An outbox. Kafka down still returned 201 and kept the row. See E29. +- Confetti and show-password are merged (E40) but are not demo beats. +- `final-presentation.pdf`. Not in the repo. Slides come from the outline. +- A rehearsed demo or a fallback video. Script only. +- Brandon's scope. `docs/team-roles.md` still says TBD. +- Speaker and operator. Not named in the repo. diff --git a/defense/feedback-log.md b/defense/feedback-log.md new file mode 100644 index 0000000..84d12ba --- /dev/null +++ b/defense/feedback-log.md @@ -0,0 +1,7 @@ +# Feedback log + +Panel is Thu/Fri Oct 22-23, 2026. No questions yet. + +| # | Question / feedback | Owner | Due | Done | +| - | --- | --- | --- | --- | +| 1 | | | | [ ] | diff --git a/defense/final-presentation-outline.md b/defense/final-presentation-outline.md new file mode 100644 index 0000000..cadb287 --- /dev/null +++ b/defense/final-presentation-outline.md @@ -0,0 +1,134 @@ +# Final presentation outline + +11 slides. No PDF in the repo. Build the deck from this file. +Speaker on every slide: TBD. About 12 minutes of talking, then the demo is its own block inside slide 5, then questions. +Evidence IDs are in `defense/evidence-index.md`. No claim without an ID. + +## 1. Users and the problem + +- Service agents look up a customer and write down the call, email, or note. +- Northstar CRM is that slice, not a full CRM. +- Synthetic people only: Amina Khan `CUS-1001`, Ravi Singh `CUS-1002`. +- Success for the slice is CAP-12. + +Evidence: E01, E02 + +Speaker notes: Start with the agent, not the tools. One sentence on who uses it and what "done" means. Point at Amina so the demo later is the same person. + +## 2. What we are willing to call done + +- Note saved for `CUS-1001`, row in Postgres, one `CustomerInteractionRecorded` event. +- Unknown id `CUS-9999` does not write a row. +- Admin closes a customer. An agent cannot. +- Cluster deploy is not in the done column. + +Evidence: E02, E07, E08 + +Speaker notes: Read the done list, then say the deploy line out loud so we do not get caught later. The NFR page is where the unmet rollback target lives. + +## 3. Architecture, from the ADRs + +- Angular 19 calls Spring Boot 3.3 on Java 21. +- JWT at the API. Postgres 16 is the record. Flyway V1-V3. +- Kafka after the commit. Topics `crm.customer.interactions.v1` and `crm.customer.lifecycle.v1`. +- No outbox. A down broker can drop the event. +- GitHub Actions builds once. The deploy unit is the digest. Target cluster is k3s, not OpenShift, until someone says otherwise. + +Evidence: E01, E10, E11, E12 + +Speaker notes: Three decisions, not a tool tour. Postgres because that is the course database and the tests use it. Kafka after commit so a rollback does not publish. Digests so we do not rebuild on the way to the cluster. Mention OpenShift as an open question, not as a feature. + +## 4. The slice, before we click + +- Sign in as `agent`. +- Search Amina, open `CUS-1001`. +- Record a NOTE. Correlation `lab-request-001`. +- Show the SQL row and the Kafka line. +- Then a 400 and a 403. Those are curls, on purpose. + +Evidence: E03, E04, E09, E21 + +Speaker notes: Tell them the path so a missed click is not a surprise. Say the close button will be missing for the agent and that the 403 comes from curl. The form cannot submit a bad interaction type. + +## 5. Live demo + +- Follow `defense/demo-script.md`. About 11 minutes. +- Speaker talks. Operator drives. Names are TBD. +- If the API dies, use `defense/notes/fallback-pack.md`. +- Keep the 403 even if we cut the 404. + +Evidence: E05, E27, E29, demo script + +Speaker notes: Do not narrate every click. Say what the agent is trying to do, then let the operator catch up. The correlation id on the list page is the same id we will grep in the log. + +## 6. Security + +- `POST /api/v1/auth/login`. HS256. 15 minutes. No cookie. +- `agent` is AGENT. `admin` is AGENT and ADMIN. +- 401 if the token is missing or bad. 403 if the role is wrong. Both are Problem Details with `correlationId`. +- Close and reopen are ADMIN in `CustomerService` and, for DELETE, in `SecurityConfig`. Commit `8e573e9`. +- Angular stores the token in memory. The guard is UX. + +Evidence: E17, E18, E19, E20, E21 + +Speaker notes: Offer to show the 403 body, not the token. If they ask where validation happens, say `NimbusJwtDecoder` in `SecurityConfig`. If they ask about a stolen token, say it works until the 15 minutes are up. We have no revoke list. + +## 7. CI and the digests + +- Run 39777251733 on `ebda5ed`, pushed 2026-10-22 8:18 AM ET. Conclusion success. +- Frontend 56 tests and a prod build. Backend `mvn verify`, 99 tests, Postgres service plus Testcontainers. +- Trivy fs and image scans ran with `exit-code` 0. +- Images: backend `sha256:ae571851…581d`, frontend `sha256:fa7e4cf7…0ca1`. +- JAR sha256 `3b260400cb99…10f7c7` from the package-once job. +- CodeQL on that same push passed. It is a different workflow. + +Evidence: E23, E30, E31, E32, E35, E39 + +Speaker notes: Read the two digests slowly or point at them. Say green CI means tests passed and reports were uploaded. It does not mean Trivy found zero issues. CodeQL passes now. It failed until Oct 21 because code scanning was off. + +## 8. Deploy: not run, and the plan + +- Capstone Deploy has never been started. Dry-run is the default. It only accepts digests. +- No kubeconfig on this laptop. Student number not confirmed. +- Fixes for the class cluster are on `feature/k3s-class-deploy` (uid 10001, in-namespace Kafka, `deploy-class.sh`). +- Those manifests pin the digests from slide 7. +- Rollback is written. It has not been executed. + +Evidence: E06, E33, E37, E38 + +Speaker notes: This is the gap. Do not apologize for a full minute. State it, show the four commits, and say the next command is `STUDENT=studentNN DRY_RUN=true scripts/deploy-class.sh` once we have the yaml. `kubectl rollout undo` is the emergency path after a real deploy, not something we can demo today. + +## 9. What the evidence does not cover + +- No cluster smoke and no rollback. +- Trivy does not block. +- CodeQL passes, but we have not read its alert list. +- Selenium is local only. +- PR #23 (confetti) and PR #24 (show password) are open. They are not in this demo. +- Branch protection requires one review. It does not require the CI jobs. +- The laptop database has two extra customers. We will not use them. + +Evidence: E34, E35, E39, E40, E25, E27 + +Speaker notes: Pick three, not all of them, unless someone asks. The three that matter are deploy, Trivy exit 0, and CodeQL. The open PRs are so nobody thinks confetti is part of the defended build. + +## 10. Retro and next steps + +- Five actions in `defense/retrospective.md`. Each has a role and a measure. +- First one is the class deploy and the CUS-1001 smoke line. +- Then a recorded fallback, required CI checks, a CodeQL decision, and a Trivy fail-after-upgrade. +- Kafka without an outbox stays an accepted risk until the backend role builds one. + +Evidence: E08, E10, retro + +Speaker notes: Do not read the whole retro. Say what we would do on Monday: kubeconfig, dry-run, deploy, smoke. Mention that we have not had the team retro meeting yet, so the actions are from the repo review. + +## 11. Questions + +- Answers are in `defense/technical-q-and-a.md`. +- If we do not know, say unknown and name the file or command we would check. +- Do not open `application-local.yml` or a kubeconfig. + +Evidence: Q&A file, E17, E29, E35 + +Speaker notes: Likely questions are JWT, Kafka down, why it is not deployed, CodeQL, and Trivy. The 403 curl can stay in a terminal. Unset the token before you sit down. diff --git a/defense/notes/demo-commands.md b/defense/notes/demo-commands.md new file mode 100644 index 0000000..d7ebe19 --- /dev/null +++ b/defense/notes/demo-commands.md @@ -0,0 +1,138 @@ +# Northstar CRM demo: commands, in order + +Run everything from the repo root on main (on this laptop: ~/TEK/CapstoneProjectBoot). API is http://localhost:8081, UI is http://localhost:4200 (use "localhost", not 127.0.0.1, for the UI). + +## 0. Before anyone walks in (about 10 min early) + +Check what is already running (don't start a second copy): + + docker ps --format '{{.Names}} {{.Status}}' + lsof -nP -iTCP:8081 -iTCP:4200 -sTCP:LISTEN + +If nothing is up, start it. Terminal 1: + + cd ~/TEK/CapstoneProjectBoot + git switch main && git pull + cp -n .env.example .env + docker compose up -d + +Terminal 2 (backend, leave it visible, the Kafka log lines show up here): + + cd ~/TEK/CapstoneProjectBoot/backend + SPRING_PROFILES_ACTIVE=local SERVER_PORT=8081 mvn spring-boot:run + +Terminal 3 (frontend): + + cd ~/TEK/CapstoneProjectBoot/frontend + npm ci + npx ng serve + +Health check (expect {"status":"UP"}): + + curl -sS http://localhost:8081/actuator/health/readiness; echo + +Fixture check (expect Amina ACTIVE, Ravi PROSPECT): + + docker exec crm-postgres psql -U crm -d crm -c "SELECT public_id, full_name, status FROM customer WHERE public_id IN ('CUS-1001','CUS-1002');" + +## 1. Get a token right before you start (it dies in 15 minutes) + +In the curl terminal. This asks for the password without showing it (the local agent password is in README.md): + + read -rs 'PW?agent password: '; echo + TOKEN=$(curl -sS -X POST http://localhost:8081/api/v1/auth/login \ + -H 'Content-Type: application/json' \ + -d "{\"username\":\"agent\",\"password\":\"$PW\"}" \ + | python3 -c 'import json,sys; print(json.load(sys.stdin)["accessToken"])') + unset PW + [ -n "$TOKEN" ] && echo "token ready" || echo "login failed" + +Never run `echo $TOKEN`. + +The script `bash defense/demo-walkthrough.sh` (run from the repo root) does steps 3 to 7 below in one go, with a check mark per step. Use the raw curls here if the script breaks. + +## 2. UI part (click, no commands) + +- http://localhost:4200/login, user agent, Sign in. Header should say "agent (AGENT)". +- Look up a customer, search Amina, open Profile on CUS-1001. +- Point at "Only an ADMIN can close a customer." +- Record an interaction: NOTE, summary "Resolved login question", create. + +## 3. Prove the note is in Postgres + + docker exec crm-postgres psql -U crm -d crm -c "SELECT c.public_id, i.interaction_type, i.correlation_id, i.deleted_at IS NULL AS visible FROM customer_interaction i JOIN customer c ON c.customer_id = i.customer_id WHERE i.correlation_id = 'lab-request-001' ORDER BY i.created_at DESC LIMIT 5;" + +Expect CUS-1001, NOTE, lab-request-001, visible = t. + +## 4. Prove the Kafka event went out + +First look at Terminal 2 for "Publishing" and "Applied" with correlationId=lab-request-001. If you need more: + + docker exec crm-kafka /opt/kafka/bin/kafka-console-consumer.sh \ + --bootstrap-server localhost:9092 \ + --topic crm.customer.interactions.v1 \ + --from-beginning --timeout-ms 8000 + +Point at correlationId and customerId. The summary is not in the event on purpose. + +## 5. Bad input gets a clean 400 + + curl -sS -i -X POST http://localhost:8081/api/v1/interactions \ + -H "Authorization: Bearer $TOKEN" \ + -H 'Content-Type: application/json' \ + -H 'X-Correlation-Id: lab-request-001' \ + -d '{"customerId":"CUS-1001","interactionType":"TEXT","summary":"bad type","correlationId":"lab-request-001"}' + +Expect 400, "Validation failed", and a message listing CALL, EMAIL, NOTE, MEETING. + +## 6. THE KEY MOMENT: agent tries to close Ravi, gets 403 + + curl -sS -i -X DELETE http://localhost:8081/api/v1/customers/CUS-1002 \ + -H "Authorization: Bearer $TOKEN" \ + -H 'X-Correlation-Id: lab-request-001' + +Expect 403, "Your role does not allow this action.", correlationId echoed. Then show Ravi didn't change: + + curl -sS http://localhost:8081/api/v1/customers/CUS-1002 \ + -H "Authorization: Bearer $TOKEN"; echo + +Expect status PROSPECT. + +Optional, same 403 through the "sneaky" route (edit status to CLOSED): + + curl -sS -i -X PUT http://localhost:8081/api/v1/customers/CUS-1002 \ + -H "Authorization: Bearer $TOKEN" \ + -H 'Content-Type: application/json' \ + -H 'X-Correlation-Id: lab-request-001' \ + -d '{"fullName":"Ravi Singh","status":"CLOSED"}' + +## 7. Optional extras (skip if past 9:30) + +Unknown customer, expect 404: + + curl -sS -i http://localhost:8081/api/v1/customers/CUS-9999 \ + -H "Authorization: Bearer $TOKEN" + +Fake token, expect 401: + + curl -sS -i http://localhost:8081/api/v1/customers/CUS-1001 \ + -H 'Authorization: Bearer not-a-real-jwt' + +## 8. CI and digests (browser) + +https://github.com/WillCraig/CapstoneProjectBoot/actions/runs/39777251733 +Read the two digest lines. Say "checks run on every PR" and "Trivy scans and saves a report". + +## 9. Deploy gap (file) + +Open defense/notes/deployment-gap.md. Not deployed yet; fix is on feature/k3s-class-deploy. + +## 10. Clean up + + unset TOKEN + +## If something breaks + +- UI dies: keep going with the curls above. +- API dies: stop typing, open defense/notes/fallback-pack.md and read the saved 403 from defense/notes/failure-experiments.md. +- Kafka console empty: "The DB row is the source of truth; the event can be late." diff --git a/defense/notes/demo-recording-guide.md b/defense/notes/demo-recording-guide.md new file mode 100644 index 0000000..52b9160 --- /dev/null +++ b/defense/notes/demo-recording-guide.md @@ -0,0 +1,61 @@ +# Demo recording guide (about 8–10 minutes) + +## Set up (2 minutes, before you hit record) + +1. Stack is running: open http://localhost:4200 (use "localhost", not 127.0.0.1). +2. Browser: one tab on http://localhost:4200/login, one tab on + https://github.com/WillCraig/CapstoneProjectBoot/actions/runs/39777251733 +3. Terminal at the repo root (`cd ~/TEK/CapstoneProjectBoot` on this laptop), font size bumped up (Cmd + a few times). + Optional: a second terminal running the backend so the log is visible. +4. Do Not Disturb on. Close Slack, Messages, Mail. +5. Have the agent password ready (README.md), but don't open README on screen. +6. Start recording: Cmd+Shift+5, Record Entire Screen, Options, pick your mic. + +## Part 1: the UI (about 4 minutes) + +| # | Do | Say | +|---|----|-----| +| 1 | Show the login page. | "Northstar CRM. Agents need one place to find a customer and log what happened on a call. Angular front end, Spring Boot API, Postgres, and Kafka." | +| 2 | Sign in as `agent`. Header shows `agent (AGENT)`. | "I'm signing in as an agent. The token is only kept in memory, so a refresh logs you out. The page isn't the security; the API is." | +| 3 | Click **Look up a customer**, type `Amina`, **Search**. | "Looking up our seeded customer, Amina Khan." | +| 4 | Click **Profile** on `CUS-1001`. Shows ACTIVE. | "Here's her profile: CUS-1001, active." | +| 5 | Point at "Only an ADMIN can close a customer." | "As an agent I don't get a Close button. That's just a hint in the UI; I'll show the API actually blocks it in a minute." | +| 6 | Click **Record an interaction**. Type NOTE, summary `Resolved login question`, create. | "Now I'll log the call as a note." | +| 7 | Detail page for the new interaction appears. | "It saved. Next I'll prove where it went." | + +Don't scroll the full customer list (there are extra test rows). Don't refresh the page. + +## Part 2: the script (about 4 minutes) + +In the terminal, from the repo root: + + bash defense/demo-walkthrough.sh + +Type the agent password when asked (it doesn't show). Press Enter between steps. + +| Step | What you'll see | Say | +|------|-----------------|-----| +| 1 App is up | ✔ API is up | "Quick health check." | +| 2 Test customers | Amina ACTIVE, Ravi PROSPECT | "Our two seeded customers. Remember Ravi is a prospect." | +| 3 Sign in | ✔ Signed in | "Same agent login from the terminal. The token is never printed." | +| 4 Note in Postgres | Top row: CUS-1001, NOTE, lab-request-001, **t** | "The note I just made is in Postgres. That's our source of truth. Older rows marked f are earlier test notes that were soft-deleted." | +| 5 Kafka event | JSON with customerId CUS-1001, NOTE, correlationId | "After the save we publish an event to Kafka. Notice the summary isn't in it, only IDs." | +| 6 Bad input | HTTP 400, "Validation failed" | "Bad input gets a clean error with the allowed types, not a stack trace." | +| 7 Close Ravi | HTTP 403, then ✔ Ravi is still PROSPECT | "This is the important one. Same agent tries to close Ravi straight through the API. 403, and Ravi didn't change. The rule lives on the server." | +| 8 Unknown customer | HTTP 404 | "Unknown customer, clean 404." | +| 9 Fake token | HTTP 401 | "And a fake token gets 401." | + +## Part 3: CI and what's left (about 1 minute) + +| Do | Say | +|----|-----| +| Switch to the Actions run tab. Scroll to the digest lines. | "CI on main: 56 frontend tests and 99 backend tests passed, including 17 security tests. CodeQL passes too. Trivy scans and saves a report. The images were pushed and we deploy them by digest, not a rebuild." | +| Stay there. | "What we haven't done is the deploy to the class cluster. The config is ready on a branch, feature/k3s-class-deploy; the next step is my student namespace, deploy those digests, and smoke test CUS-1001." | + +Stop recording (the stop button in the menu bar). Watch it once: no password or token visible, the 403 and "Ravi is still PROSPECT" are readable. + +## If something goes wrong while recording + +- A stumble: keep going. One honest take is fine. +- Login fails in the script: check the password and run the script again. +- API not up: start the backend (see demo-commands.md), then start the recording over. diff --git a/defense/notes/demo-validation.md b/defense/notes/demo-validation.md new file mode 100644 index 0000000..f0c418c --- /dev/null +++ b/defense/notes/demo-validation.md @@ -0,0 +1,139 @@ +# Demo validation notes + +Checked 2026-10-21 about 5:46-5:54 PM ET. A stack was already running. It was left running. + +| Port | What was already there | +| --- | --- | +| 5432 | container `crm-postgres` (healthy) | +| 9092 | container `crm-kafka` | +| 8081 | Java pid 42016, cwd `backend/` of the main checkout, `com.northstar.crm.CrmApplication` | +| 4200 | `ng serve --port 4200` (pid 46576), listening on `[::1]` only | + +Do not start a second compose project on 5432/9092, and do not `docker compose down` this one unless the team means to. + +## Start from scratch (README) + +From the repo root, with Docker Desktop running, JDK 21, Maven, Node: + +```bash +cp .env.example .env +docker compose up -d +``` + +Backend: + +```bash +cd backend +SPRING_PROFILES_ACTIVE=local SERVER_PORT=8081 mvn spring-boot:run +``` + +Frontend, other terminal: + +```bash +cd frontend +npm ci +npx ng serve +``` + +UI: http://localhost:4200 (this `ng serve` is on IPv6 localhost only; `http://127.0.0.1:4200` did not connect) +API: http://localhost:8081 + +The local profile is what supplies the signing key and the two demo passwords. Those values stay in `backend/src/main/resources/application-local.yml`. Do not paste them into slides. The password string is also written in `README.md`. + +CORS allows 4200 and 4201 only. Other Angular ports get a 403 on login. + +## Health + +```bash +curl -sS http://127.0.0.1:8081/actuator/health/readiness +curl -sS http://127.0.0.1:8081/actuator/health/liveness +``` + +Observed on the already-running API: readiness `200` and `{"status":"UP"}`. The response also echoed `X-Correlation-Id`. + +`http://localhost:4200/` returned 200 and `Northstar CRM`. `http://127.0.0.1:4200` did not connect. Use `localhost`. + +## Fixtures on that database + +```bash +docker exec crm-postgres psql -U crm -d crm -c \ + "SELECT public_id, full_name, status FROM customer ORDER BY public_id;" +``` + +Observed: + +| public_id | full_name | status | +| --- | --- | --- | +| CUS-1001 | Amina Khan | ACTIVE | +| CUS-1002 | Ravi Singh | PROSPECT | +| CUS-1003 | (extra local row, not in Flyway) | ACTIVE | +| CUS-1004 | (extra local row, not in Flyway) | CLOSED | + +Search **Amina** or **Ravi** so the extra rows stay off camera. Do not invent a new customer during the demo. + +`GET /api/v1/customers/CUS-1001` as `agent` returned Amina Khan, ACTIVE. +`GET /api/v1/customers/CUS-1002` returned Ravi Singh, PROSPECT. +`GET /api/v1/customers/CUS-9999` returned 404 `Unknown customer: CUS-9999`. + +## Smoke (do this before the panel if you want a fresh line) + +Against the laptop API, frontend skipped: + +```bash +CRM_BASE_URL=http://localhost:8081 \ +CRM_SMOKE_SKIP_FRONTEND=true \ +CRM_SMOKE_PASSWORD='<local agent password from README>' \ +bash scripts/smoke-crm.sh +``` + +Expected last line, from the script and from `reports/local-test-run-2026-10-21.md`: + +```text +Smoke passed for CUS-1001 with correlation lab-request-001 +``` + +Not re-run while writing this pack. The script creates a note and soft-deletes it. + +## Kafka console (path checked on `crm-kafka`) + +```bash +docker exec crm-kafka /opt/kafka/bin/kafka-console-consumer.sh \ + --bootstrap-server localhost:9092 \ + --topic crm.customer.interactions.v1 \ + --from-beginning --timeout-ms 8000 +``` + +The event has no summary field. It does have `correlationId` and `customerId`. + +## SQL after a demo note + +```bash +docker exec crm-postgres psql -U crm -d crm -c \ + "SELECT c.public_id, i.interaction_type, i.correlation_id, i.deleted_at IS NULL AS visible + FROM customer_interaction i + JOIN customer c ON c.customer_id = i.customer_id + WHERE i.correlation_id = 'lab-request-001' + ORDER BY i.created_at DESC + LIMIT 5;" +``` + +## Tests run for this pack + +Backend, worktree, 2026-10-21 17:48 ET: + +```text +mvn -B clean verify +Tests run: 99, Failures: 0, Errors: 0, Skipped: 0 +SecurityIT: Tests run: 17 +BUILD SUCCESS +``` + +Frontend, same worktree: + +```text +npm ci +npx ng test --watch=false --browsers=ChromeHeadless +TOTAL: 43 SUCCESS +``` + +CI on `0235018` (run 39649860445) reported the same 99 and 43. diff --git a/defense/notes/deployment-gap.md b/defense/notes/deployment-gap.md new file mode 100644 index 0000000..57684cc --- /dev/null +++ b/defense/notes/deployment-gap.md @@ -0,0 +1,38 @@ +# What we missed: deployment + +No cluster deploy has been run. + +- `.github/workflows/capstone-deploy.yml` is `workflow_dispatch` only, digest-only, `dry_run` default `true`. `gh run list --workflow capstone-deploy.yml` returned no runs. +- `~/.kube/config` is not on this machine. `kubectl config current-context` says `current-context is not set`. +- Student number is not in the repo and was not confirmed here. +- The manifests on `main` still use namespace placeholders and host `crm-dev.example.invalid` (`deploy/k3s/overlays/dev/kustomization.yaml`). The backend container sets `runAsNonRoot: true` but the image `USER` is the name `spring` (`backend/Dockerfile`). The class branch adds numeric uid 10001 because k3s cannot resolve that name. That change is not on `main`. +- GitHub Environments, variables, and secrets in the runbook were not verified. This `gh` token cannot list packages (`read:packages` missing), so GHCR visibility is unknown. + +## Work already on `feature/k3s-class-deploy` (not merged) + +Four commits on top of `0235018`: + +| Commit | What | +| --- | --- | +| `f679691` | `runAsUser` / `runAsGroup` 10001 | +| `060e886` | `deploy/k3s/overlays/class/` (Kafka in the namespace) and `scripts/deploy-class.sh` | +| `078e15a` | Deploy workflow: class target, no namespace create, smoke over HTTP | +| `2c121c3` | `docs/lab51/class-cluster-deploy.md` | + +The class overlay pins the digests from CI run 39649860445 (same values as evidence E31). Host pattern in that file: `http://crm-api-studentNN.32.189.172.33.nip.io/`. Postgres URL in the overlay points at `32.189.172.33:5432/bootcamp` with schema `crm_studentNN`. + +## Remaining steps + +Do these from a checkout of `feature/k3s-class-deploy`, not from `main` and not from this defense branch. Do not commit the kubeconfig, the DB password, or the GitHub token. + +1. Get `studentNN.yaml` from the instructor. Save it as `~/.kube/config`. `kubectl config current-context` must print `studentNN`. +2. Confirm the number. `scripts/deploy-class.sh` rejects anything that is not `student` plus two digits. +3. Get the class database username and password. +4. Get a GitHub token with `read:packages`, or confirm another way for the cluster to pull `ghcr.io/willcraig/capstone-crm-backend` and `capstone-crm-frontend`. Not confirmed from here. +5. Create `crm-secrets` and `ghcr-pull-secret` once, with the prompts in `docs/lab51/class-cluster-deploy.md`. The JWT value is `openssl rand -base64 48` at the prompt. Do not put it in git. +6. Dry run: `STUDENT=studentNN DRY_RUN=true scripts/deploy-class.sh`. Read the image lines. They should be the two digests from run 39649860445. +7. Deploy: `STUDENT=studentNN scripts/deploy-class.sh`. It applies, waits for `kafka`, `crm-backend`, and `crm-frontend`, and prints the nip.io URL. +8. Smoke: `CRM_BASE_URL=http://crm-api-$STUDENT.32.189.172.33.nip.io CRM_SMOKE_PASSWORD='<agent password>' bash scripts/smoke-crm.sh`. Expect `Smoke passed for CUS-1001 with correlation lab-request-001`. +9. Rollback only after a second deploy exists. Either `kubectl rollout undo deployment/crm-backend` and `deployment/crm-frontend`, or run `deploy-class.sh` again with the previous digests. Then smoke again. Flyway V1-V3 are additive. The runbook says older images still match this schema. That was not tried on a cluster. + +The GitHub **Capstone Deploy** workflow is the other path (Environments, approval, `dry_run: true` first). It has never been started. The class script is the one written for this cluster. diff --git a/defense/notes/failure-experiments.md b/defense/notes/failure-experiments.md new file mode 100644 index 0000000..276af31 --- /dev/null +++ b/defense/notes/failure-experiments.md @@ -0,0 +1,95 @@ +# Failure experiments + +Three were run on 2026-10-21. Tokens were not written down. The laptop API on port 8081 was already up (pid 42016). It was not restarted. The Kafka test used a second Postgres and Kafka on 15432 / 19092 and an API on 18081, then those were removed. + +## 1. Bad token -> 401 + +Against `http://127.0.0.1:8081`. + +`GET /api/v1/customers/CUS-1001` with `Authorization: Bearer not-a-real-jwt` and `X-Correlation-ID: defense-bad-token`. + +Result: **401** + +```json +{"type":"about:blank","title":"Unauthorized","status":401,"detail":"Bearer token is invalid or expired.","instance":"/api/v1/customers/CUS-1001","correlationId":"defense-bad-token"} +``` + +`WWW-Authenticate: Bearer error="invalid_token"`. + +A call with no `Authorization` header, earlier the same hour, was also **401**, detail `A bearer token is required.`, and `WWW-Authenticate: Bearer`. + +Matches `ProblemDetailAuthHandlers` and `SecurityIT.garbageToken_is401` / `noToken_is401ProblemDetail_withCorrelationId`. + +## 2. Agent close -> 403 + +Logged in as `agent` (roles `["AGENT"]`, `expiresIn` 900). Token not stored. + +`DELETE /api/v1/customers/CUS-1002` with `X-Correlation-ID: defense-agent-close`. + +Result: **403** + +```json +{"type":"about:blank","title":"Forbidden","status":403,"detail":"Your role does not allow this action.","instance":"/api/v1/customers/CUS-1002","correlationId":"defense-agent-close"} +``` + +`GET` before and after: Ravi Singh, status `PROSPECT`. The row did not change. + +Same session, `PUT /api/v1/customers/CUS-1002` body `{"fullName":"Ravi Singh","status":"CLOSED"}`, correlation `defense-agent-put-close`. + +Result: **403**, same detail sentence. Status still `PROSPECT`. + +The UI hides Close for an agent (`close-requires-admin`). The 403 is the API. `CustomerService` throws `AccessDeniedException` on a close/reopen PUT, and `ProblemDetailAuthHandlers` replaces that message with the fixed sentence above. `SecurityIT.agentClosingCustomerThroughPut_is403ProblemDetail_andRowUnchanged` expects that sentence. + +## 3. Kafka down at publish time + +Not run on the laptop's `crm-kafka`. That container was left up. + +Isolated compose project `crm-defense-exp`: Postgres `crm-defense-postgres` on 15432, Kafka `crm-defense-kafka` on 19092. Backend from this worktree: + +```text +SPRING_PROFILES_ACTIVE=local SERVER_PORT=18081 +SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:15432/crm +SPRING_KAFKA_BOOTSTRAP_SERVERS=localhost:19092 +``` + +Readiness on 18081: `{"status":"UP"}`. + +Broker up. `POST /api/v1/interactions` for `CUS-1001`, type `NOTE`, correlation `defense-kafka-up`. + +Result: **201**. Id `a1f52996-33b4-4448-aeee-38030d4305a6`. +SQL: one `customer_interaction` row, correlation `defense-kafka-up`. +`processed_event`: one row, `CustomerInteractionRecorded`, same correlation. +Log: `Publishing CustomerInteractionRecorded` then `Applied CustomerInteractionRecorded`, both with `correlationId=defense-kafka-up`. + +Then `docker stop crm-defense-kafka` only. + +`POST` again, correlation `defense-kafka-down`. + +Result: **201**. Id `037e7c89-7b8e-4809-b754-70e2051240b2`. +SQL: both interaction rows present. +`processed_event`: still only `defense-kafka-up`. No row for `defense-kafka-down`. +Log: `Publishing CustomerInteractionRecorded` with `correlationId=defense-kafka-down`, then producer and consumer lines `Node 1 disconnected` to `localhost:19092`. + +The API did not fail the request. The publisher calls `kafkaTemplate.send` after commit and does not wait on it (`InteractionEventPublisher`). About 40 seconds later the producer was still logging disconnects. We did not wait for the client to give up, and we did not start Kafka again, so this run does not prove the record is unrecoverable if the broker returns inside the producer timeout. It does prove a saved row with no consumer apply while the broker stays down. That is the gap in `docs/adrs/001-event-contract.md`. + +Cleanup: stopped the 18081 process, `docker compose -p crm-defense-exp down -v`. Ports 18081, 15432, and 19092 were free afterward. pid 42016 and `crm-postgres` / `crm-kafka` were still up. + +## Also seen, same laptop API (not the three above) + +`POST /api/v1/interactions` with `interactionType` `TEXT`, correlation `defense-invalid-type`: **400** + +```json +{"title":"Bad Request","status":400,"detail":"Validation failed","instance":"/api/v1/interactions","correlationId":"defense-invalid-type","errors":["interactionType: interactionType must be CALL, EMAIL, NOTE, or MEETING"]} +``` + +`POST` for `CUS-9999`: **404** `Unknown customer: CUS-9999`. + +## Not run + +| Experiment | Why | +| --- | --- | +| Kill the laptop API mid-rehearsal | That process belongs to the open demo. Use the fallback notes instead of stopping it. | +| Selenium `npm run e2e` | Needs port 4300 and a dedicated server. Last pass is the Oct 21 report, not this session. | +| `scripts/smoke-crm.sh` | Would write a row on the laptop DB. The Oct 21 report already quotes a pass. | +| Class cluster smoke | No kubeconfig. See `defense/notes/deployment-gap.md`. | +| CodeQL upload | Would mean changing GitHub settings. Not done. | diff --git a/defense/notes/fallback-pack.md b/defense/notes/fallback-pack.md new file mode 100644 index 0000000..3083272 --- /dev/null +++ b/defense/notes/fallback-pack.md @@ -0,0 +1,71 @@ +# Fallback pack + +Use this when the live click-through breaks. One person calls the switch. Do not argue in front of the panel. + +Say this: + +> The live cluster is not deployed. We are switching to the laptop API. If that is down too, we use the notes in defense/notes and the Capstone CI run 39649860445, plus the Lab 50 SQL note for CUS-1001. Here is what that evidence does and does not prove. + +What it proves: the slice ran on a laptop (health, login, CUS-1001, a saved interaction, a Kafka apply when the broker was up, 401 and 403). CI on `0235018` built images and printed digests. + +What it does not prove: a pod on the class cluster, an Ingress smoke, or a rollback. + +## When to switch + +| What broke | Switch to | +| --- | --- | +| UI on 4200 | API curls below. Say the page is down. | +| API on 8081 | Stop curling. Open this file and `reports/local-test-run-2026-10-21.md`. | +| Kafka console empty | The DB row is the source of truth (`docs/adrs/001-event-contract.md`). Say the event may be late or lost. | +| Projector or login | Read the CI digest lines and the 403 body in `failure-experiments.md`. | + +No screenshot folder. The lab said not to commit screenshots, and none were taken. + +## Checklist (open these before the panel) + +- [ ] This file +- [ ] `defense/notes/failure-experiments.md` (401 and 403 bodies) +- [ ] `defense/notes/demo-validation.md` +- [ ] `reports/local-test-run-2026-10-21.md` (smoke line and Selenium line) +- [ ] `docs/lab50/frontend-persistence-demo.md` SQL section (dated 2026-10-20, old demo token) +- [ ] Actions run https://github.com/WillCraig/CapstoneProjectBoot/actions/runs/39649860445 +- [ ] `docs/capstone-cicd-runbook.md` rollback section +- [ ] `defense/notes/deployment-gap.md` + +## Curls if the UI dies and the API is still up + +Get a token in the shell. Do not echo it. + +```bash +TOKEN=$(curl -sS -X POST http://127.0.0.1:8081/api/v1/auth/login \ + -H 'Content-Type: application/json' \ + -d '{"username":"agent","password":"<from README>"}' \ + | python3 -c 'import json,sys; print(json.load(sys.stdin)["accessToken"])') + +curl -sS -H "Authorization: Bearer $TOKEN" \ + http://127.0.0.1:8081/api/v1/customers/CUS-1001 + +curl -i -X POST http://127.0.0.1:8081/api/v1/interactions \ + -H "Authorization: Bearer $TOKEN" \ + -H 'Content-Type: application/json' \ + -H 'X-Correlation-Id: lab-request-001' \ + -d '{"customerId":"CUS-1001","interactionType":"NOTE","summary":"Resolved login question","correlationId":"lab-request-001"}' +``` + +Expect 201, then the SQL in `demo-validation.md`. + +Deny, still as agent: + +```bash +curl -i -X DELETE http://127.0.0.1:8081/api/v1/customers/CUS-1002 \ + -H "Authorization: Bearer $TOKEN" \ + -H 'X-Correlation-Id: lab-request-001' +``` + +Expect 403 and Ravi still `PROSPECT`. + +`unset TOKEN` when you are done. + +## If they ask for a cluster command + +`kubectl` on this machine has no current context. Do not run `rollout undo` against nothing. Show the command in the runbook and say it has not been run. diff --git a/defense/notes/walkthrough-run.txt b/defense/notes/walkthrough-run.txt new file mode 100644 index 0000000..d2c136c --- /dev/null +++ b/defense/notes/walkthrough-run.txt @@ -0,0 +1,117 @@ +# bash defense/demo-walkthrough.sh, AUTO=1, run 2026-10-22 08:26 ET +# Local stack: backend from this branch on 8081, crm-postgres, crm-kafka. Colors stripped. No token or password in this file. +# The NOTE was created through the API with X-Correlation-Id lab-request-001 just before (same as saving it in the UI). + +== 1. Is the app up? == +Checking the API's readiness endpoint. +$ curl http://localhost:8081/actuator/health/readiness +✔ API is up + +== 2. Our two test customers == +Amina should be ACTIVE, Ravi should be PROSPECT. +$ SELECT public_id, full_name, status FROM customer ... + public_id | full_name | status +-----------+------------+---------- + CUS-1001 | Amina Khan | ACTIVE + CUS-1002 | Ravi Singh | PROSPECT +(2 rows) + +✔ Amina is ACTIVE, Ravi is PROSPECT + +== 3. Sign in as the agent == +The token stays in this shell only. It is never printed. +$ POST http://localhost:8081/api/v1/auth/login (user: agent) +✔ Signed in as agent (token good for 15 minutes) + +== 4. The note is in Postgres == +Postgres is the source of truth. Looking for correlation lab-request-001. +$ SELECT ... FROM customer_interaction WHERE correlation_id = 'lab-request-001' + public_id | interaction_type | correlation_id | visible +-----------+------------------+-----------------+--------- + CUS-1001 | NOTE | lab-request-001 | t + CUS-1001 | NOTE | lab-request-001 | f + CUS-1001 | NOTE | lab-request-001 | f +(3 rows) + +✔ Found a visible NOTE for CUS-1001 + +== 5. The event went out on Kafka == +After the save, we publish CustomerInteractionRecorded. The summary is NOT in the event. +$ kafka-console-consumer --topic crm.customer.interactions.v1 +{ + "eventId": "616fcea8-5bb7-4073-80c3-0c237899422b", + "eventType": "CustomerInteractionRecorded", + "eventVersion": 1, + "occurredAt": 1792671988.857309, + "correlationId": "lab-request-001", + "actor": "agent", + "customerId": "CUS-1001", + "interactionId": "7b0e9103-5f24-444b-bc60-8306b1c53479", + "interactionType": "NOTE" +} +✔ Event found for CUS-1001 + +== 6. Bad input gets a clean error == +Sending a type of TEXT, which isn't allowed. Expect 400, not a stack trace. +$ POST http://localhost:8081/api/v1/interactions {interactionType: TEXT} +HTTP 400 +{ + "type": "about:blank", + "title": "Bad Request", + "status": 400, + "detail": "Validation failed", + "instance": "/api/v1/interactions", + "errors": [ + "interactionType: interactionType must be CALL, EMAIL, NOTE, or MEETING" + ], + "correlationId": "lab-request-001" +} +✔ Rejected with 400 + +== 7. An agent tries to close Ravi == +The UI already hides the Close button. This goes straight at the API. Expect 403. +$ DELETE http://localhost:8081/api/v1/customers/CUS-1002 (as agent) +HTTP 403 +{ + "type": "about:blank", + "title": "Forbidden", + "status": 403, + "detail": "Your role does not allow this action.", + "instance": "/api/v1/customers/CUS-1002", + "correlationId": "lab-request-001" +} +✔ Blocked with 403 + +And Ravi didn't change: +$ GET http://localhost:8081/api/v1/customers/CUS-1002 +✔ Ravi is still PROSPECT + +== 8. Unknown customer == +Optional. Expect 404. +$ GET http://localhost:8081/api/v1/customers/CUS-9999 +HTTP 404 +{ + "type": "about:blank", + "title": "Not Found", + "status": 404, + "detail": "Unknown customer: CUS-9999", + "instance": "/api/v1/customers/CUS-9999", + "correlationId": "lab-request-001" +} +✔ 404 as expected + +== 9. A fake token == +No real sign-in, no access. Expect 401. +$ GET http://localhost:8081/api/v1/customers/CUS-1001 (Authorization: Bearer not-a-real-jwt) +HTTP 401 +{ + "type": "about:blank", + "title": "Unauthorized", + "status": 401, + "detail": "Bearer token is invalid or expired.", + "instance": "/api/v1/customers/CUS-1001", + "correlationId": "lab-request-001" +} +✔ Rejected with 401 + +✔ Demo done. Token cleared. diff --git a/defense/retrospective.md b/defense/retrospective.md new file mode 100644 index 0000000..c575108 --- /dev/null +++ b/defense/retrospective.md @@ -0,0 +1,38 @@ +# Retrospective + +Blameless. The panel is Thu/Fri Oct 22-23, 2026. This is from the repo and the checks on Oct 21, not from a facilitated meeting. Team to confirm anything we got wrong. + +## Went well + +- CAP-12 is on `main`: login, lookup, a saved interaction, a Kafka event after commit, tests around it. +- Auth is a real JWT. Agent close is 403 in `SecurityIT` and on the laptop API. The UI hide is not the only control. +- One Capstone CI run on `0235018` published both image digests. +- The Lab 48 docs on this branch match the system we actually built (Postgres, Kafka after commit, digest deploy). + +## What got in the way + +- The class-cluster fixes never landed on `main`. Main still has placeholder hosts. The numeric uid and the in-namespace Kafka are four commits to the side. +- Nobody on this machine has `~/.kube/config`. The deploy workflow has no runs. We kept writing the happy path while the cluster step waited on an instructor file. +- Capstone CI can be green in the same minute CodeQL is red. Branch protection does not require either check. A red scan does not stop a merge, and a green scan does not mean the image is clean, because Trivy exits 0. +- `docs/team-roles.md` still says Brandon's piece is TBD. Speaker and operator are not named. The demo script cannot assign itself. +- We accepted no outbox. The Oct 21 Kafka stop showed a 201 with no `processed_event` row. That is the trade-off we wrote down, and it is still open. + +## Actions + +| Action | Owner | Due | Success measure | +| --- | --- | --- | --- | +| Put the class overlay on the branch we deploy, get `studentNN.yaml` onto the laptop, dry-run, deploy, smoke | Deploy role | Before the panel if the yaml shows up. Otherwise say the gap in the room. Team to confirm the date. | One smoke line from the class host: `Smoke passed for CUS-1001 with correlation lab-request-001`, plus the run or the script output saved outside git (no kubeconfig) | +| Record one fallback pass of the 11 minute script, including the 403 curl and the digest page | Speaker / operator. Names: Team to confirm | Before the panel | A video or a timed notes file that covers sign-in, CUS-1001, the note, the 403, and run 39649860445. Not committed if it could show a token | +| Require the four Capstone CI jobs on `main`. Leave CodeQL off that list until it can pass | Repo admin role | After the panel, so tonight's open PRs are not stuck | A pull request with a broken unit test cannot merge | +| Either enable code scanning and keep one green CodeQL URL, or disable `.github/workflows/codeql.yml` and say so in the index | Security role | Team to confirm | The evidence index links a green run, or it says the workflow is disabled and Trivy is the scan we run | +| Upgrade the Spring Boot parent and base images, retest, then set the image Trivy `exit-code` to 1 | Backend role and CI role | After the defense | A later main CI run is green with `exit-code` 1, and the runbook's 44/53 fixable counts are replaced with the new counts | + +Five actions. No sixth. + +## Reflection + +The decision that shapes the story is publish-after-commit with no outbox, plus deploy-by-digest. We can show a saved row and a digest, and we have to say the cluster step is still open. + +The strongest proof the CRM works is `InteractionApiIT` plus the laptop SQL for `CUS-1001`, backed by the 99 tests on run 39649860445. It is not the slide. + +The hard question is "why isn't it deployed?" The answer is the missing kubeconfig and the unmerged class branch. We should not talk past that. diff --git a/defense/self-assessment.md b/defense/self-assessment.md new file mode 100644 index 0000000..5e3b77a --- /dev/null +++ b/defense/self-assessment.md @@ -0,0 +1,45 @@ +# Self-assessment + +Honest status against the brief's defense list (`CAPSTONE-BRIEF-AND-RUBRIC.md` sections 9.2 and 9.3) and the Lab 52 outcomes. Scores are ours, not the instructor's. 4 would mean we would show it without a caveat. We are not there on deploy. + +Checked 2026-10-21. Evidence IDs are in `defense/evidence-index.md`. + +## Week close-out + +| Outcome | Evidence | Status | +| --- | --- | --- | +| Lab 48: architecture, NFRs, backlog, ADRs, risks, AI plan | E01, E07, E02, E10-E12, E08, E14, E16 | Present. AI "Must verify" boxes in `docs/ai-usage-plan.md` are still unchecked. Team sign-off table in `docs/team-roles.md` is blank. | +| Lab 49: REST slice, Kafka, tests | E03, E10, E22, E28, E29 | Shown on the laptop and in CI (99 tests, 0 failures). Outbox not built. | +| Lab 50: Angular + Postgres | E04, E24, E25, E27 | Unit tests 43/43 here and on CI. UI click-through not repeated today. Selenium not in CI. | +| Lab 51: security, Actions, digest, deploy, smoke, rollback | E05, E17-E21, E23, E31, E33, E06 | Security and CI digests shown. Deploy, cluster smoke, and rollback not shown. | +| Lab 52 packet | This folder | Script, index, Q&A, retro, self-assessment, and outline are in git. No PDF. No panel yet (`defense/feedback-log.md`). | +| No secrets in the packet | Scrub before commit. Local key stays in `application-local.yml`, which this folder does not quote. | We grepped `defense/` before committing. | +| Limitations have owners | E08, `defense/retrospective.md`, `defense/notes/deployment-gap.md` | Deploy, CodeQL, and Trivy have a role and a measure. Brandon's scope and the speaker names are still "Team to confirm". | + +## What the panel may ask to see + +| Outcome | Evidence | Status | +| --- | --- | --- | +| Working Angular app | `README.md`, E25, E27 | `http://localhost:4200` returned 200 and the title Northstar CRM (IPv6 localhost only). We did not click through it. Selenium pass is the Oct 21 report only. | +| Architecture and the ADRs | E01, E10, E11, E12 | Can explain from the docs. OpenShift vs k3s is still an open question. | +| Backend, messaging, UI, Postgres | E03, E04, E29 | Can walk the code and the SQL. Cluster path not shown. | +| Automated tests | E22, E23, E24 | 99 backend, 43 frontend, local and on run 39649860445. | +| Security scan | E35, E39 | Trivy ran and did not fail the build. CodeQL passes now (run 39777251809). We have not read its finding list. | +| GitHub Actions and OpenShift | E23, E31, E33 | Actions and digests yes. OpenShift no. k3s deploy no. | +| Risks, limits, AI | E08, E14, retro | Risks are short and named. AI plan is a page, not a close-out of what each person used. | +| Q&A with evidence | `defense/technical-q-and-a.md` | Written. Not rehearsed out loud. | +| Retrospective | `defense/retrospective.md` | Written from the repo. Not a team meeting. | +| Individual reflection and next steps | Retro "Reflection" plus the five actions | One shared note. No separate write-up per person. | + +## Starter scores + +| Criterion | Score (1-5) | Why | +| --- | --- | --- | +| Architecture clarity | 3 | Diagrams and three ADRs match the code. OpenShift is unresolved. | +| Working vertical slice | 4 | Laptop API, seed data, and tests. Not the cluster. | +| Security / release | 3 | JWT and 403 are real. Release stops at the digest. | +| Evidence discipline | 3 | This index exists. Some Lab 49/50 pages still describe the old demo token. | +| Demo professionalism | 2 | Script is timed. Nobody has rehearsed it. No fallback video. | +| Honesty about gaps | 4 | Deploy, CodeQL, and Trivy are written as gaps. | + +**Overall:** We can defend the slice and the pipeline. We cannot defend a deployment. Full credit on the security/CI/deploy category would be the wrong claim. diff --git a/defense/technical-q-and-a.md b/defense/technical-q-and-a.md new file mode 100644 index 0000000..27c1cfa --- /dev/null +++ b/defense/technical-q-and-a.md @@ -0,0 +1,115 @@ +# Technical Q&A + +Say the four lines. Stop. About 60-90 seconds each. If we do not know, say "unknown" and the check we would run. + +### Q: Where is the JWT validated? +- Claim: On every API request, in Spring Security, not in Angular. +- Evidence (path/id): `SecurityConfig` builds a `NimbusJwtDecoder` with `MacAlgorithm.HS256` and issuer `northstar-crm` (E17). `TokenService` sets a 15 minute TTL (`expiresIn` 900 on a live login). Missing or short `CRM_JWT_SECRET` throws at startup (`MIN_SECRET_BYTES` 32). +- Trade-off: HS256 means the API holds the signing key. We have no refresh token and no revoke list. A stolen token works until it expires. +- Next step / residual risk: A real IdP would replace `AuthController` and `DemoUserDirectory`. Controllers only see the JWT. +- Practice time (seconds): 70 + +### Q: What if Kafka is down when we publish? +- Claim: The interaction stays saved. The event can miss the consumer. There is no outbox. +- Evidence (path/id): `docs/adrs/001-event-contract.md` (E10). `InteractionEventPublisher.send` runs in `afterCommit` and does not fail the request. Isolated run 2026-10-21: broker up gave 201 plus a `processed_event` row; after `docker stop` on that broker, the next POST was still 201, the row existed, and `processed_event` had no row for `defense-kafka-down` (E29). +- Trade-off: Postgres is the source of truth. We can lose the audit event. The producer was still retrying when we stopped the test, so a broker that returns quickly might still get the record. We did not measure that. +- Next step / residual risk: An outbox table, written in the same transaction, with a publisher that retries from the table. Not built. Owner in the risk register: backend. +- Practice time (seconds): 80 + +### Q: How do you prove the UI wrote PostgreSQL? +- Claim: The UI calls the API. The API inserts a row. We can show the row. +- Evidence (path/id): `InteractionApiIT` hits HTTP, Postgres, and Kafka (E03). Flyway `V1__crm_schema.sql` seeds Amina and Ravi (E04). `docs/lab50/frontend-persistence-demo.md` records a 2026-10-20 browser edit and a SQL check. That write-up still describes the old demo token. Today's proof of the seed is the `psql` query in `defense/notes/demo-validation.md` (E27). Selenium (`frontend/e2e/crm-happy-path.e2e.mjs`) drives the real UI but is not in CI, and we did not re-run it for this pack (E25). +- Trade-off: A toast is not proof. The SQL is. The Oct 20 note and today's API check are not the same run. +- Next step / residual risk: During the demo, run the `lab-request-001` query after the click. Do not cite the Oct 20 UUID as today's row. +- Practice time (seconds): 75 + +### Q: What is the rollback unit? +- Claim: The pair of registry digests from run 39777251733. Not the git tag alone. +- Evidence (path/id): E31. Backend `sha256:ae571851d8c74da1d3f279d421a3576b9d9e4520523a1411b4a48f3e55c9581d`. Frontend `sha256:fa7e4cf7c53c36b83a867709ad8f72e2d983312c2e255c905fbe634f029a0ca1`. `capstone-deploy.yml` rejects anything that is not `sha256:` plus 64 hex chars. Rollback text: `docs/capstone-cicd-runbook.md` (E06). +- Trade-off: Tags are easy to say and easy to move. The digest is the bytes we scanned. +- Next step / residual risk: Nothing has been rolled back. You need two deploys before `kubectl rollout undo` has a previous ReplicaSet. Migrations V1-V3 are additive, so an older app image should still match the schema. That was not tried on a cluster. +- Practice time (seconds): 70 + +### Q: Which NFR is not met? +- Claim: Rollback within 10 minutes is not met, because we have not deployed. A few others are met on a laptop or in CI only. +- Evidence (path/id): `docs/nfrs.md` (E07). 401/403: `SecurityIT` and the live probes (E05). 15 minute tokens: `application.yml` and `expiresIn` 900. PR time: run 39777251733 went from 12:18:22Z to 12:21:47Z (8:18 to 8:21 AM ET), under 10 minutes (E23). "No secrets in git" is the policy plus Trivy secret scan, not a proof I re-ran today. +- Trade-off: Writing the target down was the Lab 48 point. Leaving the unmet one visible is the Lab 52 point. +- Next step / residual risk: One real deploy, then time a rollback. Until then the NFR stays open. +- Practice time (seconds): 65 + +### Q: How do you stop a duplicate event from doing the work twice? +- Claim: The consumer stores `eventId` in `processed_event` and skips a repeat. +- Evidence (path/id): `V2__processed_event.sql`. `InteractionEventConsumerIT.duplicateDelivery_appliesOnlyOnce` (E28). Bad versions go to `crm.customer.interactions.v1.DLT` (`docs/lab49/backend-demo.md`). +- Trade-off: Dedupe is in the consumer, after publish. It does not save you if the publish never happened (see Kafka down). +- Next step / residual risk: The HTTP create still makes a new interaction every time. Two clicks are two notes. We did not add an idempotency key on POST. +- Practice time (seconds): 70 + +### Q: What does `lab-request-001` prove? +- Claim: It ties one request to the log line, the row, the error body, and the event. It does not prove who the user is or that the cluster ran. +- Evidence (path/id): The Angular interceptor sets `X-Correlation-ID: lab-request-001` on API calls (`correlation.interceptor.ts`, E09). The filter reads `X-Correlation-Id`, keeps values that match `[A-Za-z0-9._:-]{1,64}`, otherwise makes a UUID, and echoes it (`CorrelationIdFilter`). Live 401/403/400 bodies echoed the id we sent (E20). +- Trade-off: A fixed demo id will collide in the logs if two people use it. That is fine for one demo and useless as a trace id in production. +- Next step / residual risk: Say "this is a demo constant." Do not say it proves a unique production request. +- Practice time (seconds): 70 + +### Q: Why is Angular not the security boundary? +- Claim: Hiding a button does not stop the HTTP call. The API checks the JWT and the role. +- Evidence (path/id): `auth-session.service.ts` keeps the token in a signal, not `localStorage` (E21). `authGuard` only redirects. The close button renders only when `session.isAdmin()` (`customer-detail-page.component.ts`). `SecurityIT` and the live DELETE both return 403 for `agent`, and Ravi stayed `PROSPECT` (E05, E19). +- Trade-off: A refresh signs the user out. That is so a script in the page cannot read a stored token. +- Next step / residual risk: Anyone can edit the signal in devtools and still get 403 from the API. We should say that out loud. +- Practice time (seconds): 65 + +### Q: Why isn't it deployed? +- Claim: We never got a kubeconfig or a student number, and the class fixes are not on main. The deploy workflow has zero runs. +- Evidence (path/id): E33, E37, E38. `~/.kube/config` is absent. `gh run list --workflow capstone-deploy.yml` was empty. Steps that are left are in `defense/notes/deployment-gap.md`. +- Trade-off: We can show digests and a laptop smoke note. We cannot show pods. +- Next step / residual risk: Checkout `feature/k3s-class-deploy`, create the two Secrets, dry-run `scripts/deploy-class.sh`, then deploy and smoke. Owner: deploy role. Blocked on the instructor file. +- Practice time (seconds): 80 + +### Q: Does CodeQL pass? +- Claim: Yes, now. It used to fail at the upload step because code scanning was not enabled. It was never a compile error in our Java. +- Evidence (path/id): `.github/workflows/codeql.yml` (E35). Up to Oct 21 2:25 PM ET it failed with `Code scanning is not enabled for this repository.` (run 39670104483). Every CodeQL run since the PR #23/#24 merges passes. Run 39777251809 on `ebda5ed` logged `Successfully uploaded results`. +- Trade-off: A green check means the scan ran and uploaded. It does not mean zero findings. +- Next step / residual risk: Read the alert list in the Security tab before claiming anything about findings. We have not reviewed it. +- Practice time (seconds): 80 + +### Q: What does Trivy block? +- Claim: Nothing, right now. It writes a HIGH/CRITICAL report and exits 0. +- Evidence (path/id): `exit-code: "0"` on the fs scan and both image scans in `.github/workflows/capstone-ci.yml` (E30, E39). The security job on run 39777251733 succeeded. The runbook's 2026-10-20 local count was 44 fixable highs/criticals on the backend image and 53 on the frontend. We did not re-count that today. +- Trade-off: Failing the build on that baseline would have blocked every PR before an upgrade. A green run means "the scan ran," not "the image is clean." +- Next step / residual risk: Bump Spring Boot 3.3.5 and the base images, retest, then set the image scan `exit-code` to 1. Until then, say the residual risk the way the runbook does. +- Practice time (seconds): 70 + +### Q: OpenShift or k3s? +- Claim: The running manifests are k3s. The course brief says OpenShift. We have not been told to switch. +- Evidence (path/id): `docs/architecture.md` ("the labs use k3s"). `deploy/k3s/`. Traefik Ingress in `deploy/k3s/base/ingress.yaml`. Risk register line: ask the instructor (E08). There is no `openshift/` tree. +- Trade-off: k3s matches the class cluster the unmerged runbook describes. It does not match the word OpenShift on the rubric. +- Next step / residual risk: Ask in the room if k3s counts. If they want OpenShift, that is new work, not a rename. +- Practice time (seconds): 60 + +### Q: Why PostgreSQL? +- Claim: The course stack is Postgres. Flyway owns the schema. Tests use Postgres, not H2. +- Evidence (path/id): `docs/adrs/002-postgresql.md` (E11). Image `postgres:16` in `compose.yaml` and in the CI service. `ddl-auto: validate`. `InteractionPersistenceIT` and `InteractionApiIT` in the 99-test run (E22). +- Trade-off: `mvn verify` needs Docker. That is why a laptop without Docker cannot reproduce the ITs. +- Next step / residual risk: Do not edit V1-V3 in place. Add V4 if the schema changes. +- Practice time (seconds): 55 + +### Q: What if the panel asks to see the JWT? +- Claim: We do not put it on the slide, in the chat, or in the notes. +- Evidence (path/id): Login returns `accessToken`. We redacted it in the experiment notes. `ProblemDetailAuthHandlers` does not echo the token. Logs are supposed to skip passwords, tokens, and summaries (`docs/lab51/security-and-observability.md`). +- Trade-off: They cannot "see" the signature. They can see `expiresIn`, the 401 body, and the code that checks HS256. +- Next step / residual risk: If one lands in a screenshot, stop the projector, do not commit the file, and treat that local token as burned (15 minute TTL). +- Practice time (seconds): 50 + +### Q: What fails closed? +- Claim: No token or a bad token is 401. Wrong role is 403. Unknown customer is 404 and writes nothing. Readiness goes down when Postgres is down. Liveness does not, so a DB blip does not restart-loop the pod. +- Evidence (path/id): E20, E05. `application.yml` readiness group includes `db`. Liveness group is `livenessState` only. Probes: `deploy/k3s/base/backend.yaml`. `HealthEndpointsIT` is in the verify run. +- Trade-off: `/actuator/health` is public so the probe and the smoke can call it. `show-details` is `never`. `/actuator/metrics` is ADMIN (`SecurityIT.healthIsPublic_butMetricsAreAdminOnly`). +- Next step / residual risk: We have not watched a pod leave the Service when Postgres dies, because we have not deployed. +- Practice time (seconds): 75 + +### Q: Do the CI checks block a merge? +- Claim: Not as required status checks. A review does. +- Evidence (path/id): E34. Branch protection on `main`: one approving review, stale reviews dismissed, last push needs approval. `required_status_checks` is null. The runbook's list of required check names is a plan. Two of those names are not the job names in the YAML: the run showed `frontend` and `backend`, while the runbook says `Frontend (Angular)` and `Backend (Maven)`. The Trivy and image job names do match. +- Trade-off: A red CodeQL check did not stop PR #22. Capstone CI was green on that merge anyway. CodeQL passes now, but nothing makes it required. +- Next step / residual risk: After the panel, require the Capstone CI job names, and CodeQL with them. +- Practice time (seconds): 60 diff --git a/docs/adrs/001-event-contract.md b/docs/adrs/001-event-contract.md new file mode 100644 index 0000000..d7c9ba5 --- /dev/null +++ b/docs/adrs/001-event-contract.md @@ -0,0 +1,10 @@ +# ADR 001: Kafka events after commit + +## Context +When an agent records an interaction we save it and also tell Kafka about it. We needed one event shape, and it needed an `eventId` so consumers can spot duplicates. + +## Decision +We publish `CustomerInteractionRecordedV1` and `CustomerStatusChangedV1`, keyed by customer id, only after the DB transaction commits. Consumers skip event ids they've already seen, and bad events go to a `.DLT` topic after 3 tries. + +## Consequences +The database is always the source of truth. With no outbox table, an event can get lost if Kafka goes down right after a commit. We're OK with that for the capstone. diff --git a/docs/adrs/002-postgresql.md b/docs/adrs/002-postgresql.md new file mode 100644 index 0000000..76a84f5 --- /dev/null +++ b/docs/adrs/002-postgresql.md @@ -0,0 +1,10 @@ +# ADR 002: PostgreSQL + +## Context +Customers and interactions have to stick around, and the course stack says PostgreSQL. + +## Decision +PostgreSQL 16 with Spring Data JPA. Flyway owns the schema (V1-V3) and Hibernate only validates it. Tests run against a real Postgres through Testcontainers, not H2. We picked this over Oracle, which isn't the taught path. + +## Consequences +Every schema change is a new migration file, and we don't edit old ones. Running `mvn verify` needs Docker. diff --git a/docs/adrs/003-github-actions-digest-promotion.md b/docs/adrs/003-github-actions-digest-promotion.md new file mode 100644 index 0000000..1c4ec37 --- /dev/null +++ b/docs/adrs/003-github-actions-digest-promotion.md @@ -0,0 +1,10 @@ +# ADR 003: GitHub Actions, build once + +## Context +We need CI that tests Angular and Spring Boot, scans the code, and deploys to k3s without rebuilding anything. + +## Decision +GitHub Actions on GitHub-hosted runners. CI tests and builds on every PR. Merges to `main` push the images to GHCR and record their digests. A manual deploy workflow with an approval step deploys those digests. We picked this over Bitbucket Pipelines, which isn't the taught path. + +## Consequences +What we deploy is exactly what we tested. Nothing deploys until PR #22 is merged into `main`. diff --git a/docs/ai-usage-plan.md b/docs/ai-usage-plan.md index abda4d9..d41828a 100644 --- a/docs/ai-usage-plan.md +++ b/docs/ai-usage-plan.md @@ -1,35 +1,19 @@ -# Northstar CRM: AI Usage Plan (Lab 48) - -Our stack is Angular, Spring Boot, PostgreSQL, Kafka, GitHub Actions, and k3s. OpenShift isn't our path, so don't let AI suggestions pull us there. - -**Tools we use:** GitHub Copilot, Cursor, ChatGPT, IntelliJ AI Assistant, and Google Gemini. Anything similar follows the same rules. +# AI usage plan ## Allowed -- Boilerplate code (DTOs, getters/setters, Angular services and components) -- First drafts of unit and integration tests -- Sketches of Terraform HCL, GitHub Actions workflows, and k8s manifests -- Explaining unfamiliar code, errors, and stack traces -- Code review help before a human reviewer looks at the PR -- Tightening and proofreading docs +- Boilerplate (DTOs, Angular services and components) +- First drafts of tests +- Sketches of Terraform, workflows and k8s manifests +- Explaining errors and unfamiliar code ## Must verify -AI-drafted code goes through the same CI gates as everything else. No skipped checks. - -- [ ] Angular: `npm run build` and `npm test` pass in `frontend/` -- [ ] Angular: TypeScript models match the Spring Boot API response DTOs (field names and types checked against a real response from the running API) -- [ ] Flyway/SQL: migration uses PostgreSQL types only (no `VARCHAR2`, `NUMBER`, `SYSDATE`, or other Oracle syntax) -- [ ] Flyway/SQL: migration runs clean on an empty Postgres 16 database (`docker compose up postgres`, then start the backend and confirm Flyway applies it) -- [ ] HCL, Actions, and k8s sketches pass `terraform validate`, a green workflow run, or `kubectl apply --dry-run=client` before review -- [ ] `git diff` checked for secrets, tokens, and hardcoded passwords before pushing -- [ ] All CI checks are green on the PR -- [ ] The author can explain every changed line without the AI tool +- [ ] Angular changes compile and match DTOs +- [ ] Flyway/SQL reviewed for PostgreSQL correctness +- [ ] No secrets introduced ## Forbidden -- Pasting secrets, tokens, passwords, kubeconfig, or customer PII into any AI prompt -- Committing secrets or kubeconfig files -- Letting AI deploy to or change the shared k3s cluster on its own -- Production applies (Terraform, Ansible, kubectl) without team approval -- Copying proprietary or license-incompatible code from AI output or anywhere else +- Committing secrets or kubeconfig +- Applying Terraform/Ansible to prod without approval +- Copying proprietary third-party code -## Attribution -Every PR has an "AI assistance" section in its description. It says which tool was used, what it drafted, and who verified it (name plus which checks above they ran). If no AI was used, write "None." The reviewer doesn't approve until that section is filled in. +We used AI tools to help draft these docs and checked them against our code. diff --git a/docs/architecture.md b/docs/architecture.md index 433becf..6d467bb 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -1,72 +1,68 @@ -# Northstar CRM Architecture +# Northstar CRM architecture -Agents search a customer, open the profile, and record an interaction (call, email, note, meeting). The Angular app talks to a Spring Boot REST API. The API checks the JWT, saves the note in PostgreSQL, then publishes a versioned Kafka event. GitHub Actions builds and scans the change and deploys a digest-pinned image to the shared k3s cluster behind Traefik Ingress. +Agents log in, find a customer and record interactions (calls, emails, notes, meetings). Admins can also close and reopen customers. Angular calls our Spring Boot REST API, which checks the JWT, saves to PostgreSQL and then publishes a Kafka event. GitHub Actions builds and tests everything once, and we deploy the image digests to k3s. -## Stack - -| Layer | Choice | +| Layer | Tech | | --- | --- | -| Frontend | Angular | -| API | REST / OpenAPI | -| Backend | Spring Boot | -| Database | PostgreSQL | +| Frontend | Angular 19 | +| Backend | Spring Boot 3.3, Java 21 | +| Security | JWT, roles AGENT and ADMIN | +| Database | PostgreSQL 16 + Flyway | | Messaging | Kafka | -| Containers | Docker | -| Runtime | k3s (Traefik Ingress) | +| Deploy | Docker, GHCR, k3s with Traefik | | CI/CD | GitHub Actions | -| IaC | Terraform / Ansible | - -## Non-goals - -Not the taught path: **React**, **SOAP**, **Oracle**, **Bitbucket Pipelines**, and **OpenShift** (`oc`, Routes). We deploy to the **shared k3s cluster**. - -## Runtime path +| IaC | Terraform and Ansible (validate only for now) | -Angular SPA → REST (JWT) → Spring Boot → PostgreSQL. +## Mandatory runtime path +Angular SPA → REST (JWT) → Spring Boot → PostgreSQL +Spring Boot ↔ Kafka -Spring Boot also talks to Kafka for versioned events, but **PostgreSQL is the system of record**. The API saves the interaction first, commits, then publishes. Kafka never replaces the database. If the customer is missing (`CUS-9999`), the API returns 404 and writes nothing and publishes nothing. +## Mandatory delivery path +GitHub → Actions (security / test / build) → k3s -Fixtures: `CUS-1001` Amina Khan (ACTIVE), `CUS-1002` Ravi Singh (PROSPECT), `CUS-9999` not found. Default correlation id `lab-request-001`. +## Non-goals (do not teach as primary path) +- Bitbucket Pipelines +- Oracle +- React +- SOAP -## Delivery path +The rubric mentions OpenShift but the labs use k3s, so we went with k3s. TBD, ask the instructor. -GitHub → Actions (test, scan, build) → image digest → shared k3s. The delivery Mermaid lives with the Actions plan (#11). The Kafka Mermaid and event field freeze live with the event ADR (#6). +## Diagrams -## Application path - -Left to right: browser app calls the API; the API saves to the database, then may publish an event. +Application and security. The interceptor adds the token, but the API does the real check. ```mermaid flowchart LR - A[Angular] -->|REST with JWT| B[Spring Boot] - B --> C[(PostgreSQL)] - B -->|after save| D[Kafka] + UI["Angular<br/>auth interceptor"] -->|"REST + Bearer JWT"| SEC["Spring Security"] + SEC -->|"401 / 403 if bad"| UI + SEC --> API["Spring Boot API"] + API --> PG[("PostgreSQL")] + API -->|"after commit"| K[["Kafka"]] ``` -## JWT interceptor and customer fixtures - -After sign-in, Angular keeps the JWT in memory and an HTTP interceptor sticks `Authorization: Bearer …` (plus a correlation id) on each API call. Spring Security on the server is the real gate (bad token → 401, wrong role → 403). The interceptor is only for convenience. - -Same call path for every customer id. Known customers succeed; the missing one does not. +Messaging. Events go out after the DB commit, consumers skip duplicates, and failures end up on a DLT. ```mermaid -flowchart TD - A[Agent uses Angular] --> B[Interceptor adds JWT] - B --> C[Spring Boot API] - C --> D{Customer id?} - D -->|CUS-1001 Amina or CUS-1002 Ravi| E[Save in PostgreSQL then optional Kafka] - E --> F[200 or 201] - D -->|CUS-9999| G[404 — no row, no event] +flowchart LR + API["Spring Boot"] --> T1[["crm.customer.interactions.v1"]] + API --> T2[["crm.customer.lifecycle.v1"]] + T1 --> C["audit consumers"] + T2 --> C + C -.->|"fails 3 times"| DLT[[".DLT"]] ``` -## Architecture decisions - -Short ADRs (written under issues #6, #8, and #11): +Delivery. -| Decision | ADR (lands with) | -| --- | --- | -| Event contract (`CustomerInteractionRecordedV1`, topic, publish-after-commit) | [docs/adrs/001-event-contract.md](adrs/001-event-contract.md) (#6) | -| PostgreSQL as system of record (not Oracle) | [docs/adrs/002-postgresql.md](adrs/002-postgresql.md) (#8) | -| GitHub Actions on a self-hosted runner → digest deploy to k3s | [docs/adrs/003-github-actions-self-hosted-runner.md](adrs/003-github-actions-self-hosted-runner.md) (#11) | +```mermaid +flowchart LR + PR["PR"] --> CI["Actions: test, scan, build"] + CI -->|"merge to main"| GHCR["GHCR image digests"] + GHCR --> DEP["manual deploy + approval"] + DEP --> K3S["k3s + smoke test"] +``` -Those files are created by their issues. This overview links them so the Lab 48 pack stays one story. +## ADRs +1. [Kafka events after commit](adrs/001-event-contract.md) +2. [PostgreSQL](adrs/002-postgresql.md) +3. [GitHub Actions, build once](adrs/003-github-actions-digest-promotion.md) diff --git a/docs/backlog.md b/docs/backlog.md index 3920774..7ffaf39 100644 --- a/docs/backlog.md +++ b/docs/backlog.md @@ -1,17 +1,20 @@ -# Capstone backlog — TODO (Lab 48) +# Capstone backlog -## CAP-12 — Record customer interaction +## CAP-12: Record customer interaction **As** an agent **I want** to POST an interaction for `CUS-1001` **So that** the note persists in PostgreSQL and emits a versioned Kafka event. **Acceptance** 1. `201` with correlation `lab-request-001` 2. Row visible in PostgreSQL -3. Event `CustomerInteractionRecordedV1` (or equivalent) published +3. Event `CustomerInteractionRecordedV1` published 4. `CUS-9999` → `404` +Status: done. + ## Additional seeds -- CAP-?? Angular list/detail for interactions — TODO -- CAP-?? JWT login shell — TODO -- CAP-?? Actions PR gate (Angular + Maven) — TODO -- CAP-?? OpenShift smoke via Route — TODO +- CAP-13 Angular list/detail for interactions: agent sees a customer's interactions newest first and can open one. Done. +- CAP-14 JWT login shell: log in once, token goes on every API call, 401 sends you back to login. Done. +- CAP-15 Flyway interaction table: schema builds from an empty database. Done. +- CAP-16 Actions PR gate (Angular + Maven): every PR runs `ng test`, `ng build` and `mvn verify`. Done. +- CAP-17 k3s smoke via Ingress: deploy, log in and create an interaction through the Ingress. Waiting on cluster access. diff --git a/docs/environment-strategy.md b/docs/environment-strategy.md index d52106b..b06838f 100644 --- a/docs/environment-strategy.md +++ b/docs/environment-strategy.md @@ -1,32 +1,13 @@ -# Northstar CRM Environment Strategy - -Four environments on the shared k3s cluster. Each env gets its own namespace so we never share config or blast radius. We promote by **image digest** from GitHub Actions — the same artifact moves forward; only ConfigMaps, Secrets, and replica counts change. +# Environment strategy | Env | k3s namespace | Approvals | Config source | -| --- | --- | --- | --- | -| dev | pending instructor | optional (author or teammate) | ConfigMap + Secret in the namespace | -| test | pending instructor | required (one teammate) | ConfigMap + Secret in the namespace | -| stage | pending instructor | required (merge keeper) | ConfigMap + Secret in the namespace | -| prod-like | pending instructor | required (merge keeper + second teammate) | ConfigMap + Secret in the namespace | +| --- | ----------------- | --------- | ------------- | +| dev | `northstar-crm-dev` | optional | ConfigMap/Secret | +| test | `northstar-crm-test` | one teammate | ConfigMap/Secret | +| stage | `northstar-crm-stage` | required | ConfigMap/Secret | +| prod-like | `northstar-crm-prod-like` | required | ConfigMap/Secret | -Namespace names are filled in when the instructor assigns them. Until then every row stays **pending instructor**, and no two environments share a namespace. +The real namespaces depend on cluster access. TBD, ask the instructor. ## Promotion rule - -Digest from Actions → k3s. Do not rebuild the image per environment. Laptop-only builds are not a release identity. - -## What differs between envs - -Same image digest everywhere. What changes: ConfigMap values, Secret references, replica counts, and Ingress hostnames once we have them. - -## Data rule - -Below prod-like, only synthetic fixtures: `CUS-1001` Amina Khan (ACTIVE), `CUS-1002` Ravi Singh (PROSPECT), correlation id `lab-request-001`. No real customer data. - -## Stage → prod-like gate - -Promote only when all of these are true: - -1. Stage smoke is green against the digest we plan to promote -2. Named approvers as in the table above -3. Rollback command rehearsed (redeploy the previous digest) +Digest from Actions → k3s; no laptop-only builds as release identity. diff --git a/docs/github-actions-plan.md b/docs/github-actions-plan.md index 1522d98..063df91 100644 --- a/docs/github-actions-plan.md +++ b/docs/github-actions-plan.md @@ -1,20 +1,11 @@ -# GitHub Actions plan — implemented in Lab 51 +# GitHub Actions plan | Trigger | Jobs | Evidence | | ------- | ---- | -------- | -| `pull_request` | Angular `npm ci` / Karma / production build; Maven verify; Trivy repository and image reports; CodeQL Java + TypeScript | Required check runs and uploaded artifacts | -| `push` to `main` | Same gates, then push the scanned images to GHCR, record registry digests, and package the verified JAR with SHA-256 | `image-digests-<sha>` and `crm-package-<sha>` artifacts | -| `push` of a `v*` tag | Same publication path as `main`; no automatic environment promotion | Digest pair for a manual Capstone Deploy run | -| Weekly / manual | CodeQL refresh | Code scanning results | -| Manual `workflow_dispatch` | Render or deploy one environment from supplied digests, Terraform plan/Ansible checks, rollout, and `CUS-1001` smoke | Rendered-manifest artifact and approved deploy run | +| pull_request | Angular `npm ci` / `ng test` / `ng build`; Maven verify; Trivy and CodeQL scans | Actions logs | +| main | Same, plus push images to GHCR and record digests | digest artifacts | +| tag / env | Manual k3s deploy with approval, then smoke test | Environment approval + logs | -## Rules - -- Angular and Java are separate required gates; one cannot hide the other. -- Package once: image and deploy jobs consume verified artifacts/digests and - never silently rebuild application code. -- Trivy is evidence-producing but currently non-blocking because the starter - dependency baseline has documented fixed HIGH/CRITICAL findings. The owner - and exit condition are in `docs/capstone-cicd-runbook.md`. -- Branch protection and GitHub Environment reviewers are external settings; - the exact check and environment names are listed in the runbook. +## Notes +- Package-once: the deploy never rebuilds, it just deploys the digests CI made. +- The Angular build and tests run in CI next to the Maven ones. diff --git a/docs/lab48/README.md b/docs/lab48/README.md new file mode 100644 index 0000000..023122d --- /dev/null +++ b/docs/lab48/README.md @@ -0,0 +1,13 @@ +# Lab 48 planning pack + +- [Architecture](../architecture.md) +- [ADR 001](../adrs/001-event-contract.md), [ADR 002](../adrs/002-postgresql.md), [ADR 003](../adrs/003-github-actions-digest-promotion.md) +- [AI usage plan](../ai-usage-plan.md) +- [GitHub Actions plan](../github-actions-plan.md) +- [Terraform / Ansible plan](../terraform-ansible-plan.md) +- [Environment strategy](../environment-strategy.md) +- [Backlog](../backlog.md) +- [NFRs](../nfrs.md) +- [Risk register](../risk-register.md) +- [Team roles](../team-roles.md) +- [Plan review](../reviews/lab48-plan-review.md) diff --git a/docs/nfrs.md b/docs/nfrs.md new file mode 100644 index 0000000..0fed6f8 --- /dev/null +++ b/docs/nfrs.md @@ -0,0 +1,10 @@ +# Non-functional requirements + +| Target | How we check | +| --- | --- | +| Requests with no token or a bad token get 401, and an agent doing admin stuff gets 403 | `SecurityIT` | +| Tokens expire after 15 minutes | `application.yml` | +| No secrets in git | `.gitignore` + Trivy secret scan | +| Bad input or `CUS-9999` saves nothing and sends no event | `InteractionApiIT` | +| PR checks finish in under 10 minutes | Actions run times (about 3-4 min now) | +| Rollback to the last digests in 10 minutes or less | Not done yet, needs a cluster | diff --git a/docs/reviews/lab48-plan-review.md b/docs/reviews/lab48-plan-review.md new file mode 100644 index 0000000..7b13000 --- /dev/null +++ b/docs/reviews/lab48-plan-review.md @@ -0,0 +1,15 @@ +# Lab 48 plan review + +- [ ] Architecture uses Angular, REST, Spring Boot, PostgreSQL, Kafka, k3s and Actions +- [ ] AI usage plan has checks and forbids +- [ ] Actions plan includes Angular and Java gates +- [ ] Terraform/Ansible and environment strategy are there +- [ ] CAP-12 is ready for Lab 49 + +## Sign-off + +| Name | Approve? | Date | +| --- | --- | --- | +| Keifer Kolar | | | +| Jason McGill | | | +| Brandon | | | diff --git a/docs/risk-register.md b/docs/risk-register.md new file mode 100644 index 0000000..f41eb55 --- /dev/null +++ b/docs/risk-register.md @@ -0,0 +1,7 @@ +# Risk register + +- No access to the k3s cluster yet, so no real deploy. Will, ask the instructor. +- OpenShift vs k3s isn't clear. Will, ask the instructor. +- CodeQL can't upload results on our private repo. Will. +- Trivy reports findings but doesn't fail the build yet. Will. +- Kafka going down right after a save could lose an event (no outbox). Keifer, accepted for now. diff --git a/docs/team-roles.md b/docs/team-roles.md new file mode 100644 index 0000000..f620bc8 --- /dev/null +++ b/docs/team-roles.md @@ -0,0 +1,17 @@ +# Team roles + +- Will Craig: planning, CI/CD, deployment and security +- Keifer Kolar: backend, Kafka and the database +- Jason McGill: Angular frontend +- Brandon: TBD + +Every change goes through a PR with one approval from someone else. + +## Sign-off + +| Name | Agree? | Date | +| --- | --- | --- | +| Will Craig | | | +| Keifer Kolar | | | +| Jason McGill | | | +| Brandon | | | diff --git a/docs/terraform-ansible-plan.md b/docs/terraform-ansible-plan.md index abfbca1..c004fed 100644 --- a/docs/terraform-ansible-plan.md +++ b/docs/terraform-ansible-plan.md @@ -1,38 +1,11 @@ -# Terraform / Ansible plan — Lab 51 implementation +# Terraform / Ansible plan ## Terraform - -- Code: `infra/terraform/` -- Scope: the four environment namespace names and Ingress-host contract for - the shared **k3s** cluster (not OpenShift Projects). -- `manage_namespaces` defaults to `false` because the instructor assigns and - owns those namespaces today. The workflow runs format, init without a - backend, validate, and—after environment approval—plan only. -- There is no `terraform apply` in GitHub Actions. -- Before setting `manage_namespaces = true`, configure an approved remote - backend and least-privilege cluster credentials. State files, plans, and - credentials must never be committed. -- Forbidden: public database exposure, committed `*.tfstate`, and long-lived - cluster credentials in YAML. +- Scope (non-prod): k3s namespace names `northstar-crm-dev`, `-test`, `-stage` and `-prod-like`. We only validate and plan, we don't apply. +- State backend (no credentials in Git): none yet, since we don't apply anything. +- Forbidden: public DB, committed `*.tfstate` ## Ansible - -- Code: `infra/ansible/site.yml` -- Purpose: an idempotent, no-change promotion preflight rather than click-ops - mutation. It validates the target environment, namespace, Ingress host, - and both image digest formats, then prints only non-secret values. -- The deploy workflow installs `ansible-core`, syntax-checks the playbook, - and runs it before rendering manifests. -- Actual cluster mutation remains in the digest-pinned Kustomize apply step - after GitHub Environment approval. -- Secrets come from GitHub Environment secrets or Vault-backed operator - tooling—never plaintext inventory or playbooks. - -## Promotion sequence - -1. Terraform format/validate and Ansible preflight. -2. GitHub Environment approval. -3. Terraform plan with `manage_namespaces=false` until ownership and the - remote backend are explicitly approved. -4. Apply the rendered Kustomize overlay by image digest. -5. Roll out, smoke `CUS-1001`, and roll back by digest if needed. +- Playbooks: `site.yml` runs a preflight check before a deploy. +- Idempotence notes: it only runs checks, so it never changes anything. +- Secrets via vault / CI secrets: we use GitHub Environment secrets, never plaintext in the repo. diff --git a/infra/terraform/.gitignore b/infra/terraform/.gitignore index 415e7f4..4565b69 100644 --- a/infra/terraform/.gitignore +++ b/infra/terraform/.gitignore @@ -4,3 +4,5 @@ *.tfplan crash.log crash.*.log +*.tfvars +!*.tfvars.example