Draft reviewed release pipeline and document proxy setup

This commit is contained in:
Codex
2026-11-04 20:41:36 +00:00
parent 4cc9a2c6ac
commit 2bdb431ef2
2 changed files with 110 additions and 0 deletions
+99
View File
@@ -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 } }
}
+11
View File
@@ -55,3 +55,14 @@
## Jenkins deployment credential ## 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. - 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.