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 extra_snakeoil_certs_arvados_snakeoil_ca_cmd_run:
47 # Taken from https://github.com/arvados/arvados/blob/master/tools/arvbox/lib/arvbox/docker/service/certificate/run
50 # These dirs are not too CentOS-ish, but this is a helper script
51 # and they should be enough
52 /bin/bash -c "mkdir -p /etc/ssl/certs/ /etc/ssl/private/ && \
58 -subj \"/C=CC/ST=Some State/O=Arvados Formula/OU=arvados-formula/CN=snakeoil-ca-{{ arvados.cluster.name }}.{{ arvados.cluster.domain }}\" \
59 -extensions x509_ext \
60 -config <(cat {{ openssl_conf }} \
61 <(printf \"\n[x509_ext]\nbasicConstraints=critical,CA:true,pathlen:0\nkeyUsage=critical,keyCertSign,cRLSign\")) \
62 -out {{ arvados_ca_cert_file }} \
63 -keyout {{ arvados_ca_key_file }} \
65 cp {{ arvados_ca_cert_file }} {{ arvados_ca_cert_dest }} && \
68 - test -f {{ arvados_ca_cert_file }}
69 - openssl verify -CAfile {{ arvados_ca_cert_file }} {{ arvados_ca_cert_file }}
71 - pkg: extra_snakeoil_certs_dependencies_pkg_installed
73 {%- set arvados_cert_file = orig_cert_dir ~ '/arvados-__HOSTNAME_EXT__.pem' %}
74 {%- set arvados_csr_file = orig_cert_dir ~ '/arvadoos-__HOSTNAME_EXT__.csr' %}
75 {%- set arvados_key_file = orig_cert_dir ~ '/arvados-__HOSTNAME_EXT__.key' %}
77 extra_snakeoil_certs_arvados_snakeoil_cert___HOSTNAME_EXT___cmd_run:
80 cat > /tmp/__HOSTNAME_EXT__.openssl.cnf <<-CNF
85 distinguished_name = dn
88 subjectAltName = @alt_names
93 O = Arvados Provision Example Single Host / Single Hostname
94 OU = arvados-provision-example-single_host_single_hostname
95 CN = {{ arvados.cluster.name }}.{{ arvados.cluster.domain }}
96 emailAddress = admin@{{ arvados.cluster.name }}.{{ arvados.cluster.domain }}
98 {%- for entry in grains.get('ipv4') %}
99 IP.{{ loop.index }} = {{ entry }}
101 DNS.1 = {{ arvados.cluster.name }}.{{ arvados.cluster.domain }}
102 DNS.2 = '__HOSTNAME_EXT__'
107 -config /tmp/__HOSTNAME_EXT__.openssl.cnf \
111 -out {{ arvados_csr_file }} \
112 -keyout {{ arvados_key_file }} > /tmp/snake_oil_certs.__HOSTNAME_EXT__.output 2>&1 && \
117 -in {{ arvados_csr_file }} \
118 -out {{ arvados_cert_file }} \
119 -extfile /tmp/__HOSTNAME_EXT__.openssl.cnf \
121 -CA {{ arvados_ca_cert_file }} \
122 -CAkey {{ arvados_ca_key_file }} \
123 -set_serial $(date +%s) && \
124 chmod 0644 {{ arvados_cert_file }} && \
125 chmod 0640 {{ arvados_key_file }}
127 - test -f {{ arvados_key_file }}
128 - openssl verify -CAfile {{ arvados_ca_cert_file }} {{ arvados_cert_file }}
130 - pkg: extra_snakeoil_certs_dependencies_pkg_installed
131 - cmd: extra_snakeoil_certs_arvados_snakeoil_ca_cmd_run
133 - file: extra_custom_certs___HOSTNAME_EXT___cert_file_copy
134 - file: extra_custom_certs___HOSTNAME_EXT___key_file_copy
136 {%- if grains.get('os_family') == 'Debian' %}
137 extra_snakeoil_certs_certs_permissions___HOSTNAME_EXT___cmd_run:
139 - name: {{ arvados_key_file }}
143 - cmd: extra_snakeoil_certs_arvados_snakeoil_cert___HOSTNAME_EXT___cmd_run
144 - pkg: extra_snakeoil_certs_ssl_cert_pkg_installed