diff --git a/secure-delivery/docs/ARCHITECTURE.md b/secure-delivery/docs/ARCHITECTURE.md new file mode 100644 index 0000000..af5f907 --- /dev/null +++ b/secure-delivery/docs/ARCHITECTURE.md @@ -0,0 +1,317 @@ +# Chapter 6 — Secure Delivery Architecture + +## 1. Overview + +Chapter 6 extends the team's existing DigitalOcean infrastructure +with a secure, reproducible delivery workflow for the Startup Pricing +Service. + +The architecture combines Jenkins, a trusted execution agent, +Docker, a Gitea container registry, Ansible, Docker Compose, +Caddy, and the existing Chapter 5 monitoring infrastructure. + +Staging and production-like environments run as separate Docker +Compose projects on the same DigitalOcean Droplet. + +This is a single-host educational deployment, not a highly +available production system. + +## 2. Existing Infrastructure + +The team previously established: + +- A DigitalOcean Droplet running Ubuntu Linux. +- Docker Engine and Docker Compose. +- Self-hosted Gitea for source control and collaboration. +- Jenkins for continuous integration. +- Caddy for HTTPS reverse proxying. +- Prometheus for metrics collection. +- Grafana for visualization. +- Node Exporter for host metrics. +- Blackbox Exporter for HTTPS availability checks. + +Chapter 6 must preserve these services, their configurations, +and their persistent data. + +## 3. Logical Architecture + +```text + Developers + | + v + Gitea Repository + | + v + Jenkins CI/CD + | + v + Trusted Jenkins Agent + / \ + / \ + v v + Docker Build Ansible / SSH + | | + v | + Security Scanning | + | | + v | + Gitea OCI Registry | + | | + +--------------+ + | + v + DigitalOcean Droplet + | + +-----------------+------------------+ + | | + v v + Pricing Staging Pricing Production + Docker Compose Docker Compose + pricing-staging pricing-production + | | + +-----------------+------------------+ + | + v + Caddy HTTPS + | + +-----------+-----------+ + | | + v v + Staging URL Production URL + | + v + Blackbox Exporter + | + v + Prometheus + | + v + Grafana +``` + +This is a logical representation. Actual host and container +boundaries must be confirmed during implementation. + +## 4. Source Control + +Gitea hosts the application's source code, deployment +configuration, Jenkins pipeline, security policy, and operational +documentation. + +The Chapter 6 feature branch is: + +`chapter6-secure-delivery` + +Changes must be reviewed before entering the protected main branch. + +The existing Chapter 4 application and CI configuration must remain +available until the new delivery workflow has been verified. + +## 5. Jenkins and Trusted Agent + +Jenkins orchestrates the delivery pipeline. + +The intended pipeline stages are: + +1. Source checkout. +2. Python syntax validation. +3. Unit testing. +4. Dependency security scanning. +5. Secret scanning. +6. Docker image build. +7. Container image vulnerability scanning. +8. Registry publication. +9. Staging deployment through Ansible. +10. Staging HTTPS verification. +11. Authorized production approval. +12. Production deployment using the same immutable image digest. +13. Production HTTPS verification. + +Privileged deployment stages must execute only on a trusted +agent with appropriately restricted credentials. + +Untrusted pull-request builds must not receive deployment +or registry-write credentials. + +The actual agent topology and installed tool versions must be +recorded after verification. + +## 6. Container Registry and Immutable Releases + +Approved container images are published to the Gitea OCI registry. + +Each release must be identified by: + +- Application source commit. +- Jenkins build number. +- Container image repository digest. +- Deployment configuration commit. +- Security scan results. + +Production must use the exact same image digest that passed +staging verification. + +Rebuilding an image during promotion is prohibited. + +## 7. Ansible Deployment + +Ansible connects to the deployment host through SSH. + +The deployment playbook: + +1. Validates the selected release. +2. Creates the target deployment directory. +3. Renders the Docker Compose configuration. +4. Deploys the selected immutable image. +5. Waits for application health. +6. Verifies HTTPS health, version, source commit, and pricing. + +Deployment configuration is maintained in Git. + +The same approved release configuration should converge +without unnecessary changes when applied repeatedly. + +## 8. Environment Separation + +The two environments use separate Docker Compose projects. + +| Environment | Compose Project | Application Port | +|---|---|---| +| Staging | pricing-staging | 8000 (internal) | +| Production-like | pricing-production | 8000 (internal) | + +Both environments share the same physical Droplet. + +They must use separate container names, network aliases, +deployment directories, and HTTPS hostnames. + +The application port must not be exposed directly to the Internet. + +## 9. HTTPS Reverse Proxy + +The existing Caddy instance terminates HTTPS and routes +requests to the appropriate application container. + +The staging and production routes must be added without +removing or changing existing Gitea, Jenkins, Grafana, +or other application routes. + +Actual DNS names and the Docker proxy network must be +verified before deployment. + +## 10. Security Boundaries + +The architecture includes several trust boundaries: + +### Source Control + +Unreviewed application changes must not receive privileged +deployment credentials. + +### Jenkins + +The Jenkins controller schedules work, while the trusted agent +executes privileged build and deployment operations. + +### Registry + +Registry-write credentials are restricted to authorized +publishing operations. + +The deployment host uses read-only registry credentials. + +### SSH and Host Access + +Ansible uses a dedicated deployment account. + +SSH host identity must be verified and pinned. + +Privilege escalation must follow an approved policy. + +### Application Containers + +Application containers run as non-root users. + +The Compose configuration uses: + +- Read-only root filesystem. +- Temporary writable storage. +- Dropped Linux capabilities. +- No-new-privileges protection. + +### HTTPS + +Public application access uses valid HTTPS certificates. + +TLS certificate verification must remain enabled. + +## 11. Monitoring + +The existing Chapter 5 monitoring stack is extended with +a production HTTPS health probe. + +Blackbox Exporter checks the production endpoint. + +Prometheus collects the probe metrics. + +Grafana displays availability and allows comparison with +release and rollback timestamps. + +Existing monitoring jobs and dashboards must be preserved. + +## 12. Rollback + +The architecture supports explicit application rollback. + +A previous release is restored using: + +- Its approved immutable image digest. +- Its matching deployment configuration. +- Its recorded application source commit. +- Its corresponding Ansible release record. + +Rollback must not rebuild the application image. + +The current deployment approach does not guarantee zero downtime. + +## 13. Infrastructure Limitations + +The architecture uses a single DigitalOcean Droplet. + +Consequently: + +- Staging and production share a failure domain. +- A host outage can affect all services. +- Resource contention can affect build and deployment performance. +- Monitoring is not independent of the application host. +- Container recreation may temporarily interrupt requests. + +The deployment demonstrates controlled software delivery, +not high availability or physical environment isolation. + +## 14. Implementation Verification + +The following information must be confirmed and recorded +during Sergio's implementation: + +- Actual Jenkins agent topology. +- Agent tool versions. +- DigitalOcean Droplet specifications. +- Available disk space and memory. +- Actual Docker network names. +- Registry hostname and repository path. +- Staging and production DNS names. +- SSH deployment account and access policy. +- Exact application image digests. +- Actual monitoring configuration. +- Final deployed container topology. + +Any differences between this planned architecture and the +implemented environment must be documented. + +## Status + +Architecture documentation prepared. + +Actual infrastructure verification, implementation, and +supporting evidence remain pending. \ No newline at end of file