Skip to content

CHETANPATILL/zero-trust-gitops

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 

Repository files navigation

πŸ” Zero-Trust GitOps

Kubernetes manifests demonstrating zero-trust architecture with admission control, policy enforcement, and GitOps automation.

GitOps Policy Security

🎯 Overview

Production Kubernetes manifests with:

  • βœ… Zero-Trust Networking - Default-deny NetworkPolicies
  • βœ… Admission Control - Kyverno validates all deployments
  • βœ… GitOps - ArgoCD auto-sync from Git
  • βœ… Multi-Environment - Dev, Staging, Production with Kustomize
  • βœ… Secret Management - External Secrets Operator + AWS Secrets Manager
  • βœ… Runtime Security - Falco threat detection

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     Git Repository                          β”‚
β”‚  (Source of Truth for Cluster State)                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚
        Application push updates image digest
                  β”‚
                  β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       ArgoCD                                β”‚
β”‚  - Detects changes every 3 minutes                         β”‚
β”‚  - Auto-sync to dev                                        β”‚
β”‚  - Manual sync to staging/production                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚
          kubectl apply
                  β”‚
                  β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  Admission Control                          β”‚
β”‚  Kyverno Validates:                                        β”‚
β”‚  ❌ Block unsigned images                                  β”‚
β”‚  ❌ Block missing SBOM                                     β”‚
β”‚  ❌ Block latest tag                                       β”‚
β”‚  ❌ Block privileged containers                            β”‚
β”‚  βœ… Allow only compliant workloads                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚
         If validation passes
                  β”‚
                  β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Kubernetes Cluster (EKS)                       β”‚
β”‚                                                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                   β”‚
β”‚  β”‚   Backend      β”‚  β”‚   Database     β”‚                   β”‚
β”‚  β”‚   (IRSA)       β”‚  β”‚   (StatefulSet)β”‚                   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜                   β”‚
β”‚           β”‚                    β”‚                           β”‚
β”‚           └──── NetworkPolicy β”€β”˜                           β”‚
β”‚                (Zero-Trust)                                β”‚
β”‚                                                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”‚
β”‚  β”‚  Falco (Runtime Security)                      β”‚       β”‚
β”‚  β”‚  - Detects shell spawns                        β”‚       β”‚
β”‚  β”‚  - Detects privilege escalation                β”‚       β”‚
β”‚  β”‚  - Alerts to Slack                             β”‚       β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Repository Structure

.
β”œβ”€β”€ argocd/
β”‚   β”œβ”€β”€ applications/
β”‚   β”‚   β”œβ”€β”€ app-of-apps.yaml      # Root application
β”‚   β”‚   β”œβ”€β”€ backend.yaml
β”‚   β”‚   β”œβ”€β”€ admin.yaml
β”‚   β”‚   └── platform.yaml
β”‚   └── projects/
β”‚       └── ecommerce.yaml
β”‚
β”œβ”€β”€ base/                          # Kustomize base manifests
β”‚   β”œβ”€β”€ backend/
β”‚   β”‚   β”œβ”€β”€ deployment.yaml
β”‚   β”‚   β”œβ”€β”€ service.yaml
β”‚   β”‚   β”œβ”€β”€ serviceaccount.yaml   # IRSA annotation
β”‚   β”‚   β”œβ”€β”€ externalsecret.yaml   # Secrets from AWS
β”‚   β”‚   β”œβ”€β”€ networkpolicy.yaml    # Zero-trust rules
β”‚   β”‚   └── kustomization.yaml
β”‚   β”‚
β”‚   β”œβ”€β”€ platform/
β”‚   β”‚   β”œβ”€β”€ external-secrets/
β”‚   β”‚   β”œβ”€β”€ kyverno/
β”‚   β”‚   β”‚   β”œβ”€β”€ verify-images.yaml
β”‚   β”‚   β”‚   β”œβ”€β”€ require-sbom.yaml
β”‚   β”‚   β”‚   └── security-policies.yaml
β”‚   β”‚   └── falco/
β”‚   β”‚       └── custom-rules.yaml
β”‚   β”‚
β”‚   └── ...
β”‚
└── overlays/                      # Environment-specific
    β”œβ”€β”€ dev/
    β”‚   └── backend/
    β”‚       β”œβ”€β”€ kustomization.yaml
    β”‚       └── patches/
    β”‚           β”œβ”€β”€ replicas.yaml  # 1 replica
    β”‚           └── resources.yaml # Lower limits
    β”‚
    β”œβ”€β”€ staging/                   # 2 replicas
    └── production/                # 3 replicas + HPA

πŸ” Zero-Trust Implementation

Default Deny All Traffic

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-all
spec:
  podSelector: {}
  policyTypes:
  - Ingress
  - Egress

Allow Only Required Traffic

# Backend can ONLY talk to:
# - Database (port 5432)
# - Redis (port 6379)
# - External HTTPS (port 443)
# - DNS (port 53)

πŸ›‘οΈ Admission Control Policies

Kyverno Policies

1. Verify Image Signatures

- Block unsigned images
- Verify Cosign signature with GitHub OIDC
- Use Rekor transparency log

2. Require SBOM

- Block images without SBOM attestation
- Support SPDX and CycloneDX formats

3. Security Best Practices

- Require non-root user
- Block latest tag
- Require resource limits
- Block privileged containers
- Require read-only root filesystem

πŸ”„ GitOps Workflow

Development

# Developer pushes code
git push origin main

# CI/CD builds, signs, scans image
# Updates this GitOps repo with new image digest

# ArgoCD detects change (within 3 min)
# Auto-syncs to dev environment

# Kyverno validates signature
# Deployment proceeds

Staging/Production

# Create PR to promote
gh pr create --title "Promote backend to staging"

# Team reviews
# Merge PR

# ArgoCD syncs (manual approval required)
# Canary deployment with Argo Rollouts

πŸš€ ArgoCD Setup

Install ArgoCD

kubectl create namespace argocd
kubectl apply -n argocd -f \
  https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

Deploy Applications

kubectl apply -f argocd/applications/app-of-apps.yaml

Access UI

# Get admin password
kubectl -n argocd get secret argocd-initial-admin-secret \
  -o jsonpath="{.data.password}" | base64 -d

# Port forward
kubectl port-forward svc/argocd-server -n argocd 8080:443

πŸ“š Documentation

πŸ§ͺ Testing

Verify NetworkPolicies

# Should FAIL (default deny)
kubectl run test --image=busybox -- wget backend:9000

# Should SUCCEED (after adding label)
kubectl label pod test app=admin
kubectl exec test -- wget backend:9000

Verify Admission Control

# Should FAIL (unsigned)
kubectl run test --image=nginx:latest

# Should SUCCEED (signed)
kubectl run test --image=ACCOUNT.dkr.ecr.REGION.amazonaws.com/backend@sha256:...

πŸ“Š Monitoring

ArgoCD Metrics

  • Sync success rate
  • Sync duration
  • Application health status

Kyverno Metrics

  • Policy violations
  • Admission decisions
  • Background scan results

πŸ‘€ Author

Chetan Patil - Senior DevSecOps Engineer


⭐ Demonstrates production GitOps and zero-trust security

About

πŸ” Zero-trust Kubernetes manifests | ArgoCD | Kyverno Policy Enforcement | NetworkPolicies | GitOps Best Practices

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors