Skip to content

Commit 9d1280c

Browse files
committed
fix(frp): make certificate validity configurable (default 5000 days)
Signed-off-by: Oleksander Piskun <oleksandr2088@icloud.com>
1 parent 067c09f commit 9d1280c

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,11 @@ The FRP client-server connections, i.e. the connection from the above FRP client
399399
}
400400
```
401401

402+
> **Note:** These FRP certificates are valid for `HP_FRP_CERT_VALIDITY_DAYS` days (default `5000`, ~13 years) and are
403+
> not renewed automatically. The FRP connection uses mutual TLS, so once a certificate expires the tunnel stops
404+
> working. To renew them, stop HaRP, delete its `/certs/frp` folder, and start HaRP again, then re-copy `client.crt`,
405+
> `client.key`, and `ca.crt` to each external Docker Engine and restart its `frpc`.
406+
402407
## Adapting ExApps to use HaRP
403408

404409
> We strongly recommend starting support for `HaRP` in ExApps from the start of Nextcloud `32`, as the old `DSP` way will be deprecated and marked for removal in Nextcloud `35`.

start.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ set -e
2121
# - CA key and certificate (ca.key, ca.crt)
2222
# - Server key, CSR, and certificate (server.key, server.csr, server.crt)
2323
# - Client key, CSR, and certificate (client.key, client.csr, client.crt)
24+
# The certificates are valid for HP_FRP_CERT_VALIDITY_DAYS days (default 5000) and are not rotated automatically.
2425
# We do not generate /certs/cert.pem file, as for HaProxy it is admin task to mount generated cert if needed.
2526
# ----------------------------------------------------------------------------
2627

@@ -199,6 +200,23 @@ if [ "${HP_FRP_DISABLE_TLS}" != "true" ]; then
199200
log "INFO: /certs/frp directory created."
200201
log "INFO: Generating self-signed certificates in /certs/frp..."
201202

203+
# Validity (in days) for the self-signed FRP certificates (CA, server and client). Configurable so
204+
# admins who run their own certificate renewal can shorten it. The long default keeps the CA and the
205+
# client certificate - both copied to external Docker engines (see README) - valid for the lifetime
206+
# of a typical deployment, since HaRP does not rotate them automatically.
207+
HP_FRP_CERT_VALIDITY_DAYS="${HP_FRP_CERT_VALIDITY_DAYS:-5000}"
208+
case "$HP_FRP_CERT_VALIDITY_DAYS" in
209+
''|*[!0-9]*)
210+
echo "ERROR: HP_FRP_CERT_VALIDITY_DAYS must be a positive integer number of days, got '$HP_FRP_CERT_VALIDITY_DAYS'."
211+
exit 1
212+
;;
213+
esac
214+
if [ "$HP_FRP_CERT_VALIDITY_DAYS" -lt 1 ]; then
215+
echo "ERROR: HP_FRP_CERT_VALIDITY_DAYS must be a positive integer number of days, got '$HP_FRP_CERT_VALIDITY_DAYS'."
216+
exit 1
217+
fi
218+
log "INFO: FRP certificates will be valid for ${HP_FRP_CERT_VALIDITY_DAYS} days."
219+
202220
# Write OpenSSL configuration for server to /certs/frp/server-openssl.cnf.
203221
cat > /certs/frp/server-openssl.cnf <<EOF
204222
[ req ]
@@ -217,15 +235,15 @@ EOF
217235

218236
# Generate CA key and certificate.
219237
openssl genrsa -out /certs/frp/ca.key 2048
220-
openssl req -x509 -new -nodes -key /certs/frp/ca.key -subj "/CN=harp.nc" -days 5000 -out /certs/frp/ca.crt
238+
openssl req -x509 -new -nodes -key /certs/frp/ca.key -subj "/CN=harp.nc" -days "$HP_FRP_CERT_VALIDITY_DAYS" -out /certs/frp/ca.crt
221239

222240
# Generate server key and CSR.
223241
openssl genrsa -out /certs/frp/server.key 2048
224242
openssl req -new -sha256 -key /certs/frp/server.key -subj "/CN=harp.nc" \
225243
-reqexts req_ext -config /certs/frp/server-openssl.cnf -out /certs/frp/server.csr
226244

227245
# Sign the server certificate with the CA.
228-
openssl x509 -req -days 365 -sha256 -in /certs/frp/server.csr \
246+
openssl x509 -req -days "$HP_FRP_CERT_VALIDITY_DAYS" -sha256 -in /certs/frp/server.csr \
229247
-CA /certs/frp/ca.crt -CAkey /certs/frp/ca.key -CAcreateserial \
230248
-extfile /certs/frp/server-openssl.cnf -extensions req_ext -out /certs/frp/server.crt
231249

@@ -252,7 +270,7 @@ EOF
252270
openssl req -new -sha256 -key /certs/frp/client.key -subj "/CN=harp.client.nc" \
253271
-config /certs/frp/client-openssl.cnf -out /certs/frp/client.csr
254272

255-
openssl x509 -req -days 365 -sha256 -in /certs/frp/client.csr \
273+
openssl x509 -req -days "$HP_FRP_CERT_VALIDITY_DAYS" -sha256 -in /certs/frp/client.csr \
256274
-CA /certs/frp/ca.crt -CAkey /certs/frp/ca.key -CAcreateserial \
257275
-extfile /certs/frp/client-openssl.cnf -extensions req_ext -out /certs/frp/client.crt
258276

0 commit comments

Comments
 (0)