Konstantinos Antoniou.

← Projects

Private Certificate Authority & Multi-Domain Management for Internal Services

Project Overview

This project demonstrates the design and implementation of a fully automated internal Public Key Infrastructure (PKI) using HashiCorp Vault, integrated with an NGINX reverse proxy, DNS management, custom Python utilities and a Jenkins pipeline for automatic certificate issuance and renewal. The setup ensures secure HTTPS connections across all internal services without relying on external certificate authorities.


Problem Statement

In modern environments, managing TLS certificates and domain names across multiple internal services is complex:

  • Manual certificate issuance is error-prone and cannot scale as services increase.
  • Certificates from public CAs cannot cover internal hostnames or are costly for multiple subdomains.
  • Misconfigured certificates can cause service downtime or security vulnerabilities.

This project solves these problems by:

  1. Centralizing certificate management with Vault as an internal CA.
  2. Automating certificate issuance and renewal with a custom python script and Jenkins pipeline.
  3. Terminating TLS securely on NGINX, centralizing traffic for multiple internal services.
  4. Managing DNS internally to ensure service names resolve correctly for TLS validation.

Infrastructure Topology

Screenshot 1: Infrastructure Topology

Network:

  • All VMs are on a private subnet (192.0.2.0/25).
  • Internal DNS server resolves *.internal domains to the NGINX Reverse Proxy VM IPs.
  • NGINX acts as a central HTTPS gateway for all the internal services like Jenkins, Proxmox, Nexus Docker Registry, NAS, Vault, etc.

Screenshot 2: Infrastructure Topology


Vault PKI Setup and Security

  1. Internal Root CA:
    • A root CA (pki_root) is created for internal trust.
    • The root CA is offline to prevent accidental compromise.
  2. Intermediate CA (pki_int):
    • Vault issues certificates using an intermediate CA mounted at pki_int.
    • Intermediate CA signs short-lived certificates (default TTL: 24h–7d).
    • Short-lived certs minimize risk if a service is compromised.
  3. Roles and Policies:
    • Vault roles define which services can request certificates, allowed CNs, and SANs.
    • Role syndicate allows certs for *.internal and syndicate domains.
    • Policies enforce least privilege: Jenkins can request certs for services, but cannot extract Vault root keys.
  4. Certificate Lifecycle Automation:
    • Certificates are requested via Vault’s API leveraging custom python script.
    • Jenkins pipeline parse Vault output and copy fullchain.pem and syndicate.key to NGINX and reloads automatically without downtime.
  5. Security Enhancements:
    • TLS between Vault and clients (Jenkins) enforced.
    • Vault audit logs enabled for certificate requests.
    • Certificates are ephemeral and rotated automatically.

Screenshot 3: Vault PKI Setup and Security


NGINX Reverse Proxy

  • Centralized HTTPS Termination – Terminates TLS for all *.internal services using Vault-issued certificates, ensuring end-to-end encryption.
  • Dynamic Multi-service Routing – Maps hostnames to VM or Docker container upstreams using NGINX map, enabling flexible multi-service traffic management.
  • HTTP → HTTPS Enforcement – Redirects all insecure HTTP traffic to HTTPS, strengthening internal network security.
  • Wildcard Domain Support – Handles multiple subdomains (*.internal) for scalability and simplified onboarding of new services.
  • WebSocket & Streaming Optimization – Supports real-time workflows (e.g., n8n editor) with proxy_buffering off and upgraded headers for stable long-lived connections.
  • Docker & VM Integration – Resolves both container hostnames via Docker DNS and fixed VM IPs, enabling hybrid infrastructure support.
  • Advanced Proxy Headers & SNI – Preserves client info (X-Real-IP, X-Forwarded-For) and supports SNI for secure upstream TLS connections.
  • Long Timeout & Large Payload Support – Configured for large uploads and long-running requests (client_max_body_size 10g, proxy_read_timeout 3600s).
  • Robust Fail-Safe Handling – Returns HTTP 444 for undefined hosts, preventing misuse and ensuring operational reliability.

