Skip to content

LocalCA is a complete solution for running your own Certificate Authority (CA) within a local network environment. It allows you to generate, manage, and deploy SSL/TLS certificates for internal services and clients without relying on external certificate providers.

License

Notifications You must be signed in to change notification settings

Lazarev-Cloud/localca-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

210 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

LocalCA: Self-Hosted Certificate Authority

Docker Go REST API License

LocalCA is a complete solution for managing a private Certificate Authority within a local network. The project provides a comprehensive RESTful API for generating, managing, and deploying SSL/TLS certificates for internal services and clients.

✨ Features

Core Certificate Management

  • βœ… CA Management: Create and manage your own Certificate Authority
  • βœ… Server Certificates: Generate SSL/TLS certificates for web servers
  • βœ… Client Certificates: Create certificates for client authentication
  • βœ… Certificate Revocation: Revoke compromised certificates with CRL support
  • βœ… Certificate Renewal: Renew certificates before expiration
  • βœ… PKCS#12 Export: Export client certificates with private keys

Enhanced Storage & Performance

  • βœ… Multi-Backend Storage: File, PostgreSQL, and S3/MinIO support
  • βœ… Caching Layer: Redis/KeyDB caching for improved performance
  • βœ… Audit Logging: Comprehensive audit trail for compliance
  • βœ… Backup Support: Automated backup and recovery capabilities
  • βœ… Data Encryption: Encrypted sensitive data storage

RESTful API

  • βœ… Complete REST API: Full HTTP API for all certificate operations
  • βœ… OpenAPI/Swagger: Comprehensive API documentation
  • βœ… JSON Responses: Standard JSON response format
  • βœ… HTTP Standards: Proper status codes and content negotiation
  • βœ… Client Libraries: Compatible with any HTTP client
  • βœ… ACME Support: Standard ACME protocol endpoints

Security & Authentication

  • βœ… JWT Authentication: Token-based API authentication
  • βœ… API Security: Rate limiting and security middleware
  • βœ… Password Protection: CA private key protection with secure storage
  • βœ… Input Validation: Comprehensive request validation
  • βœ… Security Headers: Comprehensive security headers and middleware

Automation & Integration

  • βœ… ACME Protocol: Automated certificate issuance (experimental)
  • βœ… Email Notifications: Certificate expiration alerts
  • βœ… JSON Logging: Structured logging for monitoring and alerting
  • βœ… Health Checks: Service health monitoring and status endpoints

πŸš€ Quick Start

Prerequisites

  • Docker & Docker Compose (recommended)
  • Go 1.23+ (for local development)
  • HTTP Client (curl, Postman, or any REST client)

Docker Deployment (Recommended)

  1. Clone the repository:
git clone https://github.com/Lazarev-Cloud/localca-go.git
cd localca-go
  1. Start with Docker Compose:
# For production with enhanced storage
docker-compose up -d

# For development
docker-compose -f docker-compose.dev.yml up -d
  1. Access the application:

Standalone Deployment

  1. Build the API server:
go build -o localca-go
  1. Run the application:
./localca-go
  1. Access the API:

πŸ“ Project Structure

localca-go/
β”œβ”€β”€ pkg/                     # Go backend packages
β”‚   β”œβ”€β”€ acme/               # ACME protocol implementation
β”‚   β”œβ”€β”€ cache/              # Redis/KeyDB caching layer
β”‚   β”œβ”€β”€ certificates/       # Certificate operations
β”‚   β”œβ”€β”€ config/             # Configuration management
β”‚   β”œβ”€β”€ database/           # PostgreSQL integration
β”‚   β”œβ”€β”€ email/              # Email notifications
β”‚   β”œβ”€β”€ handlers/           # HTTP handlers and routing
β”‚   β”œβ”€β”€ logging/            # Structured logging
β”‚   β”œβ”€β”€ s3storage/          # S3/MinIO object storage
β”‚   β”œβ”€β”€ security/           # Security utilities
β”‚   └── storage/            # Storage backends and interfaces
β”œβ”€β”€ docs/                    # Documentation
β”‚   β”œβ”€β”€ deployment/         # Deployment guides
β”‚   β”œβ”€β”€ development/        # Development documentation
β”‚   └── security/           # Security documentation
β”œβ”€β”€ .cursor/                 # Cursor AI rules and configuration
β”‚   └── rules/              # Comprehensive project rules
β”œβ”€β”€ tools/                   # Utility scripts and tools
β”œβ”€β”€ docker-compose.yml       # Production Docker setup
β”œβ”€β”€ Dockerfile              # API server container
└── main.go                 # Application entry point

