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 extra_snakeoil_certs_arvados_snakeoil_ca_cmd_run:
50 # Taken from https://github.com/arvados/arvados/blob/master/tools/arvbox/lib/arvbox/docker/service/certificate/run
53 # These dirs are not too CentOS-ish, but this is a helper script
54 # and they should be enough
55 /bin/bash -c "mkdir -p /etc/ssl/certs/ /etc/ssl/private/ && \
61 -subj \"/C=CC/ST=Some State/O=Arvados Formula/OU=arvados-formula/CN=snakeoil-ca-{{ arvados.cluster.name }}.{{ arvados.cluster.domain }}\" \
62 -extensions x509_ext \
63 -config <(cat {{ openssl_conf }} \
64 <(printf \"\n[x509_ext]\nbasicConstraints=critical,CA:true,pathlen:0\nkeyUsage=critical,keyCertSign,cRLSign\")) \
65 -out {{ arvados_ca_cert_file }} \
66 -keyout {{ arvados_ca_key_file }} \
68 cp {{ arvados_ca_cert_file }} {{ arvados_ca_cert_dest }} && \
71 - test -f {{ arvados_ca_cert_file }}
72 - openssl verify -CAfile {{ arvados_ca_cert_file }} {{ arvados_ca_cert_file }}
74 - pkg: extra_snakeoil_certs_dependencies_pkg_installed
76 # Create independent certs for each vhost
88 # We're creating these in a tmp directory, so they're copied to their destination
89 # with the `custom_certs` state file, as if using custom certificates.
90 {%- set arvados_cert_file = orig_cert_dir ~ '/arvados-' ~ vh ~ '.pem' %}
91 {%- set arvados_csr_file = orig_cert_dir ~ '/arvados-' ~ vh ~ '.csr' %}
92 {%- set arvados_key_file = orig_cert_dir ~ '/arvados-' ~ vh ~ '.key' %}
94 extra_snakeoil_certs_arvados_snakeoil_cert_{{ vh }}_cmd_run:
97 cat > /tmp/{{ vh }}.openssl.cnf <<-CNF
102 distinguished_name = dn
103 req_extensions = rext
105 subjectAltName = @alt_names
110 O = Arvados Provision Example Single Host / Multiple Hostnames
111 OU = arvados-provision-example-single_host_multiple_hostnames
112 CN = {{ vh }}.{{ arvados.cluster.name }}.{{ arvados.cluster.domain }}
113 emailAddress = admin@{{ arvados.cluster.name }}.{{ arvados.cluster.domain }}
115 {%- for entry in grains.get('ipv4') %}
116 IP.{{ loop.index }} = {{ entry }}
118 DNS.1 = {{ vh }}.{{ arvados.cluster.name }}.{{ arvados.cluster.domain }}
125 {%- if vh == 'controller' %}
126 DNS.2 = {{ arvados.cluster.name }}.{{ arvados.cluster.domain }}
127 {%- elif vh == 'keepproxy' %}
128 DNS.2 = keep.{{ arvados.cluster.name }}.{{ arvados.cluster.domain }}
129 {%- elif vh == 'websocket' %}
130 DNS.2 = ws.{{ arvados.cluster.name }}.{{ arvados.cluster.domain }}
137 -config /tmp/{{ vh }}.openssl.cnf \
141 -out {{ arvados_csr_file }} \
142 -keyout {{ arvados_key_file }} > /tmp/snakeoil_certs.{{ vh }}.output 2>&1 && \
147 -in {{ arvados_csr_file }} \
148 -out {{ arvados_cert_file }} \
149 -extfile /tmp/{{ vh }}.openssl.cnf \
151 -CA {{ arvados_ca_cert_file }} \
152 -CAkey {{ arvados_ca_key_file }} \
153 -set_serial $(date +%s) && \
154 chmod 0644 {{ arvados_cert_file }} && \
155 chmod 0640 {{ arvados_key_file }}
157 - test -f {{ arvados_key_file }}
158 - openssl verify -CAfile {{ arvados_ca_cert_file }} {{ arvados_cert_file }}
160 - pkg: extra_snakeoil_certs_dependencies_pkg_installed
161 - cmd: extra_snakeoil_certs_arvados_snakeoil_ca_cmd_run
163 - file: extra_custom_certs_{{ vh }}_cert_file_copy
164 - file: extra_custom_certs_{{ vh }}_key_file_copy
166 {%- if grains.get('os_family') == 'Debian' %}
167 extra_snakeoil_certs_certs_permissions_{{ vh}}_cmd_run:
169 - name: {{ arvados_key_file }}
173 - cmd: extra_snakeoil_certs_arvados_snakeoil_cert_{{ vh }}_cmd_run
174 - pkg: extra_snakeoil_certs_ssl_cert_pkg_installed