Files
nageshwaran_manikumar 651acc63aa
startup-product-gitea-ci/pipeline/pr-main This commit looks good
Finalize Chapter 6 manual with verified visual evidence
2026-11-26 04:06:57 -05:00

240 lines
24 KiB
TeX

\chapter{Secure Delivery and Rollback}
\label{chap:secure-delivery}
\newcommand{\sixrepo}{https://git.nageshwaran.dev/SSW590-Startup/startup-product}
\newcommand{\sixfile}[1]{\href{https://git.nageshwaran.dev/SSW590-Startup/startup-product/src/commit/a96c888/#1}{\nolinkurl{#1}}}
\section{Scope and architecture}
This revision records the November 24--26, 2026 secure delivery exercise for the Startup Pricing Service. Staging and production are separate containers on the existing DigitalOcean host. They share the host failure domain; this is not high availability. Gitea, Jenkins, Caddy and the existing monitoring stack remain in service.
\begin{figure}[H]\centering
\begin{tikzpicture}[node distance=8mm, every node/.style={font=\small}, b/.style={draw,rounded corners,align=center,minimum height=9mm}]
\node[b](git){Gitea\\source and registry};
\node[b,right=of git](ci){Jenkins\\Mac agent};
\node[b,right=of ci](gate){Security gates\\human approval};
\node[b,below=of ci](stage){Staging\\Gunicorn :5000};
\node[b,right=of stage](prod){Production\\Gunicorn :5000};
\node[b,below=of stage](proxy){Caddy HTTPS};
\node[b,right=of proxy](mon){Blackbox /\\Prometheus / Grafana};
\draw[->](git)--(ci);\draw[->](ci)--(gate);\draw[->](ci)--(stage);\draw[->](gate)--(prod);\draw[->](proxy)--(stage);\draw[->](proxy)--(prod);\draw[->](mon)--(proxy);
\end{tikzpicture}
\caption{Logical delivery and observation paths; both application environments share one Droplet.}
\end{figure}
\section{Release integrity and locked inputs}
The registry repository is \nolinkurl{git.nageshwaran.dev/}\allowbreak\nolinkurl{ssw590-startup/startup-pricing}. Deployments select immutable registry references rather than mutable tags or local image identifiers alone.
\begin{description}
\item[V1 index digest]\leavevmode\par\nobreak {\footnotesize\nolinkurl{sha256:d0d0a2c2052b01a33ce12fd2b278e906552ea9797b5b918f44e5065f444d3027}}
\item[V1 amd64 manifest]\leavevmode\par\nobreak {\footnotesize\nolinkurl{sha256:be7e0a6d6bb82b78e68616ecb905c3232e59715490143e36d0bb71172da31a7c}}
\item[V2 index digest]\leavevmode\par\nobreak {\footnotesize\nolinkurl{sha256:14d520f6fbe60c9cc5e661551a03e944de3a2ad777a64c316ec397ee765db22d}}
\item[V2 amd64 manifest]\leavevmode\par\nobreak {\footnotesize\nolinkurl{sha256:158f8cd88eef9af7d057b8810651ae60b010ea3c598e8f04694926f0cac8ab5f}}
\item[Hardened V2 base]\leavevmode\par\nobreak {\footnotesize\nolinkurl{python:3.13-alpine@sha256:9ef1a599f863231c3d91e941389bfdc4a2d6070557243d54df1a4e57015b960e}}
\end{description}
Both releases were pulled by immutable reference. Index and platform manifest digests identify different registry objects. The hardened V2 uses hash-locked Python dependencies, including Flask 3.1.3 and Gunicorn 23.0.0. The production lock file is \href{https://git.nageshwaran.dev/SSW590-Startup/startup-product/src/commit/a96c888/pricing-service/requirements-production.lock.txt}{production dependency lock file}. Historical image-to-source commit provenance is not established; the recovery release records are reconstructed, not original reviewed release attestations.
\begin{center}\small\begin{tabularx}{\linewidth}{lYY}\toprule
& V1 & Hardened V2\\\midrule
Business response & Basic 10, Pro 25, Enterprise 50; total 85 & Starter 5, Basic 12, Pro 30, Enterprise 60; total 107\\
Health & Healthy; no version field & Healthy; version v2\\
Source commit & Unverified & Unverified\\
Recovery configuration & Reconstructed V1 record & Reconstructed V2 record; healthy staging Compose template\\
Delivery evidence & Live rollback journal & Jenkins delivery build 7; live restoration journal\\\bottomrule\end{tabularx}\end{center}
The observed totals are 85 and 107, not the course reference totals of 30 and 36. The application does not expose a source commit in its health response. These are outstanding rubric gaps, not verified equivalence.
\section{Container hardening and Ansible deployment}
The application runs as non-root \texttt{appuser}, with a read-only root filesystem, all capabilities dropped, no-new-privileges, 64 MiB memory, 128 MiB memory plus swap, half a CPU, 64 processes and a 16 MiB restricted temporary filesystem. Staging uses one Gunicorn worker; production uses two. Host mappings are loopback-only (5062 staging and 5061 production); Caddy provides HTTPS. Jenkins reaches staging through its internal Docker network.
\par Configuration and automation: \href{https://git.nageshwaran.dev/SSW590-Startup/startup-product/src/commit/a96c888/pricing-service/recovery/staging/compose.yml}{\nolinkurl{compose.yml}}, \href{https://git.nageshwaran.dev/SSW590-Startup/startup-product/src/commit/a96c888/pricing-service/ansible/staging-recovery.yml}{\nolinkurl{staging-recovery.yml}}, and \href{https://git.nageshwaran.dev/SSW590-Startup/startup-product/src/commit/a96c888/pricing-service/ansible/production-recovery-transaction.yml}{production recovery transaction}. The healthy staging Compose configuration checks the application on port 5000. The recovery transaction uses a shared production lock to exclude competing promotion operations.
\par The November 26 guarded unchanged staging run reported ok=9, changed=0, failed=0, skipped=8. Replacement was explicitly disabled for that run; it demonstrates verification without mutation, not unrestricted deployment idempotence. Production HTTPS remained healthy.
\section{Jenkins delivery and security gates}
The dedicated \href{https://ci.nageshwaran.dev/job/startup-product-chapter6-delivery/7/}{delivery build 7} completed successfully on November 26. Gitleaks reported no leaks, pip-audit reported no known vulnerabilities, and Trivy reported zero HIGH or CRITICAL findings for the configured scan of hardened V2. This does not establish absence of all vulnerabilities. Earlier image scans motivated the hardened rebuild. A narrowly scoped Gitleaks exception identifies a public Python signing fingerprint, not a secret.
\par Production approval was recorded as \texttt{chapter6-approver}. The developer was denied approval in build 6, which was subsequently aborted. The restricted deployment account uses a forced-command SSH gateway and narrowly scoped sudo helpers. A root-managed, time-limited, single-use authorization file is consumed before promotion. The authorization file is not cryptographically bound to a Jenkins build; privileged administrators and races within its validity window remain trust considerations.
\par Build 7 verified staging, promoted the immutable V2 release, retained the previous production container and independently verified production HTTPS. The promotion log recorded start at 06:18:42 UTC and completion at 06:19:01 UTC, with Jenkins HTTPS verification by 06:19:06. A transient 502 was observed; continuous downtime was not measured for this promotion.
\par The separate \href{https://ci.nageshwaran.dev/job/chapter6-synthetic-secret-test/3/}{synthetic-secret build 3} detected a generated test token, exited 42, skipped the delivery sentinel and finished FAILURE. This was an isolated negative-test job, not a negative run of the full production pipeline.
\par \href{https://git.nageshwaran.dev/SSW590-Startup/startup-product/pulls/13}{PR 13} had a successful Jenkins build 8 before the final recovery evidence commit. Final-head CI, independent review and merge must be verified separately.
\section{Production rollback and restoration}
On November 26 an authorized Ansible transaction ran on the host under systemd, independently of the initiating SSH connection. It acquired the promotion lock, verified V2, preserved the original container, deployed cached V1, verified its HTTPS health and business response, then restored the original V2 container and verified its identity and response. Emergency restoration was exercised in simulation before the live drill.
\begin{center}\small\begin{tabularx}{\linewidth}{lY}\toprule UTC & Observed event\\\midrule
07:50:37.935 & Lock acquired\\
07:50:42.066 & V2 verified\\
07:50:44.469 & Rollback decision\\
07:50:44.475 & Rollback started\\
07:50:58.351 & V1 recovery verified\\
07:51:08.370 & V2 restoration started\\
07:51:25.439 & Original V2 recovered\\
07:51:25.446 & Lock released\\\bottomrule\end{tabularx}\end{center}
Rollback took 13.877 seconds from recorded start to verification; restoration took 17.069 seconds. Independent HTTPS sampling recorded 21 failed probes among 45 drill-window samples. The two failure timestamp spans were 9.264 and 10.036 seconds; surrounding healthy-probe brackets were 11.272 and 14.121 seconds. These are sampled estimates, not exact continuous downtime. The original V2 container was restored and the transaction reported success. Host crash or forced process termination can still require manual recovery.
\section{Staging configuration failure and recovery}
A separate authorized drill used \href{https://git.nageshwaran.dev/SSW590-Startup/startup-product/src/commit/a96c888/pricing-service/recovery/staging/compose.failure.yml}{\nolinkurl{compose.failure.yml}} to override Gunicorn's bind port to 8001 while leaving the health check on 5000. No Docker daemon or proxy failure was induced. Compose wait returned 1 with an unhealthy container; the Ansible deployment gate failed with exit 2. Production health assertions passed before and after the operation.
\begin{center}\small\begin{tabularx}{\linewidth}{lY}\toprule UTC & Observed event\\\midrule
08:22:39 & Failure exercise started\\
08:23:01.334 & First failed staging probe\\
08:23:29.391 & Compose failure returned\\
08:24:21 & Restoration exercise started\\
08:24:34.262 & Healthy Compose deployment started\\
08:24:50.900 & First subsequent healthy staging probe\\
08:24:55.937 & Compose healthy, exit 0\\
08:25:02 & HTTPS health and pricing verification complete\\\bottomrule\end{tabularx}\end{center}
Restoration used the healthy template without the failure override. Ansible reported ok=12, changed=1, failed=0. Staging returned healthy V2 and all four expected plans; production returned healthy V2. Staging recorded 88 failed probes in 111 drill-window samples, a failure timestamp span of 108.437 seconds and first-failure-to-recovery interval of 109.566 seconds. Production recorded zero failures in 111 samples (100 percent sampled availability). These are not continuous availability guarantees. The Ansible gate rejection is verified; a Jenkins rejection during the staging outage is not evidenced.
\section{Monitoring and operational runbooks}
The existing Prometheus, Grafana and Blackbox stack monitors HTTPS availability and latency alongside host metrics. Production health is \url{https://pricing.nageshwaran.dev/health}; staging health is \url{https://staging-pricing.nageshwaran.dev/health}. PricingServiceDown uses probe failure for one minute; PricingServiceHighLatency uses duration above two seconds for two minutes. Configuration validation and rule loading were observed; alert firing during the drills is not established. The independent CSV probes provide the recovery measurements above.
\begin{description}
\item[Release] Developer opens a PR; reviewer checks source, locked inputs and tests. Require passing security gates, immutable registry identity and staging health/business checks. Authorized approver reviews the exact release before promotion. Verify production and retain evidence.
\item[Failure] Stop promotion on any failed scan, health check or identity mismatch. Record UTC time, build, digest and configuration; inspect scoped container logs and monitoring. Do not bypass gates or restart unrelated services.
\item[Rollback] Obtain authorization, confirm cached immutable release and matching configuration, verify capacity and acquire the shared lock through the recovery transaction. Verify health and business output after rollback and restoration. Escalate if emergency restoration fails.
\item[State compatibility] The observed pricing exercise does not demonstrate database or payment rollback. For future persistent state use expand-and-contract migrations, backward-compatible schemas and tested backups; do not reverse a destructive migration blindly or replay payments without idempotency controls.
\item[Cleanup] Preserve previous releases, logs, configuration backups and persistent service volumes. Inspect disk and memory before any operation. Remove only explicitly reviewed obsolete artifacts after backup and authorization; never use blanket prune or volume deletion on this shared host.
\end{description}
\section{Evidence and remaining limitations}
Recovery evidence is committed in \href{https://git.nageshwaran.dev/SSW590-Startup/startup-product/commit/a96c888}{commit a96c888}. The following paths identify the original evidence; raw logs and reports must be reviewed for sensitive content before publication.
\begin{itemize}
\item \href{https://git.nageshwaran.dev/SSW590-Startup/startup-product/src/commit/a96c888/pricing-service/chapter6-evidence/06-rollback-recovery/production-recovery-final-20261126-075316.log}{\nolinkurl{production-recovery-final-20261126-075316.log}}
\item \href{https://git.nageshwaran.dev/SSW590-Startup/startup-product/src/commit/a96c888/pricing-service/chapter6-evidence/06-rollback-recovery/production-downtime-analysis-20261126-075411.log}{\nolinkurl{production-downtime-analysis-20261126-075411.log}}
\item \href{https://git.nageshwaran.dev/SSW590-Startup/startup-product/src/commit/a96c888/pricing-service/chapter6-evidence/06-rollback-recovery/staging-failure-20261126-082239.log}{\nolinkurl{staging-failure-20261126-082239.log}}
\item \href{https://git.nageshwaran.dev/SSW590-Startup/startup-product/src/commit/a96c888/pricing-service/chapter6-evidence/06-rollback-recovery/staging-restoration-20261126-082421.log}{\nolinkurl{staging-restoration-20261126-082421.log}}
\item \href{https://git.nageshwaran.dev/SSW590-Startup/startup-product/src/commit/a96c888/pricing-service/chapter6-evidence/06-rollback-recovery/staging-downtime-analysis-20261126-082556.log}{\nolinkurl{staging-downtime-analysis-20261126-082556.log}}
\end{itemize}
Additional local evidence directories contain registry, Jenkins, dependency and monitoring reports; publication and grader access must be confirmed. Outstanding items include historical source provenance, reference pricing totals, Jenkins staging-outage rejection, independent final PR approval, and final-head CI verification. No credit is claimed for unobserved tests. ChatGPT assisted with recovery planning, evidence interpretation and drafting on November 26, 2026; the team is responsible for checking the report against actual execution records.
\clearpage
\section{Selected screenshot evidence}
These original captures supplement the execution records. Build 5 is historical gate evidence; build 7 records actual production delivery. Historical PR 12 is not the final PR 13 review.
\begin{figure}[H]\centering
\includegraphics[width=\linewidth,height=0.65\textheight,keepaspectratio]{img/chapter6-selected/build5-gitleaks.png}
\caption{Delivery build 5: Gitleaks scanned 23 commits and reported no leaks.}
\end{figure}
\begin{figure}[H]\centering
\includegraphics[width=\linewidth,height=0.65\textheight,keepaspectratio]{img/chapter6-selected/build5-pip-audit.png}
\caption{Delivery build 5: dependency audit reported no known vulnerabilities.}
\end{figure}
\begin{figure}[H]\centering
\includegraphics[width=\linewidth,height=0.65\textheight,keepaspectratio]{img/chapter6-selected/build5-trivy.png}
\caption{Delivery build 5: Trivy scan of the immutable V2 image, configured for HIGH and CRITICAL severity.}
\end{figure}
\begin{figure}[H]\centering
\includegraphics[width=\linewidth,height=0.65\textheight,keepaspectratio]{img/chapter6-selected/build5-smoke.png}
\caption{Delivery build 5: staging digest verification and smoke tests before approval.}
\end{figure}
\begin{figure}[H]\centering
\includegraphics[width=\linewidth,height=0.65\textheight,keepaspectratio]{img/chapter6-selected/restricted-ssh.png}
\caption{Restricted deployment account: authorized verification succeeded and an unauthorized command was denied.}
\end{figure}
\begin{figure}[H]\centering
\includegraphics[width=\linewidth,height=0.65\textheight,keepaspectratio]{img/chapter6-selected/build6-denied.png}
\caption{Delivery build 6: unauthorized production approval rejection.}
\end{figure}
\begin{figure}[H]\centering
\includegraphics[width=\linewidth,height=0.65\textheight,keepaspectratio]{img/chapter6-selected/step240-build7-designated-human-approval.png}
\caption{Delivery build 7: designated human approval.}
\end{figure}
\begin{figure}[H]\centering
\includegraphics[width=\linewidth,height=0.65\textheight,keepaspectratio]{img/chapter6-selected/step241-build7-fullscreen-production-success.png}
\caption{Delivery build 7: successful production delivery.}
\end{figure}
\begin{figure}[H]\centering
\includegraphics[width=\linewidth,height=0.65\textheight,keepaspectratio]{img/chapter6-selected/prometheus-alert-rules-validation-20261123.png}
\caption{Production monitoring: Prometheus alert configuration validation.}
\end{figure}
\begin{figure}[H]\centering
\includegraphics[width=\linewidth,height=0.65\textheight,keepaspectratio]{img/chapter6-selected/step295A-unchanged-staging-check.png}
\caption{November 26 unchanged staging dry run: replacement not required, health and pricing checks passed, changed=0.}
\end{figure}
\begin{figure}[H]\centering
\includegraphics[width=\linewidth,height=0.65\textheight,keepaspectratio]{img/chapter6-selected/grafana-pricing-availability.png}
\caption{November 23 Grafana dashboard: pricing HTTPS probe returned 1 (healthy), alongside Jenkins, Gitea and host metrics. This predates the recovery drills.}
\end{figure}
\begin{figure}[H]\centering
\includegraphics[width=\linewidth,height=0.65\textheight,keepaspectratio]{img/chapter6-selected/historical-pr12.png}
\caption{Historical PR 12 reviewer approval and merge into main; not evidence of final PR 13 approval.}
\end{figure}
\clearpage
\section{Recovery and security execution evidence}
The following selected output is transcribed from the recorded execution results, not new screenshots or simulated tests. The complete recovery logs are linked in Section 6.8. All recovery timestamps are UTC on November 26, 2026.
\subsection*{Production rollback and restoration}
Selected transaction events, presented as a compact transcription of the journal timeline:
\begin{lstlisting}
07:50:37.934593 PRODUCTION_LOCK_ACQUIRED
07:50:44.468507 ROLLBACK_DECISION
07:50:44.474884 ROLLBACK_STARTED
07:50:58.351494 ROLLBACK_RECOVERED
07:51:08.369626 RESTORATION_STARTED
07:51:25.438908 RESTORATION_RECOVERED
07:51:25.444577 RECOVERY_TRANSACTION_SUCCESS
07:51:25.445828 PRODUCTION_LOCK_RELEASED
\end{lstlisting}
The production recovery journal reported successful restoration of the original V2 container. V1 returned the three expected plans (total 85); restored V2 returned four plans (total 107). See the full \href{https://git.nageshwaran.dev/SSW590-Startup/startup-product/src/commit/a96c888/pricing-service/chapter6-evidence/06-rollback-recovery/production-recovery-final-20261126-075316.log}{production recovery record}. Independent probes recorded two interruption spans, as described in Section 6.5.
\subsection*{Staging configuration failure}
Selected lines from the recorded Ansible failure output:
\begin{lstlisting}
container startup-pricing-staging is unhealthy
Compose deployment failed; delivery blocked
ANSIBLE_EXIT_CODE=2
Health=unhealthy Command=["gunicorn","--workers","1",
"--bind","0.0.0.0:8001","app:app"]
=== PRODUCTION HEALTH ===
{"status":"healthy","version":"v2"}
\end{lstlisting}
The Compose return code was 1. Ansible rejected the deployment. The Jenkins outage-specific failure was not captured; this is an Ansible gate result, not a Jenkins failure result.
\clearpage\subsection*{Healthy restoration and HTTPS verification}
Selected output from the recorded restoration run (08:24:21--08:25:02):
\begin{lstlisting}
Container startup-pricing-staging Healthy
PLAY RECAP
digitalocean : ok=12 changed=1 unreachable=0 failed=0
=== STAGING HTTPS HEALTH ===
{"status":"healthy","version":"v2"}
=== STAGING HTTPS PRICING ===
{"plans":[{"name":"Starter","price":5},
{"name":"Basic","price":12},{"name":"Pro","price":30},
{"name":"Enterprise","price":60}],
"service":"Startup Pricing Service","version":"v2"}
=== PRODUCTION HTTPS HEALTH ===
{"status":"healthy","version":"v2"}
\end{lstlisting}
Public endpoints: \href{https://staging-pricing.nageshwaran.dev/health}{staging health}, \href{https://staging-pricing.nageshwaran.dev/pricing}{staging pricing}, \href{https://pricing.nageshwaran.dev/health}{production health}, and \href{https://pricing.nageshwaran.dev/pricing}{production pricing}.
\subsection*{Independent availability measurements}
Selected output from the saved staging downtime analysis:
\begin{lstlisting}
=== STAGING ===
Drill window samples: 111
Failed samples: 88
Sampled availability: 20.72 %
Failure timestamp span: 108.436741 seconds
First failure to recovery: 109.565538 seconds
=== PRODUCTION ===
Drill window samples: 111
Failed samples: 0
Sampled availability: 100.0 %
\end{lstlisting}
The observation window is the staging drill only; these are sampled estimates, not long-term SLO compliance or exact continuous downtime.
\subsection*{Synthetic-secret negative test}
Recorded result summary (not raw console output): Jenkins \href{https://ci.nageshwaran.dev/job/chapter6-synthetic-secret-test/3/}{synthetic-secret build 3} detected a generated test token (rule \texttt{github-pat}); Gitleaks returned 42, the delivery sentinel was skipped, and the build finished FAILURE. This separate test job does not demonstrate a full production-pipeline negative run. The test token is deliberately not reproduced. The archived console and reports remain in the local evidence directory, \nolinkurl{04-jenkins-ci/synthetic-secret-build-3/}. See also \href{https://ci.nageshwaran.dev/job/startup-product-chapter6-delivery/7/consoleText}{delivery build 7 console} and \href{https://ci.nageshwaran.dev/job/startup-product-chapter6-delivery/7/artifact/}{build 7 artifacts} for the passing scan and promotion evidence. Access to these links must be confirmed by the team.
\clearpage
\section{Additional visual execution evidence}
The following authentic screenshots supplement the saved log transcriptions. The availability screenshot documents the production rollback drill, not the staging drill. Staging downtime is supported by the saved analysis in Section 6.6. The synthetic-secret test was an isolated Jenkins job.
\clearpage
\begin{figure}[H]\centering
\includegraphics[width=\linewidth,height=0.80\textheight,keepaspectratio]{img/chapter6-selected/staging-restoration.png}
\caption{Saved Ansible restoration output: Compose healthy, zero failed tasks, staging and production HTTPS healthy at 08:25:02 UTC.}
\end{figure}
\clearpage
\begin{figure}[H]\centering
\includegraphics[width=\linewidth,height=0.80\textheight,keepaspectratio]{img/chapter6-selected/live-https.png}
\caption{Live HTTPS verification at 08:59:26 UTC on November 26, 2026: both environments returned healthy V2 and matching pricing plans.}
\end{figure}
\clearpage
\begin{figure}[H]\centering
\includegraphics[width=\linewidth,height=0.80\textheight,keepaspectratio]{img/chapter6-selected/production-downtime.png}
\caption{Saved production rollback availability analysis: two observed interruption groups; sampled estimates rather than exact continuous downtime.}
\end{figure}
\clearpage
\begin{figure}[H]\centering
\includegraphics[width=\linewidth,height=0.80\textheight,keepaspectratio]{img/chapter6-selected/synthetic-secret-start.png}
\caption{Jenkins synthetic-secret test build 3: recorded job execution and environment validation.}
\end{figure}
\clearpage
\begin{figure}[H]\centering
\includegraphics[width=\linewidth,height=0.80\textheight,keepaspectratio]{img/chapter6-selected/synthetic-secret-blocked.png}
\caption{Jenkins synthetic-secret test build 3: delivery sentinel skipped, exit code 42, final result FAILURE.}
\end{figure}
\clearpage
\begin{figure}[H]\centering
\includegraphics[width=\linewidth,height=0.80\textheight,keepaspectratio]{img/chapter6-selected/synthetic-secret-report.png}
\caption{Redacted archived report for synthetic-secret build 3: one github-pat finding, exit code 42, delivery sentinel skipped. The generated token is omitted.}
\end{figure}