1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
5 {%- set curr_tpldir = tpldir %}
6 {%- set tpldir = 'arvados' %}
7 {%- from "arvados/map.jinja" import arvados with context %}
8 {%- set tpldir = curr_tpldir %}
10 {%- set orig_cert_dir = salt['pillar.get']('extra_custom_certs_dir', '/srv/salt/certs') %}
17 # Debian uses different dirs for certs and keys, but being a Snake Oil example,
18 # we'll keep it simple here.
19 {%- set arvados_ca_cert_file = '/etc/ssl/private/arvados-snakeoil-ca.pem' %}
20 {%- set arvados_ca_key_file = '/etc/ssl/private/arvados-snakeoil-ca.key' %}
22 {%- if grains.get('os_family') == 'Debian' %}
23 {%- set arvados_ca_cert_dest = '/usr/local/share/ca-certificates/arvados-snakeoil-ca.crt' %}
24 {%- set update_ca_cert = '/usr/sbin/update-ca-certificates' %}
25 {%- set openssl_conf = '/etc/ssl/openssl.cnf' %}
27 extra_snakeoil_certs_ssl_cert_pkg_installed:
34 {%- set arvados_ca_cert_dest = '/etc/pki/ca-trust/source/anchors/arvados-snakeoil-ca.pem' %}
35 {%- set update_ca_cert = '/usr/bin/update-ca-trust' %}
36 {%- set openssl_conf = '/etc/pki/tls/openssl.cnf' %}
40 extra_snakeoil_certs_dependencies_pkg_installed:
46 # Remove the RANDFILE parameter in openssl.cnf as it makes openssl fail in Ubuntu 18.04
47 # Saving and restoring the rng state is not necessary anymore in the openssl 1.1.1
48 # random generator, cf
49 # https://github.com/openssl/openssl/issues/7754
51 extra_snakeoil_certs_file_comment_etc_openssl_conf:
53 - name: /etc/ssl/openssl.cnf
55 - onlyif: grep -q ^RANDFILE /etc/ssl/openssl.cnf
57 - cmd: extra_snakeoil_certs_arvados_snakeoil_ca_cmd_run
59 extra_snakeoil_certs_arvados_snakeoil_ca_cmd_run:
60 # Taken from https://github.com/arvados/arvados/blob/master/tools/arvbox/lib/arvbox/docker/service/certificate/run
63 # These dirs are not too CentOS-ish, but this is a helper script
64 # and they should be enough
65 /bin/bash -c "mkdir -p /etc/ssl/certs/ /etc/ssl/private/ && \
71 -subj \"/C=CC/ST=Some State/O=Arvados Formula/OU=arvados-formula/CN=snakeoil-ca-{{ arvados.cluster.name }}.{{ arvados.cluster.domain }}\" \
72 -extensions x509_ext \
73 -config <(cat {{ openssl_conf }} \
74 <(printf \"\n[x509_ext]\nbasicConstraints=critical,CA:true,pathlen:0\nkeyUsage=critical,keyCertSign,cRLSign\")) \
75 -out {{ arvados_ca_cert_file }} \
76 -keyout {{ arvados_ca_key_file }} \
78 cp {{ arvados_ca_cert_file }} {{ arvados_ca_cert_dest }} && \
81 - test -f {{ arvados_ca_cert_file }}
82 - openssl verify -CAfile {{ arvados_ca_cert_file }} {{ arvados_ca_cert_file }}
84 - pkg: extra_snakeoil_certs_dependencies_pkg_installed
86 {%- set arvados_cert_file = orig_cert_dir ~ '/arvados-__HOSTNAME_EXT__.pem' %}
87 {%- set arvados_csr_file = orig_cert_dir ~ '/arvadoos-__HOSTNAME_EXT__.csr' %}
88 {%- set arvados_key_file = orig_cert_dir ~ '/arvados-__HOSTNAME_EXT__.key' %}
90 extra_snakeoil_certs_arvados_snakeoil_cert___HOSTNAME_EXT___cmd_run:
93 cat > /tmp/__HOSTNAME_EXT__.openssl.cnf <<-CNF
98 distinguished_name = dn
101 subjectAltName = @alt_names
106 O = Arvados Provision Example Single Host / Single Hostname
107 OU = arvados-provision-example-single_host_single_hostname
108 CN = {{ arvados.cluster.name }}.{{ arvados.cluster.domain }}
109 emailAddress = admin@{{ arvados.cluster.name }}.{{ arvados.cluster.domain }}
111 {%- for entry in grains.get('ipv4') %}
112 IP.{{ loop.index }} = {{ entry }}
114 DNS.1 = {{ arvados.cluster.name }}.{{ arvados.cluster.domain }}
115 DNS.2 = '__HOSTNAME_EXT__'
120 -config /tmp/__HOSTNAME_EXT__.openssl.cnf \
124 -out {{ arvados_csr_file }} \
125 -keyout {{ arvados_key_file }} > /tmp/snake_oil_certs.__HOSTNAME_EXT__.output 2>&1 && \
130 -in {{ arvados_csr_file }} \
131 -out {{ arvados_cert_file }} \
132 -extfile /tmp/__HOSTNAME_EXT__.openssl.cnf \
134 -CA {{ arvados_ca_cert_file }} \
135 -CAkey {{ arvados_ca_key_file }} \
136 -set_serial $(date +%s) && \
137 chmod 0644 {{ arvados_cert_file }} && \
138 chmod 0640 {{ arvados_key_file }}
140 - test -f {{ arvados_key_file }}
141 - openssl verify -CAfile {{ arvados_ca_cert_file }} {{ arvados_cert_file }}
143 - pkg: extra_snakeoil_certs_dependencies_pkg_installed
144 - cmd: extra_snakeoil_certs_arvados_snakeoil_ca_cmd_run
146 - file: extra_custom_certs___HOSTNAME_EXT___cert_file_copy
147 - file: extra_custom_certs___HOSTNAME_EXT___key_file_copy
149 {%- if grains.get('os_family') == 'Debian' %}
150 extra_snakeoil_certs_certs_permissions___HOSTNAME_EXT___cmd_run:
152 - name: {{ arvados_key_file }}
156 - cmd: extra_snakeoil_certs_arvados_snakeoil_cert___HOSTNAME_EXT___cmd_run
157 - pkg: extra_snakeoil_certs_ssl_cert_pkg_installed