Spring Boot utility that dynamically generates CockroachDB certificates
6.7K
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:
The application runs once at container startup, generates all necessary certificates, then provides a health endpoint for monitoring container readiness.
| 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:
cockroach-node-1, db.example.com192.168.1.100, 10.0.0.5cockroachdb-service (for Kubernetes)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:latest
docker run -p 9999:9999 \
--env NODE_ALTERNATIVE_NAMES=localhost \
timveil/cockroachdb-dynamic-certs:latest
docker 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:latest
initContainers:
- 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-key
version: '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/health
The application is built using:
Certificate generation follows this sequence:
ci.yml)release.yml)src/**)pom.xml)latest - Always points to newest buildYYYY.MM.DD - Date of releaseYYYY.MM.DD-sha - Date plus commit SHA for uniquenessContributions welcome! Please:
git checkout -b feature/amazing-featuremvn clean packagedocker build -t test .# 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
This project is open source. See the repository for license details.
For issues, questions, or contributions:
Quick Start: docker run --rm -e NODE_ALTERNATIVE_NAMES=localhost timveil/cockroachdb-dynamic-certs:latest
Content type
Image
Digest
sha256:69a80fe78…
Size
294.6 MB
Last updated
4 months ago
docker pull timveil/cockroachdb-dynamic-certs