certman/README.md

105 lines
3 KiB
Markdown
Raw Normal View History

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 expiration monitoring
2025-02-28 21:48:08 +01:00
- Interactive menu-driven interface
2025-03-03 13:30:15 +01:00
- Force update option for certificate renewals
2025-03-03 12:37:55 +01:00
- Support for multiple certificates
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
2025-05-07 13:04:49 +02:00
1. Clone this repository into `/opt/certman/`:
2025-02-28 21:48:08 +01:00
```bash
2025-05-07 13:04:49 +02:00
git clone https://forge.dmz.skyfritt.net/Skyfritt/certman.git --depth=1 /opt/certman && cd certman
2025-02-28 21:48:08 +01:00
```
2025-05-07 13:04:49 +02:00
2. Rename `example.env` to `.env` and modify as needed:
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
2025-05-07 13:04:49 +02:00
CERT_PATH="/etc/certs"
KEY_PATH="/etc/certs"
2025-03-03 12:37:55 +01:00
TEMP_PATH="/tmp/certman"
2025-05-07 13:04:49 +02:00
FULLCHAIN_PEM="true"
2025-02-28 21:48:08 +01:00
2025-03-03 12:37:55 +01:00
# Service Configuration
2025-05-07 13:04:49 +02:00
SERVICE_NAME="nginx"
CERT_OWNER="www-data"
CERT_GROUP="www-data"
2025-03-03 12:37:55 +01:00
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)
2025-03-03 14:11:49 +01:00
# Add as many or few domains as you need (but remember to add or delete the JSON comma!)
2025-03-03 12:37:55 +01:00
CERTIFICATES='[
{
2025-03-03 14:11:49 +01:00
"domain": "example-one.com",
"cert_api_key": "your_cert_api_key",
"key_api_key": "your_key_api_key"
2025-03-03 12:37:55 +01:00
}
]'
2025-02-28 21:48:08 +01:00
```
2025-03-03 12:37:55 +01:00
## Usage
### Interactive Mode
2025-05-07 13:04:49 +02:00
Run the script without any arguments
2025-03-03 12:37:55 +01:00
```bash
./certman.sh
```
2025-05-07 13:04:49 +02:00
### Cron Configuration
Add these lines to your crontab for automated certificate management:
```cron
@reboot sleep 15 && /path/to/certman.sh --silent
2 2 * * 7 /opt/certman/certman.sh --silent
```
2025-03-03 12:37:55 +01:00
2025-05-07 13:04:49 +02:00
### Silent Mode
Run the script with the `--silent` flag for a silent certificate check. It will use the options set in the `.env` file.
2025-03-03 13:30:15 +01:00
```bash
./certman.sh --silent
```
### Force Update
Use the `--force` flag to force certificate updates regardless of current status:
```bash
./certman.sh --force
```
2025-05-07 13:04:49 +02:00
### Disable fetching fullchain PEM
Use the `--disable-pem` to only fetch the .key and .crt:
```bash
2025-05-07 13:04:49 +02:00
./certman.sh --disable-pem
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 |
2025-05-07 13:04:49 +02:00
| FULLCHAIN_PEM | Enabled by default | No |
2025-03-03 13:30:15 +01:00
| 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 |