πŸ”§ Configuration

Environment Variables

The application is configured through environment variables:

Variable Description Default Status
Core Configuration
CA_NAME Certificate Authority name "LocalCA" βœ… Working
CA_KEY_PASSWORD CA private key password required βœ… Working
ORGANIZATION Organization name "LocalCA Organization" βœ… Working
COUNTRY Country code "US" βœ… Working
DATA_DIR Data storage directory "./data" βœ… Working
LISTEN_ADDR HTTP server address ":8080" βœ… Working
Security Configuration
TLS_ENABLED Enable HTTPS "false" βœ… Working
SESSION_SECRET Session encryption key auto-generated βœ… Working
Enhanced Storage
DATABASE_ENABLED Enable PostgreSQL storage "false" βœ… Working
DATABASE_URL PostgreSQL connection string optional βœ… Working
S3_ENABLED Enable S3/MinIO storage "false" βœ… Working
S3_ENDPOINT S3 endpoint URL optional βœ… Working
CACHE_ENABLED Enable Redis/KeyDB caching "false" βœ… Working
REDIS_URL Redis connection URL optional βœ… Working
Notifications
EMAIL_NOTIFY Enable email notifications "false" βœ… Working
SMTP_HOST SMTP server hostname optional βœ… Working
SMTP_PORT SMTP server port "587" βœ… Working
Logging
LOG_FORMAT Logging format (json/text) "text" βœ… Working
LOG_LEVEL Logging level "info" βœ… Working
Frontend
NEXT_PUBLIC_API_URL Frontend API URL "http://localhost:8080" βœ… Working

Docker Environment

For Docker deployments, copy .env.example to .env and modify as needed:

cp .env.example .env
# Edit .env with your preferred settings

Example .env configuration:

# Core Configuration
CA_NAME=MyLocalCA
CA_KEY_PASSWORD=secure-ca-password
ORGANIZATION=My Organization
COUNTRY=US

# Enhanced Storage
DATABASE_ENABLED=true
DATABASE_URL=postgres://localca:localca_password@postgres:5432/localca
S3_ENABLED=true
S3_ENDPOINT=http://minio:9000
S3_ACCESS_KEY=minioadmin
S3_SECRET_KEY=minioadmin
CACHE_ENABLED=true
REDIS_URL=redis://keydb:6379

# Email Notifications
EMAIL_NOTIFY=true
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USERNAME=your-email@gmail.com
SMTP_PASSWORD=your-app-password

🎯 Function Status

βœ… Fully Working Features

1. Certificate Management

  • CA Creation: Automatic CA certificate generation with secure key storage
  • Server Certificates: SSL/TLS certificates for web servers with SAN support
  • Client Certificates: Client authentication certificates with PKCS#12 export
  • Certificate Revocation: CRL generation and certificate revocation
  • Certificate Renewal: Automated and manual certificate renewal
  • Certificate Validation: X.509 certificate chain validation

2. Enhanced Storage System

  • Multi-Backend Storage: File, PostgreSQL, and S3/MinIO storage backends
  • Caching Layer: Redis/KeyDB caching for improved performance
  • Audit Logging: Comprehensive audit trail for compliance
  • Backup & Recovery: Automated backup and disaster recovery
  • Health Monitoring: Storage backend health checks and monitoring

3. RESTful API

  • Complete REST API: Full HTTP API for all certificate operations
  • OpenAPI Documentation: Comprehensive API documentation and examples
  • JSON Responses: Standard JSON response format with proper HTTP codes
  • Content Negotiation: Support for JSON and XML content types
  • Client Libraries: Compatible with any HTTP client or library

4. API Integration

  • REST API: Complete RESTful API for all operations
  • ACME Protocol: Standard ACME endpoints for automated certificate issuance
  • Authentication: JWT-based API authentication
  • Rate Limiting: Built-in rate limiting for security
  • API Versioning: Versioned API endpoints for backward compatibility

5. Security Features

  • JWT Authentication: Token-based API authentication
  • Security Headers: Comprehensive HTTP security headers
  • Input Validation: Server-side input validation and sanitization
  • TLS Configuration: Modern TLS 1.2/1.3 configuration
  • Audit Logging: Complete audit trail for all operations

6. Monitoring & Logging

  • Structured Logging: JSON and text logging formats
  • Performance Metrics: System and application performance monitoring
  • Health Checks: Service health and readiness endpoints
  • Error Tracking: Comprehensive error logging and alerting

🚧 Experimental Features

1. ACME Protocol

  • Basic ACME Server: ACME protocol implementation for automated certificate issuance
  • HTTP-01 Challenge: Web-based domain validation
  • Account Management: ACME account creation and management
  • Order Processing: Certificate order lifecycle management

