From 33e4ea121e3de35384b11388576162cb6b1129c7 Mon Sep 17 00:00:00 2001 From: turanisl Date: Wed, 11 Nov 2026 03:06:39 +0000 Subject: [PATCH] Chapter 6: Add rollback and recovery runbook (#10) --- secure-delivery/runbooks/ROLLBACK.md | 209 +++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100644 secure-delivery/runbooks/ROLLBACK.md diff --git a/secure-delivery/runbooks/ROLLBACK.md b/secure-delivery/runbooks/ROLLBACK.md new file mode 100644 index 0000000..97580b5 --- /dev/null +++ b/secure-delivery/runbooks/ROLLBACK.md @@ -0,0 +1,209 @@ +# Chapter 6 — Rollback and Recovery Runbook + +## Purpose + +Document safe, repeatable recovery procedures for the Startup Pricing Service. + +This runbook covers: + +1. Rolling back a healthy production deployment from v2 to v1. +2. Recovering from an intentionally failed staging deployment. + +Both procedures must preserve the existing Gitea, Jenkins, Caddy, +Prometheus, Grafana, and monitoring infrastructure. + +The application is stateless. No database migration or persistent +application data restoration is required. + +## Preconditions + +Before beginning: + +- Confirm that the trusted Jenkins agent and Ansible deployment + environment are operational. +- Confirm that the previously approved image digests are available + in the container registry. +- Confirm that the corresponding reviewed deployment configuration + commits and release records are available. +- Confirm that staging and production HTTPS endpoints are reachable. +- Confirm that the operator has authorized deployment privileges. +- Record the initial application version, image digest, configuration + commit, and deployment timestamp. + +Never use an unverified image tag as a substitute for the recorded +immutable repository digest. + +## Scenario 1 — Healthy Production Rollback + +### Objective + +Demonstrate that a working v2 production release can be restored +to the previously approved v1 release. + +### Expected Application Behavior + +| Release | Version | Quantity | Expected Total | +|---|---|---|---| +| v2 | v2 | 3 | USD 36 | +| v1 | v1 | 3 | USD 30 | + +### Procedure + +1. Confirm that production is running the approved v2 image digest. +2. Verify the production HTTPS `/health` endpoint. +3. Verify that `/` reports version v2 and the expected source commit. +4. Verify that `/price?quantity=3` returns total 36. +5. Record the rollback decision timestamp. +6. Retrieve the previously approved v1 image digest and release record. +7. Restore the reviewed deployment configuration associated with v1. +8. Record the rollback execution start timestamp. +9. Execute the Ansible deployment using the v1 production release record. +10. Wait for the application health verification to complete. +11. Verify the production HTTPS `/health` endpoint. +12. Verify that `/` reports version v1 and the original v1 source commit. +13. Verify that `/price?quantity=3` returns total 30. +14. Confirm that the deployed image digest matches the approved v1 digest. +15. Record the successful recovery timestamp. +16. Calculate recovery duration and observed service interruption. +17. Capture Jenkins, Ansible, HTTPS, and monitoring evidence. + +### Acceptance Criteria + +- Production returns HTTP 200 from `/health`. +- Production reports version v1. +- Production reports the expected v1 source commit. +- Three units cost USD 30. +- The deployed image digest matches the approved v1 digest. +- Existing infrastructure remains operational. +- Recovery duration and service interruption are documented. + +## Scenario 2 — Failed Staging Deployment + +### Objective + +Demonstrate that an invalid deployment configuration is detected +and that the service can be restored using a previously reviewed +configuration. + +This exercise must run in staging only. + +### Controlled Failure + +Create a separate configuration commit that overrides the +application's Gunicorn command: + +```yaml +command: + - gunicorn + - --bind + - 0.0.0.0:8001 + - app:app +``` + +The container image healthcheck continues to probe port 8000. + +This mismatch should cause the container healthcheck to fail +and prevent the deployment from completing successfully. + +### Procedure + +1. Confirm that staging is healthy before the test. +2. Record the currently approved staging image digest. +3. Record the currently approved staging configuration commit. +4. Record the initial staging HTTPS responses. +5. Create a separate Git commit containing the controlled port mismatch. +6. Deploy the intentionally invalid configuration to staging only. +7. Confirm that the container healthcheck fails. +8. Confirm that Ansible or Jenkins reports a failed deployment. +9. Capture the failure logs, build number, and timestamp. +10. Record the recovery decision timestamp. +11. Restore the previously reviewed staging configuration. +12. Use the previously approved staging release record and image digest. +13. Execute the Ansible deployment again. +14. Verify that the application becomes healthy. +15. Verify the expected version and source commit. +16. Verify the correct pricing response. +17. Record the recovery completion timestamp. +18. Calculate recovery duration and observed interruption. +19. Capture Jenkins, Ansible, HTTPS, and monitoring evidence. + +### Acceptance Criteria + +- The intentionally invalid staging deployment is rejected. +- The failure is visible in Jenkins or Ansible output. +- No production deployment is triggered by the failed staging run. +- The previously reviewed configuration is restored. +- Staging returns HTTP 200 from `/health`. +- The restored application version and source commit are correct. +- Pricing behavior matches the restored release. +- Recovery duration and service interruption are documented. + +## Recovery Timing + +Record the following timestamps for both scenarios: + +| Measurement | Description | +|---|---| +| Decision time | When the operator decides to restore the previous release | +| Recovery start | When the recovery deployment begins | +| Recovery complete | When all required verification checks pass | +| Recovery duration | Recovery complete minus recovery start | +| Service interruption | Measured period during which the endpoint is unavailable | + +Record actual observations rather than estimated durations. + +If no interruption is observed, report that result and explain +the measurement method. + +## Safety Requirements + +- Never run the controlled failure against production. +- Never stop or restart the host Docker daemon. +- Never remove shared Docker volumes. +- Never use `docker compose down -v`. +- Never run destructive Docker cleanup commands. +- Never modify Gitea, Jenkins, Caddy, or monitoring configurations + as part of the controlled failure. +- Never rebuild an image during rollback. +- Never replace the approved digest with a mutable image tag. +- Never silently report a failed deployment as successful. + +## Limitations + +The staging and production environments share one DigitalOcean Droplet. + +Therefore: + +- The environments are logically separated but not physically isolated. +- A host failure can affect both environments. +- Container recreation can cause temporary service interruption. +- The deployment strategy does not guarantee zero downtime. +- This exercise does not demonstrate high availability. + +The application is stateless, making image rollback relatively simple. + +For a stateful application, database schema compatibility must also +be considered. A backward-compatible expand-and-contract migration +strategy would allow older and newer application versions to coexist +during a controlled rollback window. + +## Evidence Checklist + +- [ ] Healthy v2 production verification. +- [ ] Approved v1 repository digest. +- [ ] v1 rollback deployment output. +- [ ] Restored v1 production verification. +- [ ] Controlled staging configuration commit. +- [ ] Failed staging deployment output. +- [ ] Restored configuration commit. +- [ ] Successful staging recovery output. +- [ ] Recovery timestamps and calculations. +- [ ] Monitoring screenshots. +- [ ] Confirmation that existing infrastructure remains operational. + +## Status + +Runbook prepared. + +Execution, measured results, and supporting evidence remain pending +Sergio's implementation and verification. \ No newline at end of file