17 Commits

Author SHA1 Message Date
samahk13 9fdfd00fa6 Patch libzstd1 (CVE-2026-124851) found by the image scan
Scrap-Web/pipeline/pr-main This commit looks good
Scrap-Web/pipeline/head Something is wrong with the build of this commit
2026-11-30 02:04:11 +00:00
samahk13 927df037b0 Add semantic versioning, LaTeX manual stage and versioned ZIP
Scrap-Web/pipeline/pr-main This commit looks good
Scrap-Web/pipeline/head There was a failure building this commit
2026-11-29 20:24:54 -05:00
samahk13 dae5b47373 Uploading final manual files for 11/13 submission
Scrap-Web/pipeline/head This commit looks good
Scrap-Web/pipeline/pr-main This commit looks good
2026-11-13 23:11:36 -05:00
samahk13 944ca0f203 Update jenkisn
Scrap-Web/pipeline/head This commit looks good
2026-11-13 23:06:26 -05:00
samahk13 1841a7d4ab Revert "Controlled failure: staging Gunicorn on 8001"
Scrap-Web/pipeline/head This commit looks good
This reverts commit 12226285c6.
2026-11-13 22:39:21 -05:00
samahk13 12226285c6 Controlled failure: staging Gunicorn on 8001
Scrap-Web/pipeline/head There was a failure building this commit
2026-11-13 22:33:04 -05:00
samahk13 7b73df19bd Added the v2 production and staging .yml files
Scrap-Web/pipeline/head Something is wrong with the build of this commit
2026-11-13 22:26:56 -05:00
samahk13 d6787727f8 Updating files
Scrap-Web/pipeline/head This commit looks good
2026-11-13 22:13:00 -05:00
samahk13 69f1fe05cf Merge branch 'feature/issue-24-delivery' of https://git.ssw590-08.me/SSW-590-08/Scrap-Web into feature/issue-24-delivery
Scrap-Web/pipeline/head This commit looks good
2026-11-13 21:59:03 -05:00
samahk13 c5172fca86 Update Jenkinsfile 2026-11-13 21:57:27 -05:00
samahk13 90c5d9a3b1 Updating Jenkinsfile 2026-11-13 21:54:31 -05:00
Kay-H7 f14abad27b current progress
Scrap-Web/pipeline/head This commit looks good
2026-11-13 21:40:56 -05:00
Kay-H7 c46f127e8c removed forced error
Scrap-Web/pipeline/head This commit looks good
2026-11-13 21:03:27 -05:00
Kay-H7 05d3c58c3a testing build block
Scrap-Web/pipeline/head There was a failure building this commit
2026-11-13 20:59:49 -05:00
samahk13 3fcd04010a Rebuild v1 on patched base image and add security gates (#24)
Scrap-Web/pipeline/head Something is wrong with the build of this commit
2026-11-13 19:46:41 -05:00
Kay-H7 ad37d148ed updated security
Scrap-Web/pipeline/head This commit looks good
2026-11-13 18:48:15 -05:00
Kay-H7 c864ddd0d2 updated security
Scrap-Web/pipeline/head This commit looks good
2026-11-13 17:50:59 -05:00
45 changed files with 1113 additions and 110 deletions
+1
View File
@@ -1 +1,2 @@
__pycache__/
security-reports/
Vendored
+192 -40
View File
@@ -7,16 +7,50 @@
// which holds the Docker socket and the registry/deploy credentials.
// TODO before submission: remove the feature branch from TRUSTED_BRANCH so
// only reviewed code on main can deliver.
//
// Release version: major.minor.changelist = 1.0.<Jenkins build number>,
// shown as the build name and used for the image tag, ZIP, and manual PDF.
//
// Two kinds of run:
// * Normal run (DEPLOY_RECORD empty): test, scan, build once, publish, deploy
// staging, prove idempotence, human approval, promote the SAME digest.
// * Redeploy run (DEPLOY_RECORD = a committed release record, e.g.
// releases/v1-production.yml): no build; redeploys exactly that record with
// this commit's Ansible files. Used for rollback and failed-deploy recovery.
// Production redeploys need the same approval.
def TRUSTED_BRANCH = 'main'
def TRUSTED_BRANCH = 'main|feature/issue-24-delivery'
// Jenkins user IDs allowed to approve production. Anonymous users cannot.
def APPROVERS = 'samahk,kaylah7'
// Semantic version: bump MAJOR_MINOR by hand for a feature or breaking release;
// the changelist part is the Jenkins build number, so every build is unique.
def MAJOR_MINOR = '1.0'
def deployRecord(String record) {
withCredentials([sshUserPrivateKey(credentialsId: 'deploy-ssh', keyFileVariable: 'DEPLOY_KEY')]) {
withEnv(["RECORD=${record}"]) {
sh '''
export PATH=/opt/ansible-venv/bin:$PATH
ansible-playbook -i ansible/inventory.ini ansible/deploy.yml --syntax-check
ansible-playbook -i ansible/inventory.ini ansible/deploy.yml \
--private-key "$DEPLOY_KEY" -e @"$RECORD"
'''
}
}
}
pipeline {
agent none
parameters {
string(name: 'DEPLOY_RECORD', defaultValue: '',
description: 'Leave EMPTY for a normal release. For rollback/recovery, the path of a committed release record, e.g. releases/v1-production.yml')
}
options {
skipDefaultCheckout()
disableConcurrentBuilds() // no competing releases
timeout(time: 30, unit: 'MINUTES')
timeout(time: 60, unit: 'MINUTES')
buildDiscarder(logRotator(numToKeepStr: '50'))
}
@@ -40,7 +74,11 @@ pipeline {
// ---------------- Chapter 6 delivery (trusted branches, agent) ---------
stage('Delivery') {
when { beforeAgent true; branch pattern: TRUSTED_BRANCH, comparator: 'REGEXP' }
when {
beforeAgent true
branch pattern: TRUSTED_BRANCH, comparator: 'REGEXP'
expression { (params.DEPLOY_RECORD ?: '').trim() == '' }
}
agent { label 'delivery' }
stages {
stage('Checkout') {
@@ -49,8 +87,12 @@ pipeline {
script {
env.APP_COMMIT = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
env.IMAGE_TAG = "${env.IMAGE}:${env.APP_COMMIT}"
env.SEMVER = "${MAJOR_MINOR}.${env.BUILD_NUMBER}"
env.SEMVER_TAG = "${env.IMAGE}:${env.SEMVER}"
currentBuild.displayName = "#${env.BUILD_NUMBER} v${env.SEMVER}"
}
echo "Source commit: ${env.APP_COMMIT}"
echo "Release version: ${env.SEMVER}"
}
}
@@ -67,38 +109,45 @@ pipeline {
}
}
// 6.4.5 (kholmes): dependency + secret checks on the source.
stage('Security scan: source') {
// LaTeX: compile the IT manual on the Droplet, in the same TeX Live
// image the Gitea Actions workflow uses (manual/ci/Dockerfile).
// The agent talks to the host's Docker daemon, so files are copied
// into and out of the container instead of bind-mounted.
stage('Compile manual (LaTeX)') {
steps {
sh '''
if [ -x security/scan.sh ]; then
security/scan.sh source
else
echo "security/scan.sh not added yet (6.4.5)"
fi
docker build -q -t ssw590/manual-latex:1 manual/ci
cid=$(docker create -w /work ssw590/manual-latex:1 latexmk devopsAssignment.tex)
docker cp manual/. "$cid":/work
if docker start -a "$cid"; then rc=0; else rc=$?; fi
docker cp "$cid":/work/devopsAssignment.pdf "manual-$SEMVER.pdf" || true
docker rm "$cid" > /dev/null
[ "$rc" -eq 0 ] && [ -s "manual-$SEMVER.pdf" ] || { echo "Manual build failed"; exit 1; }
echo "Manual compiled: manual-$SEMVER.pdf"
'''
archiveArtifacts artifacts: "manual-${env.SEMVER}.pdf", fingerprint: true
}
}
// 6.4.5: dependency and secret checks on the source. Fails closed:
// a missing script, a scanner error, or a finding stops the run.
stage('Security scan: source') {
steps { sh 'bash security/scan.sh source' }
post { always { archiveArtifacts artifacts: 'security-reports/**', allowEmptyArchive: true } }
}
stage('Build image') {
steps {
dir('pricing') {
sh 'docker build --build-arg APP_COMMIT="$APP_COMMIT" -t "$IMAGE_TAG" .'
sh 'docker build --build-arg APP_COMMIT="$APP_COMMIT" -t "$IMAGE_TAG" -t "$SEMVER_TAG" .'
}
}
}
// 6.4.5 (kholmes): image vulnerability scan before publishing.
// 6.4.5: image vulnerability scan before publishing. Fails closed.
stage('Security scan: image') {
steps {
sh '''
if [ -x security/scan.sh ]; then
security/scan.sh image "$IMAGE_TAG"
else
echo "security/scan.sh not added yet (6.4.5)"
fi
'''
}
steps { sh 'bash security/scan.sh image "$IMAGE_TAG"' }
post { always { archiveArtifacts artifacts: 'security-reports/**', allowEmptyArchive: true } }
}
stage('Publish') {
@@ -111,7 +160,8 @@ pipeline {
sh '''
printf '%s' "$REG_TOKEN" | docker login "$REGISTRY" -u "$REG_USER" --password-stdin
docker push "$IMAGE_TAG"
docker image rm "$IMAGE_TAG"
docker push "$SEMVER_TAG"
docker image rm "$IMAGE_TAG" "$SEMVER_TAG"
docker pull "$IMAGE_TAG"
docker logout "$REGISTRY"
docker image inspect "$IMAGE_TAG" --format '{{index .RepoDigests 0}}' > image-digest.txt
@@ -119,7 +169,9 @@ pipeline {
'''
}
script { env.IMAGE_DIGEST = readFile('image-digest.txt').trim() }
writeFile file: 'build-record.txt', text: """source_commit: ${env.APP_COMMIT}
writeFile file: 'build-record.txt', text: """version: ${env.SEMVER}
source_commit: ${env.APP_COMMIT}
version_tag: ${env.SEMVER_TAG}
image_tag: ${env.IMAGE_TAG}
image_digest: ${env.IMAGE_DIGEST}
jenkins_build: ${env.BUILD_URL}
@@ -128,33 +180,43 @@ jenkins_build: ${env.BUILD_URL}
}
}
// Deployment-ready ZIP named with the semantic version.
stage('Package') {
steps {
sh '''
rm -rf dist && mkdir -p "dist/pricing-$SEMVER"
cp pricing/app.py pricing/requirements.txt pricing/Dockerfile "dist/pricing-$SEMVER/"
cp -r ansible "dist/pricing-$SEMVER/ansible"
cp build-record.txt "dist/pricing-$SEMVER/"
printf '%s\n' "$SEMVER" > "dist/pricing-$SEMVER/VERSION"
cd dist && python3 -m zipfile -c "pricing-$SEMVER.zip" "pricing-$SEMVER"
python3 -m zipfile -l "pricing-$SEMVER.zip"
'''
archiveArtifacts artifacts: "dist/pricing-${env.SEMVER}.zip", fingerprint: true
}
}
// 6.4.6: deploy the digest just published to staging with Ansible,
// then rerun unchanged and require changed=0 (idempotence).
stage('Deploy staging') {
steps {
script {
// Expected behaviour comes from the source, not from config.
def version = sh(script: "sed -n 's/^VERSION = \"\\(.*\\)\"/\\1/p' pricing/app.py", returnStdout: true).trim()
def unit = sh(script: "sed -n 's/^UNIT_PRICE = //p' pricing/app.py", returnStdout: true).trim()
env.APP_VERSION = version
writeFile file: "release-${version}-staging.yml", text: """target_env: staging
env.APP_VERSION = sh(script: "sed -n 's/^VERSION = \"\\(.*\\)\"/\\1/p' pricing/app.py", returnStdout: true).trim()
def unit = sh(script: "sed -n 's/^UNIT_PRICE = //p' pricing/app.py", returnStdout: true).trim()
env.EXPECTED_TOTAL = "${3 * (unit as Integer)}"
writeFile file: "release-${env.APP_VERSION}-staging.yml", text: """target_env: staging
release_image: ${env.IMAGE_DIGEST}
expected_version: ${version}
expected_version: ${env.APP_VERSION}
expected_commit: ${env.APP_COMMIT}
expected_total: ${3 * (unit as Integer)}
expected_total: ${env.EXPECTED_TOTAL}
release_version: ${env.SEMVER}
public_url: https://staging.ssw590-08.me
proxy_network: gitea-net
"""
}
archiveArtifacts artifacts: "release-${env.APP_VERSION}-staging.yml", fingerprint: true
withCredentials([sshUserPrivateKey(credentialsId: 'deploy-ssh', keyFileVariable: 'DEPLOY_KEY')]) {
sh '''
export PATH=/opt/ansible-venv/bin:$PATH
ansible-playbook -i ansible/inventory.ini ansible/deploy.yml --syntax-check
ansible-playbook -i ansible/inventory.ini ansible/deploy.yml \
--private-key "$DEPLOY_KEY" -e @release-$APP_VERSION-staging.yml
'''
}
deployRecord("release-${env.APP_VERSION}-staging.yml")
}
}
@@ -172,10 +234,100 @@ proxy_network: gitea-net
}
}
// 6.4.7: restricted human approval, then promote the SAME digest.
stage('Approve production') {
steps {
script {
def scan = fileExists('security-reports/image-summary.txt') ?
readFile('security-reports/image-summary.txt').trim() : 'see security-reports'
// Only APPROVERS can approve; Abort or the timeout stops the run.
timeout(time: 30, unit: 'MINUTES') {
env.APPROVER = input(
message: """Promote ${env.APP_VERSION} (release ${env.SEMVER}) to production (https://app.ssw590-08.me)?
Source commit: ${env.APP_COMMIT}
Image digest: ${env.IMAGE_DIGEST}
Security scans: source and image gates PASSED (fixable HIGH/CRITICAL block).
${scan}
Staging: deployed, HTTPS health/version/commit/total ${env.EXPECTED_TOTAL} passed, rerun changed=0.""",
ok: 'Approve and deploy to production',
submitter: APPROVERS,
submitterParameter: 'APPROVER')
}
env.APPROVED_AT = sh(script: 'date -Is', returnStdout: true).trim()
echo "APPROVED by ${env.APPROVER} at ${env.APPROVED_AT}"
}
}
}
// 6.4.7 (kholmes): approval + production deploy.
stage('Approve and deploy production') {
steps { echo 'Not implemented yet (6.4.7).' }
stage('Deploy production') {
steps {
// Same digest and commit as staging; only environment and URL change. No rebuild.
writeFile file: "release-${env.APP_VERSION}-production.yml", text: """target_env: production
release_image: ${env.IMAGE_DIGEST}
expected_version: ${env.APP_VERSION}
expected_commit: ${env.APP_COMMIT}
expected_total: ${env.EXPECTED_TOTAL}
release_version: ${env.SEMVER}
public_url: https://app.ssw590-08.me
proxy_network: gitea-net
approved_by: ${env.APPROVER}
approved_at: ${env.APPROVED_AT}
"""
archiveArtifacts artifacts: "release-${env.APP_VERSION}-production.yml", fingerprint: true
deployRecord("release-${env.APP_VERSION}-production.yml")
}
}
}
}
// ---------------- Rollback / recovery: redeploy a committed record -----
stage('Redeploy release record') {
when {
beforeAgent true
branch pattern: TRUSTED_BRANCH, comparator: 'REGEXP'
expression { (params.DEPLOY_RECORD ?: '').trim() != '' }
}
agent { label 'delivery' }
stages {
stage('Load record') {
steps {
checkout scm
script {
env.RECORD = params.DEPLOY_RECORD.trim()
if (!(env.RECORD ==~ /releases\/[A-Za-z0-9._-]+\.yml/) || !fileExists(env.RECORD)) {
error "No committed release record at ${env.RECORD}"
}
env.TARGET_ENV = sh(script: 'sed -n "s/^target_env: //p" "$RECORD"', returnStdout: true).trim()
env.CONFIG_COMMIT = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
}
echo "Redeploying ${env.RECORD} to ${env.TARGET_ENV} with configuration commit ${env.CONFIG_COMMIT}"
sh 'cat "$RECORD"'
archiveArtifacts artifacts: "${env.RECORD}", fingerprint: true
}
}
stage('Approve redeploy') {
when { environment name: 'TARGET_ENV', value: 'production' }
steps {
script {
timeout(time: 30, unit: 'MINUTES') {
env.APPROVER = input(
message: "Redeploy ${env.RECORD} to PRODUCTION (configuration commit ${env.CONFIG_COMMIT})?",
ok: 'Approve redeploy',
submitter: APPROVERS,
submitterParameter: 'APPROVER')
}
echo "APPROVED by ${env.APPROVER} at ${sh(script: 'date -Is', returnStdout: true).trim()}"
}
}
}
stage('Redeploy') {
steps {
sh 'echo "Redeploy start: $(date -Is)"'
deployRecord(env.RECORD)
sh 'echo "Redeploy verified: $(date -Is)"'
}
}
}
}
BIN
View File
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 309 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 435 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

+16
View File
@@ -114,4 +114,20 @@ confirmed, as the assistant did not create those two chapters.
Exporter to the public hostnames is inferred from the Compose networks, not
tested.
\item \textbf{Secure delivery and rollback.} Date: November 12--13, 2026.
Tool and model: Claude (configured model claude-opus-5-5). Task: split the
work; write the delivery agent Dockerfile and Compose file, the hash-locked
requirements, the Dockerfile changes, and the \texttt{Jenkinsfile} stages for
publishing, staging, idempotence, restricted approval, production promotion,
and record-based redeployment; guide the registry, deploy-account, Caddy,
rollback, failure, and monitoring steps; draft and edit Chapter 11 and the
deployment diagram. Inputs: manual Chapter 6 and its starter files; Jenkins
console output, screenshots, release records, commit hashes, and per-second
probe logs supplied by the students. Output used: the files above and
chapter text. Human review and corrections: the students ran every step on
the real services and supplied all evidence; a registry token pasted into
the chat was revoked and replaced; Jenkins times were found to be UTC and
converted to EST; the Prometheus edit was found not to be loaded and the
container was recreated. Unresolved assumptions: none.
\end{itemize}
+1 -1
View File
@@ -43,7 +43,7 @@
\newcommand{\Organization}{Stevens Institute of Technology}
\newcommand{\DocumentDate}{November 13, 2026}
\newcommand{\DueDate}{[Due Date and Time]}
\newcommand{\VERSION}{Version 1.7 (draft)}
\newcommand{\VERSION}{Version 1.7}
\newcommand{\AssignmentNumber}{7}
\newcolumntype{Y}{>{\raggedright\arraybackslash}X}
+1 -1
View File
@@ -10,7 +10,7 @@
\toprule \textbf{Date / Version} & \textbf{Authors} & \textbf{Change} & \textbf{Changed At}\\ \midrule
\endhead
November 13, 2026 / 1.7 (draft) & SK, KH & In progress: Secure Delivery and Rollback assignment. Added the trusted Jenkins delivery agent, locked dependencies and pinned base image, the Gitea container registry, staging and production proxy routes, image build and publish by digest, and Ansible deployment to staging with an idempotence check. Security gates, approval and promotion, v2 and recovery, and monitoring sections still to be completed. Updated the Hosts and Passwords tables and the Glossary. & \ChapterRef{SecureDelivery}, \ChapterRef{PWDHST} \\
November 13, 2026 / 1.7 & SK, KH & Secure Delivery and Rollback assignment: trusted Jenkins delivery agent, locked dependencies and pinned base image, Gitea container registry, staging and production proxy routes, security gates with a blocked run, build once and publish by digest, Ansible deployment with an unchanged rerun, restricted approval and promotion of the same digest, v2 release, production rollback and staging failure recovery, production health probe, runbooks, and traceability. Updated the Hosts and Passwords tables, Glossary, Bibliography, and AI Prompt Log. & \ChapterRef{SecureDelivery}, \ChapterRef{PWDHST} \\
October 29, 2026 / 1.6 & SK, KH & Completed the Introduction to SRE assignment: deployed Prometheus, Grafana OSS, Node Exporter, and Blackbox Exporter as four pinned, persistent containers on the existing Droplet; published authenticated Grafana at \texttt{metrics.ssw590-08.me}; built a six-panel dashboard; defined an availability SLI and SLO; configured and tested Grafana-managed alerts with a Discord contact point; and ran a controlled Jenkins outage with a blameless review. Updated the Hosts and Passwords tables and the Glossary. & \ChapterRef{SRE}, \ChapterRef{PWDHST} \\
+4
View File
@@ -74,6 +74,10 @@ Gitea container registry
& Push: Jenkins credential \texttt{gitea-registry-push}; pull: root on the Droplet
& Package-write and package-read tokens; never stored in Git, logs, or screenshots\\
\hline
Production approvers (Jenkins)
& samahk, kaylah7
& Personal Jenkins logins; passwords not recorded here. Only these users can approve production or a production rollback\\
\hline
Jenkins delivery agent
& delivery-agent
& Agent secret in a file on the Droplet beside \texttt{agent/compose.yaml}; not in Git\\
+27
View File
@@ -140,3 +140,30 @@
url = {https://www.jenkins.io/doc/book/using/using-agents/},
note = {Accessed: Nov. 13, 2026}
}
@misc{TrivyDocs,
author = {{Aqua Security}},
title = {{Trivy Documentation}},
howpublished = {Trivy project documentation},
year = {2026},
url = {https://trivy.dev/docs/latest/},
note = {Accessed: Nov. 13, 2026}
}
@misc{PipAudit,
author = {{Python Packaging Authority}},
title = {{pip-audit: Audit Python environments and requirements for known vulnerabilities}},
howpublished = {Project repository},
year = {2026},
url = {https://github.com/pypa/pip-audit},
note = {Accessed: Nov. 13, 2026}
}
@misc{JenkinsInput,
author = {{Jenkins Project}},
title = {{Pipeline: Input Step}},
howpublished = {Jenkins Pipeline Steps Reference},
year = {2026},
url = {https://www.jenkins.io/doc/pipeline/steps/pipeline-input-step/},
note = {Accessed: Nov. 13, 2026}
}
+712 -63
View File
@@ -31,10 +31,21 @@ Droplet, so they share a failure domain and its CPU, memory, and disk: separate
Compose projects give configuration separation, not high availability.
\textbf{Division of work.} Sections~\ref{sec:del-baseline}--\ref{sec:del-build}
and Section~\ref{sec:del-ansible} were carried out by \texttt{samahk13}, who
holds the Gitea administrator, Jenkins, DNS, and Droplet SSH access.
Sections~\ref{sec:del-security} and~\ref{sec:del-promote}--\ref{sec:del-ops}
were carried out by \texttt{kholmes}.
and~\ref{sec:del-ansible}--\ref{sec:del-ops} were carried out by
\texttt{samahk13} (Jenkins user \texttt{samahk}), who holds the Gitea
administrator, Jenkins, DNS, and Droplet SSH access.
Section~\ref{sec:del-security} was carried out by \texttt{kholmes} (Jenkins user
\texttt{kaylah7}).
\textbf{Times and run numbers.} Jenkins displays times in UTC. This chapter gives
each time in Eastern Standard Time (EST, UTC$-$5) and, where it helps, the UTC
value shown in a screenshot. The Jenkins job for
\texttt{feature/issue-24-delivery} restarted its run numbers on November 13,
2026, so the November 12 runs in Sections~\ref{sec:del-baseline}
and~\ref{sec:del-ansible} (an earlier \#5--\#8) are recorded by their
screenshots and are no longer listed in Jenkins. Every run link in this chapter
points to the current numbering, \#1 onwards from November 13
(Figure~\ref{fig:del-run-history}).
\section{Deployment Architecture}
\label{sec:del-architecture}
@@ -62,9 +73,22 @@ were carried out by \texttt{kholmes}.
Section~\ref{sec:del-ops}.
\end{itemize}
\FillIn{team deployment diagram (HW8 images/delivery-architecture.png) showing
actual hosts, container boundaries, volumes and bind mounts, Ansible SSH, both
environments, proxy, and monitoring}
\delfig{delivery-architecture.png}{1.0}{Deployment architecture on the single
Droplet. Red arrows are the only connections that cross the host boundary or carry
deployment rights: public HTTPS to Caddy, and Ansible SSH from the trusted agent
to the \texttt{deploy} account.}{fig:del-architecture}
\textbf{Public versus private.} Only Caddy is reachable from the Internet
(HTTPS 443, plus 80 for redirects); SSH is restricted by the firewall. Gitea,
Jenkins, the agent, both pricing containers, and the monitoring stack listen only
on Docker networks, and no application port is published on the host. Prometheus
probes the public HTTPS names through Caddy, as a user would.
\textbf{Deployment rights.} Only the Jenkins delivery agent holds the registry
write token and the \texttt{deploy} SSH key, and it runs only for trusted branches.
Production changes additionally need a Jenkins approval from \texttt{samahk} or
\texttt{kaylah7}. Droplet administration (Caddy, DNS, monitoring) is limited to
\texttt{samahk13}.
\section{Prepare the Repository and Establish a Baseline}
\label{sec:del-baseline}
@@ -126,8 +150,8 @@ python3 -m venv .venv
\begin{itemize}
\item \textbf{Controlled failure:} Jenkins run
\texttt{feature/issue-24-delivery} \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/6/}{\#6}, started by a push at 11:19 PM EST on
November 12, 2026, ran on \texttt{delivery-agent}. The deliberately
\texttt{feature/issue-24-delivery} \#6 of the earlier numbering, started by a
push at 6:19 PM EST (23:19 UTC) on November 12, 2026, ran on \texttt{delivery-agent}. The deliberately
broken test \texttt{test\_price} failed, so the \emph{Unit tests} stage
failed after 6 seconds and every later delivery stage (security scans,
build, publish, deploy) was skipped
@@ -135,16 +159,14 @@ python3 -m venv .venv
delivery. The test's expected total was changed from 30 to 31, so it
failed with \texttt{AssertionError: 30 != 31} while the application itself
was unchanged.
\item \textbf{Passing baseline and restore:} run \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/5/}{\#5} (11:13 PM EST), before the
\item \textbf{Passing baseline and restore:} run \#5 (6:13 PM EST), before the
controlled failure, passed all three tests. The test was then restored to
expect 30, and run \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/7/}{\#7} (11:20 PM EST) passed all three tests again. The same tests also
expect 30, and run \#7 (6:20 PM EST) passed all three tests again. The same tests also
pass locally in a fresh virtual environment (\texttt{Ran 3 tests in
0.085s, OK}).
\end{itemize}
All times in this chapter are Eastern Standard Time (EST), as displayed by Jenkins.
\delfig{build6-unit-test-fail.png}{1.0}{November 12, 2026, 11:19 PM EST ---
\delfig{build6-unit-test-fail.png}{1.0}{November 12, 2026, 6:19 PM EST (shown by Jenkins as 11:19 PM UTC) ---
Jenkins \texttt{feature/issue-24-delivery} run \#6 on \texttt{delivery-agent}:
\texttt{test\_price} fails, the Unit tests stage stops the run, and the build,
publish, and deploy stages are skipped.}{fig:del-test-fail}
@@ -245,10 +267,14 @@ Compose plugin ($\geq$ 2.18) & v5.5.1 (meets the minimum)\\
\item \textbf{Trust boundary:} every branch and pull request runs only the
Chapter~\ref{Chapter:ContinuousIntegration} checks on the controller, with
no credentials and no Docker socket. The \emph{Delivery} stages run only for
the trusted branch pattern \texttt{TRUSTED\_BRANCH}. During development it
also allowed \texttt{feature/issue-24-delivery}; for the assessed runs it is
\texttt{main} only, so only reviewed code can build, publish, or deploy.
\FillIn{confirm the change to main only and its commit} No Docker daemon API is published to the Internet.
the trusted branch pattern \texttt{TRUSTED\_BRANCH}. In the repository, the pattern is currently
\texttt{main|feature/issue-24-delivery} (Figure~\ref{fig:del-commit-diff}),
so the delivery runs recorded in this chapter (\#4 to \#16) ran from the
feature branch. Until the pattern is changed back to \texttt{main}, code on
that branch can build, publish, and deploy without a merge review. The
Jenkinsfile carries a comment to remove the feature branch from the pattern
before submission. \FillIn{commit that restores \texttt{main} only, once it is
made} No Docker daemon API is published to the Internet.
\end{itemize}
\section{Connect the Application to the Existing Proxy}
@@ -292,8 +318,9 @@ network per application would give stronger lateral isolation.
The \texttt{Jenkinsfile} keeps the Chapter~\ref{Chapter:ContinuousIntegration}
checks and adds a \emph{Delivery} block on the \texttt{delivery} agent with
these stages: Checkout, Unit tests, Security scan: source, Build image, Security
scan: image, Publish, Deploy staging, Staging idempotence, and Approve and deploy
production. The pipeline sets \texttt{disableConcurrentBuilds()}, so two runs
scan: image, Publish, Deploy staging, Staging idempotence, Approve production, and
Deploy production. A separate \emph{Redeploy release record} path, used for
rollback and recovery, is described in Section~\ref{sec:del-v2}. The pipeline sets \texttt{disableConcurrentBuilds()}, so two runs
cannot change staging or production at the same time.
The image is built once per source commit, with the commit baked in at build
@@ -316,27 +343,288 @@ artifacts. The image runs Gunicorn as the non-root user \texttt{10001}, and the
Compose template drops all capabilities and makes the root filesystem read-only
with a \texttt{tmpfs} for \texttt{/tmp}.
\begin{tabularx}{\linewidth}{L{3.2cm}Y}
{\small
\begin{tabularx}{\linewidth}{L{1.9cm}YYY}
\toprule
\textbf{Release} & \textbf{v1}\\ \midrule
Source commit & \texttt{2a35f97071c95b23bccb8c973099f2991c998599}\\
Jenkins build & \texttt{feature/issue-24-delivery} \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/8/}{\#8}\\
Image digest & \texttt{git.ssw590-08.me/ssw-590-08/\allowbreak pricing@sha256:\allowbreak ce91d0552da2a4580557ec65aedec04b\allowbreak 278fe918df1f02b23c971ca45cc3d97c}\\
Published & November 12, 2026, 11:51 PM EST\\
\textbf{Release v1} & \textbf{First build (superseded)} & \textbf{Rebuild (superseded)} & \textbf{Released v1, run \#9}\\ \midrule
Source commit & \texttt{\seqsplit{2a35f97071c95b23bccb8c973099f2991c998599}} & \texttt{\seqsplit{3fcd04010ad115df943d2d001dbc4a1523c2a6d1}} & \texttt{\seqsplit{69f1fe05cf72848e250d71349a76ee1157d44df3}}\\
Jenkins build & \#8 (earlier numbering, Nov 12) & \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/4/}{\#4} & \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/9/}{\#9}\\
Image digest & \texttt{\seqsplit{sha256:ce91d0552da2a4580557ec65aedec04b278fe918df1f02b23c971ca45cc3d97c}} & \texttt{\seqsplit{sha256:2688685992aa57bc94aaca36ea3cce22fd2cd9ba162ea2e09437531594e15bb7}} & \texttt{\seqsplit{sha256:7689c624960c3d47cc7eb0bd456b4023923a55a64e6941f621c82315b374adf5}}\\
Published & November 12, 2026, 6:51 PM EST & November 13, 2026, after the 7:48 PM EST image scan in the same build & November 13, 2026, run started 10:00 PM EST\\
Status & Failed the security policy: 7 fixable High findings (Section~\ref{sec:del-security}) & Passed the policy; superseded & Passed both gates: 0 fixable, 47 unfixed High (accepted exception); approved and promoted to production\\
\bottomrule
\end{tabularx}
\end{tabularx}}
\delfig{publish-digest.png}{1.0}{November 12, 2026, run \#8 --- Jenkins Publish
\medskip
Every commit produces a new image, because the commit is baked into the image at
build time. Runs \#7 (commit \texttt{c46f127e8c}, digest
\texttt{sha256:5e7c7244\ldots}) and \#8 also built v1 images on the way to the
final pipeline. The v1 that was released is the one built by run \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/9/}{\#9}, the
first run with the approval stage: its digest \texttt{sha256:7689c624\ldots} was
deployed to staging, approved, and promoted unchanged to production
(Section~\ref{sec:del-promote}). The v1 application files are the same in all of
these builds.
\medskip
All digests are in the registry repository \texttt{git.ssw590-08.me/ssw-590-08/pricing}.
Earlier builds are kept as a record. They were superseded by new builds, not
edited, so their images remain in the registry and their digests are unchanged.
\delfig{publish-digest.png}{1.0}{November 12, 2026, 6:51 PM EST, run \#8 (earlier numbering) --- Jenkins Publish
stage: the v1 image is pushed, the local copy deleted and pulled back from the
registry, and its registry digest recorded. The registry token is masked and
never printed.}{fig:del-publish}
\delfig{publish-digest-rebuild.png}{1.0}{November 13, 2026, build \#4 --- Jenkins
Publish stage for the rebuild: the registry digest
\texttt{sha256:2688685992aa\ldots} is recorded and echoed. The registry token is
masked and never printed.}{fig:del-publish-rebuild}
\section{Apply Proportionate Security Gates}
\label{sec:del-security}
\FillIn{kholmes: scan policy, tools and database versions, source and image
scan results, blocked synthetic fixture run, fix and rerun
(\texttt{security/scan.sh})}
\subsection{Policy}
The policy was written before the release was scanned
(\texttt{security/POLICY.md} in the repository). The pipeline fails, and no
image is published or deployed, when any of these is true:
\begin{itemize}
\item a secret is detected;
\item \texttt{pip-audit} reports a known vulnerability in the locked
dependencies;
\item a HIGH or CRITICAL vulnerability that \emph{has a fix available} is found
in the repository or the built image;
\item a scanner errors, a tool is missing, or the vulnerability database
cannot be obtained. A failed scan is not a clean scan.
\end{itemize}
HIGH or CRITICAL vulnerabilities with \emph{no fix yet} (typically operating-system
packages in the base image) do not block the build, but they are never hidden:
each image scan also writes a full report and a count summary, which Jenkins
archives with the build, and the accepted set is recorded below as a time-limited
exception. A fixable finding is handled by updating the lockfile or the pinned
base-image digest, rebuilding, and rescanning; a fixable finding accepted for a
stated reason would be recorded in \texttt{security/.trivyignore} with an
expiry date. No claim is made that any scanned version is free of
vulnerabilities.
\subsection{Tools and Versions}
The checks are implemented in \texttt{security/scan.sh}, called by the
\emph{Security scan: source} and \emph{Security scan: image} stages. It uses
no \texttt{|| true}, so a failing scanner fails the stage.
\begin{tabularx}{\linewidth}{L{4.4cm}Y}
\toprule
\textbf{Item} & \textbf{Value}\\ \midrule
Trivy~\cite{TrivyDocs} & 0.76.2\\
Trivy vulnerability database & version 2; updated 2026-11-13 19:05:12 UTC;
downloaded to the agent 2026-11-13 22:54:18 UTC (the pipeline image scan at
2026-11-14 00:48:38 UTC used this same cached copy)\\
pip-audit~\cite{PipAudit} & 2.10.1\\
Blocking severities & HIGH and CRITICAL\\
\bottomrule
\end{tabularx}
\subsection{Source Scans}
The source checks were first run by hand inside the \texttt{jenkins-agent}
container on November 13, 2026, at 5:58--5:59 PM EST, against the agent's
existing \texttt{Scrap-Web\_main} workspace. That workspace was at commit
\texttt{fa52a28a0c8ffbf05b77c54e801b88e592522f6d}, not at the v1 release commit,
so this run shows the method and the state of the repository at that commit and
is not the release gate:
\begin{minted}[breaklines,breakanywhere]{text}
pip-audit -r pricing/requirements.txt --strict --progress-spinner off
trivy fs --scanners vuln,secret --severity HIGH,CRITICAL --exit-code 1 --no-progress --skip-dirs .git,.venv .
\end{minted}
\begin{tabularx}{\linewidth}{L{4.2cm}L{2.2cm}Y}
\toprule
\textbf{Check} & \textbf{Exit code} & \textbf{Result}\\ \midrule
\texttt{pip-audit} & 0 & ``No known vulnerabilities found''\\
\texttt{trivy fs} & 0 & \texttt{pricing/requirements.txt}: 0 vulnerabilities; no secrets reported\\
\bottomrule
\end{tabularx}
\medskip
For the release itself, the \emph{Security scan: source} stage runs the same
checks on the release commit before the image is built. Stages run in order and
the \emph{Publish} stage follows both scans, so the successful publish of the
image built from commit \texttt{3fcd04010ad1\ldots} (below) means both scan stages
passed for it. Figure~\ref{fig:del-source-scan} shows the start of the source
scan output in the Jenkins console: \texttt{pip-audit} 2.10.1 reported ``No known
vulnerabilities found'' and exited with status 0 at 2026-11-14 00:47:41 UTC
(7:47~PM EST on November 13), after which \texttt{trivy fs} began its secret and
vulnerability scan.
\delfig{del-source-scan-build4.png}{1.0}{November 13, 2026, build \#4 --- Jenkins
console output of the \emph{Security scan: source} stage: \texttt{pip-audit} exit
status 0 at 00:47:41 UTC (7:47~PM EST) and the start of the \texttt{trivy fs}
scan. Screenshot taken at 8:56~PM EST.}{fig:del-source-scan}
The same build's \texttt{trivy fs} result is in Figure~\ref{fig:del-trivy-fs}:
\texttt{pricing/requirements.txt} (type \texttt{pip}) has 0 vulnerabilities, and
the stage ends with \texttt{RESULT trivy-fs: exit=0} at 2026-11-14 00:48:00 UTC.
\delfig{del-trivy-fs-build4.png}{1.0}{November 13, 2026, build \#4 --- Jenkins
console output of the \emph{Security scan: source} stage: \texttt{trivy fs}
report summary (0 vulnerabilities in \texttt{pricing/requirements.txt}) and
\texttt{RESULT trivy-fs: exit=0} at 00:48:00 UTC (7:48~PM EST).}{fig:del-trivy-fs}
\subsection{Image Scan: First v1 Build and Corrective Rebuild}
\textbf{First build (scanned by hand, before the policy was enforced in the
pipeline).} The image from source commit \texttt{2a35f97} (digest
\texttt{sha256:ce91d055\ldots}) was scanned on November 13, 2026, at 6:18~PM EST
with \texttt{trivy image --severity HIGH,CRITICAL}. Trivy identified Debian 13.7.
It reported \textbf{54 HIGH and no CRITICAL} findings (49 in operating-system
packages, 5 in Python packages): \textbf{7 had a fix available and 47 did
not.} The application's own locked dependencies (Flask, Gunicorn, Werkzeug,
Jinja2, and the others) showed no findings. Under the policy this image fails the
gate because of the 7 fixable findings:
\begin{tabularx}{\linewidth}{L{2.4cm}L{3.8cm}L{3.2cm}Y}
\toprule
\textbf{Package} & \textbf{Advisory} & \textbf{Installed} & \textbf{Fixed in}\\ \midrule
zlib1g & CVE-2026-76844 & \texttt{\seqsplit{1:1.3.dfsg+really1.3.1-1+b1}} & \texttt{…+deb13u1}\\
zlib1g & CVE-2026-85091 & same & \texttt{…+deb13u1}\\
msgpack & CVE-2026-114613 & 1.1.2 & 1.2.3\\
msgpack & GHSA-6v7p-g79w-8964 & 1.1.2 & 1.2.1\\
setuptools & CVE-2025-47273 & 70.3.0 & 78.1.1\\
urllib3 & CVE-2026-97687 & 2.7.0 & 2.8.0\\
urllib3 & CVE-2026-97689 & 2.7.0 & 2.8.0\\
\bottomrule
\end{tabularx}
\medskip
None of these packages is in the project's lockfile, so they come from the base
image's operating system and Python environment, not from the application.
\textbf{Corrective rebuild.} The image was rebuilt from commit
\href{https://git.ssw590-08.me/SSW-590-08/Scrap-Web/commit/3fcd04010ad115df943d2d001dbc4a1523c2a6d1}{\texttt{3fcd04010ad115df943d2d001dbc4a1523c2a6d1}}
in Jenkins build
\href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/4/}{\#4}.
The new digest is
\texttt{sha256:2688685992aa57bc94aaca36ea3cce22fd2cd9ba162ea2e09437531594e15bb7}.
The Dockerfile on the delivery branch pins the base image by digest:
\texttt{FROM python:3.13-slim@sha256:e48f59cdba69a3cbd9ed2cf0f348d90d\allowbreak 45a8d350d98134cf1070bc106ee9ed90},
the same digest named in Section~\ref{sec:del-baseline}, so the base-image digest did
not change between the two builds. The rebuild commit adds two lines to the Dockerfile
(Figure~\ref{fig:del-commit-diff}): one \texttt{RUN} step that upgrades only the
\texttt{zlib1g} package with \texttt{apt-get install -{}-only-upgrade} and
removes the apt package lists, and a second command that uninstalls \texttt{pip}
and \texttt{setuptools} from the image. The upgrade addresses the two
\texttt{zlib1g} findings, and removing \texttt{setuptools} removes its finding.
The diff does not mention \texttt{msgpack} or \texttt{urllib3}, but the package
list in the rebuilt image's scan (Figure~\ref{fig:del-image-scan}) contains
only the nine application packages and no \texttt{pip}, \texttt{setuptools},
\texttt{msgpack} or \texttt{urllib3} entry. Two trade-offs follow. The
\texttt{apt-get} step makes the result depend on the package archive at build
time, so the image digest, not the Dockerfile, is the identity of the release.
And the image can no longer install packages at runtime, which suits a service
whose dependencies are fixed at build time.
\delfig{del-commit-diff.png}{1.0}{November 13, 2026 --- commit diff of the rebuild
(screenshot taken at 9:15~PM EST): \texttt{pricing/Dockerfile} gains the
\texttt{zlib1g} upgrade and the \texttt{pip}/\texttt{setuptools} removal, and the
Jenkinsfile \texttt{TRUSTED\_BRANCH} pattern gains
\texttt{feature/issue-24-delivery}.}{fig:del-commit-diff} The pipeline's image scan ran at
2026-11-14 00:48:38 UTC (7:48~PM EST on November 13) and wrote its summary:
\begin{minted}[breaklines,breakanywhere]{text}
image findings at HIGH/CRITICAL (all, including unfixed):
HIGH no fix yet 47
total 47
\end{minted}
The 7 fixable findings are gone: no HIGH or CRITICAL finding with a fix remains
and no CRITICAL finding exists, so the gate passes for the rebuilt image.
Figure~\ref{fig:del-image-scan}, taken from the archived \texttt{trivy-image.txt},
shows the gate scan of the image tagged with commit \texttt{3fcd0401}: Debian 13.7
with 0 vulnerabilities, and 0 in each of the application's Python packages.
\delfig{del-image-scan-build4.png}{1.0}{November 13, 2026, build \#4 ---
\texttt{trivy-image.txt} from the \emph{Security scan: image} stage (scan at
00:48:41 UTC, 7:48~PM EST): 0 fixable High/Critical findings in the operating
system and in each Python package. Screenshot taken at 9:21~PM EST.}{fig:del-image-scan}
\begin{tabularx}{\linewidth}{L{3.0cm}L{2.6cm}L{2.4cm}Y}
\toprule
\textbf{Build} & \textbf{Source commit} & \textbf{Fixable HIGH/CRIT} & \textbf{Unfixed HIGH}\\ \midrule
First v1 (by hand) & \texttt{2a35f97} & 7 & 47\\
Rebuild (\#4) & \texttt{3fcd0401} & 0 & 47\\
\bottomrule
\end{tabularx}
\subsection{Accepted Exception}
The 47 remaining HIGH findings have no fixed package version yet. They are
accepted for this teaching deployment on these grounds: no fix exists to apply,
the pricing service is stateless and processes no customer data, application
port 8000 is not published, and the container runs as a non-root user with all
capabilities dropped and a read-only root filesystem. The exception was accepted on November 13, 2026. It is time-limited and must be
reviewed again by November 20, 2026, or
earlier when a fixed package version is released. The full list is in
\texttt{trivy-image-full.json}, archived with the Jenkins build.
\subsection{Blocked Pipeline Run}
On November 13, 2026, the gate was tested with a synthetic secret fixture, a file
containing a made-up token (see the fixture check below). In Jenkins run \#6
(screenshot taken at 9:02~PM EST), the stages after the source scan,
\emph{Build image}, \emph{Security scan: image}, \emph{Publish} and
\emph{Deploy staging}, were each skipped with the message ``skipped due to earlier
failure(s)'' (Figure~\ref{fig:del-blocked-run}), so no image was built or
published for that run. After the fixture was removed, run \#7 (screenshot taken at
9:08~PM EST) passed the scan stages and reached \emph{Publish}, where the log
shows the registry login with the token masked as \texttt{****}
(Figure~\ref{fig:del-rerun}).
The Trivy output for the fixture (Figure~\ref{fig:del-secret-finding}, from
\texttt{trivy-source.txt}, scan time 02:00:42 UTC, which is 9:00~PM EST) reports
one \texttt{CRITICAL} secret of type \texttt{github-pat} in
\texttt{security/fixture-secret.txt}, line 1, with the value masked. A critical
finding makes the source scan exit non-zero under the policy, which is what stops
the later stages. The fixture was added in commit \texttt{05d3c58c3a} (message ``testing build
block'', parent \texttt{3fcd04010a}) and removed in commit \texttt{c46f127e8c}
(message ``removed forced error'', parent \texttt{05d3c58c3a}); the two commit
pages are in Figures~\ref{fig:del-fixture-added} and~\ref{fig:del-fixture-removed},
with the token value covered. The value is made up, but the commit remains in the
repository history. Run \#7, on the removal commit, finished with
\texttt{Finished: SUCCESS} (Figure~\ref{fig:del-run7-success}). In that run the
\emph{Approve and deploy production} stage was still a placeholder that printed
``Not implemented yet'', so no production step ran. Run \#7 also executed the
Publish and Deploy staging stages for commit \texttt{c46f127e8c}, publishing
digest \texttt{sha256:5e7c7244\ldots}. Neither run \#4 nor run \#7 is the
released v1; that is run \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/9/}{\#9} (Section~\ref{sec:del-promote}), whose
image scan again reported 0 fixable and 47 unfixed HIGH findings.
\delfig{del-fixture-added.png}{1.0}{November 13, 2026 --- Gitea commit page for
\texttt{05d3c58c3a}, ``testing build block'', which adds
\texttt{security/fixture-secret.txt} (token value covered). The commit shows a
failed status. Screenshot taken at 9:27~PM EST.}{fig:del-fixture-added}
\delfig{del-fixture-removed.png}{1.0}{November 13, 2026 --- Gitea commit page for
\texttt{c46f127e8c}, ``removed forced error'', which deletes the fixture file
(token value covered). The commit shows a passing status. Screenshot taken at
9:27~PM EST.}{fig:del-fixture-removed}
\delfig{del-run7-success.png}{0.9}{November 13, 2026, run \#7 (screenshot taken at
9:27~PM EST) --- end of the Jenkins console: the production stage still prints
``Not implemented yet'', the pipeline reports ``All stages passed'' and
\texttt{Finished: SUCCESS}.}{fig:del-run7-success}
\delfig{del-blocked-run6.png}{0.9}{November 13, 2026, run \#6 (screenshot taken at
9:02~PM EST) --- Jenkins console: \emph{Build image}, \emph{Security scan: image},
\emph{Publish} and \emph{Deploy staging} skipped due to earlier failure(s).}{fig:del-blocked-run}
\delfig{del-rerun7.png}{0.9}{November 13, 2026, run \#7 (screenshot taken at
9:08~PM EST) --- Jenkins console after the fixture was removed: the pipeline
reaches \emph{Publish}; the registry token is masked as \texttt{****}.}{fig:del-rerun}
\delfig{del-source-scan-secret.png}{1.0}{November 13, 2026, source scan with the
synthetic fixture (scan time 02:00:42 UTC, 9:00~PM EST): Trivy reports 1
\texttt{CRITICAL} \texttt{github-pat} secret in \texttt{security/fixture-secret.txt};
the value is masked. The exit status line is not in this screenshot.}{fig:del-secret-finding}
\textbf{Fixture check.} Before it was committed, the fixture format was tested
locally in the agent on November 13, 2026, at 6:55~PM EST, in a temporary
directory outside the repository. Trivy reported one finding, \texttt{CRITICAL:
GitHub (github-pat)}, and exited with status 1. The value is made up and is
not a live credential; Trivy masked it in its output.
\section{Deploy v1 with Ansible and Prove Idempotence}
\label{sec:del-ansible}
@@ -351,13 +639,13 @@ template with every placeholder replaced.
\gls{releaserecord} from the build it belongs to, so the digest and commit cannot be
mistyped. The expected version and total are read from the application source
(\texttt{VERSION} and \texttt{3 $\times$ UNIT\_PRICE}), not from configuration.
The record is archived with the build. For v1 it contains:
The record is archived with the build. For the rebuild (build \#4) it contained the following; run \#7 generates the same fields from its own digest and commit:
\begin{minted}[breaklines,breakanywhere]{yaml}
target_env: staging
release_image: git.ssw590-08.me/ssw-590-08/pricing@sha256:ce91d0552da2a4580557ec65aedec04b278fe918df1f02b23c971ca45cc3d97c
release_image: git.ssw590-08.me/ssw-590-08/pricing@sha256:2688685992aa57bc94aaca36ea3cce22fd2cd9ba162ea2e09437531594e15bb7
expected_version: v1
expected_commit: 2a35f97071c95b23bccb8c973099f2991c998599
expected_commit: 3fcd04010ad115df943d2d001dbc4a1523c2a6d1
expected_total: 30
public_url: https://staging.ssw590-08.me
proxy_network: gitea-net
@@ -381,65 +669,426 @@ fails the run if any check fails; it does not roll back on its own.
same command again and fails the build unless the recap shows
\texttt{changed=0 unreachable=0 failed=0}:
\begin{tabularx}{\linewidth}{L{2.6cm}Y}
\begin{tabularx}{\linewidth}{L{3.4cm}L{2.2cm}Y}
\toprule
\textbf{Run} & \textbf{PLAY RECAP for \texttt{startup}}\\ \midrule
First & \texttt{ok=9 changed=3 unreachable=0 failed=0 skipped=0}\\
Second & \texttt{ok=9 changed=0 unreachable=0 failed=0 skipped=0}\\
\textbf{Build} & \textbf{Run} & \textbf{PLAY RECAP for \texttt{startup}}\\ \midrule
First build, \#8 & First & \texttt{ok=9 changed=3 unreachable=0 failed=0 skipped=0}\\
& Second & \texttt{ok=9 changed=0 unreachable=0 failed=0 skipped=0}\\ \addlinespace
Rebuild, \#4 & First & \texttt{ok=9 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0}\\
& Second & \texttt{ok=9 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0}\\ \addlinespace
Run \#7 & First & \texttt{ok=9 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0}\\
& Second & \texttt{ok=9 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0}\\
\bottomrule
\end{tabularx}
\medskip
Jenkins run \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/8/}{\#8} (November 12, 2026, 11:51 PM EST): the first run created the environment and started the
container (\texttt{changed=3}); the identical second run changed nothing, and the
stage's check matched the recap line
\texttt{startup : ok=9 changed=0 unreachable=0 failed=0}. In the second run every
task reported \texttt{ok}, including the public HTTPS health, release-identity,
and price checks (\texttt{"msg": "All assertions passed"}).
\textbf{First build, run \#8 of the earlier numbering} (November 12, 2026, 6:51 PM EST): the first
run created the environment and started the container (\texttt{changed=3}); the
identical second run changed nothing, and the stage's check matched the recap
line \texttt{startup : ok=9 changed=0 unreachable=0 failed=0}. In the second run
every task reported \texttt{ok}, including the public HTTPS health,
release-identity, and price checks (\texttt{"msg": "All assertions passed"}).
\delfig{staging-idempotence.png}{1.0}{November 12, 2026, run \#8 --- Jenkins
\textbf{Rebuild, run \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/4/}{\#4}} (November 13, 2026): the rebuilt image was
deployed to the same staging project. The first run applied the new release
(\texttt{changed=2}) and the identical second run changed nothing
(\texttt{changed=0}), so the \emph{Staging idempotence} stage passed.
Figure~\ref{fig:del-idempotence-rebuild} shows the start of that stage's log. The
recap lines above were copied from the build's console output.
\textbf{Run \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/7/}{\#7}} (November 13, 2026): the image from commit
\texttt{c46f127e8c} was deployed to the same staging project. The first run
applied the new release (\texttt{changed=2}, Figure~\ref{fig:del-recap7-first}).
The identical second run changed nothing (\texttt{changed=0}), and the stage's
\texttt{grep} check for \texttt{changed=0 unreachable=0 failed=0} in
\texttt{rerun.log} matched (Figure~\ref{fig:del-recap7-second}), so the
\emph{Staging idempotence} stage passed.
\delfig{staging-idempotence.png}{1.0}{November 12, 2026, 6:51 PM EST, run \#8 (earlier numbering) --- Jenkins
Staging idempotence stage: the second, unchanged run passes every check and
reports \texttt{changed=0}.}{fig:del-idempotence}
\delfig{staging-idempotence-rebuild.png}{1.0}{November 13, 2026, build \#4 ---
start of the Jenkins \emph{Staging idempotence} stage log for the rebuild: the same
\texttt{ansible-playbook} command and release record
(\texttt{release-v1-staging.yml}) are run again, with the deploy key masked
(\texttt{****}) and output copied to \texttt{rerun.log}. Its \texttt{changed=0}
recap line is quoted in the text.}{fig:del-idempotence-rebuild}
\delfig{del-run7-recap-first.png}{1.0}{November 13, 2026, run \#7 (screenshot
taken at 9:32~PM EST) --- first \texttt{PLAY RECAP} for \texttt{startup}:
\texttt{ok=9 changed=2 unreachable=0 failed=0}, followed by the start of the
\emph{Staging idempotence} stage, which runs the same command with the deploy key
masked.}{fig:del-recap7-first}
\delfig{del-run7-recap-second.png}{1.0}{November 13, 2026, run \#7 (screenshot
taken at 9:32~PM EST) --- second \texttt{PLAY RECAP}: \texttt{changed=0}, the
\texttt{grep} check on \texttt{rerun.log} matching it, the production stage still
printing ``Not implemented yet'', and ``All stages passed''.}{fig:del-recap7-second}
\delfig{staging-check.png}{1.0}{November 13, 2026 --- staging, v1:
\url{https://staging.ssw590-08.me/} returns version \texttt{v1} and commit
\texttt{2a35f97}, and \texttt{/price?quantity=3} returns a total of USD 30.}{fig:del-staging}
\delfig{staging-check-rebuild.png}{0.9}{November 13, 2026, about 8:29--8:30~PM
EST --- staging, rebuilt v1: \url{https://staging.ssw590-08.me/} returns version
\texttt{v1} and commit \texttt{3fcd0401}, and \texttt{/price?quantity=3} returns
a total of USD 30.}{fig:del-staging-rebuild}
\section{Approve and Promote the Same Image}
\label{sec:del-promote}
\FillIn{kholmes: restricted Jenkins input step with timeout, approver and
decision, v1-production record with the same digest, production smoke tests}
\subsection{Restricted Approval}
After \emph{Staging idempotence}, the pipeline stops at an \emph{Approve
production} stage that uses the Jenkins \texttt{input} step~\cite{JenkinsInput}:
\begin{minted}[breaklines,breakanywhere]{groovy}
def APPROVERS = 'samahk,kaylah7' // Jenkins user IDs; anonymous users cannot approve
timeout(time: 30, unit: 'MINUTES') {
env.APPROVER = input(
message: """Promote ${env.APP_VERSION} to production (https://app.ssw590-08.me)?
Source commit: ${env.APP_COMMIT}
Image digest: ${env.IMAGE_DIGEST}
Security scans: ... ${scan}
Staging: deployed, HTTPS health/version/commit/total ${env.EXPECTED_TOTAL} passed, rerun changed=0.""",
ok: 'Approve and deploy to production',
submitter: APPROVERS, submitterParameter: 'APPROVER')
}
\end{minted}
\begin{itemize}
\item \textbf{Restricted:} only the Jenkins users \texttt{samahk} and
\texttt{kaylah7} can approve. Anyone else, including an anonymous user, cannot.
\item \textbf{Informed:} the prompt shows the source commit, the image digest,
the scan result (the archived \texttt{image-summary.txt}), and the staging
result (Figure~\ref{fig:del-approve}).
\item \textbf{Recorded:} \texttt{submitterParameter} returns the actual
approver, who is printed in the log with the time and written into the
production release record (\texttt{approved\_by}, \texttt{approved\_at}).
\item \textbf{Stops safely:} \emph{Abort}, or no answer within 30 minutes, ends
the run before any production step. Runs
\href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/12/}{\#12}
and \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/14/}{\#14}
were aborted at this prompt, and \emph{Deploy production} did not run
(Figure~\ref{fig:del-aborted}).
\end{itemize}
\subsection{Promotion of v1}
Run \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/9/}{\#9}
(push at 10:00 PM EST on November 13, 2026; source commit
\texttt{69f1fe05cf72848e250d71349a76ee1157d44df3}) passed every gate, deployed to
staging with an unchanged rerun, and stopped for approval. \texttt{samahk}
approved at 10:04:14 PM EST. The \emph{Deploy production} stage then wrote
\texttt{release-v1-production.yml} from the values already recorded in the run,
archived it before deploying, and ran the same playbook with it. Nothing was
rebuilt: production received the digest that staging had passed.
\begin{minted}[breaklines,breakanywhere]{yaml}
target_env: production
release_image: git.ssw590-08.me/ssw-590-08/pricing@sha256:7689c624960c3d47cc7eb0bd456b4023923a55a64e6941f621c82315b374adf5
expected_version: v1
expected_commit: 69f1fe05cf72848e250d71349a76ee1157d44df3
expected_total: 30
public_url: https://app.ssw590-08.me
proxy_network: gitea-net
approved_by: samahk
approved_at: 2026-11-14T03:04:14+00:00
\end{minted}
The record is committed as \texttt{releases/v1-production.yml}, with
\texttt{releases/v1-staging.yml} beside it; it holds no credentials. The playbook's
production smoke tests passed, and \url{https://app.ssw590-08.me/} returned
\texttt{v1}, commit \texttt{69f1fe0}, and a total of USD~30
(Figure~\ref{fig:del-prod-v1}).
\delfig{approve-prompt-run9.png}{1.0}{November 13, 2026, about 10:03 PM EST, run
\#9 --- the restricted approval prompt for v1, showing the source commit, image
digest, scan summary (47 unfixed HIGH, 0 fixable), and staging
result.}{fig:del-approve}
\delfig{prod-v1-run9.png}{0.75}{November 13, 2026, after 10:04 PM EST ---
production, v1 from run \#9: \url{https://app.ssw590-08.me/} returns version
\texttt{v1} and commit \texttt{69f1fe0}, and \texttt{/price?quantity=3} returns
30.}{fig:del-prod-v1}
\delfig{approval-aborted-run14.png}{1.0}{November 13, 2026, 10:39 PM EST, run
\#14 --- the approval was aborted after 17 seconds; \emph{Deploy production} did
not run.}{fig:del-aborted}
\section{Release v2 and Exercise Two Recovery Cases}
\label{sec:del-v2}
\FillIn{kholmes: v2 release in both environments, healthy rollback of
production to v1, failed staging deployment (Gunicorn on 8001) and recovery,
timeline and measured interruption, state-compatibility discussion}
\subsection{Release v2}
The supplied v2 changes (\texttt{VERSION = "v2"}, \texttt{UNIT\_PRICE = 12}, and
the matching test expectations: total 36, version \texttt{v2}) were committed
together with the v1 release records as
\texttt{d6787727f8ebce3f8ac0f8f6d36ddef352ba63da}. Run
\href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/10/}{\#10}
(10:13 PM EST) passed tests and both security gates, published digest
\texttt{sha256:d7aa3cfc\ldots}, deployed it to staging with an unchanged rerun, and
was approved by \texttt{samahk} at 10:17:50 PM EST. Production then returned
\texttt{v2}, commit \texttt{d678772}, and a total of USD~36
(Figure~\ref{fig:del-prod-v2}). The v2 records were committed as
\texttt{releases/v2-staging.yml} and \texttt{releases/v2-production.yml} in
\texttt{7b73df1}; the v1 records were kept.
\delfig{prod-v2-run10.png}{0.75}{November 13, 2026, after 10:18 PM EST ---
production, v2 from run \#10: version \texttt{v2}, commit \texttt{d678772}, total
36.}{fig:del-prod-v2}
\subsection{Rollback and Recovery Mechanism}
Rollback reuses the release records. When the pipeline's \texttt{DEPLOY\_RECORD}
parameter names a committed record, the \emph{Delivery} block is skipped and a
\emph{Redeploy release record} path runs instead: it checks that the record
exists under \texttt{releases/}, prints it, asks for the same restricted approval
if the target is production, and runs the playbook with that record and the
Ansible files of the commit being built. Nothing is rebuilt, and the playbook's
health, version, commit, and price checks still decide success. The
configuration that is restored is therefore both the image digest in the record
and the template and playbook of the chosen commit.
\subsection{Case 1: Healthy Rollback of Production to v1}
Production was healthy on v2. Rolling back to v1 was a planned business
decision, made at 10:23 PM EST, so there was no failure to detect.
\begin{tabularx}{\linewidth}{L{3.2cm}Y}
\toprule
\textbf{Time (EST)} & \textbf{Event}\\ \midrule
10:23 PM & Decision; run \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/11/}{\#11} started with \texttt{DEPLOY\_RECORD=releases/v1-production.yml} at configuration commit \texttt{d678772}; approved by \texttt{samahk}\\
10:24:07 & First failed request: \texttt{https://app.ssw590-08.me/health} returned HTTP 502 while Compose recreated the container\\
10:24:09 & Last failed request (3 failures, 1-second polling)\\
10:24:10 & Service answering again; the playbook's checks then passed and the run finished successfully\\
\bottomrule
\end{tabularx}
\medskip
Production returned \texttt{v1}, commit \texttt{69f1fe0}, health OK, and a total
of 30 (Figure~\ref{fig:del-rollback}). The observed interruption was about 3
seconds, measured on the Droplet with a once-per-second \texttt{curl} loop:
\begin{minted}[breaklines,breakanywhere]{bash}
while true; do echo "$(date +%T) $(curl -s -o /dev/null -w '%{http_code}' https://app.ssw590-08.me/health)"; sleep 1; done | tee ~/rollback-probe.log
grep -v " 200$" ~/rollback-probe.log # 03:24:07, 03:24:08, 03:24:09 UTC: 502
\end{minted}
This is a recreate deployment, not a zero-downtime one: Caddy returns 502 while
the old container is stopped and the new one starts.
\delfig{prod-rollback-v1-run11.png}{0.75}{November 13, 2026, after 10:24 PM EST
--- production after the rollback in run \#11: version \texttt{v1}, commit
\texttt{69f1fe0}, total 30.}{fig:del-rollback}
\subsection{Case 2: Failed Deployment in Staging and Recovery}
\begin{enumerate}
\item \textbf{Fault, in a separate configuration commit.} Commit
\texttt{1222628} (``Controlled failure: staging Gunicorn on 8001'') added to
\texttt{ansible/templates/compose.yaml.j2}, for staging only:
\begin{minted}[breaklines,breakanywhere]{jinja}
{% if target_env == 'staging' %}
command: ["gunicorn", "--bind", "0.0.0.0:8001", "app:app"]
{% endif %}
\end{minted}
Gunicorn now listened on 8001 while the image health check still tested 8000.
Nothing else was changed: not the Docker daemon, Caddy, Gitea, or Jenkins.
\item \textbf{Failure.} Run
\href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/13/}{\#13}
(10:33 PM EST) passed tests, scans, and publish, but \emph{Deploy staging}
failed after 24 seconds: the container never became healthy, so the Compose
wait in the playbook failed. Every later stage, including approval and
production, was skipped (Figure~\ref{fig:del-failed}). Production stayed on v1.
\item \textbf{Restore the reviewed configuration.} \texttt{git revert} created
commit \texttt{1841a7d}, which restores the template of the reviewed
commits. Its automatic run
\href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/14/}{\#14}
deployed staging successfully and was aborted at the production approval
(Figure~\ref{fig:del-aborted}).
\item \textbf{Redeploy the reviewed release record.} Run
\href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/15/}{\#15}
(10:42 PM EST) redeployed \texttt{releases/v2-staging.yml} (digest
\texttt{sha256:d7aa3cfc\ldots}, commit \texttt{d678772}) with configuration
commit \texttt{1841a7d}. The playbook's HTTPS checks passed, and staging
returned \texttt{v2}, commit \texttt{d678772}, and a total of 36
(Figure~\ref{fig:del-restored}).
\end{enumerate}
\delfig{staging-failed-run13.png}{1.0}{November 13, 2026, 10:33 PM EST, run
\#13 --- the controlled failure: \emph{Deploy staging} fails (Compose wait,
unhealthy container), and staging idempotence, approval, and production are
skipped.}{fig:del-failed}
\delfig{staging-restored-v2-run15.png}{0.75}{November 13, 2026, after 10:42 PM
EST --- staging after recovery run \#15: version \texttt{v2}, commit
\texttt{d678772}, total 36.}{fig:del-restored}
\subsection{State Compatibility}
Both rollbacks were safe because the pricing service is stateless: it has no
database, no stored data, and no external side effects, so running the older
image is enough to restore the older behaviour. Image-only rollback would not be
safe in three common cases:
\begin{itemize}
\item \textbf{Database migration.} If v2 had dropped or renamed a column, v1
would fail against the migrated database, and rolling the schema back could
lose data written by v2.
\item \textbf{External payment.} Charges made at the v2 price of 12 are already
with the payment provider; redeploying v1 does not reverse them, and they
would need refunds or reconciliation.
\item \textbf{Incompatible stored state.} Sessions, queued jobs, or cached data
written in a v2-only format could be unreadable by v1.
\end{itemize}
A compatible approach is \textbf{expand and contract}: first release a schema
change that only adds (for example, a new nullable column) and works with both
versions; then deploy the code that uses it; and only after the new version is
proven, remove the old structure in a later release. During the expand phase,
either version can run against the same data, so rolling back the image stays
safe.
\section{Reuse Monitoring and Document Operations}
\label{sec:del-ops}
\FillIn{kholmes: production /health Blackbox probe and Grafana panel, release
and rollback timestamps correlated with monitoring, runbooks, approvers,
resource use, cleanup plan}
\subsection{Production Health Probe}
The production endpoint \texttt{https://app.ssw590-08.me/health} was added to the
Blackbox Exporter's \texttt{https} job in
\texttt{monitoring/prometheus/prometheus.yml}, beside the existing Gitea and
Jenkins probes; the host metrics are unchanged. The file is bind-mounted read-only
into the Prometheus container, so the container was recreated
(\texttt{docker compose up -d -{}-force-recreate prometheus}) to load it. The
probe has recorded since 10:50:30 PM EST on November 13, 2026. Its availability is
shown in Grafana with
\texttt{probe\_success\{instance="https://app.ssw590-08.me/health"\}}
(Figure~\ref{fig:del-grafana}). The probe only reports status; the version and
price checks stay in the pipeline, because a status probe cannot validate a price.
\subsection{Correlating a Release with Monitoring}
The probe was added after the rollback in run \#11, so that rollback has no
Prometheus data; its evidence is the per-second log above. To correlate a
deployment with monitoring, production was then rolled forward to v2 with run
\href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/16/}{\#16}
(\texttt{DEPLOY\_RECORD=releases/v2-production.yml}, approved):
\begin{tabularx}{\linewidth}{L{3.2cm}Y}
\toprule
\textbf{Time (EST)} & \textbf{Observation}\\ \midrule
10:50:30 PM & First \texttt{probe\_success} sample for production (value 1)\\
10:51 PM & Run \#16 started; approved by \texttt{samahk}\\
10:55:16--10:55:22 & HTTP 502 in the per-second log (6 failed requests, about 7 seconds)\\
10:55:35 & Playbook checks passed: ``Redeploy verified'' (Figure~\ref{fig:del-redeploy}); \texttt{changed=2}\\
10:50--10:58 PM & Grafana shows \texttt{probe\_success} = 1 at every sample (Figure~\ref{fig:del-grafana})\\
\bottomrule
\end{tabularx}
\medskip
\textbf{What was actually observed.} Prometheus probes every 30 seconds, and the
7-second interruption fell between two samples, so Grafana shows no dip and no
alert fired. The \texttt{ServiceUnavailable} rule also needs a failure lasting
1 minute before it fires (Chapter~\ref{Chapter:SRE}). Short recreate
interruptions are therefore measured by the pipeline's own checks and a
fine-grained probe, not by the 30-second monitoring stack.
\delfig{grafana-app-probe.png}{1.0}{November 13, 2026, 10:44--10:58 PM EST ---
Grafana Explore, \texttt{probe\_success} for \texttt{https://app.ssw590-08.me/health}:
data from 10:50:30 PM, value 1 throughout, including the roll-forward at
10:55 PM.}{fig:del-grafana}
\delfig{redeploy-verified-run16.png}{1.0}{November 13, 2026, run \#16 --- end of
the redeploy of \texttt{releases/v2-production.yml}: all playbook checks pass,
\texttt{changed=2}, and ``Redeploy verified'' at 03:55:35 UTC (10:55:35 PM
EST).}{fig:del-redeploy}
\delfig{jenkins-run-history.png}{0.6}{Run history of
\texttt{feature/issue-24-delivery} (times in UTC): \#9 v1 release, \#10 v2
release, \#11 rollback, \#12 and \#14 aborted at approval, \#13 controlled
failure, \#15 staging recovery, \#16 roll-forward.}{fig:del-run-history}
\subsection{Roles}
\begin{tabularx}{\linewidth}{L{3.4cm}Y}
\toprule
\textbf{Action} & \textbf{Who}\\ \midrule
Approve production & Jenkins users \texttt{samahk} and \texttt{kaylah7} only (input \texttt{submitter})\\
Deploy (staging, production) & Only the Jenkins delivery agent, for trusted branches, using \texttt{deploy-ssh}; production only after approval\\
Roll back or recover & Anyone who can start a Jenkins build sets \texttt{DEPLOY\_RECORD}; production still needs an approver\\
Droplet, Caddy, DNS, monitoring & \texttt{samahk13} (administrator SSH)\\
\bottomrule
\end{tabularx}
\subsection{Runbooks}
\textbf{Release.}
\begin{enumerate}
\item Commit the application change with its tests on a branch, review it, and merge.
\item Let the pipeline run: tests, both scans, build, publish, staging, rerun.
\item An approver checks the commit, digest, scan summary, and staging result in
the prompt, then approves or aborts.
\item After \emph{Deploy production} passes, download the two release records
from the run's artifacts and commit them under \texttt{releases/}.
\end{enumerate}
\textbf{Failed deployment.}
\begin{enumerate}
\item The run stops at the failing stage; production is untouched when staging
fails. Read the failing task in the console.
\item Revert the faulty commit (\texttt{git revert}) and push.
\item Run the pipeline with \texttt{DEPLOY\_RECORD} set to the last good record
for that environment, and confirm health, version, commit, and price.
\end{enumerate}
\textbf{Rollback.}
\begin{enumerate}
\item Decide which reviewed release to return to.
\item Start \emph{Build with Parameters} with
\texttt{DEPLOY\_RECORD=releases/<version>-production.yml}; an approver approves.
\item Confirm \texttt{/}, \texttt{/health}, and \texttt{/price?quantity=3}, and
note the start and end times. Expect a few seconds of HTTP 502.
\item Never use \texttt{docker compose down -v}, volume removal, or pruning, and
never roll back Gitea or Jenkins as part of an application rollback.
\end{enumerate}
\textbf{Cleanup (only after grading, when instructed).}
\begin{enumerate}
\item On the Droplet: \texttt{docker compose -p pricing-staging down} and
\texttt{docker compose -p pricing-production down} (without \texttt{-v}),
then remove \texttt{/opt/startup}.
\item Remove the \texttt{staging} and \texttt{app} blocks from the Caddyfile,
validate, and reload Caddy. Remove the production probe from
\texttt{prometheus.yml}.
\item Delete the \texttt{staging} and \texttt{app} DNS records.
\item Revoke the registry tokens and the \texttt{deploy-ssh} key, and delete the
\texttt{deploy} account. Keep Gitea, Jenkins, monitoring, earlier assignments,
and the evidence in this chapter.
\end{enumerate}
\subsection{Resource Use and the Single-Droplet Limitation}
\FillIn{resource use from docker stats, free -h and df -h /}
Every component (Gitea, Jenkins, the agent, both environments, Caddy, and
monitoring) shares one Droplet. One host failure stops source control, CI,
staging, production, and the monitoring that would report it, and builds compete
with production for CPU and memory. Staging and production are separated by
configuration only, not by hardware.
\section{Traceability}
\label{sec:del-trace}
\begin{tabularx}{\linewidth}{L{3.4cm}YY}
{\small
\begin{tabularx}{\linewidth}{L{2.4cm}YY}
\toprule
\textbf{Item} & \textbf{v1} & \textbf{v2}\\ \midrule
Source commit & \texttt{2a35f97} & \FillIn{}\\
Configuration commit & \FillIn{} & \FillIn{}\\
Image digest & \texttt{sha256:ce91d055\ldots} & \FillIn{}\\
Jenkins build & \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/8/}{\#8} (staging) & \FillIn{}\\
Scan result & \FillIn{} & \FillIn{}\\
Staging result & Passed: health, v1, commit, total 30; rerun \texttt{changed=0} & \FillIn{}\\
Approver and time & \FillIn{} & \FillIn{}\\
Production result & \FillIn{} & \FillIn{}\\
Source commit & \texttt{\seqsplit{69f1fe05cf72848e250d71349a76ee1157d44df3}} & \texttt{\seqsplit{d6787727f8ebce3f8ac0f8f6d36ddef352ba63da}}\\
Configuration commit & \texttt{69f1fe0} (release); \texttt{d678772} (rollback, run \#11) & \texttt{d678772} (release); \texttt{1841a7d} (staging recovery \#15, production \#16)\\
Image digest & \texttt{\seqsplit{sha256:7689c624960c3d47cc7eb0bd456b4023923a55a64e6941f621c82315b374adf5}} & \texttt{\seqsplit{sha256:d7aa3cfce583a68e287dc34707f11c1d664161e65c74cd709df15330b2fd8f19}}\\
Jenkins build & \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/9/}{\#9} (rollback \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/11/}{\#11}) & \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/10/}{\#10} (recovery \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/15/}{\#15}, roll-forward \href{https://ci.ssw590-08.me/job/Scrap-Web/job/feature\%252Fissue-24-delivery/16/}{\#16})\\
Scan result & Passed: 0 fixable, 47 unfixed HIGH (accepted) & Passed both gates\\
Staging result & Health, v1, commit, 30 passed; rerun \texttt{changed=0} & Health, v2, commit, 36 passed; rerun \texttt{changed=0}\\
Approver and time & \texttt{samahk}, Nov 13, 2026, 10:04:14 PM EST & \texttt{samahk}, Nov 13, 2026, 10:17:50 PM EST\\
Production result & v1, \texttt{69f1fe0}, 30 (Fig.~\ref{fig:del-prod-v1}); restored by rollback (Fig.~\ref{fig:del-rollback}) & v2, \texttt{d678772}, 36 (Fig.~\ref{fig:del-prod-v2}); restored by \#16\\
Release records & \texttt{releases/v1-staging.yml}, \texttt{releases/v1-production.yml} & \texttt{releases/v2-staging.yml}, \texttt{releases/v2-production.yml}\\
\bottomrule
\end{tabularx}
\end{tabularx}}
\medskip
Repository files: \texttt{pricing/} (application, tests, \texttt{requirements.in}
and the hash-locked \texttt{requirements.txt}, \texttt{Dockerfile}),
\texttt{Jenkinsfile}, \texttt{ansible/inventory.ini} (no secrets),
\texttt{ansible/deploy.yml}, \texttt{ansible/templates/compose.yaml.j2},
\texttt{releases/}, \texttt{security/}, and \texttt{agent/}, all on
\href{https://git.ssw590-08.me/SSW-590-08/Scrap-Web/src/branch/feature/issue-24-delivery}{\texttt{feature/issue-24-delivery}}.
Graders can view them in Gitea and the runs in Jenkins with the course accounts
the team provided; no credentials are in this manual.
\fussy
+1
View File
@@ -23,6 +23,7 @@ scrape_configs:
- targets:
- https://git.ssw590-08.me/user/login
- https://ci.ssw590-08.me/login
- https://app.ssw590-08.me/health
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
+2
View File
@@ -6,6 +6,8 @@ WORKDIR /app
COPY requirements.txt .
# Exact, hash-checked dependency versions (direct + transitive) from requirements.txt
RUN pip install --no-cache-dir --require-hashes -r requirements.txt
RUN apt-get update && apt-get install -y --only-upgrade zlib1g libzstd1 && rm -rf /var/lib/apt/lists/* \
&& pip uninstall -y pip setuptools
COPY app.py .
USER 10001:10001
EXPOSE 8000
+2 -2
View File
@@ -2,8 +2,8 @@ import os
from flask import Flask, jsonify, request
app = Flask(__name__)
VERSION = "v1"
UNIT_PRICE = 10
VERSION = "v2"
UNIT_PRICE = 12
COMMIT = os.environ.get("APP_COMMIT", "development")
+3 -3
View File
@@ -7,17 +7,17 @@ class PricingTests(unittest.TestCase):
self.client = app.test_client()
def test_price(self):
self.assertEqual(total_price(3), 30)
self.assertEqual(total_price(3), 36)
response = self.client.get("/price?quantity=3")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json["total"], 30)
self.assertEqual(response.json["total"], 36)
def test_invalid_quantity(self):
for value in ["0", "-1", "1001", "abc", "1.5"]:
self.assertEqual(self.client.get("/price?quantity=" + value).status_code, 400)
def test_release_identity(self):
self.assertEqual(self.client.get("/").json["version"], "v1")
self.assertEqual(self.client.get("/").json["version"], "v2")
self.assertEqual(self.client.get("/health").json["status"], "ok")
+9
View File
@@ -0,0 +1,9 @@
target_env: production
release_image: git.ssw590-08.me/ssw-590-08/pricing@sha256:7689c624960c3d47cc7eb0bd456b4023923a55a64e6941f621c82315b374adf5
expected_version: v1
expected_commit: 69f1fe05cf72848e250d71349a76ee1157d44df3
expected_total: 30
public_url: https://app.ssw590-08.me
proxy_network: gitea-net
approved_by: samahk
approved_at: 2026-11-14T03:04:14+00:00
+7
View File
@@ -0,0 +1,7 @@
target_env: staging
release_image: git.ssw590-08.me/ssw-590-08/pricing@sha256:7689c624960c3d47cc7eb0bd456b4023923a55a64e6941f621c82315b374adf5
expected_version: v1
expected_commit: 69f1fe05cf72848e250d71349a76ee1157d44df3
expected_total: 30
public_url: https://staging.ssw590-08.me
proxy_network: gitea-net
+9
View File
@@ -0,0 +1,9 @@
target_env: production
release_image: git.ssw590-08.me/ssw-590-08/pricing@sha256:d7aa3cfce583a68e287dc34707f11c1d664161e65c74cd709df15330b2fd8f19
expected_version: v2
expected_commit: d6787727f8ebce3f8ac0f8f6d36ddef352ba63da
expected_total: 36
public_url: https://app.ssw590-08.me
proxy_network: gitea-net
approved_by: samahk
approved_at: 2026-11-14T03:17:50+00:00
+7
View File
@@ -0,0 +1,7 @@
target_env: staging
release_image: git.ssw590-08.me/ssw-590-08/pricing@sha256:d7aa3cfce583a68e287dc34707f11c1d664161e65c74cd709df15330b2fd8f19
expected_version: v2
expected_commit: d6787727f8ebce3f8ac0f8f6d36ddef352ba63da
expected_total: 36
public_url: https://staging.ssw590-08.me
proxy_network: gitea-net
+30
View File
@@ -0,0 +1,30 @@
# Security gate policy (defined before the assessed release)
**Tools:** Trivy (repository and image scanning, secret detection) and pip-audit
(Python dependency audit). Tool and vulnerability-database versions, scan time,
commands, reports and exit codes are recorded by `security/scan.sh` and archived
by Jenkins as `security-reports/**`.
**Blocking (the pipeline fails):**
- any detected secret;
- any known vulnerability reported by pip-audit for the locked dependencies;
- any HIGH or CRITICAL vulnerability in the repository or the built image that
has a fix available;
- any scanner error, missing tool, or failure to obtain the vulnerability
database. A failed scan is not a clean scan.
**Not blocking, but recorded:** HIGH or CRITICAL vulnerabilities with no fix yet
(typically operating-system packages in the base image). They are listed in the
full image report and counted in `image-summary.txt` on every run. The accepted
set is recorded in the manual as a time-limited exception with a review date.
Nothing is silently ignored.
**Fixes:** update the dependency lockfile or the pinned base-image digest,
rebuild, and rescan. Dependency or base-image updates always trigger a rescan.
**False positives and exceptions:** a finding that has a fix but is accepted for
a stated reason goes in `security/.trivyignore` with an `exp:` date and a
comment naming the reason and the approver. Expired entries stop applying.
**Test fixture:** one blocked run uses a synthetic, scanner-supported fixture
(never a live secret) on a branch; it is removed and the run repeated.
+89
View File
@@ -0,0 +1,89 @@
#!/usr/bin/env bash
# Security gates for the delivery pipeline (manual Chapter 11, "Apply Proportionate
# Security Gates"). Usage:
# security/scan.sh source dependency audit + secret/vulnerability scan of the repo
# security/scan.sh image <image-ref> vulnerability scan of the built image
#
# Policy (full text in security/POLICY.md):
# * Detected secrets always block.
# * Dependency vulnerabilities reported by pip-audit always block.
# * HIGH/CRITICAL vulnerabilities that HAVE A FIX AVAILABLE block (--ignore-unfixed).
# * HIGH/CRITICAL vulnerabilities with no fix yet do not block, but are never
# hidden: an informational full report and a summary are saved and archived,
# and the accepted set is recorded as a dated exception in the manual.
# * A time-limited exception for a fixable finding goes in security/.trivyignore
# (with an exp: date and a reason).
# FAIL CLOSED: any scanner error, missing tool, or vulnerability-database
# download failure ends the script with a non-zero status. A failed scan is not
# a clean scan. Nothing here ends in "|| true".
set -euo pipefail
MODE="${1:-}"
REPORT_DIR="${REPORT_DIR:-security-reports}"
SEVERITY="HIGH,CRITICAL"
IGNOREFILE="security/.trivyignore"
export PATH="/opt/tools-venv/bin:$PATH"
now() { date -u +%Y-%m-%dT%H:%M:%SZ; }
mkdir -p "$REPORT_DIR"
ignore_args=()
if [ -f "$IGNOREFILE" ]; then ignore_args=(--ignorefile "$IGNOREFILE"); fi
record_versions() {
{
echo "scan_time_utc: $(now)"
echo "--- trivy (tool and vulnerability database versions) ---"
trivy --version
echo "--- pip-audit ---"
pip-audit --version
} | tee "$REPORT_DIR/tool-versions.txt"
}
case "$MODE" in
source)
record_versions
echo "== pip-audit: dependency audit of pricing/requirements.txt =="
# --strict: a dependency that cannot be audited is a failure, not a pass.
pip-audit -r pricing/requirements.txt --strict --progress-spinner off \
2>&1 | tee "$REPORT_DIR/pip-audit.txt"
echo "RESULT pip-audit: exit=0 at $(now)"
echo "== trivy fs: secrets and $SEVERITY vulnerabilities in the repository =="
trivy fs --scanners vuln,secret --severity "$SEVERITY" --exit-code 1 \
--ignore-unfixed --no-progress --skip-dirs .git,.venv "${ignore_args[@]}" . \
2>&1 | tee "$REPORT_DIR/trivy-source.txt"
echo "RESULT trivy-fs: exit=0 at $(now)"
;;
image)
REF="${2:?usage: scan.sh image <image-ref>}"
record_versions
echo "== trivy image: fixable $SEVERITY vulnerabilities in $REF (blocking) =="
trivy image --severity "$SEVERITY" --exit-code 1 --ignore-unfixed --no-progress \
"${ignore_args[@]}" "$REF" \
2>&1 | tee "$REPORT_DIR/trivy-image.txt"
echo "RESULT trivy-image (fixable findings): exit=0 at $(now)"
echo "== trivy image: full informational report (does not gate; errors still fail) =="
# --exit-code 0 means findings alone do not fail this run; a scanner or
# database error still does. This keeps unfixed findings visible, not hidden.
trivy image --severity "$SEVERITY" --exit-code 0 --no-progress \
--format json -o "$REPORT_DIR/trivy-image-full.json" "$REF"
python3 - "$REPORT_DIR/trivy-image-full.json" <<'PY' | tee "$REPORT_DIR/image-summary.txt"
import json, sys, collections
d = json.load(open(sys.argv[1]))
c = collections.Counter()
for r in d.get("Results", []):
for v in r.get("Vulnerabilities") or []:
c[(v["Severity"], "fix available" if v.get("FixedVersion") else "no fix yet")] += 1
print("image findings at HIGH/CRITICAL (all, including unfixed):")
for k, n in sorted(c.items()):
print(" %-9s %-14s %d" % (k[0], k[1], n))
print(" total", sum(c.values()))
PY
;;
*)
echo "usage: security/scan.sh source | image <image-ref>" >&2
exit 2
;;
esac