This commit is contained in:
Mateusz Gruszczyński committed 2026-11-14 17:24:12 +01:00
1 parent 78dbb31487
commit f48843e934
83 files changed
+7304 -1203

No files matched your search

+110 -85
View File
@@ -1,109 +1,134 @@
# OPNsense os-acme-client -> RustProxy
A simple mechanism for automatically sending a certificate generated by `os-acme-client` on OPNsense to RustProxy via API.
Deploys certificates issued by the OPNsense **os-acme-client** plugin (Services -> ACME Client) to RustProxy through `POST /api/certificates/deploy`. The script runs as an ACME Client **automation** ("System or Plugin Command"), so every issued or renewed certificate is sent to RustProxy right away. Works with RustProxy 0.28.2 or newer; error hints match RustProxy 0.37.
## Files
- `opnsense-rustproxy-cert-deploy.sh` - sends the certificate and private key to RustProxy.
- `rustproxy-acme.conf.example` - example connection settings, API token, and certificate file paths.
- `actions_rustproxy_cert.conf` - optional `configd` action that allows the script to be executed from Cron in OPNsense.
- `opnsense-rustproxy-cert-deploy.sh` - finds the os-acme-client certificates, checks them and uploads them.
- `rustproxy-acme.conf.example` - RustProxy URL, certificate API credential and the certificate mapping.
- `actions_rustproxy_cert.conf` - `configd` action **Deploy certificates to RustProxy**, offered by the ACME Client automation and by Cron.
## 1. Installation
## 1. RustProxy credential
In RustProxy open **Settings -> Certificate API** and create (or edit) a key:
- **Allowed certificate IDs**: every RustProxy certificate id used below (the right side of `RUSTPROXY_CERTIFICATES`), one per line. `*` is not accepted; a key migrated from an older version with `*` must get the explicit list when it is edited. The ids do not have to exist yet: the first deploy creates them.
- **Also allow deploy**: enabled. Keys created before 0.28.2 were migrated as reload-only and get `HTTP 403 certificate_api.deploy_forbidden`.
Copy the key id and the token (the token is shown only once; regenerate it if lost).
## 2. Installation (OPNsense root shell, SSH or console option 8)
```sh
cp opnsense-rustproxy-cert-deploy.sh /usr/local/sbin/
cat > /usr/local/sbin/opnsense-rustproxy-cert-deploy.sh <<'RUSTPROXY_EOF'
<paste the content of opnsense-rustproxy-cert-deploy.sh>
RUSTPROXY_EOF
chmod 750 /usr/local/sbin/opnsense-rustproxy-cert-deploy.sh
cp rustproxy-acme.conf.example /usr/local/etc/rustproxy-acme.conf
cat > /usr/local/etc/rustproxy-acme.conf <<'RUSTPROXY_EOF'
<paste rustproxy-acme.conf.example and fill in the values>
RUSTPROXY_EOF
chmod 600 /usr/local/etc/rustproxy-acme.conf
```
## 2. Configuration
Edit:
```sh
vi /usr/local/etc/rustproxy-acme.conf
```
Important parameters:
```sh
RUSTPROXY_URL='https://127.0.0.1:9090'
RUSTPROXY_KEY_ID='opnsense-acme'
RUSTPROXY_TOKEN='RUSTPROXY_TOKEN'
CERTIFICATE_ID='shared-cert'
CERT_FILE='/var/etc/acme-client/certs/CERT_UUID/fullchain.pem'
KEY_FILE='/var/etc/acme-client/keys/CERT_UUID/private.key'
```
If `os-acme-client` exports the certificate to a custom directory, simply set the correct paths:
```sh
CERT_FILE='/path/to/fullchain.pem'
KEY_FILE='/path/to/private.key'
```
`CERTIFICATE_ID` is the stable external certificate id. If it does not exist, RustProxy creates a manual certificate entry. If it already exists as a manual certificate, RustProxy rotates it in place. RustProxy-managed ACME ids are rejected to prevent two renewal owners for one lineage.
## 3. RustProxy API
Create a certificate API key in **Settings -> Certificate API** and enter its values in the configuration:
```text
RUSTPROXY_KEY_ID
RUSTPROXY_TOKEN
```
The credential must explicitly allow `CERTIFICATE_ID` and **Also allow deploy** (`allow_deploy`) must be enabled. A reload-only credential will be rejected with HTTP 403.
The script sends the certificate to:
```text
POST /api/certificates/deploy
```
The connection from OPNsense to RustProxy should use HTTPS.
## 4. Test
Run the certificate reconciliation:
```sh
/usr/local/sbin/opnsense-rustproxy-cert-deploy.sh
```
On success, you should see a message similar to:
```text
RustProxy certificate reconcile succeeded (HTTP 200, id=shared-cert)
```
## 5. OPNsense Automation
Optionally install the `configd` action:
```sh
cp actions_rustproxy_cert.conf /usr/local/opnsense/service/conf/actions.d/
cat > /usr/local/opnsense/service/conf/actions.d/actions_rustproxy_cert.conf <<'RUSTPROXY_EOF'
<paste the content of actions_rustproxy_cert.conf>
RUSTPROXY_EOF
service configd restart
```
Verify the action first with `configctl rustproxy_cert deploy`. Then go to **System -> Settings -> Cron** and add a scheduled execution of the `Deploy ACME certificate to RustProxy` action.
Alternatively copy the three files with `scp`.
The script deliberately reconciles on every run instead of trusting a local cache. The server is the source of truth: an identical RustProxy-owned certificate generation is a no-op, a missing id is created, and changed material is rotated atomically. This also repairs drift when a certificate entry or generation was removed outside OPNsense.
## 3. Which certificates are sent
## Additional Options
If RustProxy uses a private CA:
os-acme-client keeps the files in `/var/etc/acme-client/certs/<id>/fullchain.pem` and `/var/etc/acme-client/keys/<id>/private.key`. The `<id>` is an internal id that the GUI does not show, so the script finds the certificate by **name** (the *Common Name* or any *Alt Name* of the ACME certificate):
```sh
RUSTPROXY_CACERT='/usr/local/etc/ssl/rustproxy-ca.pem'
/usr/local/sbin/opnsense-rustproxy-cert-deploy.sh --list
```
If you want to connect to a specific LAN address while keeping proper TLS hostname verification:
```text
66a1b2c3d4e5f *.apps.example.com apps.example.com (valid until Dec 14 13:43:31 2026 GMT)
```
Map each name to a RustProxy certificate id (`A-Z a-z 0-9 _ -`, max 64), separated by spaces:
```sh
RUSTPROXY_RESOLVE='rustproxy.lan:8443:192.168.1.20'
RUSTPROXY_CERTIFICATES='*.apps.example.com=apps-wildcard example.com=example-com'
```
Every run sends all mapped certificates. A certificate that did not change is a no-op in RustProxy, a missing id is created as a manual certificate and changed material is rotated atomically. RustProxy-managed ACME ids are rejected (409). When several ACME certificates carry the same name, the one valid longest is used.
A single certificate can also be set with `CERTIFICATE_ID` plus `ACME_CERT_NAME`, or with explicit `CERT_FILE` and `KEY_FILE`.
## 4. Connection settings
| Setting | Meaning |
|---|---|
| `RUSTPROXY_URL` | Panel origin only: `https://name:port` (no path). |
| `RUSTPROXY_KEY_ID`, `RUSTPROXY_TOKEN` | Certificate API credential. |
| `RUSTPROXY_TLS_VERIFY` | `yes` (default) verifies the panel certificate; `no` accepts a self-signed or not yet valid panel certificate. |
| `RUSTPROXY_CACERT` | PEM file of a private CA that signed the panel certificate (keeps verification on). |
| `RUSTPROXY_PINNED_PUBKEY` | `sha256//BASE64` pin of the panel key. Recommended together with `RUSTPROXY_TLS_VERIFY='no'`. |
| `RUSTPROXY_RESOLVE` | `name:port:address` - connect to a fixed IP while using the panel name for TLS and the Host header. |
| `RUSTPROXY_ALLOW_HTTP` | `yes` allows `http://` to a remote host. Only for a trusted reverse proxy that terminates HTTPS in front of RustProxy; otherwise RustProxy answers `403 certificate_api.https_required`. `http://127.0.0.1` always works. |
### Panel without a valid certificate
Pin of a self-signed panel certificate (recommended):
```sh
echo | openssl s_client -connect rustproxy.lan:9090 -servername rustproxy.lan 2>/dev/null \
| openssl x509 -pubkey -noout | openssl pkey -pubin -outform DER \
| openssl dgst -sha256 -binary | openssl enc -base64
```
```sh
RUSTPROXY_TLS_VERIFY='no'
RUSTPROXY_PINNED_PUBKEY='sha256//<output of the command above>'
```
Without the pin only `RUSTPROXY_TLS_VERIFY='no'` is needed; the script then logs a warning on every run.
### Host name
RustProxy accepts only the host names listed in **Settings -> Administration** (public panel HTTPS origin and additional allowed DNS hostnames) or an IP literal. Another DNS name gives `403 auth.invalid_host`. When the panel name does not resolve on OPNsense, keep the name in `RUSTPROXY_URL` and add `RUSTPROXY_RESOLVE='name:port:IP'`.
## 5. Test
```sh
/usr/local/sbin/opnsense-rustproxy-cert-deploy.sh --check
configctl rustproxy_cert deploy
```
`--check` finds the mapped certificates and validates key match and expiry without contacting RustProxy. `configctl` runs exactly what the automation runs. A successful upload prints:
```text
RustProxy certificate reconcile succeeded (HTTP 200, id=apps-wildcard)
```
Every run is also written to the system log (tag `rustproxy-acme`, **System -> Log Files -> General**).
## 6. ACME Client automation
1. **Services -> ACME Client -> Automations -> +**: *Run Command* = **System or Plugin Command**, *System Command* = **Deploy certificates to RustProxy**, give it a name and save.
2. **Services -> ACME Client -> Certificates**: edit each mapped certificate and add the automation under **Automations**.
3. Click **Run automations** (paper plane icon) on the certificate to test it.
From now on the deploy runs after every issue or renewal. The ACME Client log shows `running automation (configd)`, the result is in the system log.
Optionally also schedule **Deploy certificates to RustProxy** in **System -> Settings -> Cron** (for example daily) to repair drift when a certificate was changed or removed on the RustProxy side.
## Errors
On failure the script prints the HTTP status, the RustProxy error code and a hint.
| Response | Cause |
|---|---|
| `403 certificate_api.deploy_forbidden` | Key is reload-only: enable **Also allow deploy**. |
| `403 certificate_api.certificate_forbidden` | Key does not include that certificate id. |
| `403 certificate_api.https_required` | `http://` used from a non-loopback address. |
| `403 auth.invalid_host` | Host name in `RUSTPROXY_URL` is not allowed by the panel. |
| `403 auth.invalid_origin` | Scheme/host does not match the pinned public panel origin or trusted proxy settings. |
| `401 certificate_api.invalid_token` | Wrong key id or token, or the token was regenerated. |
| `409` | The id belongs to a RustProxy-managed ACME certificate. |
| `no os-acme-client certificate for NAME` | Name not found: compare with `--list`. |