1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
5 # WARNING: This file is only used for testing purposes, and should not be used
6 # in a production environment
8 {%- set curr_tpldir = tpldir %}
9 {%- set tpldir = 'arvados' %}
10 {%- from "arvados/map.jinja" import arvados with context %}
11 {%- set tpldir = curr_tpldir %}
13 {%- set orig_cert_dir = salt['pillar.get']('extra_custom_certs_dir', '/srv/salt/certs') %}
20 # Debian uses different dirs for certs and keys, but being a Snake Oil example,
21 # we'll keep it simple here.
22 {%- set arvados_ca_cert_file = '/etc/ssl/private/arvados-snakeoil-ca.pem' %}
23 {%- set arvados_ca_key_file = '/etc/ssl/private/arvados-snakeoil-ca.key' %}
25 {%- if grains.get('os_family') == 'Debian' %}
26 {%- set arvados_ca_cert_dest = '/usr/local/share/ca-certificates/arvados-snakeoil-ca.crt' %}
27 {%- set update_ca_cert = '/usr/sbin/update-ca-certificates' %}
28 {%- set openssl_conf = '/etc/ssl/openssl.cnf' %}
30 extra_snakeoil_certs_ssl_cert_pkg_installed:
37 {%- set arvados_ca_cert_dest = '/etc/pki/ca-trust/source/anchors/arvados-snakeoil-ca.pem' %}
38 {%- set update_ca_cert = '/usr/bin/update-ca-trust' %}
39 {%- set openssl_conf = '/etc/pki/tls/openssl.cnf' %}
43 extra_snakeoil_certs_dependencies_pkg_installed:
49 # Remove the RANDFILE parameter in openssl.cnf as it makes openssl fail in Ubuntu 18.04
50 # Saving and restoring the rng state is not necessary anymore in the openssl 1.1.1
51 # random generator, cf
52 # https://github.com/openssl/openssl/issues/7754
54 extra_snakeoil_certs_file_comment_etc_openssl_conf:
56 - name: /etc/ssl/openssl.cnf
58 - onlyif: grep -q ^RANDFILE /etc/ssl/openssl.cnf
60 - cmd: extra_snakeoil_certs_arvados_snakeoil_ca_cmd_run
62 extra_snakeoil_certs_arvados_snakeoil_ca_cmd_run:
63 # Taken from https://github.com/arvados/arvados/blob/master/tools/arvbox/lib/arvbox/docker/service/certificate/run
66 # These dirs are not to CentOS-ish, but this is a helper script
67 # and they should be enough
68 mkdir -p /etc/ssl/certs/ /etc/ssl/private/ && \
74 -subj "/C=CC/ST=Some State/O=Arvados Formula/OU=arvados-formula/CN=snakeoil-ca-{{ arvados.cluster.name }}.{{ arvados.cluster.domain }}" \
75 -extensions x509_ext \
76 -config <(cat {{ openssl_conf }} \
77 <(printf "\n[x509_ext]\nbasicConstraints=critical,CA:true,pathlen:0\nkeyUsage=critical,keyCertSign,cRLSign")) \
78 -out {{ arvados_ca_cert_file }} \
79 -keyout {{ arvados_ca_key_file }} \
81 cp {{ arvados_ca_cert_file }} {{ arvados_ca_cert_dest }} && \
84 - test -f {{ arvados_ca_cert_file }}
85 - openssl verify -CAfile {{ arvados_ca_cert_file }} {{ arvados_ca_cert_file }}
87 - pkg: extra_snakeoil_certs_dependencies_pkg_installed
89 # Create independent certs for each vhost
101 # We're creating these in a tmp directory, so they're copied to their destination
102 # with the `custom_certs` state file, as if using custom certificates.
103 {%- set arvados_cert_file = orig_cert_dir ~ '/arvados-' ~ vh ~ '.pem' %}
104 {%- set arvados_csr_file = orig_cert_dir ~ '/arvados-' ~ vh ~ '.csr' %}
105 {%- set arvados_key_file = orig_cert_dir ~ '/arvados-' ~ vh ~ '.key' %}
107 extra_snakeoil_certs_arvados_snakeoil_cert_{{ vh }}_cmd_run:
110 cat > /tmp/{{ vh }}.openssl.cnf <<-CNF
115 distinguished_name = dn
116 req_extensions = rext
118 subjectAltName = @alt_names
123 O = Arvados Provision Example Single Host / Multiple Hostnames
124 OU = arvados-provision-example-single_host_multiple_hostnames
125 CN = {{ vh }}.{{ arvados.cluster.name }}.{{ arvados.cluster.domain }}
126 emailAddress = admin@{{ arvados.cluster.name }}.{{ arvados.cluster.domain }}
128 {%- for entry in grains.get('ipv4') %}
129 IP.{{ loop.index }} = {{ entry }}
131 DNS.1 = {{ vh }}.{{ arvados.cluster.name }}.{{ arvados.cluster.domain }}
138 {%- if vh == 'controller' %}
139 DNS.2 = {{ arvados.cluster.name }}.{{ arvados.cluster.domain }}
140 {%- elif vh == 'keepproxy' %}
141 DNS.2 = keep.{{ arvados.cluster.name }}.{{ arvados.cluster.domain }}
142 {%- elif vh == 'websocket' %}
143 DNS.2 = ws.{{ arvados.cluster.name }}.{{ arvados.cluster.domain }}
150 -config /tmp/{{ vh }}.openssl.cnf \
154 -out {{ arvados_csr_file }} \
155 -keyout {{ arvados_key_file }} > /tmp/snakeoil_certs.{{ vh }}.output 2>&1 && \
160 -in {{ arvados_csr_file }} \
161 -out {{ arvados_cert_file }} \
162 -extfile /tmp/{{ vh }}.openssl.cnf \
164 -CA {{ arvados_ca_cert_file }} \
165 -CAkey {{ arvados_ca_key_file }} \
166 -set_serial $(date +%s) && \
167 chmod 0644 {{ arvados_cert_file }} && \
168 chmod 0640 {{ arvados_key_file }}
170 - test -f {{ arvados_key_file }}
171 - openssl verify -CAfile {{ arvados_ca_cert_file }} {{ arvados_cert_file }}
173 - pkg: extra_snakeoil_certs_dependencies_pkg_installed
174 - cmd: extra_snakeoil_certs_arvados_snakeoil_ca_cmd_run
176 - file: extra_custom_certs_file_copy_arvados-{{ vh }}.pem
177 - file: extra_custom_certs_file_copy_arvados-{{ vh }}.key
179 {%- if grains.get('os_family') == 'Debian' %}
180 extra_snakeoil_certs_certs_permissions_{{ vh}}_cmd_run:
182 - name: {{ arvados_key_file }}
186 - cmd: extra_snakeoil_certs_arvados_snakeoil_cert_{{ vh }}_cmd_run
187 - pkg: extra_snakeoil_certs_ssl_cert_pkg_installed