Skip to content

Viktoria75/devops-finalproject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

20 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ Secure Task: Automated DevSecOps Pipeline

DevOps Final Project | Fall 2025/2026

Build Status Security Scan Container Scan Platform GitOps License

A comprehensive demonstration of a T-Shaped DevOps Solution, combining a broad automated CI/CD pipeline with a Deep Dive vertical in Automated Security (DevSecOps). This project implements a fully automated "Commit-to-Production" workflow for a Python FastAPI application.


๐Ÿ“‹ Table of Contents


๐ŸŽฏ Project Overview

This project replaces manual deployments with a robust DevSecOps pipeline that ensures consistency, security, and resilience.

Key Features

  • Microservices Architecture: Containerized FastAPI application.
  • Infrastructure as Code (IaC): Terraform manages Kubernetes namespaces and resources.
  • Shift-Left Security: Vulnerabilities are caught before build using SAST (Bandit).
  • GitOps Delivery: Automated manifest updates trigger ArgoCD syncs (conceptually).
  • Zero-Downtime: Kubernetes handles rolling updates and self-healing.

๐Ÿ— Architecture & Pipeline

The solution follows a modern DevSecOps lifecycle, integrating security checks directly into the CI/CD flow.

graph TD
    subgraph "Dev Workstation"
        Dev[๐Ÿ‘ฉโ€๐Ÿ’ป Developer] -->|Git Push| GH[GitHub Repo]
    end

    subgraph "CI Pipeline (GitHub Actions)"
        GH -->|Trigger| Bandit["๐Ÿ›ก๏ธ SAST Scan (Bandit)"]
        Bandit -->|Pass| Docker[๐Ÿณ Docker Build]
        Docker -->|Push| Hub[โ˜๏ธ Docker Hub]
        Hub -->|Scan| Trivy[๐Ÿ” Trivy Image Scan]
    end

    subgraph "GitOps (CD)"
        Hub -->|Update Tag| Manifest[๐Ÿ“ Deployment YAML]
        Manifest -->|Commit| GitOps[Update Repo]
    end

    subgraph "Kubernetes Cluster"
        GitOps -.->|Sync| ArgoCD[๐Ÿ™ ArgoCD]
        ArgoCD -->|Apply| K8s[๐Ÿš€ Deployment]
        K8s --> Service[๐ŸŒ Service]
        Service --> Pod[๐Ÿ“ฆ App Pods]
        Ingress[๐Ÿšช Ingress] -->|Route| Service
    end

    style Bandit fill:#ffcccc,stroke:#333,color:black
    style ArgoCD fill:#ccffcc,stroke:#333,color:black
    style Docker fill:#ccf,stroke:#333,color:black
    style Trivy fill:#ffcccc,stroke:#333,color:black
    style Ingress fill:#e1d5e7,stroke:#333,color:black
Loading

๐Ÿ›  Technologies & Tools

Category Tool Description
Application FastAPI Python web framework for the API.
Containerization Docker Packaging the application.
Orchestration Kubernetes Managing container deployment, scaling, and Ingress.
IaC Terraform Provisioning Kubernetes namespaces.
CI/CD GitHub Actions Automating testing, building, and pushing.
Security (Code) Bandit Static Application Security Testing (SAST) for Python.
Security (Container) Trivy Vulnerability scanning for OS and dependencies.

๐Ÿ“‚ Project Structure

.
โ”œโ”€โ”€ .github/
โ”‚   โ””โ”€โ”€ workflows/
โ”‚       โ””โ”€โ”€ ci.yml                 # ๐Ÿค– The Automated Pipeline Definition
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ main.py                    # ๐Ÿ FastAPI Source Code
โ”‚   โ””โ”€โ”€ Dockerfile                 # ๐Ÿณ Container instructions
โ”œโ”€โ”€ k8s/
โ”‚   โ”œโ”€โ”€ deployment.yaml            # โ˜ธ๏ธ Deployment Manifest (Auto-updated by CI)
โ”‚   โ”œโ”€โ”€ service.yaml               # โ˜ธ๏ธ Internal ClusterIP Service
โ”‚   โ””โ”€โ”€ ingress.yaml               # ๐Ÿšช Ingress Routing Rules
โ”œโ”€โ”€ terraform/
โ”‚   โ”œโ”€โ”€ main.tf                    # ๐Ÿ—๏ธ IaC: Namespace provisioning
โ”‚   โ””โ”€โ”€ ...
โ””โ”€โ”€ README.md                      # ๐Ÿ“˜ This documentation

๐Ÿ”’ Deep Dive: Security (DevSecOps)

This project adopts a "Security First" approach by integrating Bandit (SAST) and Trivy (Container Security) into the pipeline.

Why Bandit?

Bandit is a tool designed to find common security issues in Python code. By running it before the Docker build step, we ensure that:

  1. Vulnerable code never reaches production.
  2. Feedback is immediate (the pipeline fails if issues are found).

What it checks:

  • Hardcoded passwords/secrets.
  • SQL injection risks.
  • Unsafe parsing (e.g., pickle).
  • Debug modes enabled in production.

Why Trivy?

Trivy scans the final Docker image for OS-level vulnerabilities and outdated dependencies (CVEs).

  • Layer 7 Protection: Ensures the base image (Python Slim) doesn't have known exploits.
  • Gatekeeper: Even if the code is safe, a vulnerable OS package could compromise the pod. The pipeline fails on CRITICAL or HIGH severity issues.

๐Ÿš€ CI/CD Pipeline Details

The pipeline is defined in .github/workflows/ci.yml.

1. Security Scan (SAST)

  • Action: Installs and runs bandit on the app/ directory.
  • Goal: Fail fast if security flaws are detected.

2. Build & Push

  • Action: Builds the Docker image and pushes it to Docker Hub.
  • Tagging: Uses the unique Git SHA (${{ github.sha }}) to ensure immutability and traceability.

3. Container Scan (Trivy)

  • Action: Pulled the pushed image and scans for CVEs.
  • Policy: Fails the build if CRITICAL vulnerabilities are found.

4. GitOps Update

  • Action: Updates k8s/deployment.yaml with the new image tag.
  • Meaning: The repository itself is the "Single Source of Truth". Changing the manifest in the repo triggers the deployment process (Conceptually via ArgoCD or simple application).

๐Ÿ Getting Started

Prerequisites

  • Docker Desktop (with Kubernetes enabled) or Minikube.
  • Terraform installed.
  • Python 3.9+ (for local testing).

๐Ÿƒ Local Development

  1. Clone the repo:

    git clone <repo-url>
    cd devops-finalproject/app
  2. Run the App:

    pip install fastapi uvicorn
    uvicorn main:app --reload

    Access at http://localhost:8000.

๐Ÿ“ฆ Deployment

1. Infrastructure (Terraform)

Initialize the Kubernetes namespace using Terraform.

cd terraform
terraform init
terraform apply
# Confirm 'yes' to create the 'final-project' namespace

2. Kubernetes Objects

Apply the manifests to the cluster.

kubectl apply -f k8s/

3. Access

Add the local DNS entry (if using Minikube):

echo "$(minikube ip) devops-project.local" | sudo tee -a /etc/hosts

Then visit http://devops-project.local.


๐Ÿ”ฎ Future Improvements

  • Monitoring: Add Prometheus & Grafana for metrics.
  • Testing: Add pytest for unit testing before the security scan.
  • Secret Management: Replace K8s secrets with Vault.

About

Final Project for Modern DevOps Practices course @ FMI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors