Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9fdfd00fa6 | |||
| 927df037b0 | |||
| dae5b47373 | |||
| 944ca0f203 | |||
| 1841a7d4ab | |||
| 12226285c6 | |||
| 7b73df19bd | |||
| d6787727f8 | |||
| 69f1fe05cf | |||
| c5172fca86 | |||
| 90c5d9a3b1 | |||
| f14abad27b | |||
| c46f127e8c | |||
| 05d3c58c3a | |||
| 3fcd04010a | |||
| ad37d148ed | |||
| c864ddd0d2 | |||
| 8979d92c00 | |||
| 17750b844b | |||
| fb2bac752a | |||
| 3b79b7e07a | |||
| 60019db7da | |||
| 2a35f97071 | |||
| d8a5d2717b | |||
| 5e17a009dc | |||
| 7e76950690 | |||
| 27f8f20275 | |||
| 98f86092a2 | |||
| 459838dfcd | |||
| 6553b4400c |
@@ -1 +1,2 @@
|
||||
__pycache__/
|
||||
security-reports/
|
||||
@@ -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|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()
|
||||
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.APP_VERSION = version
|
||||
writeFile file: "release-${version}-staging.yml", text: """target_env: staging
|
||||
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)"'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
# Secrets and host-specific values stay on the Droplet
|
||||
jenkins-agent.secret
|
||||
agent.secrets.env
|
||||
.env
|
||||
@@ -0,0 +1,31 @@
|
||||
# Trusted Jenkins delivery agent for Chapter 6.
|
||||
# Build context is the repository root (see agent/compose.yaml).
|
||||
FROM jenkins/inbound-agent:latest-jdk21
|
||||
|
||||
USER root
|
||||
|
||||
# Python 3 + venv for tests, pip-audit and Ansible; curl for checks
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends python3 python3-venv python3-pip ca-certificates curl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Docker CLI + buildx plugin (client only; the daemon is the host's, via the mounted socket)
|
||||
COPY --from=docker:cli /usr/local/bin/docker /usr/local/bin/docker
|
||||
COPY --from=docker/buildx-bin /buildx /usr/libexec/docker/cli-plugins/docker-buildx
|
||||
|
||||
# Trivy scanner (image vulnerabilities + secret scanning)
|
||||
COPY --from=aquasec/trivy:latest /usr/local/bin/trivy /usr/local/bin/trivy
|
||||
|
||||
# Ansible in its own virtual environment, plus the community.docker collection
|
||||
ENV ANSIBLE_COLLECTIONS_PATH=/opt/ansible-collections
|
||||
COPY ansible/requirements.yml /tmp/ansible-requirements.yml
|
||||
RUN python3 -m venv /opt/ansible-venv \
|
||||
&& /opt/ansible-venv/bin/pip install --no-cache-dir ansible-core \
|
||||
&& /opt/ansible-venv/bin/ansible-galaxy collection install -r /tmp/ansible-requirements.yml -p /opt/ansible-collections \
|
||||
&& rm /tmp/ansible-requirements.yml
|
||||
|
||||
# pip-audit in a separate tools venv
|
||||
RUN python3 -m venv /opt/tools-venv \
|
||||
&& /opt/tools-venv/bin/pip install --no-cache-dir pip-audit
|
||||
|
||||
USER jenkins
|
||||
@@ -0,0 +1,41 @@
|
||||
# Trusted delivery agent. Connects to the existing Jenkins controller over the
|
||||
# internal gitea-net network (WebSocket), so no new port is published.
|
||||
services:
|
||||
jenkins-agent:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: agent/Dockerfile
|
||||
image: ssw590/jenkins-delivery-agent:1
|
||||
container_name: jenkins-agent
|
||||
restart: unless-stopped
|
||||
# Start agent.jar directly. The secret is read from a file (-secret @file),
|
||||
# so it never appears in the process list, docker inspect, or Git.
|
||||
entrypoint:
|
||||
- java
|
||||
- -jar
|
||||
- /usr/share/jenkins/agent.jar
|
||||
- -url
|
||||
- http://jenkins:8080/
|
||||
- -webSocket
|
||||
- -name
|
||||
- delivery-agent
|
||||
- -workDir
|
||||
- /home/jenkins/agent
|
||||
- -secret
|
||||
- "@/run/secrets/jenkins-agent-secret"
|
||||
# Host Docker socket: needed to build/push images. This is effectively root
|
||||
# on the Droplet, so only reviewed main-branch delivery jobs may use this agent.
|
||||
group_add: ["${DOCKER_GID:?set DOCKER_GID in .env}"]
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
- ./jenkins-agent.secret:/run/secrets/jenkins-agent-secret:ro
|
||||
- agent_home:/home/jenkins # workspace, known_hosts, registry login
|
||||
networks: [gitea-net]
|
||||
|
||||
networks:
|
||||
gitea-net:
|
||||
external: true
|
||||
name: gitea-net
|
||||
|
||||
volumes:
|
||||
agent_home:
|
||||
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
# Print tool versions inside the agent. From the repo root on the Droplet:
|
||||
# docker exec -i jenkins-agent sh -s < agent/versions.sh
|
||||
echo "== java"; java -version 2>&1 | head -1
|
||||
echo "== python"; python3 --version
|
||||
echo "== docker"; docker version --format 'client {{.Client.Version}} / server {{.Server.Version}}'
|
||||
echo "== buildx"; docker buildx version
|
||||
echo "== trivy"; trivy --version | head -1
|
||||
echo "== pip-audit"; /opt/tools-venv/bin/pip-audit --version
|
||||
echo "== ansible"; /opt/ansible-venv/bin/ansible --version | head -3
|
||||
echo "== collections"; /opt/ansible-venv/bin/ansible-galaxy collection list community.docker 2>/dev/null | tail -2
|
||||
echo "== os"; . /etc/os-release; echo "$PRETTY_NAME $(uname -m)"
|
||||
@@ -0,0 +1,62 @@
|
||||
- name: Deploy a selected immutable pricing release
|
||||
hosts: delivery
|
||||
become: true
|
||||
vars:
|
||||
project_dir: "/opt/startup/pricing-{{ target_env }}"
|
||||
tasks:
|
||||
- name: Validate release selection
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- target_env in ['staging', 'production']
|
||||
- "'@sha256:' in release_image"
|
||||
- expected_version in ['v1', 'v2']
|
||||
- expected_total | int > 0
|
||||
- public_url.startswith('https://')
|
||||
- proxy_network | length > 0
|
||||
- name: Create deployment directory
|
||||
ansible.builtin.file:
|
||||
path: "{{ project_dir }}"
|
||||
state: directory
|
||||
mode: '0750'
|
||||
- name: Render selected Compose configuration
|
||||
ansible.builtin.template:
|
||||
src: compose.yaml.j2
|
||||
dest: "{{ project_dir }}/compose.yaml"
|
||||
mode: '0640'
|
||||
- name: Converge application without rebuilding
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: "{{ project_dir }}"
|
||||
project_name: "pricing-{{ target_env }}"
|
||||
state: present
|
||||
build: never
|
||||
pull: missing
|
||||
wait: true
|
||||
wait_timeout: 90
|
||||
- name: Verify health through public TLS endpoint
|
||||
ansible.builtin.uri:
|
||||
url: "{{ public_url }}/health"
|
||||
return_content: true
|
||||
validate_certs: true
|
||||
register: health
|
||||
until: health.status == 200 and health.json.status == 'ok'
|
||||
retries: 12
|
||||
delay: 5
|
||||
changed_when: false
|
||||
- name: Read release identity
|
||||
ansible.builtin.uri:
|
||||
url: "{{ public_url }}/"
|
||||
return_content: true
|
||||
register: identity
|
||||
changed_when: false
|
||||
- name: Exercise business behavior
|
||||
ansible.builtin.uri:
|
||||
url: "{{ public_url }}/price?quantity=3"
|
||||
return_content: true
|
||||
register: price
|
||||
changed_when: false
|
||||
- name: Check release identity and calculation
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- identity.json.version == expected_version
|
||||
- identity.json.commit == expected_commit
|
||||
- price.json.total | int == expected_total | int
|
||||
@@ -0,0 +1,4 @@
|
||||
[delivery]
|
||||
# Target: the existing Droplet, reached over SSH as the dedicated deploy account.
|
||||
# Host key must be verified and pinned in the agent's known_hosts before first use.
|
||||
startup ansible_host=147.182.179.191 ansible_user=deploy
|
||||
@@ -0,0 +1,3 @@
|
||||
collections:
|
||||
- name: community.docker
|
||||
version: ">=4.8.0,<6.0.0"
|
||||
@@ -0,0 +1,19 @@
|
||||
services:
|
||||
app:
|
||||
image: "{{ release_image }}"
|
||||
restart: unless-stopped
|
||||
read_only: true
|
||||
tmpfs:
|
||||
- /tmp
|
||||
cap_drop:
|
||||
- ALL
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
networks:
|
||||
edge:
|
||||
aliases:
|
||||
- "pricing-{{ target_env }}"
|
||||
networks:
|
||||
edge:
|
||||
external: true
|
||||
name: "{{ proxy_network }}"
|
||||
|
After Width: | Height: | Size: 96 KiB |
|
After Width: | Height: | Size: 138 KiB |
|
After Width: | Height: | Size: 120 KiB |
|
After Width: | Height: | Size: 181 KiB |
|
After Width: | Height: | Size: 216 KiB |
|
After Width: | Height: | Size: 79 KiB |
|
After Width: | Height: | Size: 78 KiB |
|
After Width: | Height: | Size: 446 KiB |
|
After Width: | Height: | Size: 93 KiB |
|
After Width: | Height: | Size: 155 KiB |
|
After Width: | Height: | Size: 192 KiB |
|
After Width: | Height: | Size: 192 KiB |
|
After Width: | Height: | Size: 189 KiB |
|
After Width: | Height: | Size: 220 KiB |
|
After Width: | Height: | Size: 309 KiB |
|
After Width: | Height: | Size: 435 KiB |
|
After Width: | Height: | Size: 86 KiB |
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 171 KiB |
|
After Width: | Height: | Size: 92 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 113 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 92 KiB |
|
After Width: | Height: | Size: 234 KiB |
|
After Width: | Height: | Size: 53 KiB |
|
After Width: | Height: | Size: 32 KiB |
@@ -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}
|
||||
@@ -41,10 +41,10 @@
|
||||
\newcommand{\CourseName}{DevOps}
|
||||
\newcommand{\Instructor}{Samah Keshiro and Kayla Holmes}
|
||||
\newcommand{\Organization}{Stevens Institute of Technology}
|
||||
\newcommand{\DocumentDate}{October 29, 2026}
|
||||
\newcommand{\DocumentDate}{November 13, 2026}
|
||||
\newcommand{\DueDate}{[Due Date and Time]}
|
||||
\newcommand{\VERSION}{Version 1.6}
|
||||
\newcommand{\AssignmentNumber}{6}
|
||||
\newcommand{\VERSION}{Version 1.7}
|
||||
\newcommand{\AssignmentNumber}{7}
|
||||
|
||||
\newcolumntype{Y}{>{\raggedright\arraybackslash}X}
|
||||
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
|
||||
@@ -137,6 +137,7 @@
|
||||
\include{devopsAutomatedManualBuild}
|
||||
\include{devopsCI}
|
||||
\include{devopsSRE}
|
||||
\include{devopsSecureDelivery}
|
||||
|
||||
\printglossaries
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
\toprule \textbf{Date / Version} & \textbf{Authors} & \textbf{Change} & \textbf{Changed At}\\ \midrule
|
||||
\endhead
|
||||
|
||||
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} \\
|
||||
|
||||
October 23, 2026 / 1.5 & SK, KH & Completed the Continuous Integration with Jenkins assignment: deployed a persistent Jenkins LTS container behind HTTPS at \texttt{ci.ssw590-08.me} with firewall-restricted access; integrated Jenkins with the Scrap-Web Gitea repository through a dedicated integration account; added a pricing module, unit tests, and a versioned \texttt{Jenkinsfile}; protected \texttt{main} with a required Jenkins status check and one required approval; and demonstrated a failed, repaired, reviewed, and merged pull request. Updated the Hosts table (Jenkins host and ports) and the Passwords table (Jenkins administrator accounts and the Gitea integration token, hints only). & \ChapterRef{ContinuousIntegration}, \ChapterRef{PWDHST} \\
|
||||
|
||||
@@ -22,3 +22,7 @@
|
||||
\newglossaryentry{errorbudget}{name={error budget},description={The amount of failure an SLO allows over its window; for a 99\% target, 1\% of scheduled measurements}}
|
||||
\newglossaryentry{probe}{name={probe},description={A synthetic request, here an HTTPS GET from Blackbox Exporter, that tests whether a service responds as expected}}
|
||||
\newglossaryentry{contactpoint}{name={contact point},description={The Grafana destination, such as a Discord webhook or email address, that receives alert notifications}}
|
||||
\newglossaryentry{idempotence}{name={idempotence},description={The property that running the same deployment again on an already-correct system changes nothing}}
|
||||
\newglossaryentry{imagedigest}{name={image digest},description={The SHA-256 content hash that identifies one exact container image in a registry; unlike a tag, it cannot be moved to another image}}
|
||||
\newglossaryentry{releaserecord}{name={release record},description={A file that ties one deployment to its image digest, source commit, expected behavior, environment, and build}}
|
||||
\newglossaryentry{trustedagent}{name={trusted agent},description={A Jenkins build node that holds deployment credentials and therefore runs only reviewed code}}
|
||||
|
||||
@@ -66,6 +66,21 @@ Discord webhook (Grafana contact point \texttt{team-alerts})
|
||||
& Webhook URL stored only in Grafana's database; re-created from the Discord channel's Integrations $\rightarrow$ Webhooks settings\\
|
||||
\hline
|
||||
|
||||
Deployment account (Ansible)
|
||||
& deploy
|
||||
& No password; SSH key stored only in Jenkins credential \texttt{deploy-ssh}\\
|
||||
\hline
|
||||
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\\
|
||||
\end{longtable}
|
||||
|
||||
|
||||
@@ -100,7 +115,7 @@ Jenkins Web Interface & ci.ssw590-08.me & 443 & HTTPS access to Jenkins through
|
||||
\hline
|
||||
Jenkins Container & jenkins & 8080 & Internal Docker network web service; not published on the host \\
|
||||
\hline
|
||||
Jenkins Agent Port & jenkins & 50000 & Not published on the host; no separate build agent is used \\
|
||||
Jenkins Agent Port & jenkins & 50000 & Not published on the host and not used; the delivery agent connects over WebSocket through port 8080 on \texttt{gitea-net} \\
|
||||
\hline
|
||||
Grafana Web Interface & metrics.ssw590-08.me & 443 & HTTPS access to Grafana through Caddy \\
|
||||
\hline
|
||||
@@ -112,4 +127,12 @@ Node Exporter Container & node-exporter & 9100 & Private, \texttt{monitoring} ne
|
||||
\hline
|
||||
Blackbox Exporter Container & blackbox-exporter & 9115 & Private, \texttt{monitoring} network only; HTTPS probes of Gitea and Jenkins \\
|
||||
\hline
|
||||
Staging Application & staging.ssw590-08.me & 443 & HTTPS access to the staging pricing service through Caddy \\
|
||||
\hline
|
||||
Production Application & app.ssw590-08.me & 443 & HTTPS access to the production-like pricing service through Caddy \\
|
||||
\hline
|
||||
Pricing Containers & pricing-staging, pricing-production & 8000 & Private, \texttt{gitea-net} only; Gunicorn; not published on the host; Compose projects under \texttt{/opt/startup/pricing-\{staging,production\}}; no data volume \\
|
||||
\hline
|
||||
Jenkins Delivery Agent & jenkins-agent & None & Container on \texttt{gitea-net}; runs Docker builds and Ansible; mounts the host Docker socket; state in volume \texttt{agent\_home} \\
|
||||
\hline
|
||||
\end{longtable}
|
||||
@@ -95,3 +95,75 @@
|
||||
url = {https://docs.digitalocean.com/support/why-is-smtp-blocked/},
|
||||
note = {Accessed: Oct. 28, 2026}
|
||||
}
|
||||
|
||||
@misc{AnsibleCompose,
|
||||
author = {{Ansible Project}},
|
||||
title = {{community.docker.docker\_compose\_v2 module}},
|
||||
howpublished = {Ansible Documentation},
|
||||
year = {2026},
|
||||
url = {https://docs.ansible.com/ansible/latest/collections/community/docker/docker_compose_v2_module.html},
|
||||
note = {Accessed: Nov. 13, 2026}
|
||||
}
|
||||
|
||||
@misc{AnsibleInstall,
|
||||
author = {{Ansible Project}},
|
||||
title = {{Installing Ansible}},
|
||||
howpublished = {Ansible Documentation},
|
||||
year = {2026},
|
||||
url = {https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html},
|
||||
note = {Accessed: Nov. 13, 2026}
|
||||
}
|
||||
|
||||
@misc{GiteaContainerRegistry,
|
||||
author = {{Gitea}},
|
||||
title = {{Container Registry}},
|
||||
howpublished = {Gitea Documentation},
|
||||
year = {2026},
|
||||
url = {https://docs.gitea.com/usage/packages/container},
|
||||
note = {Accessed: Nov. 13, 2026}
|
||||
}
|
||||
|
||||
@misc{DockerPullDigest,
|
||||
author = {{Docker Inc.}},
|
||||
title = {{docker image pull: Pull an image by digest}},
|
||||
howpublished = {Docker Documentation},
|
||||
year = {2026},
|
||||
url = {https://docs.docker.com/reference/cli/docker/image/pull/},
|
||||
note = {Accessed: Nov. 13, 2026}
|
||||
}
|
||||
|
||||
@misc{JenkinsAgents,
|
||||
author = {{Jenkins Project}},
|
||||
title = {{Using Jenkins agents}},
|
||||
howpublished = {Jenkins User Documentation},
|
||||
year = {2026},
|
||||
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}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
__pycache__
|
||||
.venv
|
||||
.ansible-venv
|
||||
.git
|
||||
*.pyc
|
||||
requirements.in
|
||||
@@ -0,0 +1,15 @@
|
||||
# Base image pinned by digest (python:3.13-slim, linux/amd64 for the Droplet).
|
||||
FROM python:3.13-slim@sha256:e48f59cdba69a3cbd9ed2cf0f348d90d45a8d350d98134cf1070bc106ee9ed90
|
||||
ARG APP_COMMIT=development
|
||||
ENV APP_COMMIT=$APP_COMMIT PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
|
||||
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
|
||||
HEALTHCHECK --interval=10s --timeout=3s --start-period=10s --retries=3 CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/health', timeout=2)"
|
||||
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "1", "--worker-tmp-dir", "/tmp", "app:app"]
|
||||
@@ -0,0 +1,33 @@
|
||||
import os
|
||||
from flask import Flask, jsonify, request
|
||||
|
||||
app = Flask(__name__)
|
||||
VERSION = "v2"
|
||||
UNIT_PRICE = 12
|
||||
COMMIT = os.environ.get("APP_COMMIT", "development")
|
||||
|
||||
|
||||
def total_price(quantity):
|
||||
if quantity < 1 or quantity > 1000:
|
||||
raise ValueError("quantity must be between 1 and 1000")
|
||||
return UNIT_PRICE * quantity
|
||||
|
||||
|
||||
@app.get("/")
|
||||
def index():
|
||||
return jsonify(service="Startup Pricing", version=VERSION, commit=COMMIT)
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
def health():
|
||||
return jsonify(status="ok", version=VERSION)
|
||||
|
||||
|
||||
@app.get("/price")
|
||||
def price():
|
||||
try:
|
||||
quantity = int(request.args.get("quantity", "1"))
|
||||
total = total_price(quantity)
|
||||
except ValueError as error:
|
||||
return jsonify(error=str(error)), 400
|
||||
return jsonify(quantity=quantity, total=total, currency="USD")
|
||||
@@ -0,0 +1,2 @@
|
||||
Flask>=3.1,<3.2
|
||||
gunicorn>=23,<24
|
||||
@@ -0,0 +1,190 @@
|
||||
# This file was autogenerated by uv via the following command:
|
||||
# uv pip compile requirements.in --universal --python-version 3.13 --generate-hashes -o requirements.txt
|
||||
blinker==1.9.0 \
|
||||
--hash=sha256:b4ce2265a7abece45e7cc896e98dbebe6cead56bcf805a3d23136d145f5445bf \
|
||||
--hash=sha256:ba0efaa9080b619ff2f3459d1d500c57bddea4a6b424b60a91141db6fd2f08bc
|
||||
# via flask
|
||||
click==8.5.1 \
|
||||
--hash=sha256:8bb5376d2006950386f8c6427613334a2acadc5f559cb80e638d00b4df957e37 \
|
||||
--hash=sha256:9bbfada76703fd1d784b83eea012e3e8c6a001a876543ef104fa56aaaeb072b4
|
||||
# via flask
|
||||
flask==3.1.3 \
|
||||
--hash=sha256:0ef0e52b8a9cd932855379197dd8f94047b359ca0a78695144304cb45f87c9eb \
|
||||
--hash=sha256:f4bcbefc124291925f1a26446da31a5178f9483862233b23c0c96a20701f670c
|
||||
# via -r requirements.in
|
||||
gunicorn==23.0.0 \
|
||||
--hash=sha256:ec400d38950de4dfd418cff8328b2c8faed0edb0d517d3394e457c317908ca4d \
|
||||
--hash=sha256:f014447a0101dc57e294f6c18ca6b40227a4c90e9bdb586042628030cba004ec
|
||||
# via -r requirements.in
|
||||
itsdangerous==2.2.0 \
|
||||
--hash=sha256:c6242fc49e35958c8b15141343aa660db5fc54d4f13a1db01a3f5891b98700ef \
|
||||
--hash=sha256:e0050c0b7da1eea53ffaf149c0cfbb5c6e2e2b69c4bef22c81fa6eb73e5f6173
|
||||
# via flask
|
||||
jinja2==3.1.6 \
|
||||
--hash=sha256:0137fb05990d35f1275a587e9aee6d56da821fc83491a0fb838183be43f66d6d \
|
||||
--hash=sha256:85ece4451f492d0c13c5dd7c13a64681a86afae63a5f347908daf103ce6d2f67
|
||||
# via flask
|
||||
markupsafe==3.0.4 \
|
||||
--hash=sha256:007e1ffd9bf65bb6ee96df7b258fc632a4868dd5566037986c64781f35a36e98 \
|
||||
--hash=sha256:02fa4acbc6a3fc5c693c34d4dd8c1130b7fe99cc915181b0ddd6f72aeb296002 \
|
||||
--hash=sha256:03470d1a8268e692ecf79ecd565593e59d44219377a7ead61f1f1b94c1f7ff6b \
|
||||
--hash=sha256:04e7902ba80ee4bac1d50a549606527a1dcf0476cd81403db41099d3b60ec653 \
|
||||
--hash=sha256:051417f74bcaaefa316276e0ff723f541616ca51043d070da00249d9bddd3e3c \
|
||||
--hash=sha256:05295589e619b9bed252a86b532b8e27350abc372d18ba89b59375325e91ec1e \
|
||||
--hash=sha256:06de8ef6331f6e822c28d577dc8bf43fe398800477c49498f38fc38b67ff33fc \
|
||||
--hash=sha256:0764a13d34cae40db7bbf3a09b7e9b491bf4603e20b263a7a9d6b8e324975d0a \
|
||||
--hash=sha256:077293e425f28ec737dbcad442a71752e28f8ae27cde3d68acd1fb212091cd92 \
|
||||
--hash=sha256:0930db9bdc62d22944e10b066448bb65dc9abe9112880c7cab8da54db4284d5f \
|
||||
--hash=sha256:0cee7cb0f9a1b6892ea482237d9403b3d1b4603aee057d0ff01f0fac2d019a97 \
|
||||
--hash=sha256:0d9c47709875fdb321452056622e930c52afbc07a7d780762fbb8b4d91ce6fa4 \
|
||||
--hash=sha256:11935df9bf455ed0c04eb87bcd720f02b1fe5e02128a9430f23aed6f93336fc7 \
|
||||
--hash=sha256:12a606a492de952afcb43b59a14aaaaad120e708d3663dd0fdf2d738d427a691 \
|
||||
--hash=sha256:14bd2d845d62ab678eaf81da89d7b621b51756c72346745c1a594c09d49207a2 \
|
||||
--hash=sha256:15ba9e28640feef770374b116a6f019c21f52404aeabe516aa7f800587b98cfc \
|
||||
--hash=sha256:18a801868a884f216e784d7d14db2a4077143ce7610440aee2ce8f734e7cfcde \
|
||||
--hash=sha256:1c0df495a977d10460a94941799c72d5b5ab03d3858d949b55b5a66c8f371c99 \
|
||||
--hash=sha256:1caa2fa5a6184fb233153b35f654e6687bd555476f6170f29d8ee9be1a8b0af9 \
|
||||
--hash=sha256:1e1451fab512d1bcc3dc26988ec1edb0b82c2db909132872cd9356070a6b63df \
|
||||
--hash=sha256:1f1f9477e174582b0a1b583d60b66e1f2cf5d3fe12cee985e4aedf44766600e5 \
|
||||
--hash=sha256:2628d3a8cb648ecebb3c5d6b0a1052d400e4d8b7ac0fb786be8d285b50040d17 \
|
||||
--hash=sha256:26e9867520db70d37f7fb421a7f0d8adb40171011fb84ce869afa1a83370dfa8 \
|
||||
--hash=sha256:2a6ef68ae94aed8721934072b27a3b654ea2100b97e4ab864cf1489c90926fbc \
|
||||
--hash=sha256:2b2b1e18af909b448bb3cf9e3433366f7a8726271fc214e8b10e0f62a78c724b \
|
||||
--hash=sha256:2cb3dd71fc6be918ad4264346a8ed69485f9b7ed7bf35495d8e22807cd6b8bea \
|
||||
--hash=sha256:2d1b7d9308288661f56672b1b157d75fc536714d3638487bbea17b6318a78248 \
|
||||
--hash=sha256:2dad610540cb2e6272855c178f08ae9a1c7ac258a7fb71660553a5f104b42741 \
|
||||
--hash=sha256:2e5a7cd7fdd14fcb1ae5d7d8bf23d24fbd1daefd1fbca2580132e1ea75f098b5 \
|
||||
--hash=sha256:2e9ad7dd851bf45fab9f75cbff4cb493fee9979e8d8c7c9c3ee119022518edd6 \
|
||||
--hash=sha256:340cbb1957ba99929cbf19a75626d36ba1ae21d1730b287d1cf7f824a20c4fc7 \
|
||||
--hash=sha256:34bdde374c5932765d7dc685c4a1d191a3207852d67e8e0a9eb6ea85156181f1 \
|
||||
--hash=sha256:353bd63081912ab8cfa6a0c7d185934cdf8426f04c618bba6bc4b394f2069b67 \
|
||||
--hash=sha256:387d8cd30e69b3f0a72877b9ae717033396404e19095b17fe89753a981fda44f \
|
||||
--hash=sha256:3882fb412298575bae3b9c46868251f15cc69307359f87bb1b382e53d6e5a2c9 \
|
||||
--hash=sha256:38fc55594dab834470b6733dead2ee9e3f657fb0608c769dcafa0ba5ab52f45c \
|
||||
--hash=sha256:396ec4e65cc889f69786b3b89478b471cee5a3bcf468b9d9bb03e1a30fb291fc \
|
||||
--hash=sha256:39dbacefc411633db5b4378b066a9aca70a3d7e2922c9e578d825f844026eeba \
|
||||
--hash=sha256:3a93d9616ddecfb393727a0041a562cf0b15a244e20f2bd25efc7949be4c4f17 \
|
||||
--hash=sha256:3d23795802fc8bd72534836d64489bbf0f67c088959091bdb22e10735a5107bf \
|
||||
--hash=sha256:434139499bb20b502ed3baa1f169e618f924a97e7a777fea1a49446d80106cf6 \
|
||||
--hash=sha256:436e3ffc6310d3c41878c601db29098102fe5d8a467c49da4a4125254e0980f2 \
|
||||
--hash=sha256:489505b03f692c3f376394e49194fa7a7f9e8558d6e293a7056a0032b0c38163 \
|
||||
--hash=sha256:4a540e2d3192792fc84eced57bef37851ccb2b41f73291bb17408eea77bcd278 \
|
||||
--hash=sha256:4a7cdc2a420ca01058182da4253329764d4bfa055564d1eced90e6ba1e8b1d3d \
|
||||
--hash=sha256:4bced6e2a6dba6a28f7dd3c6ce14df1b2dd495923f16ea484cad03decd463b2b \
|
||||
--hash=sha256:4cf3468d5ec187ffffcaca8e61929a37448f215dafc1386a12c750a72fe53634 \
|
||||
--hash=sha256:4e2c4809c14559aa7ef426f27fb35afbb38104c349a903bf8f3600456764bb38 \
|
||||
--hash=sha256:4ed644d75aa94a2baf7ec3a96eaa160ea58c742eb9d27c6506053c5c40fc84ed \
|
||||
--hash=sha256:4f6e0852a0283b1b1fd776eeb7b766a5f440b3e2bd31ab51af3b400585f3965c \
|
||||
--hash=sha256:5066b244f576f91afc8ee3ba029a89f99d39c79b1853fe9d39bea9f0afbec148 \
|
||||
--hash=sha256:5086f9975abb1ab531ee6afca1761e4b59a19b446f3f6522ed776963228cfe5a \
|
||||
--hash=sha256:50b5bedc9ed8a94fc8857a42ef4f84a81ea88f8d4f05dc8705fb23ee6d8dcca7 \
|
||||
--hash=sha256:52704c5d36eb6dda8866493decd61111fff86244c9b1ad225ca01b9e91e5970f \
|
||||
--hash=sha256:55ffd6ce583d97dc71dc92e930324c8c0d25aea7e3ade6ae54ef77cedb096811 \
|
||||
--hash=sha256:569d65055d367e3dcdf30c3f41119467b73d9ee9faf332bdf40402644f5ac08e \
|
||||
--hash=sha256:57f9947a7e57a081c1e3e0a2dd0d2dcf290a4531450e6f611e30084c222a7295 \
|
||||
--hash=sha256:5989cb26b2e1efc6a42216a9f6b5ee495ce5ace2e5b352a9af489976b32d1ee2 \
|
||||
--hash=sha256:5c22873ad1f0532ba40fa1727f3c0fc1bbbaab6d373d4cbe3f0dc74b2e2521c7 \
|
||||
--hash=sha256:5e8b3d0b18fd623afa12ecb2ce8d8becef69f9b5440c6330c7972200e0bb84b0 \
|
||||
--hash=sha256:61631e08084be9e21a8967ec3139c7616ed7c5e9368e05c86d1b39562c8a57b6 \
|
||||
--hash=sha256:64511c54db4e4987aef4c41923235927428729e8174c5dba488429be70a998ed \
|
||||
--hash=sha256:6669c1bf34080161ce49c589cc512ef24d4c704ac9d2b2d3667f519c60418378 \
|
||||
--hash=sha256:672d207103e6b16ca098611b0f9efad6bc00afd47c03d6ef62186495ca677dc0 \
|
||||
--hash=sha256:6768d67d1bce64270e0fdc2e69309d68b9b18ae56ddf6c711d168e9d051c2cac \
|
||||
--hash=sha256:6a45c3d514f2436064db00d7fc8778d888f0236ebfed649b53d13a59e69ad51b \
|
||||
--hash=sha256:6bd9e1788e15bfcf6a9082de42e30387e7b85d211ab21e57a939bb8cfaaf8d96 \
|
||||
--hash=sha256:6d2a9efe686f9de00d0d1ea32a4a5a86d558a2277501bd78d964214eab625e59 \
|
||||
--hash=sha256:6da83a088f8ef93b2d483a8232a4dbf4d69d3d8496b568a03c56becac43e1808 \
|
||||
--hash=sha256:7018d4af1cd272e847aa5917983ab5e83e4f6579f9dbfecd4a79c0ca80b144c2 \
|
||||
--hash=sha256:71f88e749ea29f67f21f3b36433c1dc54c7729ed2a6d9e2da2e0d9e0d7b224eb \
|
||||
--hash=sha256:737c9c3981998eba27f11786f84fddcbabc74068b72a4a1f454ea02094b57b65 \
|
||||
--hash=sha256:73e77980c7207854f00fc4e71fb1626868d5740ab4012623d55c7a99ad122a72 \
|
||||
--hash=sha256:799c39bdf5e2f1292fedd3009f7b3c9e760f10b2420cb9638d56920840ff6db8 \
|
||||
--hash=sha256:7a83aa6e4805df46fed18e989d3d16f86ef60cb50bbc8d9ce3a6be89165fbf6e \
|
||||
--hash=sha256:7d3391b2188d18737cb2fa147028b1096236eaa7e156446c650a489fa2cadc91 \
|
||||
--hash=sha256:7e1636da3d8dfc220b6dd10264db5f2b165e4888c4518594898fbe381049af8a \
|
||||
--hash=sha256:805c8b84534fa10891890f0e4be39f3a99e94615d93e8836bf9fa1fdca2feeb2 \
|
||||
--hash=sha256:811d02d5122171c1941357efd8f9bf4ffe907b7f0a1a4e729a880e4be3f46e3e \
|
||||
--hash=sha256:8138eb83940ec7299024d92d4dee45f601b9e6c5ffde9d25f4e35e326203c707 \
|
||||
--hash=sha256:83b3944fea42a8400edf92fd1770fb8d0d4f7de651353bd2d8525a92dba69a21 \
|
||||
--hash=sha256:849dd2bb0e5e4ab2b71c7191726a4a8d5aa8a610daa584728cbee0b710ddc4ef \
|
||||
--hash=sha256:8698d70a8081ee8c090dbb394768b5789a1da8b131b5499f89d071dd3cfaf6be \
|
||||
--hash=sha256:8781a792a070cf2bd1b86d3aa943894115faaba6e88122a7bf32d62072742453 \
|
||||
--hash=sha256:88d59b473bfb03259722600839af9bbd7fa13a2eb514beefeedb95997882f69a \
|
||||
--hash=sha256:8909c2f1c6dd65e054ac4b573a91c8384d1492281e55d82d159d653f7a13adf6 \
|
||||
--hash=sha256:8965520ac587c94a4ac48b729be3d8b8de00af39699b17585dfb599babe77977 \
|
||||
--hash=sha256:8b5d563170ff8ba3181caa967c99a3c804d1dedb702c7cb93a6a7c32247da978 \
|
||||
--hash=sha256:8e124f974786f831d6043728e38296969d3579db8896fe004682f5758e613581 \
|
||||
--hash=sha256:8f0fac8b13d14bb06c68195f849371924ae53dd7b1c00fed24650f704383b692 \
|
||||
--hash=sha256:9240187afb63d2f9ddc3e032c670356fe941f6e20662ea168a5dc3f1f317e1b3 \
|
||||
--hash=sha256:925f929d6b59a8b3f8b8c6ac363cd0af7eecc81efb3071770b3c6717c450a369 \
|
||||
--hash=sha256:9348cbb300d224fe3b89793262cb093504d4ae927004468463f745188a193e4a \
|
||||
--hash=sha256:9388003072b95f2f1e3fd908604194d653ba21330d811961a78b7da1a77e9e36 \
|
||||
--hash=sha256:9438a2648b2195980cb2dd8e53ed7b8df91319e2d0b70ae61a9e1d1bc8d3bec9 \
|
||||
--hash=sha256:94e4c421742086aeee4c32a506eec8859d7634aad943f7e6aacf70f813478768 \
|
||||
--hash=sha256:94f5407f7bc64fa6463906b896f9904beeeb7dd8dc116ee8e9056c8714ff9916 \
|
||||
--hash=sha256:971a3bbb75d97ae4e2e8f7d4834236f86f85f0c85e04ab2e191db1123b04f80b \
|
||||
--hash=sha256:9e227f3dbe6bde7491cf0a9965d00b88c6b1a4a95d11480ddf88bb96d397c19f \
|
||||
--hash=sha256:9e25feb9e330b63edb0278a0acdf85e50d0cb0fbf49c3084abbe4e24ae195346 \
|
||||
--hash=sha256:9f098115c247e11d138ab83a28fa0323c77015007ea2df73ba5fd714dfefd67c \
|
||||
--hash=sha256:a18f38cafc329bac5e3c2b96c765b4c96d3d103421ed22ab7988c1e3fce27464 \
|
||||
--hash=sha256:a4bbd2d87dd233b9fc5812160c3d0ffbe42edc22a26ce0469f58479ede633fe9 \
|
||||
--hash=sha256:a5fcffb37e602b0b3c1638a97746b9b96125caa9bcf6fa41d337a9261de231ee \
|
||||
--hash=sha256:a8e9f292fcda89b324f2f5c91d13f1424a153e40fc2756f38ee23b15835ff300 \
|
||||
--hash=sha256:a9f54054101545a9a9cccefddf54316aa6e4491611fcbef9e91b3b6bebec04f6 \
|
||||
--hash=sha256:aa2c838cc024642cc04c6854232f32b43e5e22833dd11119c1766c7873b8370d \
|
||||
--hash=sha256:ac0c7c9f1609b0c4c114feb1d7a3409564c7fb77e360bed9e97e5d25dfeaf868 \
|
||||
--hash=sha256:add96447a86d205ab616665d53b2950ee81083757f56e6ea833c8b2917646b46 \
|
||||
--hash=sha256:ae9dcb8fbe244cb82f8a6458b455b927a03685e383d9bacf1ea5ce180b96dc97 \
|
||||
--hash=sha256:b4a635a0487774f841cb1fb62e907e7195cc95bc761e053184b8acc3ceb20733 \
|
||||
--hash=sha256:b4d12837e0203bbace818ff4a7461afdcd78bcd782351cea148139180d7bcffe \
|
||||
--hash=sha256:b61687d0828e72bf5cda24a2690188f37170bd31c9359ac97e4e66569f120a16 \
|
||||
--hash=sha256:b807e598953730f82e4eae3bd30f6a122cf6b31c398c6b504c0e04c13c170429 \
|
||||
--hash=sha256:b8cd1f918b26fd7b1832ece557cc18f2d8747309ff8b3f0ef9d4250c5ad67a39 \
|
||||
--hash=sha256:b91cc9d336957239ff200f30097e6fea2dc6d6fb3c81e853eaa09eac904fd894 \
|
||||
--hash=sha256:bd3ce56ae2cbae3ba82b683bc425cd7e48d2ed8b10f3e818186b6f5646d9271c \
|
||||
--hash=sha256:be6cb0c799abb0e2ba3e618e6d28ddddf7e485f6c2ce938dfa237daf3905072c \
|
||||
--hash=sha256:befb4158af32106b9a93db8d6d1d1cbbd418c0d5aca0cabb7b1780abf0c89169 \
|
||||
--hash=sha256:bf053da3c97a4bc5ecfbb218cdd2983febd91c617be8367d139882aa11e490aa \
|
||||
--hash=sha256:c02e8f18bdedba082cef725942ac823b9b60656db07f7e265cb31618dfd00d77 \
|
||||
--hash=sha256:c1bc67752d5f21013cfe430df4062441714eab79f65a6a05e01505957e9c35fe \
|
||||
--hash=sha256:c61750fadcd119d0825bcb7d7d675dd264dcc89cc05292aab5be68ebdbb374ad \
|
||||
--hash=sha256:c90d5b3d4e944e065a301d741b3c1d784f6bd1f503aa68b4967e32b2ba313d85 \
|
||||
--hash=sha256:c9a7f43c0b202b334cc9184af09bb8f21d3a209e038efaf106936fb69e6b026e \
|
||||
--hash=sha256:cb96e6e088d6cf71c1ea977510948320234824cf226e32f6f6e044f7a9c82b34 \
|
||||
--hash=sha256:cf63c214fe879a65e69a386f915e36104fc84254ab141240f8854602d8e0be2a \
|
||||
--hash=sha256:d1aca03ede943eb80ab3d63bb082c84b7aab85ea83bd0fd0c200260945fb49d9 \
|
||||
--hash=sha256:d2e56fd3b00222722abfb3f5f0759ddbae4b90811b5ad4343c64030ad1bde70c \
|
||||
--hash=sha256:d5f93ebbeb8032d47e349328ec8662d973d9b05a70b3c35df1f91fe419b84749 \
|
||||
--hash=sha256:d882a373d8093c2941e01291b7ced96e9cbe4781da9a7751ca7e6c70385e5214 \
|
||||
--hash=sha256:d920abdfa61279ba1a2ef9484aab07bf03331f8c08a10120fa332353d06e6932 \
|
||||
--hash=sha256:da2af0d7aebfc2074080d72efa6ab8317c62481ef1f896f65d9999c1c01f4494 \
|
||||
--hash=sha256:dd8ea6ebee7aedbf7c749fa80521d9ccf1ba473e0d1e14805caafbaad281c889 \
|
||||
--hash=sha256:de8b364c423ef0a4bad9069657d617f9a5d2b2062457a89b1fa16ee199c399c1 \
|
||||
--hash=sha256:df1ae86ff54725a01fa1a0510b914ca53a161b7050be74f6204e24aded5971d0 \
|
||||
--hash=sha256:dff05cb7016dff1e9fd68f4122c127b65dfc59de5306cfb7ad92f956f230bee2 \
|
||||
--hash=sha256:e1a622f13970d81f95d0c72f9dc090dce9085fccfa4c9f2174377ee32bd15786 \
|
||||
--hash=sha256:e49fb0d1ce92cfa0cb198cc5b1b11cdf9d0638658e2a2db2687e39db7c87fc78 \
|
||||
--hash=sha256:e5c802729725bd07e2bc3ab7b76dc7e0bbfc53129d8f1eb1c002c24cf774717e \
|
||||
--hash=sha256:e841068dc0be4cb6dfb5c890eb88cbdcff2f4a332393c7ec94e8e618bd32c1a8 \
|
||||
--hash=sha256:e916035e3e9930cbdfdd10abf48861340221857f45509565898e012263f7b289 \
|
||||
--hash=sha256:eba154571c16e032112afac0dc2dfe9e63c2ceb7aedd07bb7eecf2ce26d4dd4c \
|
||||
--hash=sha256:f03460ff076f70ab595bb45a0205ccea1971443575b6920c52e755dec2b3fbfe \
|
||||
--hash=sha256:f0ec3b750b59375eab5b0fb2b9254810c00a3375be6d789899f1055a1d556237 \
|
||||
--hash=sha256:f291bcf42ae98eb5107edb162c3c998b4a89648fd8e99ed4cbd12705292788cd \
|
||||
--hash=sha256:f61efe1d2fe0de16158a5fe1d1cf3c14bdb6aecd54d8938fd26512c525c1f624 \
|
||||
--hash=sha256:f68edfc67aabac33708941f26f22a7b8e9f81429bc0cf249fcf7d66b23af8d19 \
|
||||
--hash=sha256:fa95848c929b6a75f6848d3c9793e59db365ee436776e57db835cdbfa79ba977 \
|
||||
--hash=sha256:fd9f8797427910198f95bced71ddfed61130d7e349213bfb8466c9c99e2c46a8 \
|
||||
--hash=sha256:fdb4ca07ab75ffadab4a8b135ad59cdbb3156b99310f3d565370da74a15d6bd3
|
||||
# via
|
||||
# flask
|
||||
# jinja2
|
||||
# werkzeug
|
||||
packaging==26.3 \
|
||||
--hash=sha256:94edc256424af38762eb31306eed28beb9f0efc50a8837492c9d6fd6004aed79 \
|
||||
--hash=sha256:d7193f7c8e4e93f444fde0262bf90af30e16fa0ad0ad44cb553c87339b23cd1c
|
||||
# via gunicorn
|
||||
werkzeug==3.1.9 \
|
||||
--hash=sha256:55ca7c70a75689be937aa27f8ff4b018f06ff4838fc73045560bf0f5a1291060 \
|
||||
--hash=sha256:6392e50c78460ba618e5b21f08a71f59c99ce99cdc6cf6e3dd7e6ccca8754fab
|
||||
# via flask
|
||||
@@ -0,0 +1,25 @@
|
||||
import unittest
|
||||
from app import app, total_price
|
||||
|
||||
|
||||
class PricingTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.client = app.test_client()
|
||||
|
||||
def test_price(self):
|
||||
self.assertEqual(total_price(3), 36)
|
||||
response = self.client.get("/price?quantity=3")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
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"], "v2")
|
||||
self.assertEqual(self.client.get("/health").json["status"], "ok")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,6 @@
|
||||
# Release records
|
||||
|
||||
One file per environment and release, e.g. `v1-staging.yml`, `v1-production.yml`.
|
||||
Each holds metadata only (image digest, full source commit, expected version and
|
||||
total, public URL, proxy network) - never credentials. Production uses the same
|
||||
image digest as staging. Keep old records for rollback.
|
||||
@@ -0,0 +1,8 @@
|
||||
# Copy to a release-specific file and replace EVERY placeholder.
|
||||
target_env: staging
|
||||
release_image: gitea.example.edu/team/pricing@sha256:REPLACE_DIGEST
|
||||
expected_version: v1
|
||||
expected_commit: REPLACE_FULL_GIT_COMMIT
|
||||
expected_total: 30
|
||||
public_url: https://staging.example.edu
|
||||
proxy_network: REPLACE_EXISTING_PROXY_NETWORK
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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.
|
||||
@@ -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
|
||||