Screenshot 4: NGINX Reverse Proxy


Automation & Python Script

At the heart of this setup is a custom Python utility that bridges Vault PKI, filesystem security, and automation workflows:

  • Automated PKI Management – Issues Vault certificates with dynamic SANs for multiple services.
  • Dynamic SAN Integration – Reads SANs from a text file, constructing comma-separated SAN strings for requests.
  • Secure Key Handling – Extracts private key and certificate using regex parsing and enforces file permissions (chmod 600).
  • JSON Processing & Validation – Parses Vault JSON output, ensuring leaf certificate, issuing CA, and full chain are present.
  • PEM Normalization – Cleans and standardizes PEM formatting for private keys and certificates.
  • Automated File Export – Exports private key, leaf certificate, full chain, and intermediate certificate to a dedicated directory.
  • Subprocess Automation – Executes Vault commands via Python’s subprocess for seamless CLI integration.
  • Error Handling & Robustness – Validates inputs, checks for missing files, and prevents runtime failures.

This script ensures the certificate is automatically requested and validated without manual intervention.


Jenkins Pipeline Integration

Screenshot 5: Jenkins Pipeline Integration

  • CI/CD Automation – End-to-end Jenkins pipeline orchestrating certificate issuance, deployment, NGINX reload and Telegram notification.
  • Running on schedule, every two days.
  • Secure Secret Management – Vault AppRole authentication with dynamic token extraction; credentials stored securely in Jenkins.
  • Dynamic Certificate Issuance – Automated PKI workflow using Python script with Vault integration.
  • SSH & Remote Automation – Securely copies certificates to remote NGINX servers using sshagent and scp, including automated permission hardening.
  • Infrastructure Validation – Validates remote NGINX configuration (nginx -t) before applying changes, ensuring zero downtime.
  • Idempotent Deployment – Cleans up temporary workspace artifacts (vault.token, certs/) to maintain a reproducible environment.
  • Error Handling & Fail-Safe Mechanisms – Pipeline fails gracefully with descriptive messages if Vault authentication, certificate issuance, or NGINX reload fails.
  • Integration with Version Control – GitHub checkout with secured credentials, enabling automated, branch-specific deployments.
  • Docker-Oriented Deployment – Directly interacts with containerized NGINX services to reload configuration post-deployment.
  • Telegram notifies either pipeline completed successfully or not with custom python script.

Screenshot 6: Jenkins Pipeline Integration


DNS Management

  • Internal DNS resolves *.internal domains to NGINX specific VM IP.
  • Ensures certificates match hostnames and avoids TLS warnings.

Challenges & Solutions

  • Challenge: Ensuring all services, even those running only HTTP internally, are accessible securely.
    Solution: Configured NGINX to handle HTTP→HTTPS redirection while terminating TLS centrally.
  • Challenge: Managing certificates for multiple apps with overlapping ports.
    Solution: Used hostname-based virtual hosts on NGINX.
  • Challenge: Root CA trust propagation across Linux, Windows, and browsers.
    Solution: Automated CA installation and update-ca-certificates using ansible, plus browser-specific steps.

Lessons Learned / Key Takeaways

Screenshot 7: Lessons Learned / Key Takeaways

Building this automated internal PKI and reverse proxy infrastructure reinforced the importance of security-first design, automation, and scalability in modern DevOps environments. I learned how to leverage Vault’s internal CA to issue short-lived certificates safely, integrate Python scripting for dynamic SAN handling and certificate deployment, and orchestrate seamless HTTPS termination with NGINX for multiple services. The project highlighted the value of robust error handling, standardized configurations, and CI/CD pipelines in reducing operational risk, preventing downtime, and enabling rapid onboarding of new services. Ultimately, it demonstrated how combining security, automation, and observability creates a maintainable, scalable, and professional internal network infrastructure.