2025-02-28 21:48:08 +01:00
# Certwarden Certificate Management
2025-02-28 21:24:51 +01:00
2025-03-03 12:37:55 +01:00
A bash script for managing SSL/TLS certificates through the Certwarden API. This tool provides both automated and interactive interfaces for downloading, installing, and managing certificates on your system.
2025-02-28 21:48:08 +01:00
## Features
2025-03-03 12:37:55 +01:00
- Download and verify certificates and private keys from Certwarden server
- Automatic installation with proper permissions and ownership
- Certificate and key pair validation
- Service reload after certificate updates
- Certificate expiration monitoring
2025-02-28 21:48:08 +01:00
- Interactive menu-driven interface
2025-03-03 13:30:15 +01:00
- Silent mode for automated operations
- Force update option for certificate renewals
2025-03-03 12:37:55 +01:00
- Proper error handling and logging
- Support for multiple certificates
2025-03-03 13:30:15 +01:00
- Secure temporary file handling
2025-02-28 21:48:08 +01:00
## Prerequisites
The script requires the following dependencies:
- `curl` : For API interactions
- `jq` : For JSON processing
- `openssl` : For certificate operations
## Installation
1. Clone this repository:
```bash
git clone < repository-url >
cd certman
```
2025-03-03 13:32:12 +01:00
2. Create a `.env` file with your configuration:
2025-02-28 21:48:08 +01:00
```bash
2025-03-03 12:37:55 +01:00
# Server Configuration
CERTWARDEN_SERVER="certwarden.dmz.skyfritt.net:443"
# Certificate Paths
CERT_PATH="/etc/forgejo"
KEY_PATH="/etc/forgejo"
TEMP_PATH="/tmp/certman"
2025-02-28 21:48:08 +01:00
2025-03-03 12:37:55 +01:00
# Service Configuration
SERVICE_NAME="forgejo"
CERT_OWNER="git"
CERT_GROUP="git"
CERT_PERMISSIONS="644"
KEY_PERMISSIONS="600"
2025-02-28 21:48:08 +01:00
2025-03-03 12:37:55 +01:00
# Certificate Configurations (JSON format)
CERTIFICATES='[
{
"domain": "example.com",
"cert_api_key": "your_cert_api_key",
"key_api_key": "your_key_api_key"
}
]'
2025-02-28 21:48:08 +01:00
```
2025-03-03 12:37:55 +01:00
## Usage
### Interactive Mode
Run the script without any arguments:
```bash
./certman.sh
```
This will present a menu with the following options:
1. Process all certificates
2. List installed certificates
3. Check certificate expiration
4. Exit
### Automated Mode
2025-03-03 13:30:15 +01:00
Run the script with the `--silent` flag for automated operations:
```bash
./certman.sh --silent
```
### Force Update
Use the `--force` flag to force certificate updates regardless of current status:
```bash
./certman.sh --force
```
Flags can be combined:
```bash
./certman.sh --silent --force
```
2025-03-03 12:37:55 +01:00
### Cron Configuration
Add these lines to your crontab for automated certificate management:
```cron
2025-03-03 13:30:15 +01:00
@reboot sleep 15 && /path/to/certman.sh --silent
5 4 * * 2 /path/to/certman.sh --silent
2025-03-03 12:37:55 +01:00
```
2025-03-03 13:30:15 +01:00
## Environment Variables
| Variable | Description | Required |
|----------|-------------|----------|
| CERTWARDEN_SERVER | Certwarden API server hostname and port | Yes |
| CERT_PATH | Directory for certificate storage | Yes |
| KEY_PATH | Directory for private key storage | Yes |
| TEMP_PATH | Temporary directory for downloads | Yes |
| SERVICE_NAME | Service to reload after certificate updates | Yes |
| CERT_OWNER | User owner for certificate files | Yes |
| CERT_GROUP | Group owner for certificate files | Yes |
| CERT_PERMISSIONS | Certificate file permissions | Yes |
| KEY_PERMISSIONS | Private key file permissions | Yes |
| CERTIFICATES | JSON array of certificate configurations | Yes |
2025-03-03 12:37:55 +01:00
## Security Considerations
- Store the script and `.env` file in a secure location with restricted permissions
- Use appropriate permissions for certificate and key files
- Keep API keys secure and rotate them periodically
- Run the script as a user with appropriate privileges
2025-03-03 13:30:15 +01:00
- Temporary files are automatically cleaned up using secure practices
- Certificate and key pairs are validated before installation