\chapter{Secure Delivery and Rollback} \ChapterLabel{SecureDelivery} \index{secure delivery}\index{rollback}\index{Ansible}\index{immutable image} \section{Scope and Current Status} Assignment 8 implements Chapter 6 of instructor manual version 1.43, using its Startup Pricing Service and the existing Gitea, Jenkins, Caddy and monitoring foundation. The Canvas page lists November 13, 2026 at 11:59pm; Vincent reports an extension. Preparation began November 14; DNS/TLS and the first reviewed Jenkins gate runs were verified November 15. PR~\#24 is merged, the delivery job is enabled, and the first reviewed v1 image is published. Its staging deployment stopped at SSH before creating an application container. \textbf{It is not ready for submission.} Successful v1/v2 staging and production, production rollback, staging failure/recovery and monitoring correlation remain pending. Published image metadata is not evidence of a successful deployment. The instructor's v1 source and tests were copied from \path{Examples/dosSecureDelivery/v1/} to \path{delivery/app/}. Flask validates requests and calculates the price; Gunicorn serves it with one worker on private port 8000. There is no payment processing, customer data or application volume. For three units v1 returns USD 30; the separate v2 source/test change must return USD 36. The image embeds its actual source commit during the build. Health, identity and pricing are verified separately. \section{Deployment and Trust Boundaries} \begin{figure}[htbp] \centering \renewcommand{\theHfigure}{delivery.\arabic{figure}} \resizebox{\linewidth}{!}{% \begin{tikzpicture}[ box/.style={draw=devopsBlue,rounded corners,align=center,text width=3.6cm, minimum height=1.5cm,font=\footnotesize,fill=white}, data/.style={box,draw=devopsGray,fill=gray!12,font=\scriptsize}, planned/.style={box,dashed,fill=devopsLightBlue}, flow/.style={-{Latex},thick}, note/.style={font=\scriptsize,align=center,fill=white,inner sep=1pt}] \node[box] (agent) at (4.8,2.7) {Droplet delivery agent\\512 MiB / 0.5 CPU\\Docker, scans and Ansible}; \node[data,text width=3.8cm] (local) at (0,2.7) {Agent volumes on droplet\\\texttt{ssw590-delivery-identity}\\\texttt{ssw590-delivery-workspace}}; \node[box] (builder) at (9.6,2.7) {Pinned BuildKit builder\\256 MiB / 0.5 CPU\\Private Docker control}; \node[box] (git) at (0,0) {Gitea + OCI registry\\\texttt{git.yebilly.me}\\SQLite retained}; \node[box] (jenkins) at (4.8,0) {Jenkins controller\\\texttt{ci.yebilly.me}\\Schedules trusted job}; \node[box] (host) at (9.6,0) {The-Ocean host\\\texttt{deploy} SSH account\\Python, Docker/Compose}; \node[box] (monitor) at (0,-2.8) {Prometheus, Grafana,\\Blackbox and Node Exporter\\Private metrics ports}; \node[box] (proxy) at (4.8,-2.8) {Caddy TLS proxy\\Public 80/443\\Private \texttt{gitea\_web} network}; \node[planned] (stage) at (9.6,-2.8) {Planned staging app\\\texttt{staging.yebilly.me}\\{\scriptsize\texttt{pricing-staging:8000}}}; \node[planned] (prod) at (9.6,-5.2) {Production app (planned)\\\texttt{app.yebilly.me}\\{\scriptsize\texttt{pricing-production:8000}}}; \node[data,text width=12.9cm,align=left] (storage) at (4.8,-8.45) { \textbf{Persistent state and read-only mounts on The-Ocean}\\[3pt] \begin{tabular}{@{}ll@{}} Gitea & \texttt{gitea\_gitea-data} $\rightarrow$ \texttt{/data} (includes SQLite)\\ Jenkins & \texttt{gitea\_jenkins-home} $\rightarrow$ \texttt{/var/jenkins\_home}\\ Caddy certificates & \texttt{gitea\_caddy-data} $\rightarrow$ \texttt{/data}\\ Caddy configuration & \texttt{gitea\_caddy-config} $\rightarrow$ \texttt{/config}\\ Prometheus & \texttt{monitoring\_prometheus\_data} $\rightarrow$ \texttt{/prometheus}\\ Grafana & \texttt{monitoring\_grafana\_data} $\rightarrow$ \texttt{/var/lib/grafana}\\ Proxy bind mount & \texttt{/root/gitea/Caddyfile} $\rightarrow$ \texttt{/etc/caddy/Caddyfile} (ro)\\ Monitoring mounts & \texttt{/root/monitoring/}: configuration (ro); host \texttt{/} $\rightarrow$ \texttt{/host} (ro)\\ Planned app config & \texttt{/opt/startup/pricing-\{staging,production\}}; no app data volume \end{tabular}}; \node[draw,dashed,rounded corners,fit=(agent)(local)(builder)(git)(host)(monitor)(prod)(storage), inner sep=0.55cm,label={[font=\small]below:Existing droplet: 1 vCPU, 2 GiB RAM, 25 GB plan disk}] {}; \draw[flow,dotted] (local)--(agent); \draw[flow] (agent)--node[note,right,pos=0.25]{private WS}(jenkins); \draw[flow] (agent)--node[note,above]{build}(builder); \draw[flow] (agent.south west)--node[note,above,sloped]{Git / OCI}(git.north east); \draw[flow] (agent.south east)--node[note,above,sloped]{SSH}(host.north west); \draw[flow] (git)--node[note,above]{hook}(jenkins); \draw[flow,dashed] (host)--node[note,right]{apply}(stage); \draw[flow,dashed] (host.east)--++(0.35,0)|-(prod.east); \draw[flow,dashed] (monitor)--node[note,above]{probe}(proxy); \draw[flow,dashed] (proxy)--node[note,above]{HTTP}(stage); \draw[flow,dashed] (proxy.south east)--node[note,above,sloped]{HTTP}(prod.north west); \end{tikzpicture}} \caption{Preparation architecture. Solid boxes are installed; dashed blue boxes and connections are planned application work. Gray boxes identify durable state or read-only mounts. Pricing is stateless; each environment retains only its Compose and release files on the host. The agent and builder now share the droplet; deployment SSH uses Docker's host gateway with the original pinned host-key alias. Browser access remains through Caddy HTTPS.} \label{Figure:SecureDeliveryArchitecture} \end{figure} The exclusive node \texttt{ssw590-vince-delivery} has one executor and label \texttt{delivery-trusted}. Originally installed on Vincent's laptop, it now runs on The-Ocean because campus networking blocks SSH from the laptop. Its legacy node name is retained and its description records the new location. It connects to \texttt{jenkins:8080} over private HTTP/WebSocket, with no published agent or Docker API port. Docker socket membership (group 987 on this host) grants administrative control over the same host as Jenkins, Gitea and monitoring; containerization is not isolation from malicious Docker-authorized jobs. The \texttt{deploy} account's \texttt{NOPASSWD} sudo permits root commands for Ansible; a separate account does not remove that administrative authority. Its authorized key disables SSH forwarding and PTY allocation. The host's ED25519 key was read through the existing strictly pinned administrator SSH connection and stored as a Jenkins file credential; verification is not disabled. A mounted SSH configuration maps the existing inventory address to \texttt{host.docker.internal}, retaining \texttt{HostKeyAlias 147.182.178.136}. Thus neither the Jenkins-agent connection nor deployment SSH crosses campus Wi-Fi. Campus browser HTTPS access still needs rehearsal. The Gitea Actions PDF runner subsequently moved to The-Ocean too; \ChapterRef{AutomatedManualBuild} records its separate migration and real workflow verification. Neither active runner now requires Docker Desktop. Keep manual compilation and delivery releases sequential on the shared host. The agent is capped at 512 MiB RAM / 768 MiB RAM+swap and 0.5 CPU, with a 96 MiB Java heap. Its separate pinned BuildKit container is capped at 256 MiB / 384 MiB and 0.5 CPU; builds explicitly select that builder because a Docker socket does not make child containers inherit agent limits. Both use \texttt{unless-stopped}. Agent restart/reconnect was verified at 03:57:57 UTC. The laptop copy is stopped and its helper now requires an explicit fallback switch; two copies must never connect as the same node. VS maintains the agent; BY retains host administration. No extra instance or plan resize was made. Deployment credentials belong to the \texttt{secure-delivery} Jenkins folder, not the root multibranch PR job. That job retains its earlier ordinary tests, plus Python syntax and release-control tests; it does not bind delivery credentials or a Docker socket. The new release job loads \path{delivery/Jenkinsfile} from protected main and was enabled after PR~\#24 merged. Only trusted reviewed code may use the privileged node. Exclusive scheduling is not a defense against an administrator or an author permitted to select that node; the two-member repository and Jenkins administration remain trust boundaries. Shared proxy-network membership is a lab simplification, not strong lateral isolation. Both environments share the droplet's failure domain. \section{Installation Inventory and Preparation Evidence} \small \begin{longtable}{@{}L{3.0cm}L{9.9cm}@{}} \toprule Item & Verified selection or result\\\midrule\endhead Trusted agent & Python 3.13.5; Ansible core 2.21.6 in \texttt{/opt/delivery-tools}; community.docker 5.4.0 and its community.library\_inventory\_filtering\_v1 dependency 1.1.5.\\ Build and scan tools & Docker 29.9.3, Compose 5.7.1, Trivy 0.76.2 and pip-audit 2.10.1. Base tool images are pinned in the agent Dockerfile; direct/transitive Python tools and collections are locked in Git.\\ Target & Ubuntu 24.04 LTS; Python 3.12.3; Docker 29.9.3 and Compose 5.7.1. At 20:46 UTC: 1,967 MiB RAM, 878 MiB available, 102 MiB swap used; root filesystem 41\% used. This is one prerequisite sample, not a load test.\\ Runtime image & Python 3.13 Alpine, Linux/amd64, selected registry digest: \newline\texttt{sha256:9ef1a599f863231c3d91e941389bfdc4}\allowbreak% \texttt{a2d6070557243d54df1a4e57015b960e}.\\ Application lock & Flask 3.1.3; Gunicorn 23.0.0; blinker 1.9.0; click 8.5.1; itsdangerous 2.2.0; Jinja2 3.1.6; MarkupSafe 3.0.4; packaging 26.3; Werkzeug 3.1.9. No claim is made that a pinned version remains vulnerability-free.\\ Runtime constraints & UID 10001; one Gunicorn worker; 64 MiB RAM / 96 MiB RAM+swap; 0.25 CPU; 64 PIDs; read-only root; 16 MiB temporary filesystem; all capabilities dropped and no host application port.\\ Initial Jenkins prerequisite run & \href{https://ci.yebilly.me/job/secure-delivery/job/agent-preflight/1/}{Agent preflight build 1} passed on November 14 at 20:46 UTC, including strict-key SSH as deploy and noninteractive sudo. \path{delivery/evidence/agent-preflight-1.txt} preserves its non-secret inventory. This run did not deploy an application.\\ Remote agent migration & At 03:47 UTC on November 15 (November 14 Eastern), \href{https://ci.yebilly.me/job/secure-delivery/job/agent-preflight/2/}{preflight build 2} passed on The-Ocean with real credentials, pinned host verification and sudo. \path{delivery/evidence/agent-preflight-2.txt} preserves the inventory.\\ Remote capacity trial & At 03:50--03:51 UTC, a preparation snapshot passed 12 control tests, 3 app tests, source/dependency gates, a limited image build, the full image gate and a temporary 64 MiB HTTP smoke test. Its source identity was \texttt{uncommitted-remote-preflight}; nothing was published or promoted. Observed available RAM exceeded 700 MiB; swap used rose from 263 to 372 MiB. Agent memory-limit events occurred, but no OOM kill was recorded. This short trial does not establish full release or presentation performance.\\ Local tests & Three Flask tests passed; a generated wrong-price assertion failed as intended; twelve release/security-control tests passed. Gunicorn health/identity/price/invalid-input smoke checks passed under the stated cap. Its baked identity was explicitly \texttt{uncommitted-preflight}, not a release SHA.\\ Local scans & Source/dependency gates passed; a generated synthetic secret blocked the gate. At 20:32 UTC the complete runtime-image gate passed with no HIGH/CRITICAL findings. Reports and exit codes remain in ignored local evidence. Later assessed Jenkins runs and published-image scans are recorded below.\\ \bottomrule \end{longtable} \normalsize Vincent resized the droplet while keeping its 25 GB plan disk, then updated packages. Post-maintenance checks found all seven earlier containers running, no failed systemd services, no required reboot marker, and HTTP 200 for Gitea, Jenkins and Grafana from the laptop. Before administrator bootstrap, a protected consistent Jenkins-home archive and an online Gitea SQLite backup were saved under \path{/root/ssw590-delivery-bootstrap/}. The one-time setup then created the deploy key, distinct package-only tokens under \texttt{vsun1}, the folder, node and disabled release job. No token or private key was printed or copied into the repository. Private bootstrap inputs were removed after Jenkins stored the credentials; generated agent identity stays in protected named volumes. \section{Prepared Pipeline and Release Records} The normal release path is checkout of reviewed main ancestry, control and application tests, repository-secret and dependency checks, build, image scan, registry push/pull, exact digest recording, staging deployment, unchanged rerun, human approval, and production deployment. Existing commit tags are reused on retry rather than overwritten. A new image is scanned before push and again by its registry digest. The same digest is promoted without rebuilding. Concurrent delivery builds are disabled. Release and scan reports are archived on failure and before the approval prompt. The policy in \path{delivery/SECURITY.md} was selected before the scans: block detected secrets, HIGH/CRITICAL image findings (including unfixed issues), all reported Python dependency advisories, scanner errors and missing/malformed reports. No exceptions are approved. A proposed exception requires instructor acceptance, advisory ID, owner, rationale, controls and expiry. Earlier Debian and installer-containing Alpine preflight scans failed; their reports were retained. The runtime was changed to the pinned Alpine base and unneeded pip/ ensurepip were removed; the scanner policy was not weakened. The release record contains source and configuration commits, exact registry digest, version/expected total, environment, public URL, proxy network, build URL and creation time. Both commits must be ancestors of protected main. Only the expected team registry, URL/environment pair and metadata fields are accepted. Production requires an input restricted to \texttt{billy,vsun1}, with a 20-minute timeout; the actual human approval and UTC time are recorded. Administrators retain their normal override powers. No unattended approval is claimed. Ansible restores the selected playbook/template from the recorded configuration commit, deploys without rebuilding, waits for health, then checks HTTPS health, version, source commit and price. A separate JSON recap records timing and makes a nonzero changed count on the unchanged rerun a blocking error. \small \begin{tabularx}{\linewidth}{L{2.1cm}Y Y} \toprule Traceability field & v1 & v2\\\midrule Source / config commits & Reviewed merge \texttt{09731ac}; SSH fix awaits review & Separate change pending\\ Registry digest / Jenkins release build & Published in build 3; full digest below & Not published / not run\\ Staging + unchanged rerun & SSH blocked before deployment; rerun not reached & Pending\\ Production approval / result & No approval or promotion yet & No approval or promotion yet\\ Recovery evidence & Healthy rollback pending & Staging failure/recovery pending\\ \bottomrule \end{tabularx} \normalsize \section{Reviewed Gate Runs and Deployment Correction} Billy approved the updated PR~\#24 head \texttt{ed0a862} at 21:06 UTC on November 15; Vincent merged it as \texttt{09731ac} at 21:59 UTC. The resulting Actions manual build 13 passed in 2m25s. It finished before the delivery runs. All times in this section are UTC. \begin{itemize} \item \href{https://ci.yebilly.me/job/secure-delivery/job/pricing/1/}{Pricing build 1}, \texttt{blocked-test}, took 54.202 seconds. Twelve control tests and the three normal Flask tests passed. The deliberate expected-total=$-1$ assertion failed against the actual total 30. Publication, deployment and approval were skipped. \item \href{https://ci.yebilly.me/job/secure-delivery/job/pricing/2/}{Pricing build 2}, \texttt{blocked-secret}, took 31.375 seconds. Tests, clean-source scanning and all nine locked dependency audits passed. The generated synthetic-secret finding blocked the gate and all publication/deployment stages. Match/code fields in the archived secret report are redacted; no real secret was introduced. \item \href{https://ci.yebilly.me/job/secure-delivery/job/pricing/3/}{Pricing build 3}, \texttt{release}, took 77.799 seconds. Tests and source/dependency gates passed. Both pre-push and registry-digest image scans analyzed two targets and found zero HIGH/CRITICAL findings. The image was published and pulled back by exact digest. \end{itemize} Build 3 recorded these exact source/configuration and image identifiers: \begin{Verbatim}[fontsize=\footnotesize,frame=single] Source/configuration: 09731acb0370566471dd4e401e59bafe55e927dc Image repository: git.yebilly.me/ssw590-group1/pricing Registry digest: sha256:cccd47f112f839f3443c88c4d16fd7a1ed0fec2100a26464156526d53ccc2695 \end{Verbatim} Staging failed at 22:26:39 UTC during Gathering Facts: \texttt{PTY allocation request failed on channel 0}. The recap was \texttt{ok=0 changed=0 unreachable=1 failed=0}, Ansible exit code 4. No app configuration or container was created, and production approval was not reached. Its generated records are retained as attempt evidence, not known-good recovery selections in \path{delivery/releases/}. Ansible defaults to forcing a terminal, but the dedicated deploy key intentionally forbids PTY allocation. The inventory correction sets \texttt{ansible\_ssh\_use\_tty=false}; it preserves the restricted key, pinned host verification and noninteractive sudo. The expanded administrator preflight exercises Ansible's actual connection/become path as well as plain SSH. \href{https://ci.yebilly.me/job/secure-delivery/job/agent-preflight/3/}{Preflight build 3} passed in 17 seconds at 22:50 UTC: Ansible ran \texttt{id -u} as root and returned 0 without a terminal. Its \texttt{CHANGED} label describes the command module's default reporting, not a pricing deployment or idempotence test. This validates connection prerequisites only; the corrected configuration must be reviewed and merged before the assessed release is retried. \begin{figure}[htbp] \centering \renewcommand{\theHfigure}{delivery.preflight.\arabic{figure}} \includegraphics[width=\linewidth,trim=330bp 880bp 900bp 0bp,clip]{images/assignment8-ansible-preflight-3-20261115.jpg} \caption{Actual successful Jenkins prerequisite build 3 after adding the noninteractive Ansible connection check. No pricing environment was deployed.} \label{Figure:DeliveryAnsiblePreflight} \end{figure} Dated records under \path{delivery/evidence/} preserve the results: \begin{itemize} \item \path{gates-20261115.md}: deliberate blocking demonstrations. \item \path{release-attempt-3-20261115.md}: publication and SSH failure. \item \path{agent-preflight-3.txt}: successful noninteractive connection. \end{itemize} Jenkins archives the complete reports. The ignored local evidence directory is: \begin{quote}\small \path{build/evidence/assignment8-execution/} \end{quote} \section{Release, Recovery and Monitoring Runbooks} The versioned \path{delivery/RUNBOOKS.md} gives the executable sequence. Vincent handles commits/pushes; Billy reviews repository changes. The v1 preparation is now on main, DNS/TLS are ready, and the two deliberate gate demonstrations have run. Review/merge the noninteractive SSH correction, then retry \texttt{release} using the corrected full main commit. Verify staging and changed=0 before a real human approval promotes v1. Save and review its generated staging/production records. Apply the supplied v2 source and test changes in another reviewed commit and repeat, expecting 36. For healthy production rollback, record detection/decision time, start the HTTPS observer, select the committed v1 production record and approve the operation. Ansible restores its original image and configuration, then verifies v1, original source SHA and total 30. Preserve start, recovery, verification and sampled interruption. A zero-failure sample set cannot prove zero downtime between requests. For failed staging deployment recovery, use a separate reviewed configuration commit to bind Gunicorn to 8001 only in staging while the image healthcheck still probes 8000. Run \texttt{staging-failure} with the good v2 staging release record and bad configuration SHA. Compose wait must fail and Jenkins must stop before production. Restore/review the correct template and rerun \texttt{recover-staging} with the original good record. Verify v2, its source, total 36 and changed=0. Do not alter shared infrastructure or data to create the failure. The production \texttt{/health} probe and Grafana availability panel are prepared in Git but not deployed while production is absent. Apply them after health is verified, keeping existing Gitea/Jenkins probes and host metrics. Correlate real Prometheus/Grafana samples with release/rollback times; 30-second scrapes and alert durations can miss a brief interruption. Uptime probes do not verify pricing. The observer in \path{delivery/ci/observe.py} records finer HTTPS samples without treating an intended failure as an observer-script failure. This stateless service needs no database restore. A real incompatible schema, external payment or stored state could make image-only rollback unsafe. A compatible expand/migrate/contract approach keeps both old and new code working during migration and delays destructive changes until rollback is no longer needed. This assignment does not add a database. \section{Outstanding Work and Cleanup Boundary} Billy added A records for \texttt{staging} and \texttt{app}. On November 15, Google and Cloudflare both returned \texttt{147.182.178.136} for each name, with no AAAA answer. Codex validated the prepared Caddy additions, saved the previous configuration and gracefully reloaded it while preserving the earlier routes, allowlists, volumes and bind-mounted inode. Normal curl and Python TLS checks confirmed trusted hostname-matching certificates, TLS 1.3 and HTTP 308 redirects. HTTPS currently returns 502 because the pricing backends have not been deployed; this is not evidence of application health. Certificate and DNS details are recorded in \path{delivery/evidence/https-20261115.md}. Existing Gitea/Jenkins/Grafana checks still passed. The public application port is HTTPS 443, with internal port 8000 remaining private. Distinct DNS hostnames satisfy the planned routing boundary; successful application deployment remains outstanding. PR~\#24 now includes the runner migration and HTTPS changes and is merged. Issue creation, review/merge of the SSH correction, successful v1/v2 releases, production approvals, both recovery demonstrations, final traceability and monitoring evidence, and the final submission review remain outstanding. Local checks are not a replacement for those executions. After grading, only when instructed, retain required evidence and remove only the two pricing projects, their routes, monitoring additions and test DNS. Revoke their package tokens; retire deploy access and the delivery node/folder after preserving job history. Do not prune Docker or use \texttt{down -v}. Preserve earlier Gitea/Jenkins/proxy/monitoring services and all shared volumes. The stopped laptop fallback, active remote agent, cache/identity volumes and protected remote backup are retained while work and assessment remain in progress.