Skip to content

Commit bc59091

Browse files
authored
Merge pull request #11 from danb35/use-config-file
Use config file
2 parents 26d6c3f + 86fcfc3 commit bc59091

File tree

4 files changed

+71
-15
lines changed

4 files changed

+71
-15
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
deploy_config

README.md

+18-7
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,25 @@
22

33
deploy-freenas.py is a Python script to deploy TLS certificates to a FreeNAS server using the FreeNAS API. This should ensure that the certificate data is properly stored in the configuration database, and that all appropriate services use this certificate. It's intended 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.
44

5+
# Installation
6+
This script can run on any machine running Python 3 that has network access to your FreeNAS server, but in most cases it's best to run it directly on the FreeNAS box. Change to a convenient directory and run `git clone https://github.com/danb35/deploy-freenas`.
7+
58
# Usage
69

7-
There are no command-line arguments to deploy-freenas.py; the relevant configuration needs to be made in the script itself. The required changes are mostly self-explanatory, but are as follows:
8-
* PRIVATEKEY_PATH is the path to your TLS private key
9-
* FULLCHAIN_PATH is the path to concatenation of your certificate and the issuer's certificate. With most ACME clients, this file is saved as fullchain.pem or fullchain.cer.
10-
* USER should always be "root"
11-
* PASSWORD needs to be the root password for your FreeNAS server
12-
* DOMAIN_NAME is the FQDN of your FreeNAS server
13-
* PROTOCOL is the protocol used to connect to the API. If your FreeNAS server is configured to use HTTPS with a trusted certificate, it can be set to "https://". Otherwise, set it to "http://".
10+
There are no command-line arguments to deploy-freenas.py; the relevant configuration takes place in the `deploy_config` file. You can create this file either by copying `depoy_config.example` from this repository, or directly using your preferred text editor. Its format is as follows:
11+
12+
```
13+
[deploy]
14+
password = YourReallySecureRootPassword
15+
cert_fqdn = foo.bar.baz
16+
connect_host = baz.bar.foo
17+
verify = false
18+
privkey_path = /some/other/path
19+
fullchain_path = /some/other/other/path
20+
protocol = https://
21+
port = 443
22+
```
1423

24+
Everything but the password is optional, and the defaults are documented in `depoy_config.example`.
1525

26+
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 `--deploy-hook "/path/to/deploy_freenas.py"` to your command.

deploy_config.example

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Configuration file for deploy_freenas.py
2+
3+
[deploy]
4+
# This is the only line that is mandatory
5+
# Set it to your FreeNAS root password
6+
password = YourSuperSecurePassword#@#$*
7+
8+
# Everything below here is optional
9+
10+
# cert_fqdn specifies the FQDN used for your certificate. Default is your system hostname
11+
# cert_fqdn = foo.bar.baz
12+
13+
# connect_host specifies the hostname the script should attempt to connect to, to deploy the cert.
14+
# Default is localhost (assuming the script is running on your FreeNAS box)
15+
# connect_host = baz.bar.foo
16+
17+
# verify sets whether the script will attempt to verify the server's certificate with a HTTPS
18+
# connection. Set to true if you're using a HTTPS connection to a remote host. If connect_host
19+
# is set to localhost (or is unset), set to false. Default is false.
20+
# verify = false
21+
22+
# privkey_path is the path to the certificate private key on your system. Default
23+
# assumes you're using acme.sh:
24+
# /root/.acme.sh/cert_fqdn/cert_fqdn.key
25+
# privkey_path = /some/other/path
26+
27+
# fullchain_path is the path to the full chain (leaf cert + intermediate certs)
28+
# on your system. Default assumes you're using acme.sh:
29+
# /root/.acme.sh/cert_fqdn/fullchain.cer
30+
# fullchain_path = /some/other/other/path
31+
32+
# protocol sets the connection protocol, http or https. Include '://' at the end.
33+
# Default is http
34+
# protocol = https://
35+
36+
# port sets the port to use to connect. Default is 80. If protocol is https,
37+
# this MUST be set to your https port.
38+
# port = 443

deploy_freenas.py

100644100755
+14-8
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,26 @@
1919
import json
2020
import requests
2121
import subprocess
22+
import configparser
23+
import socket
2224
from datetime import datetime
2325
from urllib3.exceptions import InsecureRequestWarning
2426
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
2527

26-
DOMAIN_NAME = "your_fqdn"
27-
PASSWORD = "ReallySecurePassword"
28+
config = configparser.ConfigParser()
29+
config.read('deploy_config')
30+
deploy = config['deploy']
2831

2932
USER = "root"
30-
FREENAS_ADDRESS = "localhost"
31-
VERIFY = False # Or True (Caution! False disables certificate checking)
32-
PRIVATEKEY_PATH = "/root/.acme.sh/" + DOMAIN_NAME + "/" + DOMAIN_NAME + ".key"
33-
FULLCHAIN_PATH = "/root/.acme.sh/" + DOMAIN_NAME + "/fullchain.cer"
34-
PROTOCOL = 'http://'
35-
PORT = '80'
33+
PASSWORD = deploy.get('password')
34+
35+
DOMAIN_NAME = deploy.get('cert_fqdn',socket.gethostname())
36+
FREENAS_ADDRESS = deploy.get('connect_host','localhost')
37+
VERIFY = deploy.getboolean('verify',fallback=False)
38+
PRIVATEKEY_PATH = deploy.get('privkey_path',"/root/.acme.sh/" + DOMAIN_NAME + "/" + DOMAIN_NAME + ".key")
39+
FULLCHAIN_PATH = deploy.get('fullchain_path',"/root/.acme.sh/" + DOMAIN_NAME + "/fullchain.cer")
40+
PROTOCOL = deploy.get('protocol','http://')
41+
PORT = deploy.get('port','80')
3642
now = datetime.now()
3743
cert = "letsencrypt-%s-%s-%s-%s" %(now.year, now.strftime('%m'), now.strftime('%d'), ''.join(c for c in now.strftime('%X') if
3844
c.isdigit()))

0 commit comments

Comments
 (0)