From 344dbcbcd4b8169aaf089d6f3fd4ca809fee3c33 Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 4 Nov 2026 19:01:59 +0000 Subject: [PATCH 01/17] Add pricing service and Ansible starter with pinned dependencies --- secure-delivery/README.md | 129 ++++++++++++++++++ secure-delivery/ansible/deploy.yml | 62 +++++++++ secure-delivery/ansible/inventory.ini | 3 + secure-delivery/ansible/release.example.yml | 8 ++ secure-delivery/ansible/requirements.yml | 3 + .../ansible/templates/compose.yaml.j2 | 19 +++ secure-delivery/v1/.dockerignore | 4 + secure-delivery/v1/Dockerfile | 11 ++ secure-delivery/v1/app.py | 33 +++++ secure-delivery/v1/requirements.txt | 9 ++ secure-delivery/v1/test_app.py | 25 ++++ 11 files changed, 306 insertions(+) create mode 100644 secure-delivery/README.md create mode 100644 secure-delivery/ansible/deploy.yml create mode 100644 secure-delivery/ansible/inventory.ini create mode 100644 secure-delivery/ansible/release.example.yml create mode 100644 secure-delivery/ansible/requirements.yml create mode 100644 secure-delivery/ansible/templates/compose.yaml.j2 create mode 100644 secure-delivery/v1/.dockerignore create mode 100644 secure-delivery/v1/Dockerfile create mode 100644 secure-delivery/v1/app.py create mode 100644 secure-delivery/v1/requirements.txt create mode 100644 secure-delivery/v1/test_app.py diff --git a/secure-delivery/README.md b/secure-delivery/README.md new file mode 100644 index 0000000..88406d7 --- /dev/null +++ b/secure-delivery/README.md @@ -0,0 +1,129 @@ +# Chapter 6: Startup Pricing Service + +`v1/` and `v2/` are two releases of the same stateless Flask service. Version 1 +charges USD 10 per unit; version 2 charges USD 12. Three units cost 30 and 36. +Both use Gunicorn, run as a non-root container user, and expose port 8000. +No database, real customer data, payment processing, or credentials are involved. + +## Local checks + +Run from either version directory, using a disposable virtual environment: + +```sh +python3 -m venv .venv +. .venv/bin/activate +pip install -r requirements.txt +python -m unittest -v +``` + +Requirements are compatibility ranges, not a reproducible lock. Before the +assessed release, resolve, review, scan, and commit exact dependency versions +(including transitive dependencies) and an approved base-image digest. Save +scanner versions and reports. These starter files make no vulnerability claim. + +## Build and publish + +Copy v1 into the team application's working directory and commit it. Build from +that directory on the trusted Jenkins agent. Use the Gitea registry hostname +without a URL scheme; replace the owner/team with its actual lowercase name. + +```sh +COMMIT=$(git rev-parse HEAD) +IMAGE=gitea.example.edu/team/pricing +# Authenticate separately using a Jenkins credential and --password-stdin. +docker build --build-arg APP_COMMIT="$COMMIT" -t "$IMAGE:$COMMIT" . +docker push "$IMAGE:$COMMIT" +docker pull "$IMAGE:$COMMIT" +docker image inspect "$IMAGE:$COMMIT" --format '{{index .RepoDigests 0}}' +``` + +Save that repository digest in a release record. Build once; use the same digest +in staging and production. For v2, replace app.py and test_app.py with the v2 +files, commit, and repeat the pipeline. Do not build the entire parent directory. +Use a Linux image architecture compatible with the droplet. + +## One-time deployment preparation + +Install Ansible in a virtual environment on a trusted Linux Jenkins agent; use a +Python version supported by your selected ansible-core release. Record exact +resolved versions after installation. + +```sh +python3 -m venv .ansible-venv +. .ansible-venv/bin/activate +pip install ansible-core +ansible-galaxy collection install -r ansible/requirements.yml +ansible --version +ansible-galaxy collection list +``` + +On the target droplet, install Python 3, Docker Engine and the Compose v2 plugin +(at least 2.18); verify `docker compose version`. Configure a dedicated SSH +account and the approved escalation policy. The playbook uses become and needs +noninteractive sudo; this is powerful host access. Do not grant it to untrusted +pull-request jobs. Verify/pin the SSH host key in the Jenkins agent's known_hosts. +Keep private keys, sudo credentials and package tokens in Jenkins credentials. + +Identify the existing reverse proxy's Docker network with `docker network ls` +and its current Compose configuration. Both app projects join that external +network. Configure the proxy once, preserving all existing routes: + +```caddyfile +staging.example.edu { + reverse_proxy pricing-staging:8000 +} +app.example.edu { + reverse_proxy pricing-production:8000 +} +``` + +Use your real DNS names pointing to the droplet and valid TLS certificates. +The proxy must be attached to that network. For a host-based proxy, adapt the +Compose template to distinct loopback ports and proxy to those ports instead. +The supplied template is for a container-based proxy; do not publish raw 8000. + +Authenticate Docker on the target as the account used by become (normally root) +using a read-only package credential and `docker login --password-stdin` through +a protected administrator session. The Jenkins build agent separately needs a +package-write credential. Never commit either credential or Docker config.json. +Do not enable insecure registry access or disable certificate verification. + +## Deploy and roll back + +Fill inventory.ini and copy release.example.yml to releases/v1-staging.yml. +Replace every placeholder. Keep this release metadata in Git; it has no secrets. +Use the exact source commit, registry digest, proxy network, URL and expected +values. From this starter directory: + +```sh +ansible-playbook -i ansible/inventory.ini ansible/deploy.yml --syntax-check +ansible-playbook -i ansible/inventory.ini ansible/deploy.yml -e @releases/v1-staging.yml +``` + +Run again unchanged and show changed=0. If the module reports unexpected +changes, inspect Compose/plugin versions and the task diff before claiming +idempotence. Create a production record with the same image digest and the +production target and URL; deploy only after an authorized Jenkins approval. +Disable concurrent delivery builds to prevent competing releases. + +Preserve each release's Compose template/configuration commit as well as its +image digest. For rollback, check out the previous reviewed deployment files +and run its production release record again. The current playbook does not +perform an automatic rollback: a failed check fails the run and requires the +explicit rollback stage/runbook. Never use `down -v`, prune shared volumes, or +roll back Gitea/Jenkins as part of the application exercise. + +For a controlled failure, use staging only: temporarily set the service's +Compose `command` to `["gunicorn", "--bind", "0.0.0.0:8001", "app:app"]` in a +separate configuration commit. The image healthcheck still probes 8000, so +Compose wait should fail. Save the failure, restore the previous configuration +commit, and redeploy its release record. Do not stop the host Docker service. + +For the business rollback, deploy healthy v2, verify version v2 and total 36, +then redeploy v1 and verify version v1 and total 30. Measure interruption and +recovery time. This recreate strategy does not provide zero downtime. + +Implement the Jenkins stages, security policy, approval and evidence described +in Chapter 6; the examples are application/deployment starters, not a complete +Jenkins pipeline. Container builds and remote deployment were not executed by +the author in a student environment. diff --git a/secure-delivery/ansible/deploy.yml b/secure-delivery/ansible/deploy.yml new file mode 100644 index 0000000..b0c4fa2 --- /dev/null +++ b/secure-delivery/ansible/deploy.yml @@ -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 diff --git a/secure-delivery/ansible/inventory.ini b/secure-delivery/ansible/inventory.ini new file mode 100644 index 0000000..18494a3 --- /dev/null +++ b/secure-delivery/ansible/inventory.ini @@ -0,0 +1,3 @@ +[delivery] +# Replace address and user; verify the SSH host key before first use. +startup ansible_host=REPLACE_DROPLET_ADDRESS ansible_user=deploy diff --git a/secure-delivery/ansible/release.example.yml b/secure-delivery/ansible/release.example.yml new file mode 100644 index 0000000..8e5be10 --- /dev/null +++ b/secure-delivery/ansible/release.example.yml @@ -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 diff --git a/secure-delivery/ansible/requirements.yml b/secure-delivery/ansible/requirements.yml new file mode 100644 index 0000000..5ccd5c4 --- /dev/null +++ b/secure-delivery/ansible/requirements.yml @@ -0,0 +1,3 @@ +collections: + - name: community.docker + version: ">=4.8.0,<6.0.0" diff --git a/secure-delivery/ansible/templates/compose.yaml.j2 b/secure-delivery/ansible/templates/compose.yaml.j2 new file mode 100644 index 0000000..7c003c7 --- /dev/null +++ b/secure-delivery/ansible/templates/compose.yaml.j2 @@ -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 }}" diff --git a/secure-delivery/v1/.dockerignore b/secure-delivery/v1/.dockerignore new file mode 100644 index 0000000..e1b2920 --- /dev/null +++ b/secure-delivery/v1/.dockerignore @@ -0,0 +1,4 @@ +__pycache__ +.venv +.git +*.pyc diff --git a/secure-delivery/v1/Dockerfile b/secure-delivery/v1/Dockerfile new file mode 100644 index 0000000..f7212fe --- /dev/null +++ b/secure-delivery/v1/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.13-slim +ARG APP_COMMIT=development +ENV APP_COMMIT=$APP_COMMIT PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 +WORKDIR /app +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt +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"] diff --git a/secure-delivery/v1/app.py b/secure-delivery/v1/app.py new file mode 100644 index 0000000..1ea1194 --- /dev/null +++ b/secure-delivery/v1/app.py @@ -0,0 +1,33 @@ +import os +from flask import Flask, jsonify, request + +app = Flask(__name__) +VERSION = "v1" +UNIT_PRICE = 10 +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") diff --git a/secure-delivery/v1/requirements.txt b/secure-delivery/v1/requirements.txt new file mode 100644 index 0000000..81b6476 --- /dev/null +++ b/secure-delivery/v1/requirements.txt @@ -0,0 +1,9 @@ +blinker==1.9.0 +click==8.5.0 +Flask==3.1.3 +gunicorn==23.0.0 +itsdangerous==2.2.0 +Jinja2==3.1.6 +MarkupSafe==3.0.4 +packaging==26.3 +Werkzeug==3.1.9 diff --git a/secure-delivery/v1/test_app.py b/secure-delivery/v1/test_app.py new file mode 100644 index 0000000..40b4207 --- /dev/null +++ b/secure-delivery/v1/test_app.py @@ -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), 30) + response = self.client.get("/price?quantity=3") + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json["total"], 30) + + 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("/health").json["status"], "ok") + + +if __name__ == "__main__": + unittest.main() -- 2.54.0 From bda4ac82406b14486fda0c801b96344030420228 Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 4 Nov 2026 19:06:22 +0000 Subject: [PATCH 02/17] Pin pricing base image and record baseline evidence --- secure-delivery/WORK_LOG.md | 11 +++++++++++ secure-delivery/v1/Dockerfile | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 secure-delivery/WORK_LOG.md diff --git a/secure-delivery/WORK_LOG.md b/secure-delivery/WORK_LOG.md new file mode 100644 index 0000000..1093d9b --- /dev/null +++ b/secure-delivery/WORK_LOG.md @@ -0,0 +1,11 @@ +# Assignment 8 work log + +## 2026-11-04 baseline +- Starting repository main: 10c85ea (Assignment 7 manual 1.9.2 merge). Working branch: assignment8/secure-delivery. +- Existing Gitea, Jenkins, Caddy, and four monitoring containers observed running. Docker 29.8.1; Compose 5.5.1; architecture x86_64. +- Jenkins controller is containerized; no dedicated agent found in initial inspection. Ansible core 2.22.0 and community.docker 5.0.4 installed under persistent Jenkins home. Python venv system package installed in running container; container recreation provisioning still needed. Controller must not be used for assessed deployment. +- Starter v1 unit tests: 3 passed locally and inside isolated Jenkins Python 3.13 environment. Exact direct/transitive versions recorded in requirements.txt. +- pip-audit against pinned requirements reported no known vulnerabilities at time of check. This does not establish image or secret scan status; retain a formal report in pipeline. +- Python 3.13 slim base digest pinned to sha256:ae14d4ce8771606477a81446e7ef429edd6762305fc50c84507c1041fa8285d1 (linux/amd64). Local baseline image built with APP_COMMIT=baseline-test; this is not an assessed release or registry digest. +- Droplet baseline: 961 MiB RAM, 270 MiB available and 840 MiB swap used at inspection. Recheck before adding services. +- No staging/production deployment, approval, image publication, controlled failure, or rollback has been performed. diff --git a/secure-delivery/v1/Dockerfile b/secure-delivery/v1/Dockerfile index f7212fe..a380e8c 100644 --- a/secure-delivery/v1/Dockerfile +++ b/secure-delivery/v1/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.13-slim +FROM python:3.13-slim@sha256:ae14d4ce8771606477a81446e7ef429edd6762305fc50c84507c1041fa8285d1 ARG APP_COMMIT=development ENV APP_COMMIT=$APP_COMMIT PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 WORKDIR /app -- 2.54.0 From f55a36468ccd97613a445aa72702f67099e1c833 Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 4 Nov 2026 19:24:55 +0000 Subject: [PATCH 03/17] Prepare restricted Jenkins delivery agent --- secure-delivery/WORK_LOG.md | 9 +++++++++ secure-delivery/agent/Dockerfile | 6 ++++++ 2 files changed, 15 insertions(+) create mode 100644 secure-delivery/agent/Dockerfile diff --git a/secure-delivery/WORK_LOG.md b/secure-delivery/WORK_LOG.md index 1093d9b..485dfc4 100644 --- a/secure-delivery/WORK_LOG.md +++ b/secure-delivery/WORK_LOG.md @@ -9,3 +9,12 @@ - Python 3.13 slim base digest pinned to sha256:ae14d4ce8771606477a81446e7ef429edd6762305fc50c84507c1041fa8285d1 (linux/amd64). Local baseline image built with APP_COMMIT=baseline-test; this is not an assessed release or registry digest. - Droplet baseline: 961 MiB RAM, 270 MiB available and 840 MiB swap used at inspection. Recheck before adding services. - No staging/production deployment, approval, image publication, controlled failure, or rollback has been performed. + +## Agent setup +- Created Jenkins permanent node assignment8-trusted with one executor and label-only scheduling. An official inbound-agent container connects through the existing private Docker network using WebSocket and a protected secret file. Agent logs reported Connected. No Docker socket or deployment credentials were granted. +- Built a draft agent Dockerfile with Python, Docker and Ansible, but image packaging stalled while the host reported all 1 GiB swap in use; the build was interrupted to avoid overloading existing services. The Dockerfile is not yet validated: the Docker collection was installed under root and must be moved to a location readable by the Jenkins user. The running agent remains the original image and does not yet have Python, Docker or Ansible. No agent job has been verified. + +## Agent progress after swap increase +- Total swap verified at 2 GiB. Agent image built and connected; Python 3.13.5, Ansible core 2.22.0 and community.docker 5.0.4 verified as Jenkins user. Docker CLI 26.1.5 installed in running container; Dockerfile corrected to include docker-cli but requires rebuilding and recreation to persist that change. No Docker socket or deployment credentials have been added. A Jenkins job has not yet been run on the agent. + +- Corrected agent image built as assignment8-jenkins-agent:2 and agent reconnected on 2026-11-04. Python 3.13.5 and Docker CLI 26.1.5 observed in recreated container. Ansible and community.docker were verified in previous image with identical installation steps; recheck after recreation. No Docker socket, deployment credential, or Jenkins test job yet. diff --git a/secure-delivery/agent/Dockerfile b/secure-delivery/agent/Dockerfile new file mode 100644 index 0000000..25b7d04 --- /dev/null +++ b/secure-delivery/agent/Dockerfile @@ -0,0 +1,6 @@ +FROM jenkins/inbound-agent@sha256:5069347cd3e72e5924e54c04fceb67209b41c8d0a3ab1c2b3f740e5fb2fab92a +USER root +RUN apt-get update && apt-get install -y --no-install-recommends python3 python3-venv docker-cli openssh-client && rm -rf /var/lib/apt/lists/* +RUN python3 -m venv /opt/ansible && /opt/ansible/bin/pip install --no-cache-dir ansible-core==2.22.0 && /opt/ansible/bin/ansible-galaxy collection install -p /usr/share/ansible/collections community.docker:5.0.4 +ENV PATH="/opt/ansible/bin:${PATH}" +USER jenkins -- 2.54.0 From f44cebd00eb2285b2c642e0eb9815a61d97ea98c Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 4 Nov 2026 19:27:26 +0000 Subject: [PATCH 04/17] Record passing Jenkins agent verification --- secure-delivery/WORK_LOG.md | 3 +++ secure-delivery/agent/Jenkinsfile.check | 10 ++++++++++ 2 files changed, 13 insertions(+) create mode 100644 secure-delivery/agent/Jenkinsfile.check diff --git a/secure-delivery/WORK_LOG.md b/secure-delivery/WORK_LOG.md index 485dfc4..0dc543e 100644 --- a/secure-delivery/WORK_LOG.md +++ b/secure-delivery/WORK_LOG.md @@ -18,3 +18,6 @@ - Total swap verified at 2 GiB. Agent image built and connected; Python 3.13.5, Ansible core 2.22.0 and community.docker 5.0.4 verified as Jenkins user. Docker CLI 26.1.5 installed in running container; Dockerfile corrected to include docker-cli but requires rebuilding and recreation to persist that change. No Docker socket or deployment credentials have been added. A Jenkins job has not yet been run on the agent. - Corrected agent image built as assignment8-jenkins-agent:2 and agent reconnected on 2026-11-04. Python 3.13.5 and Docker CLI 26.1.5 observed in recreated container. Ansible and community.docker were verified in previous image with identical installation steps; recheck after recreation. No Docker socket, deployment credential, or Jenkins test job yet. + +## Agent Jenkins verification +- Jenkins job assignment8-agent-check build #1 failed during pipeline parsing because the initial one-line declarative script lacked section separators; no agent work occurred. Corrected script and reran. Build #2 succeeded on assignment8-trusted and verified Python 3.13.5, Git 2.47.3, Docker CLI 26.1.5, Ansible core 2.22.0, and community.docker 5.0.4. Evidence: https://ci.myfileagent.tech/job/assignment8-agent-check/2/console . Docker daemon access and deployment credentials remain unconfigured. diff --git a/secure-delivery/agent/Jenkinsfile.check b/secure-delivery/agent/Jenkinsfile.check new file mode 100644 index 0000000..5f4c11d --- /dev/null +++ b/secure-delivery/agent/Jenkinsfile.check @@ -0,0 +1,10 @@ +pipeline { + agent { label 'assignment8-trusted' } + stages { + stage('Verify tools') { + steps { + sh 'hostname; python3 --version; git --version; docker --version; ansible --version; ansible-galaxy collection list community.docker' + } + } + } +} -- 2.54.0 From 242372e381ecbcab4078e7d8c0916073d600d970 Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 4 Nov 2026 19:30:57 +0000 Subject: [PATCH 05/17] Prepare application and Ansible validation pipeline --- secure-delivery/Jenkinsfile.validation | 22 ++++++++++++++++++++++ secure-delivery/WORK_LOG.md | 3 +++ 2 files changed, 25 insertions(+) create mode 100644 secure-delivery/Jenkinsfile.validation diff --git a/secure-delivery/Jenkinsfile.validation b/secure-delivery/Jenkinsfile.validation new file mode 100644 index 0000000..cef37cd --- /dev/null +++ b/secure-delivery/Jenkinsfile.validation @@ -0,0 +1,22 @@ +pipeline { + agent { label 'assignment8-trusted' } + options { disableConcurrentBuilds(); timeout(time: 15, unit: 'MINUTES'); timestamps() } + stages { + stage('Checkout') { steps { checkout scm } } + stage('Unit tests') { + steps { + dir('secure-delivery/v1') { + sh '''set -eu +python3 -m venv .test-venv +.test-venv/bin/pip install -r requirements.txt +.test-venv/bin/python -m py_compile app.py test_app.py +.test-venv/bin/python -m unittest -v +''' + } + } + } + stage('Ansible syntax') { + steps { dir('secure-delivery') { sh 'ansible-playbook -i ansible/inventory.ini ansible/deploy.yml --syntax-check' } } + } + } +} diff --git a/secure-delivery/WORK_LOG.md b/secure-delivery/WORK_LOG.md index 0dc543e..891956c 100644 --- a/secure-delivery/WORK_LOG.md +++ b/secure-delivery/WORK_LOG.md @@ -21,3 +21,6 @@ ## Agent Jenkins verification - Jenkins job assignment8-agent-check build #1 failed during pipeline parsing because the initial one-line declarative script lacked section separators; no agent work occurred. Corrected script and reran. Build #2 succeeded on assignment8-trusted and verified Python 3.13.5, Git 2.47.3, Docker CLI 26.1.5, Ansible core 2.22.0, and community.docker 5.0.4. Evidence: https://ci.myfileagent.tech/job/assignment8-agent-check/2/console . Docker daemon access and deployment credentials remain unconfigured. + +## Validation preparation +- Ansible syntax check passed on assignment8-trusted against the starter playbook on 2026-11-04. The inventory and release records still contain placeholders; syntax success is not deployment. Added a separate draft validation Jenkinsfile for tests and syntax checks; it has not been run in Jenkins. -- 2.54.0 From c35558c20beabdbbcd0e35e9b8a882900cbe6e00 Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 4 Nov 2026 19:41:49 +0000 Subject: [PATCH 06/17] Record validation and define release scan policy --- secure-delivery/SECURITY_POLICY.md | 7 +++++++ secure-delivery/WORK_LOG.md | 3 +++ 2 files changed, 10 insertions(+) create mode 100644 secure-delivery/SECURITY_POLICY.md diff --git a/secure-delivery/SECURITY_POLICY.md b/secure-delivery/SECURITY_POLICY.md new file mode 100644 index 0000000..540eb9c --- /dev/null +++ b/secure-delivery/SECURITY_POLICY.md @@ -0,0 +1,7 @@ +# Assignment 8 release security policy + +The trusted release job must run only reviewed source and must not expose deployment or registry credentials to pull-request builds. Restrict the agent to labeled release jobs and authorized Jenkins users. Docker daemon access confers host-administrator privileges. Record agent identity, access scope, tool versions, scan time, database version, exit status, and archived reports for each release. + +Before publication, fail on discovered secrets and on HIGH or CRITICAL vulnerabilities unless a documented time-limited exception is accepted by the instructor. Fail closed if a scanner fails or its database is unavailable. Investigate false positives and unfixed findings; document owner, reason, expiry, and approval for any exception. Never publish a deliberately vulnerable image as the working release. + +Run a dependency audit against the exact locked requirements, a repository secret scan, and an image vulnerability scan against the built release image. Demonstrate a blocked gate with a scanner-supported synthetic fixture and remove it before release. The initial pip-audit result in WORK_LOG.md is a baseline, not the final release scan. diff --git a/secure-delivery/WORK_LOG.md b/secure-delivery/WORK_LOG.md index 891956c..2e03af6 100644 --- a/secure-delivery/WORK_LOG.md +++ b/secure-delivery/WORK_LOG.md @@ -24,3 +24,6 @@ ## Validation preparation - Ansible syntax check passed on assignment8-trusted against the starter playbook on 2026-11-04. The inventory and release records still contain placeholders; syntax success is not deployment. Added a separate draft validation Jenkinsfile for tests and syntax checks; it has not been run in Jenkins. + +## Gitea-backed validation +- Published branch assignment8/secure-delivery at 242372e381ecbcab4078e7d8c0916073d600d970. Jenkins assignment8-validation build #1 checked out that commit on assignment8-trusted, passed all 3 v1 unit tests and passed Ansible syntax check. Evidence: https://ci.myfileagent.tech/job/assignment8-validation/1/console . This does not demonstrate deployment, security gates, or image publication. -- 2.54.0 From 83da3087c9aa15bdebd43e118ccc2c301dc61862 Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 4 Nov 2026 19:49:32 +0000 Subject: [PATCH 07/17] Use scanned lean pricing image and record baseline evidence --- secure-delivery/WORK_LOG.md | 5 +++++ secure-delivery/v1/Dockerfile | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/secure-delivery/WORK_LOG.md b/secure-delivery/WORK_LOG.md index 2e03af6..500fc16 100644 --- a/secure-delivery/WORK_LOG.md +++ b/secure-delivery/WORK_LOG.md @@ -27,3 +27,8 @@ ## Gitea-backed validation - Published branch assignment8/secure-delivery at 242372e381ecbcab4078e7d8c0916073d600d970. Jenkins assignment8-validation build #1 checked out that commit on assignment8-trusted, passed all 3 v1 unit tests and passed Ansible syntax check. Evidence: https://ci.myfileagent.tech/job/assignment8-validation/1/console . This does not demonstrate deployment, security gates, or image publication. + +## Initial image security checks +- User approved host Docker daemon access for the label-restricted trusted agent; its connection was verified. This access is effectively host administration. Agent-built test image succeeded with placeholder identity, not a release. +- Trivy 0.69.1 scan of the Debian slim test image failed the HIGH/CRITICAL gate: 45 Debian and 5 Python findings. A pinned Python Alpine candidate had no OS findings but 5 Python tooling findings. After removing pip and ensurepip bundled wheels from runtime, the candidate scan reported zero HIGH/CRITICAL findings, exit 0, at the time of scan. Reports are in server evidence/assignment8; rescan the actual release image and archive results. +- Isolated candidate smoke test initially ran before startup and got connection refused; after allowing startup, health was ok, v1 identity returned development placeholder, and quantity 3 returned 30. No production deployment occurred. diff --git a/secure-delivery/v1/Dockerfile b/secure-delivery/v1/Dockerfile index a380e8c..921ebb2 100644 --- a/secure-delivery/v1/Dockerfile +++ b/secure-delivery/v1/Dockerfile @@ -1,9 +1,10 @@ -FROM python:3.13-slim@sha256:ae14d4ce8771606477a81446e7ef429edd6762305fc50c84507c1041fa8285d1 +FROM python:3.13-alpine@sha256:7984cf56ceaddebe4fefeb75d64000b9f45d8b77b11a09b24524da6cdc3af0c8 ARG APP_COMMIT=development ENV APP_COMMIT=$APP_COMMIT PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt +RUN python -m pip uninstall -y pip && rm -rf /usr/local/lib/python3.13/ensurepip/_bundled COPY app.py . USER 10001:10001 EXPOSE 8000 -- 2.54.0 From 28d13ef5b8757645bee640ca1dd9a8eea417ce18 Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 4 Nov 2026 19:58:51 +0000 Subject: [PATCH 08/17] Add security validation stages and record blocked gate --- secure-delivery/Jenkinsfile.security | 25 +++++++++++++++++++++++++ secure-delivery/WORK_LOG.md | 5 +++++ secure-delivery/scan-secrets.sh | 13 +++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 secure-delivery/Jenkinsfile.security create mode 100644 secure-delivery/scan-secrets.sh diff --git a/secure-delivery/Jenkinsfile.security b/secure-delivery/Jenkinsfile.security new file mode 100644 index 0000000..f99e740 --- /dev/null +++ b/secure-delivery/Jenkinsfile.security @@ -0,0 +1,25 @@ +pipeline { + agent { label 'assignment8-trusted' } + options { disableConcurrentBuilds(); timeout(time: 20, unit: 'MINUTES'); timestamps(); skipDefaultCheckout() } + stages { + stage('Checkout') { steps { checkout scm } } + stage('Unit tests and dependency audit') { + steps { dir('secure-delivery/v1') { sh '''set -eu +python3 -m venv .test-venv +.test-venv/bin/pip install -r requirements.txt pip-audit==2.10.1 +.test-venv/bin/python -m unittest -v +.test-venv/bin/pip-audit -r requirements.txt +''' } } + } + stage('Secret scan') { steps { sh 'sh secure-delivery/scan-secrets.sh' } } + stage('Ansible syntax') { steps { dir('secure-delivery') { sh 'ansible-playbook -i ansible/inventory.ini ansible/deploy.yml --syntax-check' } } } + stage('Build test image') { steps { sh 'docker build --build-arg APP_COMMIT=$(git rev-parse HEAD) -t assignment8-pricing:security-check secure-delivery/v1' } } + stage('Image vulnerability scan') { + steps { sh '''set -eu +mkdir -p reports +docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /home/codex/myfileagent-gitea/evidence/assignment8/trivy-cache:/root/.cache/ aquasec/trivy@sha256:1c78ed1ef824ab8bb05b04359d186e4c1229d0b3e67005faacb54a7d71974f73 image --quiet --scanners vuln --severity HIGH,CRITICAL --exit-code 1 --format json assignment8-pricing:security-check > reports/image-scan.json +''' } + } + } + post { always { archiveArtifacts artifacts: 'reports/*.json', allowEmptyArchive: true } } +} diff --git a/secure-delivery/WORK_LOG.md b/secure-delivery/WORK_LOG.md index 500fc16..d7df090 100644 --- a/secure-delivery/WORK_LOG.md +++ b/secure-delivery/WORK_LOG.md @@ -32,3 +32,8 @@ - User approved host Docker daemon access for the label-restricted trusted agent; its connection was verified. This access is effectively host administration. Agent-built test image succeeded with placeholder identity, not a release. - Trivy 0.69.1 scan of the Debian slim test image failed the HIGH/CRITICAL gate: 45 Debian and 5 Python findings. A pinned Python Alpine candidate had no OS findings but 5 Python tooling findings. After removing pip and ensurepip bundled wheels from runtime, the candidate scan reported zero HIGH/CRITICAL findings, exit 0, at the time of scan. Reports are in server evidence/assignment8; rescan the actual release image and archive results. - Isolated candidate smoke test initially ran before startup and got connection refused; after allowing startup, health was ok, v1 identity returned development placeholder, and quantity 3 returned 30. No production deployment occurred. + +- Trivy 0.69.1 secret scanner standalone test: an example-format fixture was ignored (exit 0), then a newly generated disposable private-key fixture produced one finding and exit 1. Both fixture files were removed. This proves scanner behavior only; a blocked Jenkins pipeline run remains required. + +## Jenkins synthetic secret gate +- Jenkins assignment8-secret-gate-demo #4 detected one generated disposable private key and failed with scanner exit 1; the job removed the fixture. Earlier attempts #1-3 failed due to transfer or job-script errors, not secret detections. Evidence: https://ci.myfileagent.tech/job/assignment8-secret-gate-demo/4/console . Prepared source-controlled security pipeline; it has not yet been run. diff --git a/secure-delivery/scan-secrets.sh b/secure-delivery/scan-secrets.sh new file mode 100644 index 0000000..68500d5 --- /dev/null +++ b/secure-delivery/scan-secrets.sh @@ -0,0 +1,13 @@ +#!/bin/sh +set -eu +scanner="a8-secret-${BUILD_NUMBER}" +trap 'docker rm -f "$scanner" >/dev/null 2>&1 || true; rm -f secret-report.json' EXIT +docker create --name "$scanner" aquasec/trivy@sha256:1c78ed1ef824ab8bb05b04359d186e4c1229d0b3e67005faacb54a7d71974f73 fs --quiet --scanners secret --exit-code 1 --format json /v1 >/dev/null +tar -C secure-delivery --exclude=v1/.test-venv --exclude=v1/__pycache__ -cf - v1 | docker cp - "$scanner":/ +set +e +docker start -a "$scanner" > secret-report.json +result=$? +set -e +python3 -c 'import json; p=json.load(open("secret-report.json")); print("Secret findings:",sum(len(r.get("Secrets",[])) for r in p.get("Results",[])))' +echo "Secret scanner exit status: $result" +exit "$result" -- 2.54.0 From dd7c12c519b14f59d9842ebd6d417e7117d92e94 Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 4 Nov 2026 20:08:01 +0000 Subject: [PATCH 09/17] Record security validation and expand repository scan --- secure-delivery/OPERATIONS_DRAFT.md | 18 ++++++++++++++++++ secure-delivery/WORK_LOG.md | 7 +++++++ secure-delivery/scan-secrets.sh | 4 ++-- secure-delivery/v1/.dockerignore | 1 + 4 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 secure-delivery/OPERATIONS_DRAFT.md diff --git a/secure-delivery/OPERATIONS_DRAFT.md b/secure-delivery/OPERATIONS_DRAFT.md new file mode 100644 index 0000000..037ac90 --- /dev/null +++ b/secure-delivery/OPERATIONS_DRAFT.md @@ -0,0 +1,18 @@ +# Secure delivery operations (draft) + +These procedures must be updated with verified hostnames, release records, commit links and actual roles before use. Never put passwords, tokens or private keys in release records or logs. + +## Release +1. Review source and configuration changes. Record source commit, configuration commit, base digest, locked dependencies, scan reports, build ID, resulting image digest and expected behavior. +2. Deploy that digest to staging with the reviewed Ansible configuration. Verify HTTPS health, version, full source commit and price for quantity three. Run the same playbook again and investigate any unexpected changes. +3. An authorized person reviews the digest, scan and staging results in Jenkins. Record their identity and decision. If rejected or timed out, stop. +4. Promote the same digest to production using its matching release record and verify the same checks. Record times and monitoring observations. + +## Failed staging deployment +Stop promotion. Preserve the failed build and checks. Restore the last reviewed template/configuration commit and its matching release record, rerun Ansible and verify HTTPS health, identity and business result. The playbook does not roll back automatically. Avoid changing shared Docker, proxy or monitoring services. + +## Production rollback +Record decision and start time. Restore the reviewed v1 deployment configuration and v1 production release record, then run Ansible. Verify health, v1 identity, original source commit and total 30. Record recovery time and observed interruption. This stateless demonstration does not prove a real database migration can be rolled back; use an expand-and-contract compatible migration for stateful services. + +## Cleanup after grading +Only when assessment and retention requirements permit, remove the two application projects, their routes, test DNS records and dedicated credentials. Preserve shared volumes, infrastructure and required evidence. Do not use compose down -v or system pruning. diff --git a/secure-delivery/WORK_LOG.md b/secure-delivery/WORK_LOG.md index d7df090..b7a87e4 100644 --- a/secure-delivery/WORK_LOG.md +++ b/secure-delivery/WORK_LOG.md @@ -37,3 +37,10 @@ ## Jenkins synthetic secret gate - Jenkins assignment8-secret-gate-demo #4 detected one generated disposable private key and failed with scanner exit 1; the job removed the fixture. Earlier attempts #1-3 failed due to transfer or job-script errors, not secret detections. Evidence: https://ci.myfileagent.tech/job/assignment8-secret-gate-demo/4/console . Prepared source-controlled security pipeline; it has not yet been run. + +## Jenkins security validation build #2 +- Jenkins assignment8-validation #2 checked out commit 28d13ef5b8757645bee640ca1dd9a8eea417ce18 on assignment8-trusted. Three unit tests, pip-audit, v1 application-source secret scan, Ansible syntax, image build and HIGH/CRITICAL image scan all passed; image JSON report was archived. Evidence: https://ci.myfileagent.tech/job/assignment8-validation/2/console . Agent briefly disconnected and reconnected during syntax check; build completed successfully. This was a test image, not a registry-published or deployed release. Secret scan currently covers v1 source, not the entire repository. +- Added .test-venv to Docker ignore after observing a 47 MB test environment in the build context; this change has not yet run in Jenkins. +- At inspection, staging.myfileagent.tech and app.myfileagent.tech did not resolve via the Droplet resolver. Existing Caddy routes serve Gitea, Jenkins and Grafana; no pricing routes added yet. + +- Expanded secret scan to the checked-out repository (excluding Git metadata, disposable test environment and generated reports); direct agent test returned zero findings and exit 0. This change still requires a Jenkins run after publication. diff --git a/secure-delivery/scan-secrets.sh b/secure-delivery/scan-secrets.sh index 68500d5..a74f827 100644 --- a/secure-delivery/scan-secrets.sh +++ b/secure-delivery/scan-secrets.sh @@ -2,8 +2,8 @@ set -eu scanner="a8-secret-${BUILD_NUMBER}" trap 'docker rm -f "$scanner" >/dev/null 2>&1 || true; rm -f secret-report.json' EXIT -docker create --name "$scanner" aquasec/trivy@sha256:1c78ed1ef824ab8bb05b04359d186e4c1229d0b3e67005faacb54a7d71974f73 fs --quiet --scanners secret --exit-code 1 --format json /v1 >/dev/null -tar -C secure-delivery --exclude=v1/.test-venv --exclude=v1/__pycache__ -cf - v1 | docker cp - "$scanner":/ +docker create --name "$scanner" aquasec/trivy@sha256:1c78ed1ef824ab8bb05b04359d186e4c1229d0b3e67005faacb54a7d71974f73 fs --quiet --scanners secret --exit-code 1 --format json /repo >/dev/null +tar --exclude=./.git --exclude=./secure-delivery/v1/.test-venv --exclude='*/__pycache__' --exclude=./reports --transform='s,^\.,repo,' -cf - . | docker cp - "$scanner":/ set +e docker start -a "$scanner" > secret-report.json result=$? diff --git a/secure-delivery/v1/.dockerignore b/secure-delivery/v1/.dockerignore index e1b2920..75832c6 100644 --- a/secure-delivery/v1/.dockerignore +++ b/secure-delivery/v1/.dockerignore @@ -2,3 +2,4 @@ __pycache__ .venv .git *.pyc +.test-venv -- 2.54.0 From 55abfbc9515dd38a6956660b7be751489c0066ca Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 4 Nov 2026 20:12:24 +0000 Subject: [PATCH 10/17] Prepare dedicated deployment account and record security checks --- secure-delivery/WORK_LOG.md | 4 ++++ secure-delivery/agent/setup-deploy-account.sh | 20 +++++++++++++++++++ secure-delivery/ansible/inventory.ini | 3 +-- secure-delivery/ansible/known_hosts | 2 ++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100755 secure-delivery/agent/setup-deploy-account.sh create mode 100644 secure-delivery/ansible/known_hosts diff --git a/secure-delivery/WORK_LOG.md b/secure-delivery/WORK_LOG.md index b7a87e4..5132872 100644 --- a/secure-delivery/WORK_LOG.md +++ b/secure-delivery/WORK_LOG.md @@ -44,3 +44,7 @@ - At inspection, staging.myfileagent.tech and app.myfileagent.tech did not resolve via the Droplet resolver. Existing Caddy routes serve Gitea, Jenkins and Grafana; no pricing routes added yet. - Expanded secret scan to the checked-out repository (excluding Git metadata, disposable test environment and generated reports); direct agent test returned zero findings and exit 0. This change still requires a Jenkins run after publication. + +## Jenkins validation #3 and deployment preparation +- Jenkins assignment8-validation #3 succeeded for commit dd7c12c519b14f59d9842ebd6d417e7117d92e94, including tests, dependency audit, expanded repository secret scan, Ansible syntax, image build and HIGH/CRITICAL image scan; report archived. Evidence: https://ci.myfileagent.tech/job/assignment8-validation/3/console . Build context was 7.68 kB after excluding test venv. +- Verified agent-to-host private SSH gateway 172.20.0.1 matches the host ED25519 fingerprint SHA256:CXrEv4+pv1jTwBtwxdTGlouS6I4H1Q6TkKbvQrbacu0. Prepared inventory and verified public known_hosts entry; dedicated account and Jenkins SSH credential are not yet configured. Prepared private deployment key and a reviewable administrator setup script, not yet executed. Gitea registry endpoint returns 401 as expected for authentication; registry push/pull has not been verified. diff --git a/secure-delivery/agent/setup-deploy-account.sh b/secure-delivery/agent/setup-deploy-account.sh new file mode 100755 index 0000000..239fee3 --- /dev/null +++ b/secure-delivery/agent/setup-deploy-account.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# Run as root after reviewing the deployment privilege scope. +set -eu +[ "$(id -u)" -eq 0 ] || { echo "Run as root" >&2; exit 1; } +key=/home/codex/myfileagent-gitea/secrets/assignment8-deploy.pub +[ -s "$key" ] || { echo "Deployment public key missing" >&2; exit 1; } +if ! id a8deploy >/dev/null 2>&1; then useradd -m -s /bin/bash a8deploy; fi +home=$(getent passwd a8deploy | cut -d: -f6) +[ "$home" = /home/a8deploy ] || { echo "Unexpected account home" >&2; exit 1; } +install -d -o a8deploy -g a8deploy -m 700 "$home/.ssh" +touch "$home/.ssh/authorized_keys" +chown a8deploy:a8deploy "$home/.ssh/authorized_keys" +chmod 600 "$home/.ssh/authorized_keys" +grep -qxF "$(cat "$key")" "$home/.ssh/authorized_keys" || cat "$key" >> "$home/.ssh/authorized_keys" +tmp=$(mktemp) +trap 'rm -f "$tmp"' EXIT +printf '%s\n' 'a8deploy ALL=(root) NOPASSWD: ALL' > "$tmp" +visudo -cf "$tmp" >/dev/null +install -o root -g root -m 440 "$tmp" /etc/sudoers.d/90-assignment8-deploy +echo 'Assignment 8 deploy account prepared.' diff --git a/secure-delivery/ansible/inventory.ini b/secure-delivery/ansible/inventory.ini index 18494a3..8c6dc5d 100644 --- a/secure-delivery/ansible/inventory.ini +++ b/secure-delivery/ansible/inventory.ini @@ -1,3 +1,2 @@ [delivery] -# Replace address and user; verify the SSH host key before first use. -startup ansible_host=REPLACE_DROPLET_ADDRESS ansible_user=deploy +startup ansible_host=172.20.0.1 ansible_user=a8deploy diff --git a/secure-delivery/ansible/known_hosts b/secure-delivery/ansible/known_hosts new file mode 100644 index 0000000..1169eeb --- /dev/null +++ b/secure-delivery/ansible/known_hosts @@ -0,0 +1,2 @@ +# 172.20.0.1:22 SSH-2.0-OpenSSH_9.6p1 Ubuntu-3ubuntu13.20 +172.20.0.1 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMLfpbUktZ4Q6KaAKA5quOhM/rc9asSxloPJFOsIv2/B -- 2.54.0 From 80c7fe2bdc7b9197148c3d6b22755d3581f236f6 Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 4 Nov 2026 20:16:13 +0000 Subject: [PATCH 11/17] Prepare pricing routes and release records --- secure-delivery/WORK_LOG.md | 4 ++++ secure-delivery/agent/pricing-routes.caddy | 7 +++++++ secure-delivery/releases/v1-production.example.yml | 8 ++++++++ secure-delivery/releases/v1-staging.example.yml | 8 ++++++++ 4 files changed, 27 insertions(+) create mode 100644 secure-delivery/agent/pricing-routes.caddy create mode 100644 secure-delivery/releases/v1-production.example.yml create mode 100644 secure-delivery/releases/v1-staging.example.yml diff --git a/secure-delivery/WORK_LOG.md b/secure-delivery/WORK_LOG.md index 5132872..6427c8b 100644 --- a/secure-delivery/WORK_LOG.md +++ b/secure-delivery/WORK_LOG.md @@ -48,3 +48,7 @@ ## Jenkins validation #3 and deployment preparation - Jenkins assignment8-validation #3 succeeded for commit dd7c12c519b14f59d9842ebd6d417e7117d92e94, including tests, dependency audit, expanded repository secret scan, Ansible syntax, image build and HIGH/CRITICAL image scan; report archived. Evidence: https://ci.myfileagent.tech/job/assignment8-validation/3/console . Build context was 7.68 kB after excluding test venv. - Verified agent-to-host private SSH gateway 172.20.0.1 matches the host ED25519 fingerprint SHA256:CXrEv4+pv1jTwBtwxdTGlouS6I4H1Q6TkKbvQrbacu0. Prepared inventory and verified public known_hosts entry; dedicated account and Jenkins SSH credential are not yet configured. Prepared private deployment key and a reviewable administrator setup script, not yet executed. Gitea registry endpoint returns 401 as expected for authentication; registry push/pull has not been verified. + +## Deployment access and DNS verification +- On 2026-11-04, a8deploy account existed. Both staging.myfileagent.tech and app.myfileagent.tech resolved to 142.93.193.110 via Droplet resolver. From assignment8-trusted, SSH using the dedicated private key and pinned host key returned uid 1001; sudo -n id returned root. The test key was removed from the agent after verification. Passwordless sudo grants host-administrator access. No Jenkins SSH credential configured yet. +- Prepared Caddy route and v1 release-record templates; neither route nor application deployment has been applied. Registry endpoint requires authentication; no registry package-write or package-read credential has been verified. diff --git a/secure-delivery/agent/pricing-routes.caddy b/secure-delivery/agent/pricing-routes.caddy new file mode 100644 index 0000000..f42774d --- /dev/null +++ b/secure-delivery/agent/pricing-routes.caddy @@ -0,0 +1,7 @@ +# Add to the existing Caddy configuration; preserve all existing routes. +staging.myfileagent.tech { + reverse_proxy pricing-staging:8000 +} +app.myfileagent.tech { + reverse_proxy pricing-production:8000 +} diff --git a/secure-delivery/releases/v1-production.example.yml b/secure-delivery/releases/v1-production.example.yml new file mode 100644 index 0000000..70d0cb0 --- /dev/null +++ b/secure-delivery/releases/v1-production.example.yml @@ -0,0 +1,8 @@ +# Replace digest and commit with the approved build values. No secrets belong here. +target_env: production +release_image: myfileagent.tech/myfileagent/pricing@sha256:REPLACE_DIGEST +expected_version: v1 +expected_commit: REPLACE_FULL_GIT_COMMIT +expected_total: 30 +public_url: https://app.myfileagent.tech +proxy_network: myfileagent-gitea_gitea-private diff --git a/secure-delivery/releases/v1-staging.example.yml b/secure-delivery/releases/v1-staging.example.yml new file mode 100644 index 0000000..9fa619d --- /dev/null +++ b/secure-delivery/releases/v1-staging.example.yml @@ -0,0 +1,8 @@ +# Replace digest and commit with the approved build values. No secrets belong here. +target_env: staging +release_image: myfileagent.tech/myfileagent/pricing@sha256:REPLACE_DIGEST +expected_version: v1 +expected_commit: REPLACE_FULL_GIT_COMMIT +expected_total: 30 +public_url: https://staging.myfileagent.tech +proxy_network: myfileagent-gitea_gitea-private -- 2.54.0 From 4cc9a2c6ac496e7da5c0c2e54c14c88ed3eb64fc Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 4 Nov 2026 20:23:14 +0000 Subject: [PATCH 12/17] Prepare Jenkins SSH credential verification --- secure-delivery/Jenkinsfile.ssh-check | 17 +++++++++++++++++ secure-delivery/WORK_LOG.md | 3 +++ 2 files changed, 20 insertions(+) create mode 100644 secure-delivery/Jenkinsfile.ssh-check diff --git a/secure-delivery/Jenkinsfile.ssh-check b/secure-delivery/Jenkinsfile.ssh-check new file mode 100644 index 0000000..6557ea4 --- /dev/null +++ b/secure-delivery/Jenkinsfile.ssh-check @@ -0,0 +1,17 @@ +pipeline { + agent { label 'assignment8-trusted' } + options { timeout(time: 5, unit: 'MINUTES'); skipDefaultCheckout() } + stages { + stage('Checkout') { steps { checkout scm } } + stage('Verify deployment connection') { + steps { + withCredentials([sshUserPrivateKey(credentialsId: 'assignment8-deploy-ssh', keyFileVariable: 'DEPLOY_KEY', usernameVariable: 'DEPLOY_USER')]) { + sh '''set +x +set -eu +ssh -o BatchMode=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile="$WORKSPACE/secure-delivery/ansible/known_hosts" -i "$DEPLOY_KEY" "$DEPLOY_USER@172.20.0.1" 'id; sudo -n id' +''' + } + } + } + } +} diff --git a/secure-delivery/WORK_LOG.md b/secure-delivery/WORK_LOG.md index 6427c8b..b16a20b 100644 --- a/secure-delivery/WORK_LOG.md +++ b/secure-delivery/WORK_LOG.md @@ -52,3 +52,6 @@ ## Deployment access and DNS verification - On 2026-11-04, a8deploy account existed. Both staging.myfileagent.tech and app.myfileagent.tech resolved to 142.93.193.110 via Droplet resolver. From assignment8-trusted, SSH using the dedicated private key and pinned host key returned uid 1001; sudo -n id returned root. The test key was removed from the agent after verification. Passwordless sudo grants host-administrator access. No Jenkins SSH credential configured yet. - Prepared Caddy route and v1 release-record templates; neither route nor application deployment has been applied. Registry endpoint requires authentication; no registry package-write or package-read credential has been verified. + +## Jenkins deployment credential +- With explicit team approval for Global scope, created Jenkins credential assignment8-deploy-ssh for a8deploy. It permits host-administrator access through the deployment account. A temporary key copy on the controller was removed after credential creation; credential binding still needs a Jenkins job verification. -- 2.54.0 From 2bdb431ef21b65e902170d02452f3e72e8e8cce3 Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 4 Nov 2026 20:41:36 +0000 Subject: [PATCH 13/17] Draft reviewed release pipeline and document proxy setup --- secure-delivery/Jenkinsfile.release.draft | 99 +++++++++++++++++++++++ secure-delivery/WORK_LOG.md | 11 +++ 2 files changed, 110 insertions(+) create mode 100644 secure-delivery/Jenkinsfile.release.draft diff --git a/secure-delivery/Jenkinsfile.release.draft b/secure-delivery/Jenkinsfile.release.draft new file mode 100644 index 0000000..130f9b6 --- /dev/null +++ b/secure-delivery/Jenkinsfile.release.draft @@ -0,0 +1,99 @@ +pipeline { + agent { label 'assignment8-trusted' } + options { disableConcurrentBuilds(); skipDefaultCheckout(); timeout(time: 45, unit: 'MINUTES'); timestamps() } + environment { IMAGE_REPO = 'myfileagent.tech/myfileagent/pricing' } + stages { + stage('Checkout reviewed source') { + steps { + checkout scm + sh '''set -eu +# Only source already present in protected main can be released. +git fetch origin main +git merge-base --is-ancestor HEAD origin/main +mkdir -p reports releases/generated +''' + script { env.SOURCE_COMMIT = sh(script: 'git rev-parse HEAD', returnStdout: true).trim() } + } + } + stage('Tests and dependency audit') { + steps { dir('secure-delivery/v1') { sh '''set -eu +python3 -m venv .test-venv +.test-venv/bin/pip install -r requirements.txt pip-audit==2.10.1 +.test-venv/bin/python -m unittest -v +.test-venv/bin/pip-audit -r requirements.txt +''' } } + } + stage('Repository secret scan') { steps { sh 'sh secure-delivery/scan-secrets.sh' } } + stage('Ansible syntax') { steps { dir('secure-delivery') { sh 'ansible-playbook -i ansible/inventory.ini ansible/deploy.yml --syntax-check' } } } + stage('Build once') { steps { sh 'docker build --build-arg APP_COMMIT="$SOURCE_COMMIT" -t "$IMAGE_REPO:$SOURCE_COMMIT" secure-delivery/v1' } } + stage('Image security scan') { + steps { sh '''set -eu +docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /home/codex/myfileagent-gitea/evidence/assignment8/trivy-cache:/root/.cache/ aquasec/trivy@sha256:1c78ed1ef824ab8bb05b04359d186e4c1229d0b3e67005faacb54a7d71974f73 image --quiet --scanners vuln --severity HIGH,CRITICAL --exit-code 1 --format json "$IMAGE_REPO:$SOURCE_COMMIT" > reports/image-scan.json +''' } + } + stage('Publish immutable image') { + steps { + withCredentials([usernamePassword(credentialsId: 'assignment8-registry-write', usernameVariable: 'REG_USER', passwordVariable: 'REG_TOKEN')]) { + sh '''#!/bin/sh +set +x +set -eu +export DOCKER_CONFIG=$(mktemp -d) +trap 'rm -rf "$DOCKER_CONFIG"' EXIT +printf '%s' "$REG_TOKEN" | docker login myfileagent.tech --username "$REG_USER" --password-stdin +docker push "$IMAGE_REPO:$SOURCE_COMMIT" +docker pull "$IMAGE_REPO:$SOURCE_COMMIT" +docker image inspect "$IMAGE_REPO:$SOURCE_COMMIT" --format '{{index .RepoDigests 0}}' > reports/image-digest.txt +''' + } + script { + env.RELEASE_IMAGE = readFile('reports/image-digest.txt').trim() + if (!(env.RELEASE_IMAGE ==~ /myfileagent\.tech\/myfileagent\/pricing@sha256:[0-9a-f]{64}/)) { error('Registry digest is missing or unexpected') } + } + } + } + stage('Deploy staging') { + steps { + script { writeFile file: 'releases/generated/v1-staging.yml', text: "target_env: staging\nrelease_image: ${env.RELEASE_IMAGE}\nexpected_version: v1\nexpected_commit: ${env.SOURCE_COMMIT}\nexpected_total: 30\npublic_url: https://staging.myfileagent.tech\nproxy_network: myfileagent-gitea_gitea-private\n" } + withCredentials([sshUserPrivateKey(credentialsId: 'assignment8-deploy-ssh', keyFileVariable: 'DEPLOY_KEY')]) { + sh '''set +x +export ANSIBLE_SSH_ARGS="-o StrictHostKeyChecking=yes -o UserKnownHostsFile=$WORKSPACE/secure-delivery/ansible/known_hosts" +ansible-playbook -i secure-delivery/ansible/inventory.ini secure-delivery/ansible/deploy.yml --private-key "$DEPLOY_KEY" -e @releases/generated/v1-staging.yml +''' + } + } + } + stage('Confirm staging idempotence') { + steps { + withCredentials([sshUserPrivateKey(credentialsId: 'assignment8-deploy-ssh', keyFileVariable: 'DEPLOY_KEY')]) { + sh '''set +x +set -eu +export ANSIBLE_SSH_ARGS="-o StrictHostKeyChecking=yes -o UserKnownHostsFile=$WORKSPACE/secure-delivery/ansible/known_hosts" +ansible-playbook -i secure-delivery/ansible/inventory.ini secure-delivery/ansible/deploy.yml --private-key "$DEPLOY_KEY" -e @releases/generated/v1-staging.yml > reports/staging-second-run.txt +cat reports/staging-second-run.txt +grep -Eq 'startup[[:space:]]*:.*changed=0[[:space:]]+unreachable=0[[:space:]]+failed=0' reports/staging-second-run.txt +''' + } + } + } + stage('Production approval') { + steps { + script { + def approver = timeout(time: 30, unit: 'MINUTES') { input message: "Promote ${env.SOURCE_COMMIT} / ${env.RELEASE_IMAGE} after successful staging and scans?", ok: 'Promote', submitter: 'ssw590', submitterParameter: 'APPROVER' } + writeFile file: 'reports/approval.txt', text: "Approver: ${approver}\nBuild: ${env.BUILD_URL}\nSource: ${env.SOURCE_COMMIT}\nImage: ${env.RELEASE_IMAGE}\n" + } + } + } + stage('Deploy production') { + steps { + script { writeFile file: 'releases/generated/v1-production.yml', text: "target_env: production\nrelease_image: ${env.RELEASE_IMAGE}\nexpected_version: v1\nexpected_commit: ${env.SOURCE_COMMIT}\nexpected_total: 30\npublic_url: https://app.myfileagent.tech\nproxy_network: myfileagent-gitea_gitea-private\n" } + withCredentials([sshUserPrivateKey(credentialsId: 'assignment8-deploy-ssh', keyFileVariable: 'DEPLOY_KEY')]) { + sh '''set +x +export ANSIBLE_SSH_ARGS="-o StrictHostKeyChecking=yes -o UserKnownHostsFile=$WORKSPACE/secure-delivery/ansible/known_hosts" +ansible-playbook -i secure-delivery/ansible/inventory.ini secure-delivery/ansible/deploy.yml --private-key "$DEPLOY_KEY" -e @releases/generated/v1-production.yml +''' + } + } + } + } + post { always { archiveArtifacts artifacts: 'reports/*,releases/generated/*', allowEmptyArchive: true } } +} diff --git a/secure-delivery/WORK_LOG.md b/secure-delivery/WORK_LOG.md index b16a20b..5c47edd 100644 --- a/secure-delivery/WORK_LOG.md +++ b/secure-delivery/WORK_LOG.md @@ -55,3 +55,14 @@ ## Jenkins deployment credential - With explicit team approval for Global scope, created Jenkins credential assignment8-deploy-ssh for a8deploy. It permits host-administrator access through the deployment account. A temporary key copy on the controller was removed after credential creation; credential binding still needs a Jenkins job verification. + +- Jenkins assignment8-validation #4 successfully bound the approved assignment8-deploy-ssh credential on assignment8-trusted, verified pinned SSH host key, connected as a8deploy, and confirmed noninteractive root sudo. Evidence: https://ci.myfileagent.tech/job/assignment8-validation/4/console . Job currently points to Jenkinsfile.ssh-check; restore security validation before further security runs. Registry endpoint requires authentication and no Jenkins package-specific credential was found. + +## Registry authentication +- Jenkins assignment8-registry-check #1 authenticated to myfileagent.tech using assignment8-registry-write, with a temporary Docker config removed at job exit. Evidence: https://ci.myfileagent.tech/job/assignment8-registry-check/1/console . Login alone does not prove permission to publish to the myfileagent organization or target-host pull access. + +- Restored assignment8-validation job configuration to Jenkinsfile.security after SSH check. Registry login #1 succeeded using a temporary Docker config, which the job removed. The glovely credential can authenticate, but organization package write and target-host read remain unverified. + +## Proxy preparation +- Validated and reloaded existing Caddy configuration with staging.myfileagent.tech -> pricing-staging:8000 and app.myfileagent.tech -> pricing-production:8000. Saved previous configuration at /home/codex/myfileagent-gitea/Caddyfile.before-assignment8. Gitea, Jenkins and Grafana HTTPS login routes returned 200 with certificate validation. New staging and app HTTPS endpoints returned 502 with certificate validation successful, expected before app containers exist. One initial staging DNS lookup timed out; retry reached HTTPS. +- Jenkinsfile.release.draft is untested and not enabled. It requires reviewed source on protected main, package publication rights, target registry authentication, scan and deployment validation before operational use. -- 2.54.0 From b0e8cead184a1249090e068cfd1e39d07eef9575 Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 4 Nov 2026 20:42:16 +0000 Subject: [PATCH 14/17] Prepare target registry authentication --- .../Jenkinsfile.registry-read-setup | 19 +++++++++++++++++++ secure-delivery/WORK_LOG.md | 2 ++ 2 files changed, 21 insertions(+) create mode 100644 secure-delivery/Jenkinsfile.registry-read-setup diff --git a/secure-delivery/Jenkinsfile.registry-read-setup b/secure-delivery/Jenkinsfile.registry-read-setup new file mode 100644 index 0000000..e0ebc13 --- /dev/null +++ b/secure-delivery/Jenkinsfile.registry-read-setup @@ -0,0 +1,19 @@ +pipeline { + agent { label 'assignment8-trusted' } + options { skipDefaultCheckout(); timeout(time: 5, unit: 'MINUTES') } + stages { + stage('Checkout') { steps { checkout scm } } + stage('Authenticate target registry reader') { + steps { + withCredentials([sshUserPrivateKey(credentialsId: 'assignment8-deploy-ssh', keyFileVariable: 'DEPLOY_KEY', usernameVariable: 'DEPLOY_USER'), usernamePassword(credentialsId: 'assignment8-registry-read', usernameVariable: 'REG_USER', passwordVariable: 'REG_TOKEN')]) { + sh '''#!/bin/sh +set +x +set -eu +case "$REG_USER" in *[!a-zA-Z0-9_.-]*|'') echo 'Invalid registry username' >&2; exit 1;; esac +printf '%s' "$REG_TOKEN" | ssh -o BatchMode=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile="$WORKSPACE/secure-delivery/ansible/known_hosts" -i "$DEPLOY_KEY" "$DEPLOY_USER@172.20.0.1" "sudo -n docker login myfileagent.tech --username $REG_USER --password-stdin" +''' + } + } + } + } +} diff --git a/secure-delivery/WORK_LOG.md b/secure-delivery/WORK_LOG.md index 5c47edd..280f7e9 100644 --- a/secure-delivery/WORK_LOG.md +++ b/secure-delivery/WORK_LOG.md @@ -66,3 +66,5 @@ ## Proxy preparation - Validated and reloaded existing Caddy configuration with staging.myfileagent.tech -> pricing-staging:8000 and app.myfileagent.tech -> pricing-production:8000. Saved previous configuration at /home/codex/myfileagent-gitea/Caddyfile.before-assignment8. Gitea, Jenkins and Grafana HTTPS login routes returned 200 with certificate validation. New staging and app HTTPS endpoints returned 502 with certificate validation successful, expected before app containers exist. One initial staging DNS lookup timed out; retry reached HTTPS. - Jenkinsfile.release.draft is untested and not enabled. It requires reviewed source on protected main, package publication rights, target registry authentication, scan and deployment validation before operational use. + +- Prepared Jenkinsfile.registry-read-setup to configure root Docker registry authentication using a separate read-only Jenkins credential over pinned SSH. Draft only; not run. Root Docker configuration will hold authentication material and must be protected and removed after assessment. -- 2.54.0 From b8a2529ce98408a6b1c67abad3e4f558598c6fd5 Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 4 Nov 2026 20:48:46 +0000 Subject: [PATCH 15/17] Record registry verification and protect release evidence --- secure-delivery/Jenkinsfile.release.draft | 1 + secure-delivery/WORK_LOG.md | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/secure-delivery/Jenkinsfile.release.draft b/secure-delivery/Jenkinsfile.release.draft index 130f9b6..e788921 100644 --- a/secure-delivery/Jenkinsfile.release.draft +++ b/secure-delivery/Jenkinsfile.release.draft @@ -5,6 +5,7 @@ pipeline { stages { stage('Checkout reviewed source') { steps { + deleteDir() checkout scm sh '''set -eu # Only source already present in protected main can be released. diff --git a/secure-delivery/WORK_LOG.md b/secure-delivery/WORK_LOG.md index 280f7e9..8786a1d 100644 --- a/secure-delivery/WORK_LOG.md +++ b/secure-delivery/WORK_LOG.md @@ -68,3 +68,8 @@ - Jenkinsfile.release.draft is untested and not enabled. It requires reviewed source on protected main, package publication rights, target registry authentication, scan and deployment validation before operational use. - Prepared Jenkinsfile.registry-read-setup to configure root Docker registry authentication using a separate read-only Jenkins credential over pinned SSH. Draft only; not run. Root Docker configuration will hold authentication material and must be protected and removed after assessment. + +## Registry reader and release guard +- Jenkins assignment8-validation #5 authenticated the Droplet root Docker client with assignment8-registry-read; login succeeded. Docker warned that its root configuration stores credentials without encryption; restrict access and remove after assessment. Actual image pull has not yet been proven. Evidence: https://ci.myfileagent.tech/job/assignment8-validation/5/console . +- Draft release pipeline parsed and Jenkins build #6 stopped at the protected-main ancestry guard for the unmerged feature commit; image publication and deployment stages were skipped. Evidence: https://ci.myfileagent.tech/job/assignment8-validation/6/console . Added a workspace clean before checkout to prevent old reports being archived in future runs; that revision remains untested. +- Build #6 used a reused workspace and its post step archived pre-existing reports; those artifacts are stale and must not be presented as build #6 scan evidence. The draft now deletes the workspace before checkout to prevent recurrence; that correction is not yet verified. -- 2.54.0 From 65e401172b0e4ec40116df0d07876484020ce454 Mon Sep 17 00:00:00 2001 From: Codex Date: Sat, 7 Nov 2026 21:23:35 +0000 Subject: [PATCH 16/17] Harden delivery checks and record test-gate evidence --- secure-delivery/Jenkinsfile.release.draft | 31 +++++++++++++++++----- secure-delivery/Jenkinsfile.test-gate-demo | 26 ++++++++++++++++++ secure-delivery/WORK_LOG.md | 9 +++++++ secure-delivery/release-intent.json | 1 + secure-delivery/scan-secrets.sh | 6 +++-- 5 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 secure-delivery/Jenkinsfile.test-gate-demo create mode 100644 secure-delivery/release-intent.json diff --git a/secure-delivery/Jenkinsfile.release.draft b/secure-delivery/Jenkinsfile.release.draft index e788921..b26f51b 100644 --- a/secure-delivery/Jenkinsfile.release.draft +++ b/secure-delivery/Jenkinsfile.release.draft @@ -13,7 +13,14 @@ git fetch origin main git merge-base --is-ancestor HEAD origin/main mkdir -p reports releases/generated ''' - script { env.SOURCE_COMMIT = sh(script: 'git rev-parse HEAD', returnStdout: true).trim() } + script { + env.SOURCE_COMMIT = sh(script: 'git rev-parse HEAD', returnStdout: true).trim() + env.RELEASE_VERSION = sh(script: "python3 -c 'import json; print(json.load(open(\"secure-delivery/release-intent.json\"))[\"version\"])'", returnStdout: true).trim() + if (!(env.RELEASE_VERSION in ['v1', 'v2'])) { error('Unknown release version') } + env.EXPECTED_TOTAL = env.RELEASE_VERSION == 'v1' ? '30' : '36' + def configured = sh(script: "python3 -c 'import json; print(json.load(open(\"secure-delivery/release-intent.json\"))[\"quantity3_total\"])'", returnStdout: true).trim() + if (configured != env.EXPECTED_TOTAL) { error('Release intent total does not match the version') } + } } } stage('Tests and dependency audit') { @@ -52,13 +59,25 @@ docker image inspect "$IMAGE_REPO:$SOURCE_COMMIT" --format '{{index .RepoDigests } } } + stage('Pull published digest on target') { + steps { + withCredentials([sshUserPrivateKey(credentialsId: 'assignment8-deploy-ssh', keyFileVariable: 'DEPLOY_KEY', usernameVariable: 'DEPLOY_USER')]) { + sh '''#!/bin/sh +set +x +set -eu +ssh -o BatchMode=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile="$WORKSPACE/secure-delivery/ansible/known_hosts" -i "$DEPLOY_KEY" "$DEPLOY_USER@172.20.0.1" sudo -n docker pull "$RELEASE_IMAGE" > reports/target-pull.txt +cat reports/target-pull.txt +''' + } + } + } stage('Deploy staging') { steps { - script { writeFile file: 'releases/generated/v1-staging.yml', text: "target_env: staging\nrelease_image: ${env.RELEASE_IMAGE}\nexpected_version: v1\nexpected_commit: ${env.SOURCE_COMMIT}\nexpected_total: 30\npublic_url: https://staging.myfileagent.tech\nproxy_network: myfileagent-gitea_gitea-private\n" } + script { writeFile file: "releases/generated/${env.RELEASE_VERSION}-staging.yml", text: "target_env: staging\nrelease_image: ${env.RELEASE_IMAGE}\nexpected_version: ${env.RELEASE_VERSION}\nexpected_commit: ${env.SOURCE_COMMIT}\nexpected_total: ${env.EXPECTED_TOTAL}\npublic_url: https://staging.myfileagent.tech\nproxy_network: myfileagent-gitea_gitea-private\n" } withCredentials([sshUserPrivateKey(credentialsId: 'assignment8-deploy-ssh', keyFileVariable: 'DEPLOY_KEY')]) { sh '''set +x export ANSIBLE_SSH_ARGS="-o StrictHostKeyChecking=yes -o UserKnownHostsFile=$WORKSPACE/secure-delivery/ansible/known_hosts" -ansible-playbook -i secure-delivery/ansible/inventory.ini secure-delivery/ansible/deploy.yml --private-key "$DEPLOY_KEY" -e @releases/generated/v1-staging.yml +ansible-playbook -i secure-delivery/ansible/inventory.ini secure-delivery/ansible/deploy.yml --private-key "$DEPLOY_KEY" -e @releases/generated/$RELEASE_VERSION-staging.yml ''' } } @@ -69,7 +88,7 @@ ansible-playbook -i secure-delivery/ansible/inventory.ini secure-delivery/ansibl sh '''set +x set -eu export ANSIBLE_SSH_ARGS="-o StrictHostKeyChecking=yes -o UserKnownHostsFile=$WORKSPACE/secure-delivery/ansible/known_hosts" -ansible-playbook -i secure-delivery/ansible/inventory.ini secure-delivery/ansible/deploy.yml --private-key "$DEPLOY_KEY" -e @releases/generated/v1-staging.yml > reports/staging-second-run.txt +ansible-playbook -i secure-delivery/ansible/inventory.ini secure-delivery/ansible/deploy.yml --private-key "$DEPLOY_KEY" -e @releases/generated/$RELEASE_VERSION-staging.yml > reports/staging-second-run.txt cat reports/staging-second-run.txt grep -Eq 'startup[[:space:]]*:.*changed=0[[:space:]]+unreachable=0[[:space:]]+failed=0' reports/staging-second-run.txt ''' @@ -86,11 +105,11 @@ grep -Eq 'startup[[:space:]]*:.*changed=0[[:space:]]+unreachable=0[[:space:]]+fa } stage('Deploy production') { steps { - script { writeFile file: 'releases/generated/v1-production.yml', text: "target_env: production\nrelease_image: ${env.RELEASE_IMAGE}\nexpected_version: v1\nexpected_commit: ${env.SOURCE_COMMIT}\nexpected_total: 30\npublic_url: https://app.myfileagent.tech\nproxy_network: myfileagent-gitea_gitea-private\n" } + script { writeFile file: "releases/generated/${env.RELEASE_VERSION}-production.yml", text: "target_env: production\nrelease_image: ${env.RELEASE_IMAGE}\nexpected_version: ${env.RELEASE_VERSION}\nexpected_commit: ${env.SOURCE_COMMIT}\nexpected_total: ${env.EXPECTED_TOTAL}\npublic_url: https://app.myfileagent.tech\nproxy_network: myfileagent-gitea_gitea-private\n" } withCredentials([sshUserPrivateKey(credentialsId: 'assignment8-deploy-ssh', keyFileVariable: 'DEPLOY_KEY')]) { sh '''set +x export ANSIBLE_SSH_ARGS="-o StrictHostKeyChecking=yes -o UserKnownHostsFile=$WORKSPACE/secure-delivery/ansible/known_hosts" -ansible-playbook -i secure-delivery/ansible/inventory.ini secure-delivery/ansible/deploy.yml --private-key "$DEPLOY_KEY" -e @releases/generated/v1-production.yml +ansible-playbook -i secure-delivery/ansible/inventory.ini secure-delivery/ansible/deploy.yml --private-key "$DEPLOY_KEY" -e @releases/generated/$RELEASE_VERSION-production.yml ''' } } diff --git a/secure-delivery/Jenkinsfile.test-gate-demo b/secure-delivery/Jenkinsfile.test-gate-demo new file mode 100644 index 0000000..506cbd3 --- /dev/null +++ b/secure-delivery/Jenkinsfile.test-gate-demo @@ -0,0 +1,26 @@ +pipeline { + agent { label 'assignment8-trusted' } + options { timeout(time: 10, unit: 'MINUTES') } + stages { + stage('Checkout v1') { + steps { git branch: 'assignment8/secure-delivery', url: 'https://myfileagent.tech/myfileagent/myfileagent-pipeline.git' } + } + stage('Controlled failing test') { + steps { + dir('secure-delivery/v1') { + sh '''#!/bin/sh +set -eu +python3 -m venv .test-venv +.test-venv/bin/pip install -r requirements.txt +trap 'git checkout -- test_app.py' EXIT +python3 -c 'from pathlib import Path; p=Path("test_app.py"); s=p.read_text(); old="self.assertEqual(total_price(3), 30)"; assert old in s; p.write_text(s.replace(old,"self.assertEqual(total_price(3), 31)",1))' +.test-venv/bin/python -m unittest -v +''' + } + } + } + stage('Delivery would proceed') { + steps { echo 'This stage must be skipped when tests fail.' } + } + } +} diff --git a/secure-delivery/WORK_LOG.md b/secure-delivery/WORK_LOG.md index 8786a1d..65bf2da 100644 --- a/secure-delivery/WORK_LOG.md +++ b/secure-delivery/WORK_LOG.md @@ -73,3 +73,12 @@ - Jenkins assignment8-validation #5 authenticated the Droplet root Docker client with assignment8-registry-read; login succeeded. Docker warned that its root configuration stores credentials without encryption; restrict access and remove after assessment. Actual image pull has not yet been proven. Evidence: https://ci.myfileagent.tech/job/assignment8-validation/5/console . - Draft release pipeline parsed and Jenkins build #6 stopped at the protected-main ancestry guard for the unmerged feature commit; image publication and deployment stages were skipped. Evidence: https://ci.myfileagent.tech/job/assignment8-validation/6/console . Added a workspace clean before checkout to prevent old reports being archived in future runs; that revision remains untested. - Build #6 used a reused workspace and its post step archived pre-existing reports; those artifacts are stale and must not be presented as build #6 scan evidence. The draft now deletes the workspace before checkout to prevent recurrence; that correction is not yet verified. + +## 2026-11-07 release draft review +- Verified branch b8a2529 on Gitea, shared services healthy and pricing routes still return 502 while application is absent. Jenkins guard build #7 rejected unmerged source before image publication; no files were archived. https://ci.myfileagent.tech/job/assignment8-validation/7/console +- Extended the local release draft to explicitly pull the published digest on the target and read a reviewed version/expected-total intent for v1 and v2. Jenkins Groovy 2.4 parser accepted syntax only; stages after the source guard, registry publication, promotion, and recovery remain untested. The v2 source is not yet applied. +- Hardened the secret scan to fail if the source archive fails, then directly tested it on the trusted agent: zero findings and exit 0. No claim is made about a new Jenkins pipeline run. + +- Registry permission-only check #4 returned token scope write:package; this does not prove glovely can publish to the organization. https://ci.myfileagent.tech/job/assignment8-registry-check/4/console +- Jenkins assignment8-test-gate-demo #1 deliberately changed one pricing assertion in its own workspace; the test failed (30 versus 31), and its following demonstration delivery stage was skipped. The trap restored the test, git diff confirmed no test change, and all three tests subsequently passed directly on the agent. https://ci.myfileagent.tech/job/assignment8-test-gate-demo/1/console +- Supplied v2 starter was tested separately on the trusted agent: all three tests passed. It has not been applied to the reviewed v1 source, committed as v2, built, published, or deployed. diff --git a/secure-delivery/release-intent.json b/secure-delivery/release-intent.json new file mode 100644 index 0000000..1afb9db --- /dev/null +++ b/secure-delivery/release-intent.json @@ -0,0 +1 @@ +{"version": "v1", "quantity3_total": 30} diff --git a/secure-delivery/scan-secrets.sh b/secure-delivery/scan-secrets.sh index a74f827..8972424 100644 --- a/secure-delivery/scan-secrets.sh +++ b/secure-delivery/scan-secrets.sh @@ -1,9 +1,11 @@ #!/bin/sh set -eu scanner="a8-secret-${BUILD_NUMBER}" -trap 'docker rm -f "$scanner" >/dev/null 2>&1 || true; rm -f secret-report.json' EXIT +archive=$(mktemp) +trap 'docker rm -f "$scanner" >/dev/null 2>&1 || true; rm -f secret-report.json "$archive"' EXIT docker create --name "$scanner" aquasec/trivy@sha256:1c78ed1ef824ab8bb05b04359d186e4c1229d0b3e67005faacb54a7d71974f73 fs --quiet --scanners secret --exit-code 1 --format json /repo >/dev/null -tar --exclude=./.git --exclude=./secure-delivery/v1/.test-venv --exclude='*/__pycache__' --exclude=./reports --transform='s,^\.,repo,' -cf - . | docker cp - "$scanner":/ +tar --exclude=./.git --exclude=./secure-delivery/v1/.test-venv --exclude='*/__pycache__' --exclude=./reports --transform='s,^\.,repo,' -cf "$archive" . +docker cp - "$scanner":/ < "$archive" set +e docker start -a "$scanner" > secret-report.json result=$? -- 2.54.0 From c1cd3ad9af12e11af7c08c398c5fc93649cfd556 Mon Sep 17 00:00:00 2001 From: Codex Date: Sat, 7 Nov 2026 21:32:11 +0000 Subject: [PATCH 17/17] Document reproducible agent and current validation --- secure-delivery/WORK_LOG.md | 6 ++++++ secure-delivery/agent/compose.yaml | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 secure-delivery/agent/compose.yaml diff --git a/secure-delivery/WORK_LOG.md b/secure-delivery/WORK_LOG.md index 65bf2da..9de923d 100644 --- a/secure-delivery/WORK_LOG.md +++ b/secure-delivery/WORK_LOG.md @@ -82,3 +82,9 @@ - Registry permission-only check #4 returned token scope write:package; this does not prove glovely can publish to the organization. https://ci.myfileagent.tech/job/assignment8-registry-check/4/console - Jenkins assignment8-test-gate-demo #1 deliberately changed one pricing assertion in its own workspace; the test failed (30 versus 31), and its following demonstration delivery stage was skipped. The trap restored the test, git diff confirmed no test change, and all three tests subsequently passed directly on the agent. https://ci.myfileagent.tech/job/assignment8-test-gate-demo/1/console - Supplied v2 starter was tested separately on the trusted agent: all three tests passed. It has not been applied to the reviewed v1 source, committed as v2, built, published, or deployed. + +- Prepared reproducible agent Compose configuration and validated it with docker compose config; it documents the currently used Docker socket group and private network but has not replaced the running container. +- Prepared isolated v2 preview commit 2147b21 on local branch assignment8/v2-preview based on the v1 feature branch. It changes the application/tests and release intent; all three tests passed on the trusted agent. It is not yet reviewed, published, built as a release or deployed, and must be based on the final reviewed v1 state before promotion. + +- Jenkins security validation #8 passed on Gitea commit 65e401172b0e4ec40116df0d07876484020ce454, including three unit tests, dependency audit, repository secret scan, Ansible syntax, image build and HIGH/CRITICAL image scan. The scan report was archived: https://ci.myfileagent.tech/job/assignment8-validation/8/console . This is validation of that commit, not an approved release. +- Agent Compose draft was checked against the running image, socket group, memory and restart policy and passed docker compose config. It has not been used to recreate the agent. diff --git a/secure-delivery/agent/compose.yaml b/secure-delivery/agent/compose.yaml new file mode 100644 index 0000000..6b1283f --- /dev/null +++ b/secure-delivery/agent/compose.yaml @@ -0,0 +1,21 @@ +# Run only after reviewing host paths, Docker socket group and privileges. +services: + assignment8-agent: + image: assignment8-jenkins-agent:2 + build: . + container_name: assignment8-jenkins-agent + restart: unless-stopped + mem_limit: 256m + group_add: + - "987" # Current Docker socket group; verify on the target host. + networks: + - private + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - /home/codex/myfileagent-gitea/secrets/assignment8-agent-secret:/run/secrets/agent-secret:ro + entrypoint: ["java"] + command: ["-jar", "/usr/share/jenkins/agent.jar", "-url", "http://myfileagent-jenkins:8080/", "-webSocket", "-secret", "@/run/secrets/agent-secret", "-name", "assignment8-trusted", "-workDir", "/home/jenkins/agent"] +networks: + private: + external: true + name: myfileagent-gitea_gitea-private -- 2.54.0