Note: ACME implementation is experimental and may require additional testing with real ACME clients.

2. Email Notifications

  • SMTP Integration: Email notifications for certificate expiration
  • Template System: HTML and text email templates
  • Batch Processing: Efficient batch email processing

Note: Email system is functional but templates and scheduling may need enhancement.

πŸ”„ Recently Enhanced

1. Storage Architecture

  • Multi-Backend Support: Added PostgreSQL and S3/MinIO storage backends
  • Caching Integration: Implemented Redis/KeyDB caching layer
  • Performance Optimization: Improved storage operation performance
  • Backup Capabilities: Added automated backup and recovery features

2. API Improvements

  • Enhanced Endpoints: Comprehensive API endpoints for all operations
  • OpenAPI Documentation: Complete API documentation with examples
  • Performance: Optimized API response times and data handling
  • Error Handling: Standardized error responses and status codes

3. Security Enhancements

  • JWT Authentication: Token-based API authentication system
  • API Security: Enhanced API security and rate limiting
  • Input Validation: Comprehensive input validation and sanitization
  • Security Headers: Added comprehensive security headers

πŸ§ͺ Testing

Run All Tests

# API tests
go test ./...

# Integration tests
go test -tags=integration ./...

# Docker-based testing
docker-compose -f docker-compose.test.yml up --abort-on-container-exit

Enhanced Storage Tests

# Test enhanced storage features
./tools/test-enhanced-storage.sh

# Comprehensive system validation
./tools/comprehensive-enhanced-test.sh

Application Tests

# Basic functionality tests
./tools/test_application.sh

# ACME protocol tests
./tools/test-acme.sh

πŸ“ˆ Monitoring & Management

Health Checks

# Check deployment status
./tools/deployment-status.sh

# Check service health
curl http://localhost:8080/api/health
curl http://localhost:3000/api/health

Performance Metrics

The application provides comprehensive performance metrics:

  • System Statistics: Real-time system metrics via /api/statistics
  • Cache Performance: Cache hit rates and performance metrics
  • Storage Metrics: Storage usage and performance monitoring
  • Certificate Statistics: Certificate counts and status overview

Logging and Monitoring

Structured logging is available in multiple formats:

# View backend logs
docker-compose logs backend

# View frontend logs
docker-compose logs frontend

# View all service logs
docker-compose logs -f

πŸ” Security

Security Features

  • Authentication: JWT-based API authentication
  • API Security: Rate limiting and security middleware
  • Security Headers: Comprehensive HTTP security headers
  • Input Validation: Server-side input validation and sanitization
  • Rate Limiting: Built-in rate limiting for API endpoints
  • Audit Logging: Complete audit trail for all operations

Security Best Practices

  1. Change default passwords before production use
  2. Enable HTTPS for production deployments using TLS_ENABLED=true
  3. Use strong CA key passwords with CA_KEY_PASSWORD
  4. Regular certificate rotation and monitoring
  5. Monitor audit logs for security events
  6. Keep software updated with latest security patches

Security Configuration

# Enable TLS for production
TLS_ENABLED=true
TLS_CERT_FILE=/path/to/cert.pem
TLS_KEY_FILE=/path/to/key.pem

# Configure JWT authentication
JWT_SECRET=your-secure-jwt-secret
JWT_EXPIRY=3600

# Enable audit logging
AUDIT_ENABLED=true
AUDIT_LOG_FILE=/var/log/localca/audit.log

πŸ“š Documentation

Comprehensive Documentation

Deployment & Operations

Security & Compliance

Development & Troubleshooting

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes following the development guidelines
  4. Add tests if applicable
  5. Commit your changes: git commit -m 'Add amazing feature'
  6. Push to the branch: git push origin feature/amazing-feature
  7. Submit a pull request

Development Guidelines

  • Follow the coding standards in Development Guide
  • Write tests for new features
  • Update documentation as needed
  • Ensure all tests pass before submitting PR

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

πŸŽ‰ Acknowledgments

  • Built with Go and Gin
  • RESTful API with comprehensive documentation
  • Enhanced storage with PostgreSQL and MinIO
  • Caching with KeyDB
  • Containerization with Docker

LocalCA - Self-hosted Certificate Authority for modern applications πŸ”’

Secure, scalable, and easy to deploy certificate management solution.

About

LocalCA is a complete solution for running your own Certificate Authority (CA) within a local network environment. It allows you to generate, manage, and deploy SSL/TLS certificates for internal services and clients without relying on external certificate providers.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors