A production-ready Spring Boot utility container that dynamically generates certificates for secure CockroachDB deployments. This application addresses the common challenge of certificate management in containerized CockroachDB environments by automating the entire certificate lifecycle at container startup.
This container combines a Spring Boot service with the official CockroachDB binary to create a complete PKI infrastructure:
- Certificate Authority (CA): Creates a root CA certificate and private key for your CockroachDB cluster
- Client Certificates: Generates user certificates with PKCS#8 private keys for secure client connections
- Node Certificates: Creates node certificates with configurable Subject Alternative Names (SANs) for cluster communication
- Kubernetes Deployments: Generate certificates dynamically in init containers or sidecar patterns
- Docker Compose: Bootstrap secure CockroachDB clusters with automated certificate generation
- CI/CD Pipelines: Create ephemeral test environments with proper certificate security
- Development: Quickly spin up secure CockroachDB instances for local development
- Multi-Node Clusters: Generate certificates with proper SANs for distributed deployments
The application runs once at container startup, generates all necessary certificates, then provides a health endpoint for monitoring container readiness.
- Certificate Generation: Creates CA, client, and node certificates using CockroachDB's cert commands
- Multiple Users: Supports custom client usernames (always includes 'root' user)
- Flexible Node Names: Configurable alternative names for node certificates
- Container Ready: Health endpoint for monitoring in orchestration environments
- Multi-stage Build: Optimized Docker image using official CockroachDB and Eclipse Temurin JDK 24 base images
- PKCS#8 Support: Generates PKCS#8 private keys for client certificates
- Security Scanning: Integrated Trivy scanning in CI/CD pipeline
- Multi-platform Support: Builds for both linux/amd64 and linux/arm64
| Variable | Required | Default | Description | Example |
|---|---|---|---|---|
NODE_ALTERNATIVE_NAMES |
Yes | - | Space-separated list of alternative names for the node certificate | localhost node1.example.com 10.0.1.5 |
CLIENT_USERNAME |
No | root |
Username for client certificate generation | myuser |
This variable is critical for proper certificate validation. Include all possible ways your CockroachDB node might be accessed:
- Hostnames:
cockroach-node-1,db.example.com - IP Addresses:
192.168.1.100,10.0.0.5 - Service Names:
cockroachdb-service(for Kubernetes) - Localhost:
localhost,127.0.0.1(for local development)
Example for Kubernetes:
NODE_ALTERNATIVE_NAMES="cockroachdb cockroachdb.default cockroachdb.default.svc.cluster.local localhost"docker build --no-cache -t timveil/cockroachdb-dynamic-certs:latest .For specific platforms:
docker build --no-cache --platform linux/arm64 -t timveil/cockroachdb-dynamic-certs:latest .docker push timveil/cockroachdb-dynamic-certs:latestdocker run -p 9999:9999 \
--env NODE_ALTERNATIVE_NAMES=localhost \
timveil/cockroachdb-dynamic-certs:latestdocker run -d \
--name cert-generator \
--env NODE_ALTERNATIVE_NAMES="cockroach-node1 cockroach-node1.internal 10.0.1.5 localhost" \
--env CLIENT_USERNAME=appuser \
-v /host/certs:/output \
timveil/cockroachdb-dynamic-certs:latestinitContainers:
- name: cert-generator
image: timveil/cockroachdb-dynamic-certs:latest
env:
- name: NODE_ALTERNATIVE_NAMES
value: "cockroachdb cockroachdb.default cockroachdb.default.svc.cluster.local"
- name: CLIENT_USERNAME
value: "root"
volumeMounts:
- name: certs
mountPath: /.cockroach-certs
- name: ca-key
mountPath: /.cockroach-keyversion: '3.8'
services:
cert-generator:
image: timveil/cockroachdb-dynamic-certs:latest
environment:
NODE_ALTERNATIVE_NAMES: "cockroachdb localhost 127.0.0.1"
CLIENT_USERNAME: "root"
volumes:
- certs-volume:/output
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9999/actuator/health"]
interval: 10s
timeout: 5s
retries: 3
cockroachdb:
image: cockroachdb/cockroach:latest
depends_on:
cert-generator:
condition: service_healthy
volumes:
- certs-volume:/.cockroach-certs:ro
command: start --certs-dir=/.cockroach-certs --host=cockroachdb
volumes:
certs-volume:The application exposes a health endpoint at:
http://localhost:9999/actuator/health
This can be used to monitor the application's status in container orchestration environments.
Inside the container, certificates are generated in:
/.cockroach-certs/- Contains all generated certificates (CA, client, and node)/.cockroach-key/- Contains the CA private key (ca.key)
# Build with Maven
mvn clean package
# Run locally (requires CockroachDB binary in PATH)
mvn spring-boot:run# Check application health
curl http://localhost:9999/actuator/healthThe application is built using:
- Spring Boot 3.5.5 with Java 21 (runs on JDK 24 in Docker)
- CockroachDB binary for certificate generation
- Multi-stage Docker build for optimized image size
- ApplicationRunner interface for startup certificate generation
Certificate generation follows this sequence:
- Create Certificate Authority (CA)
- Generate client certificates for specified users
- Create node certificates with alternative names
- Start Spring Boot application with health monitoring
- Triggers: Every push to master and pull requests
- Actions: Maven build, Docker image creation, health endpoint testing
- Security: Trivy scans for CRITICAL and HIGH vulnerabilities
- Triggers: Automatically on pushes to master that modify:
- Source code (
src/**) - Maven config (
pom.xml) - Dockerfile
- Release workflow itself
- Source code (
- Versioning: Date-based tags (YYYY.MM.DD and YYYY.MM.DD-sha)
- Multi-platform: Builds for linux/amd64 and linux/arm64
- Docker Hub: Pushes images with:
latest- Always points to newest buildYYYY.MM.DD- Date of releaseYYYY.MM.DD-sha- Date plus commit SHA for uniqueness
- Documentation: Automatically syncs README to Docker Hub description
Contributions welcome! Please:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes and test locally
- Run the build:
mvn clean package - Test with Docker:
docker build -t test . - Submit a pull request
# Clone repository
git clone https://github.com/timveil/dynamic-certs.git
cd dynamic-certs
# Build with Maven
mvn clean package
# Build Docker image
docker build -t dynamic-certs:dev .
# Test locally
docker run --rm -e NODE_ALTERNATIVE_NAMES=localhost dynamic-certs:dev- Dependabot: Monitors Maven (daily), Docker (weekly), and GitHub Actions (weekly)
This project is open source. See the repository for license details.
For issues, questions, or contributions:
- π Issues: GitHub Issues
- π Feature Requests: GitHub Discussions
- π Documentation: This README and inline code comments
Quick Start: docker run --rm -e NODE_ALTERNATIVE_NAMES=localhost timveil/cockroachdb-dynamic-certs:latest