summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Camera <cdist@dtnr.ch>2021-03-17 18:06:00 +0100
committerDennis Camera <cdist@dtnr.ch>2021-03-17 18:19:20 +0100
commit828c7cb5cb82f2bb058f57f90745bc5c4659e0b3 (patch)
treec790370837c6b9186c808e754020f442a89b830d
parent1951e0535a7266b0035297e1aa53000b69a01499 (diff)
download__dtnrch_getssl-828c7cb5cb82f2bb058f57f90745bc5c4659e0b3.tar.gz
__dtnrch_getssl-828c7cb5cb82f2bb058f57f90745bc5c4659e0b3.zip
[type/__dtnrch_getssl_cert] Implement functionality
-rw-r--r--type/__dtnrch_getssl/files/update_getssl_cfg.awk2
-rw-r--r--type/__dtnrch_getssl/man.rst2
-rwxr-xr-xtype/__dtnrch_getssl_cert/gencode-remote117
-rw-r--r--type/__dtnrch_getssl_cert/man.rst70
-rwxr-xr-xtype/__dtnrch_getssl_cert/manifest9
-rw-r--r--type/__dtnrch_getssl_cert/parameter/boolean1
-rw-r--r--type/__dtnrch_getssl_cert/parameter/default/server-type1
-rw-r--r--type/__dtnrch_getssl_cert/parameter/default/state1
-rw-r--r--type/__dtnrch_getssl_cert/parameter/optional8
-rw-r--r--type/__dtnrch_getssl_cert/parameter/optional_multiple2
10 files changed, 207 insertions, 6 deletions
diff --git a/type/__dtnrch_getssl/files/update_getssl_cfg.awk b/type/__dtnrch_getssl/files/update_getssl_cfg.awk
index 8b79639..a42f066 100644
--- a/type/__dtnrch_getssl/files/update_getssl_cfg.awk
+++ b/type/__dtnrch_getssl/files/update_getssl_cfg.awk
@@ -1,5 +1,7 @@
#!/usr/bin/awk -f
+# FIXME: This script does not handle multi-line options, e.g. bash arrays.
+
BEGIN {
FS = RS
diff --git a/type/__dtnrch_getssl/man.rst b/type/__dtnrch_getssl/man.rst
index 624c264..e9c52ef 100644
--- a/type/__dtnrch_getssl/man.rst
+++ b/type/__dtnrch_getssl/man.rst
@@ -3,7 +3,7 @@ cdist-type__dtnrch_getssl(7)
NAME
----
-cdist-type__dtnrch_getssl - Set up getssl.
+cdist-type__dtnrch_getssl - Set up GetSSL.
DESCRIPTION
diff --git a/type/__dtnrch_getssl_cert/gencode-remote b/type/__dtnrch_getssl_cert/gencode-remote
index a725ffa..f49ea8d 100755
--- a/type/__dtnrch_getssl_cert/gencode-remote
+++ b/type/__dtnrch_getssl_cert/gencode-remote
@@ -18,3 +18,120 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
+quote() { printf "'%s'" "$(printf '%s' "$*" | sed -e "s/'/'\\\\''/g")"; }
+drop_awk_comments() { quote "$(sed '/^[[:blank:]]*#.*$/d;/^$/d' "$@")"; }
+
+CONF_DIR=/etc/getssl
+
+domain=${__object_id:?}
+getssl_cfg=${CONF_DIR}/${domain}/getssl.cfg
+
+state_should=$(cat "${__object:?}/parameter/state")
+test "${state_should}" != 'absent' || exit 0 # removed in manifest
+
+################################################################################
+# Create getssl.cfg
+
+test -s "${__object:?}/explorer/cfg-values" || {
+ printf 'getssl -w %s -c %s\n' "$(quote "${CONF_DIR}")" "${domain}"
+}
+
+
+################################################################################
+# Update getssl.cfg
+
+cfg_values_should=$(
+ # CA
+ if test -s "${__object:?}/parameter/ca"
+ then
+ printf 'CA="%s"\n' "$(head -n1 "${__object:?}/parameter/ca")"
+ fi
+
+ # ACLs
+ if test -s "${__object:?}/parameter/acl"
+ then
+ if test "$(wc -l "${__object:?}/parameter/acl" | cut -d' ' -f1)" -eq 1
+ then
+ # only one ACL
+ printf "ACL=('%s')\nUSE_SINGLE_ACL=true\n" \
+ "$(cat "${__object:?}/parameter/acl")"
+ else
+ sed -e :a -e "\$!N;s/\n/','/" -e ta -e "s/.*/ACL=('&')/" \
+ "${__object:?}/parameter/acl"
+ fi
+ fi
+
+ # SANs
+ if test -s "${__object:?}/parameter/san"
+ then
+ sed -e :a -e '$!N;s/\n/,/' -e ta -e 's/.*/SANS="&"/' \
+ "${__object:?}/parameter/san"
+ fi
+
+ # File locations
+ if test -s "${__object:?}/parameter/cert-loc"
+ then
+ printf 'DOMAIN_CERT_LOCATION="%s"\n' "$(head -n1 "${__object:?}/parameter/cert-loc")"
+ fi
+ if test -s "${__object:?}/parameter/key-loc"
+ then
+ printf 'DOMAIN_KEY_LOCATION="%s"\n' "$(head -n1 "${__object:?}/parameter/key-loc")"
+ fi
+ if test -s "${__object:?}/parameter/ca-loc"
+ then
+ printf 'CA_CERT_LOCATION="%s"\n' "$(head -n1 "${__object:?}/parameter/ca-loc")"
+ fi
+ if test -s "${__object:?}/parameter/chain-loc"
+ then
+ printf 'DOMAIN_CHAIN_LOCATION="%s"\n' "$(head -n1 "${__object:?}/parameter/chain-loc")"
+ fi
+ if test -s "${__object:?}/parameter/pem-loc"
+ then
+ printf 'DOMAIN_PEM_LOCATION="%s"\n' "$(head -n1 "${__object:?}/parameter/pem-loc")"
+ fi
+
+ # Reload command
+ if test -s "${__object:?}/parameter/reload-cmd"
+ then
+ printf 'RELOAD_CMD="%s"\n' "$(head -n1 "${__object:?}/parameter/reload-cmd")"
+ fi
+
+ # Certificate check
+ if ! test -f "${__object:?}/parameter/no-check-remote"
+ then
+ printf 'CHECK_REMOTE=true\n'
+ else
+ printf 'CHECK_REMOTE=false\n'
+ fi
+ if test -s "${__object:?}/parameter/server-type"
+ then
+ printf 'SERVER_TYPE="%s"\n' "$(head -n1 "${__object:?}/parameter/server-type")"
+ fi
+
+ if test -s "${__object:?}/parameter/extra-config"
+ then
+ sort "${__object:?}/parameter/extra-config"
+ fi
+)
+
+if ! printf '%s\n' "${cfg_values_should}" | cmp -s "${__object:?}/explorer/cfg-values" -
+then
+ cat <<CODE
+post_update() {
+ if ! cmp -s $(quote "${getssl_cfg}") $(quote "${getssl_cfg}.tmp")
+ then
+ # config has changed
+ cat $(quote "${getssl_cfg}.tmp") >$(quote "${getssl_cfg}")
+ rm -f $(quote "${getssl_cfg}.tmp")
+
+ getssl ${__object_id:?}
+ else
+ rm -f $(quote "${getssl_cfg}.tmp")
+ fi
+}
+awk $(drop_awk_comments "${__type:?}/files/update_getssl_cfg.awk") <<'EOF' $(quote "${getssl_cfg}") >$(quote "${getssl_cfg}.tmp") \\
+ && post_update || exit
+${cfg_values_should}
+EOF
+CODE
+fi
diff --git a/type/__dtnrch_getssl_cert/man.rst b/type/__dtnrch_getssl_cert/man.rst
index 1117783..5b5742a 100644
--- a/type/__dtnrch_getssl_cert/man.rst
+++ b/type/__dtnrch_getssl_cert/man.rst
@@ -3,7 +3,7 @@ cdist-type__dtnrch_getssl_cert(7)
NAME
----
-cdist-type__dtnrch_getssl_cert - TODO
+cdist-type__dtnrch_getssl_cert - Manage an SSL certficiate using GetSSL.
DESCRIPTION
@@ -18,12 +18,72 @@ None.
OPTIONAL PARAMETERS
-------------------
-None.
+acl
+ "ACME Challenge Location"
+
+ The ACME Challenge Location for the domain and each SAN.
+ Can be used multiple times, to specify different ACLs for each of the SANs.
+ If used only once, the same ACL will be used for all domains.
+
+ cf. https://github.com/srvrco/getssl/wiki/Config-variables#acl
+ca
+ The URL of the ACME CA to use.
+
+ Will use the CA specified in the global configuration, by default.
+ca-loc
+ Location to copy the signed ``ca.crt`` to.
+cert-loc
+ Location to copy the signed ``domain.crt`` to.
+chain-loc
+ Location to copy the signed ``chain.crt`` to.
+
+ This is a single file containing both the domain certificate and the CA
+ certificate concatenated.
+key-loc
+ Location to copy the signed ``domain.key`` to.
+pem-loc
+ Location to copy the ``domain.pem`` to.
+
+ This is a single file with all three certificates in it.
+extra-config
+ Other configuration options that should be added to the domain
+ ``getssl.cfg``.
+reload-cmd
+ The command to be executed once a certificate has been issued and copied to
+ the ``--*-loc`` locations.
+
+ Typically, this would be something like ``/etc/init.d/httpd reload``.
+
+ | Commands can also be executed on a remote server, e.g.
+ | ``ssh:www@other-server.example.com:/etc/init.d/httpd reload``
+san
+ Subject Alternate Name.
+
+ The default is blank.
+ Can be any alternate domain you want on the same certificate, e.g. ``www.${__object_id}``.
+ This parameter can be used multiple times to add multiple alternate domains.
+
+ The primary domain ``${__object_id}`` should not be include in the SAN list.
+server-type
+ Determines the server type that GetSSL will check to determine if the
+ certificate was installed correctly.
+
+ cf. https://github.com/srvrco/getssl/wiki/Config-variables#server_typehttps
+state
+ One of:
+
+ present
+ the certficate should be created and requested
+ absent
+ | the certificate configuration should be removed from GetSSL.
+ | NB: certificates copied to ``--*-loc`` will not be removed.
BOOLEAN PARAMETERS
------------------
-None.
+no-check-remote
+ Do not check the remote server for correct installation of the certificate
+ (based on ``--server-type``.
EXAMPLES
@@ -31,8 +91,8 @@ EXAMPLES
.. code-block:: sh
- # TODO
- __dtnrch_getssl_cert
+ # Get an SSL certficate for example.com
+ __dtnrch_getssl_cert example.com
SEE ALSO
diff --git a/type/__dtnrch_getssl_cert/manifest b/type/__dtnrch_getssl_cert/manifest
index 6a7d9fd..3b2bd7a 100755
--- a/type/__dtnrch_getssl_cert/manifest
+++ b/type/__dtnrch_getssl_cert/manifest
@@ -17,3 +17,12 @@
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
+
+CONF_DIR=/etc/getssl
+
+domain=${__object_id:?}
+state_should=$(cat "${__object:?}/parameter/state")
+
+test "${state_should}" = absent || export require=__dtnrch_getssl/
+
+__directory "${CONF_DIR}/${domain}" --state "${state_should}"
diff --git a/type/__dtnrch_getssl_cert/parameter/boolean b/type/__dtnrch_getssl_cert/parameter/boolean
new file mode 100644
index 0000000..02faccf
--- /dev/null
+++ b/type/__dtnrch_getssl_cert/parameter/boolean
@@ -0,0 +1 @@
+no-check-remote
diff --git a/type/__dtnrch_getssl_cert/parameter/default/server-type b/type/__dtnrch_getssl_cert/parameter/default/server-type
new file mode 100644
index 0000000..908a0a5
--- /dev/null
+++ b/type/__dtnrch_getssl_cert/parameter/default/server-type
@@ -0,0 +1 @@
+https
diff --git a/type/__dtnrch_getssl_cert/parameter/default/state b/type/__dtnrch_getssl_cert/parameter/default/state
new file mode 100644
index 0000000..e7f6134
--- /dev/null
+++ b/type/__dtnrch_getssl_cert/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/type/__dtnrch_getssl_cert/parameter/optional b/type/__dtnrch_getssl_cert/parameter/optional
new file mode 100644
index 0000000..b679cd5
--- /dev/null
+++ b/type/__dtnrch_getssl_cert/parameter/optional
@@ -0,0 +1,8 @@
+ca-loc
+cert-loc
+chain-loc
+key-loc
+pem-loc
+reload-cmd
+server-type
+state
diff --git a/type/__dtnrch_getssl_cert/parameter/optional_multiple b/type/__dtnrch_getssl_cert/parameter/optional_multiple
new file mode 100644
index 0000000..e0c15c8
--- /dev/null
+++ b/type/__dtnrch_getssl_cert/parameter/optional_multiple
@@ -0,0 +1,2 @@
+san
+acl