Skip to content

Commit 571ba0f

Browse files
committed
Consolidate scripts
1 parent 1f73247 commit 571ba0f

5 files changed

+484
-5
lines changed

Diff for: README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Deploy TLS Certificates to FreeNAS/TrueNAS
2+
This repository contains scripts to automate deployment of a TLS certificate to your FreeNAS (11.1 or newer) or TrueNAS server. Due to a complete overhaul of the API in more recent versions of TrueNAS, this repo contains two different scripts, each with its own README.
3+
4+
* If you're using FreeNAS, or TrueNAS CORE, use `deploy_freenas.py`. [README](README_freenas.md). This will also work with TrueNAS SCALE through 24.10, but as SCALE introduced a websocket API, the other script is recommended.
5+
* If you're using TrueNAS SCALE or Community Edition (as of 25.04), use `deploy_truenas.py`. [README](README_truenas.md)
6+
* I've had no reports of compatibility, pro or con, with any version of TrueNAS Enterprise. I expect the `_freenas` version will work with FreeBSD-based TrueNAS Enterprise installations, while the `_truenas` version will work with Linux-based installations, but I'm afraid you're largely on your own.
7+

Diff for: README_freenas.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# deploy-freenas
2+
3+
deploy_freenas.py is a Python script to deploy TLS certificates to a FreeNAS/TrueNAS (Core) server using the FreeNAS/TrueNAS API. This should ensure that the certificate data is properly stored in the configuration database, and that all appropriate services use this certificate. Its original intent was to be called from a Let's Encrypt client like [acme.sh](https://github.com/Neilpang/acme.sh) after the certificate is issued, so that the entire process of issuance (or renewal) and deployment can be automated. However, it can be used with certificates from any source, whether a different ACME-based certificate authority or otherwise.
4+
5+
Since this script was developed, acme.sh has added a [deployment script](https://github.com/acmesh-official/acme.sh/wiki/deployhooks#25-deploy-the-cert-on-truenas-core-server) which can deploy newly-issued certs to your TrueNAS system, so you may not need this script. However, it isn't clear whether the acme.sh deployment script handles the services covered by this script (S3, FTP, WebDAV, Apps for SCALE).
6+
7+
# Installation
8+
This script can run on any machine running Python 3 that has network access to your FreeNAS/TrueNAS server, but in most cases it's best to run it directly on the FreeNAS/TrueNAS box. Change to a convenient directory and run `git clone https://github.com/danb35/deploy-freenas`.
9+
10+
If you're not running this script on your Free/TrueNAS server itself, you'll need to make sure that the Python `requests` module is available (it's there by default in Free/TrueNAS). How you'll do that will depend on the OS you're using wherever you're running the script.
11+
12+
# Usage
13+
14+
The relevant configuration takes place in the `deploy_config` file. You can create this file either by copying `deploy_config_freenas.example` from this repository, or directly using your preferred text editor. Its format is as follows:
15+
16+
```
17+
[deploy]
18+
password = YourReallySecureRootPassword
19+
cert_fqdn = foo.bar.baz
20+
connect_host = baz.bar.foo
21+
verify = false
22+
privkey_path = /some/other/path
23+
fullchain_path = /some/other/other/path
24+
protocol = https://
25+
port = 443
26+
ui_certificate_enabled = false
27+
s3_enabled = false
28+
ftp_enabled = false
29+
webdav_enabled = false
30+
apps_enabled = false
31+
apps_only_matching_san = false
32+
cert_base_name = letsencrypt
33+
```
34+
35+
Everything but `password` (or `api_key`) is optional, and the defaults are documented in `deploy_config.example`.
36+
37+
On TrueNAS (Core) 12.0 and up you should use API key authentication instead of password authentication.
38+
[Generate a new API token in the UI](https://www.truenas.com/docs/hub/additional-topics/api/#creating-api-keys) first, then add it as `api_key` to the config, which replaces the `password` field:
39+
```
40+
api_key = 1-DXcZ19sZoZFdGATIidJ8vMP6dxk3nHWz3XX876oxS7FospAGMQjkOft0h4itJDSP
41+
```
42+
43+
Once you've prepared `deploy_config`, you can run `deploy_freenas.py`. The intended use is that it would be called by your ACME client after issuing a certificate. With acme.sh, for example, you'd add `--reloadcmd "/path/to/deploy_freenas.py"` to your command.
44+
45+
There is an optional paramter, `-c` or `--config`, that lets you specify the path to your configuration file. By default the script will try to use `deploy_config` in the script working directoy:
46+
47+
```
48+
/path/to/deploy_freenas.py --config /somewhere/else/deploy_config
49+
```

Diff for: README_truenas.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# deploy-freenas
22

3-
deploy-freenas.py is a Python script to deploy TLS certificates to a TrueNAS SCALE server using the TrueNAS Websocket API. This should ensure that the certificate data is properly stored in the configuration database, and that all appropriate services use this certificate. Its original intent was to be called from an ACME client like [acme.sh](https://github.com/acmesh-official/acme.sh) after the certificate is issued, so that the entire process of issuance (or renewal) and deployment can be automated. However, it can be used with certificates from any source, whether a different ACME-based certificate authority or otherwise.
3+
deploy_truenas.py is a Python script to deploy TLS certificates to a TrueNAS SCALE/Community Edition server using the TrueNAS Websocket API. This should ensure that the certificate data is properly stored in the configuration database, and that all appropriate services use this certificate. Its original intent was to be called from an ACME client like [acme.sh](https://github.com/acmesh-official/acme.sh) after the certificate is issued, so that the entire process of issuance (or renewal) and deployment can be automated. However, it can be used with certificates from any source, whether a different ACME-based certificate authority or otherwise.
44

5-
Since this script was developed, acme.sh has added a [deployment script](https://github.com/acmesh-official/acme.sh/wiki/deployhooks#25-deploy-the-cert-on-truenas-core-server) which can deploy newly-issued certs to your TrueNAS system, so you may not need this script. However, it isn't clear whether the acme.sh deployment script handles the services covered by this script (S3, FTP, WebDAV, Apps for SCALE).
5+
Since this script was developed, acme.sh has added a [deployment script](https://github.com/acmesh-official/acme.sh/wiki/deployhooks#25-deploy-the-cert-on-truenas-core-server) which can deploy newly-issued certs to your TrueNAS system, so you may not need this script. However, it isn't clear whether the acme.sh deployment script handles the services covered by this script (S3, FTP, WebDAV, Apps for SCALE). `acme.sh` also has a separate deployment script for the websocket API, but again, its capabilities compared to this one are unknown.
66

77
# WORK IN PROGRESS
88
This version of this script is a work in progress, and has had minimal testing.
@@ -37,7 +37,7 @@ Then clone this repository as described above. Your system should be prepared t
3737

3838
# Usage
3939

40-
The relevant configuration takes place in the `deploy_config` file. You can create this file either by copying `deploy_config.example` from this repository, or directly using your preferred text editor. Its format is as follows:
40+
The relevant configuration takes place in the `deploy_config` file. You can create this file either by copying `deploy_config_truenas.example` from this repository, or directly using your preferred text editor. Its format is as follows:
4141

4242
```
4343
[deploy]
@@ -60,10 +60,10 @@ An API key is required for authentication. [Generate a new API token in the UI]
6060
api_key = 1-DXcZ19sZoZFdGATIidJ8vMP6dxk3nHWz3XX876oxS7FospAGMQjkOft0h4itJDSP
6161
```
6262

63-
Once you've prepared `deploy_config`, you can run `deploy_freenas.py`. The intended use is that it would be called by your ACME client after issuing a certificate. With acme.sh, for example, you'd add `--reloadcmd "/path/to/deploy_freenas.py"` to your command.
63+
Once you've prepared `deploy_config`, you can run `deploy_truenas.py`. The intended use is that it would be called by your ACME client after issuing a certificate. With acme.sh, for example, you'd add `--reloadcmd "/path/to/deploy_truenas.py"` to your command.
6464

6565
There is an optional paramter, `-c` or `--config`, that lets you specify the path to your configuration file. By default the script will try to use `deploy_config` in the script working directoy:
6666

6767
```
68-
/path/to/deploy_freenas.py --config /somewhere/else/deploy_config
68+
/path/to/deploy_truenas.py --config /somewhere/else/deploy_config
6969
```

Diff for: deploy_config_freenas.example

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Configuration file for deploy_freenas.py
2+
3+
[deploy]
4+
# Choose one of the following authentication methods, "api_key" or "password" (comment out the other one).
5+
# Auth via API keys is highly recommended, but is only available from TrueNAS (Core) 12.0 up.
6+
# You can generate a new API key in the web interface under "Settings" (upper right) > "API Keys".
7+
# api_key = YourNewlyGeneratedAPIKey#@#$*
8+
# If you are on FreeNAS 11 or lower, set this to your FreeNAS root password
9+
password = YourSuperSecurePassword#@#$*
10+
11+
# Everything below here is optional
12+
13+
# cert_fqdn specifies the FQDN used for your certificate. Default is your system hostname
14+
# cert_fqdn = foo.bar.baz
15+
16+
# connect_host specifies the hostname the script should attempt to connect to, to deploy the cert.
17+
# Default is localhost (assuming the script is running on your FreeNAS box)
18+
# connect_host = baz.bar.foo
19+
20+
# verify sets whether the script will attempt to verify the server's certificate with a HTTPS
21+
# connection. Set to true if you're using a HTTPS connection to a remote host. If connect_host
22+
# is set to localhost (or is unset), set to false. Default is false.
23+
# verify = false
24+
25+
# privkey_path is the path to the certificate private key on your system. Default
26+
# assumes you're using acme.sh:
27+
# /root/.acme.sh/cert_fqdn/cert_fqdn.key or /root/.acme.sh/cert_fqdn_ecc/cert_fqdn.key
28+
# privkey_path = /some/other/path
29+
30+
# fullchain_path is the path to the full chain (leaf cert + intermediate certs)
31+
# on your system. Default assumes you're using acme.sh:
32+
# /root/.acme.sh/cert_fqdn/fullchain.cer or /root/.acme.sh/cert_fqdn_ecc/fullchain.cer
33+
# fullchain_path = /some/other/other/path
34+
35+
# protocol sets the connection protocol, http or https. Include '://' at the end.
36+
# Default is http
37+
# protocol = https://
38+
39+
# port sets the port to use to connect. Default is 80. If protocol is https,
40+
# this MUST be set to your https port.
41+
# port = 443
42+
43+
# set ui_certificate_enabled to false if you want to skip using the new cerificate for the UI. Default is true.
44+
# ui_certificate_enabled = false
45+
46+
# set s3_enabled to true if you have the S3 service enabled on your FreeNAS. Default is false.
47+
# s3_enabled = true
48+
49+
# set ftp_enabled to true if you have the FTP service enabled on your FreeNAS. Default is false.
50+
# ftp_enabled = true
51+
52+
# set webdav_enabled to true if you have the WEBDAV service enabled on your FreeNAS. Default is false.
53+
# webdav_enabled = true
54+
55+
# set apps_enabled to true if you want to update your TrueNAS SCALE chart applications to use the new certificate. Default is false.
56+
# apps_enabled = true
57+
58+
# only update TrueNAS SCALE chart applications where the san of the current and the new cert matches. Default is false.
59+
#apps_only_matching_san = true
60+
61+
# Certificates will be given a name with a timestamp, by default it will be
62+
# letsencrypt-yyyy-mm-dd-hhmmss. You can change the first part if you like.
63+
# cert_base_name = something_else

0 commit comments

Comments
 (0)