License Server
A comprehensive microservices-based license management system for software licensing, validation, and analytics.
Features
- License Management: Create, update, and manage software licenses
- Hardware-based Validation: Bind licenses to specific devices
- Offline Support: Generate offline validation tokens
- Analytics: Track usage patterns and detect anomalies
- Rate Limiting: Protect APIs with configurable rate limits
- Event-driven Architecture: Real-time event processing with RabbitMQ
- Caching: Redis-based caching for improved performance
- Security: JWT authentication, API key management, and audit logging
Architecture
The system consists of four microservices:
- Auth Service (Port 5001): JWT token management and API authentication
- License API (Port 5002): License validation and activation
- Analytics Service (Port 5003): Usage analytics and anomaly detection
- Admin API (Port 5004): License administration and management
Quick Start
Prerequisites
- Docker and Docker Compose
- Make (optional, for using Makefile commands)
- Python 3.11+ (for local development)
Installation
- Clone the repository:
git clone <repository-url>
cd lizenzserver
- Copy environment variables:
cp .env.example .env
# Edit .env with your configuration
- Build and start services:
make build
make up
Or without Make:
docker-compose build
docker-compose up -d
- Initialize the database:
make init-db
Verify Installation
Check service health:
curl http://localhost:5001/health
curl http://localhost:5002/health
curl http://localhost:5003/health
curl http://localhost:5004/health
Usage
Creating a License
curl -X POST http://localhost:5004/api/v1/admin/licenses \
-H "X-Admin-API-Key: your-admin-key" \
-H "Content-Type: application/json" \
-d '{
"customer_id": "cust-123",
"max_devices": 5,
"expires_in_days": 365,
"features": ["premium", "support"]
}'
Validating a License
curl -X POST http://localhost:5002/api/v1/license/validate \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"license_key": "LIC-XXXXXXXXXXXX",
"hardware_id": "device-123"
}'
API Documentation
Detailed API documentation is available in API_DOCUMENTATION.md.
Configuration
Environment Variables
Key configuration options in .env:
DB_PASSWORD: PostgreSQL passwordREDIS_PASSWORD: Redis passwordJWT_SECRET: Secret key for JWT tokensADMIN_API_KEY: Admin API authentication keyFLASK_ENV: Flask environment (development/production)
Rate Limiting
Default rate limits:
- 60 requests per minute
- 1000 requests per hour
- 10000 requests per day
Configure per API key in the database.
Development
Running Locally
- Install dependencies:
pip install -r requirements.txt
- Set environment variables:
export DATABASE_URL=postgresql://user:pass@localhost:5432/licenses
export REDIS_URL=redis://localhost:6379
export RABBITMQ_URL=amqp://guest:guest@localhost:5672
- Run a service:
python services/license_api/app.py
Testing
Run tests:
make test
Database Migrations
The database schema is in init.sql. Apply migrations:
docker-compose exec postgres psql -U license_admin -d licenses -f /path/to/migration.sql
Monitoring
Logs
View logs for all services:
make logs
View logs for specific service:
make logs-auth
make logs-license
make logs-analytics
make logs-admin
Metrics
Services expose Prometheus metrics at /metrics endpoint.
RabbitMQ Management
Access RabbitMQ management UI at http://localhost:15672
- Username: admin (or configured value)
- Password: admin_password (or configured value)
Security
Best Practices
- Change default passwords in production
- Use HTTPS in production (configure in nginx.conf)
- Rotate API keys regularly
- Monitor anomalies through the analytics service
- Set up IP whitelisting for admin endpoints
- Enable audit logging for compliance
API Key Management
Create API keys through the Auth Service:
curl -X POST http://localhost:5001/api/v1/auth/api-key \
-H "X-Admin-Secret: your-admin-secret" \
-H "Content-Type: application/json" \
-d '{
"client_name": "My Application",
"allowed_endpoints": ["license.validate", "license.activate"]
}'
Troubleshooting
Common Issues
- Services not starting: Check logs with
docker-compose logs <service-name> - Database connection errors: Ensure PostgreSQL is healthy and credentials are correct
- Rate limit errors: Check rate limit configuration and API key limits
- Cache misses: Verify Redis connection and TTL settings
Health Checks
All services provide health endpoints:
- Auth: http://localhost:5001/health
- License: http://localhost:5002/health
- Analytics: http://localhost:5003/health
- Admin: http://localhost:5004/health
Contributing
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
License
[Your License Here]
Support
For support, please contact [support@example.com] or create an issue in the repository.