blob: de7a3affa18e59c8572c33407ebc8d8acb7db8df [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
Dean Troyerc83a7e12012-11-29 11:47:58 -06003# lib/tls
4# Functions to control the configuration and operation of the TLS proxy service
5
Dean Troyerc83a7e12012-11-29 11:47:58 -06006# !! source _before_ any services that use ``SERVICE_HOST``
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01007#
8# Dependencies:
9#
10# - ``functions`` file
11# - ``DEST``, ``DATA_DIR`` must be defined
12# - ``HOST_IP``, ``SERVICE_HOST``
13# - ``KEYSTONE_TOKEN_FORMAT`` must be defined
Dean Troyerc83a7e12012-11-29 11:47:58 -060014
15# Entry points:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010016#
17# - configure_CA
18# - init_CA
Dean Troyerc83a7e12012-11-29 11:47:58 -060019
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010020# - configure_proxy
21# - start_tls_proxy
Dean Troyerc83a7e12012-11-29 11:47:58 -060022
Stanislaw Pituchabd5dae02014-06-25 15:29:43 +010023# - stop_tls_proxy
24# - cleanup_CA
25
Stanislaw Pitucha2e0f0542014-06-27 16:05:53 +010026# - make_root_CA
27# - make_int_CA
28# - make_cert ca-dir cert-name "common-name" ["alt-name" ...]
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010029# - start_tls_proxy HOST_IP 5000 localhost 5000
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +100030# - ensure_certificates
31# - is_ssl_enabled_service
Rob Crittenden18d47782014-03-19 17:47:42 -040032# - enable_mod_ssl
Dean Troyerc83a7e12012-11-29 11:47:58 -060033
Dean Troyerdc97cb72015-03-28 08:20:50 -050034
Dean Troyercc6b4432013-04-08 15:38:03 -050035# Defaults
36# --------
37
Dean Troyerc83a7e12012-11-29 11:47:58 -060038if is_service_enabled tls-proxy; then
39 # TODO(dtroyer): revisit this below after the search for HOST_IP has been done
40 TLS_IP=${TLS_IP:-$SERVICE_IP}
Dean Troyerc83a7e12012-11-29 11:47:58 -060041fi
42
Rob Crittenden18d47782014-03-19 17:47:42 -040043DEVSTACK_HOSTNAME=$(hostname -f)
Dean Troyerc83a7e12012-11-29 11:47:58 -060044DEVSTACK_CERT_NAME=devstack-cert
45DEVSTACK_CERT=$DATA_DIR/$DEVSTACK_CERT_NAME.pem
46
47# CA configuration
48ROOT_CA_DIR=${ROOT_CA_DIR:-$DATA_DIR/CA/root-ca}
49INT_CA_DIR=${INT_CA_DIR:-$DATA_DIR/CA/int-ca}
50
51ORG_NAME="OpenStack"
52ORG_UNIT_NAME="DevStack"
53
54# Stud configuration
55STUD_PROTO="--tls"
56STUD_CIPHERS='TLSv1+HIGH:!DES:!aNULL:!eNULL:@STRENGTH'
57
58
59# CA Functions
60# ============
61
62# There may be more than one, get specific
63OPENSSL=${OPENSSL:-/usr/bin/openssl}
64
65# Do primary CA configuration
Ian Wienandaee18c72014-02-21 15:35:08 +110066function configure_CA {
Dean Troyerc83a7e12012-11-29 11:47:58 -060067 # build common config file
68
69 # Verify ``TLS_IP`` is good
70 if [[ -n "$HOST_IP" && "$HOST_IP" != "$TLS_IP" ]]; then
71 # auto-discover has changed the IP
72 TLS_IP=$HOST_IP
73 fi
74}
75
76# Creates a new CA directory structure
77# create_CA_base ca-dir
Ian Wienandaee18c72014-02-21 15:35:08 +110078function create_CA_base {
Dean Troyerc83a7e12012-11-29 11:47:58 -060079 local ca_dir=$1
80
81 if [[ -d $ca_dir ]]; then
82 # Bail out it exists
83 return 0
84 fi
85
Dean Troyerb1e3d0f2014-07-25 14:57:54 -050086 local i
Dean Troyerc83a7e12012-11-29 11:47:58 -060087 for i in certs crl newcerts private; do
88 mkdir -p $ca_dir/$i
89 done
90 chmod 710 $ca_dir/private
91 echo "01" >$ca_dir/serial
92 cp /dev/null $ca_dir/index.txt
93}
94
Dean Troyerc83a7e12012-11-29 11:47:58 -060095# Create a new CA configuration file
96# create_CA_config ca-dir common-name
Ian Wienandaee18c72014-02-21 15:35:08 +110097function create_CA_config {
Dean Troyerc83a7e12012-11-29 11:47:58 -060098 local ca_dir=$1
99 local common_name=$2
100
101 echo "
102[ ca ]
103default_ca = CA_default
104
105[ CA_default ]
106dir = $ca_dir
107policy = policy_match
108database = \$dir/index.txt
109serial = \$dir/serial
110certs = \$dir/certs
111crl_dir = \$dir/crl
112new_certs_dir = \$dir/newcerts
113certificate = \$dir/cacert.pem
114private_key = \$dir/private/cacert.key
115RANDFILE = \$dir/private/.rand
116default_md = default
117
118[ req ]
119default_bits = 1024
120default_md = sha1
121
122prompt = no
123distinguished_name = ca_distinguished_name
124
125x509_extensions = ca_extensions
126
127[ ca_distinguished_name ]
128organizationName = $ORG_NAME
129organizationalUnitName = $ORG_UNIT_NAME Certificate Authority
130commonName = $common_name
131
132[ policy_match ]
133countryName = optional
134stateOrProvinceName = optional
135organizationName = match
136organizationalUnitName = optional
137commonName = supplied
138
139[ ca_extensions ]
140basicConstraints = critical,CA:true
141subjectKeyIdentifier = hash
142authorityKeyIdentifier = keyid:always, issuer
143keyUsage = cRLSign, keyCertSign
144
145" >$ca_dir/ca.conf
146}
147
148# Create a new signing configuration file
149# create_signing_config ca-dir
Ian Wienandaee18c72014-02-21 15:35:08 +1100150function create_signing_config {
Dean Troyerc83a7e12012-11-29 11:47:58 -0600151 local ca_dir=$1
152
153 echo "
154[ ca ]
155default_ca = CA_default
156
157[ CA_default ]
158dir = $ca_dir
159policy = policy_match
160database = \$dir/index.txt
161serial = \$dir/serial
162certs = \$dir/certs
163crl_dir = \$dir/crl
164new_certs_dir = \$dir/newcerts
165certificate = \$dir/cacert.pem
166private_key = \$dir/private/cacert.key
167RANDFILE = \$dir/private/.rand
168default_md = default
169
170[ req ]
171default_bits = 1024
172default_md = sha1
173
174prompt = no
175distinguished_name = req_distinguished_name
176
177x509_extensions = req_extensions
178
179[ req_distinguished_name ]
180organizationName = $ORG_NAME
181organizationalUnitName = $ORG_UNIT_NAME Server Farm
182
183[ policy_match ]
184countryName = optional
185stateOrProvinceName = optional
186organizationName = match
187organizationalUnitName = optional
188commonName = supplied
189
190[ req_extensions ]
191basicConstraints = CA:false
192subjectKeyIdentifier = hash
193authorityKeyIdentifier = keyid:always, issuer
194keyUsage = digitalSignature, keyEncipherment, keyAgreement
195extendedKeyUsage = serverAuth, clientAuth
196subjectAltName = \$ENV::SUBJECT_ALT_NAME
197
198" >$ca_dir/signing.conf
199}
200
Dean Troyerca802172013-01-09 19:08:02 -0600201# Create root and intermediate CAs
Dean Troyerc83a7e12012-11-29 11:47:58 -0600202# init_CA
203function init_CA {
204 # Ensure CAs are built
205 make_root_CA $ROOT_CA_DIR
206 make_int_CA $INT_CA_DIR $ROOT_CA_DIR
207
208 # Create the CA bundle
209 cat $ROOT_CA_DIR/cacert.pem $INT_CA_DIR/cacert.pem >>$INT_CA_DIR/ca-chain.pem
Rob Crittenden18d47782014-03-19 17:47:42 -0400210 cat $INT_CA_DIR/ca-chain.pem >> $SSL_BUNDLE_FILE
211
212 if is_fedora; then
213 sudo cp $INT_CA_DIR/ca-chain.pem /usr/share/pki/ca-trust-source/anchors/devstack-chain.pem
214 sudo update-ca-trust
Clark Boylan35649ae2017-05-27 17:52:55 -0700215 elif is_suse; then
216 sudo cp $INT_CA_DIR/ca-chain.pem /usr/share/pki/trust/anchors/devstack-chain.pem
217 sudo update-ca-certificates
Rob Crittenden18d47782014-03-19 17:47:42 -0400218 elif is_ubuntu; then
219 sudo cp $INT_CA_DIR/ca-chain.pem /usr/local/share/ca-certificates/devstack-int.crt
220 sudo cp $ROOT_CA_DIR/cacert.pem /usr/local/share/ca-certificates/devstack-root.crt
221 sudo update-ca-certificates
222 fi
223}
224
Dean Troyerca802172013-01-09 19:08:02 -0600225# Create an initial server cert
226# init_cert
227function init_cert {
Dean Troyerc83a7e12012-11-29 11:47:58 -0600228 if [[ ! -r $DEVSTACK_CERT ]]; then
229 if [[ -n "$TLS_IP" ]]; then
230 # Lie to let incomplete match routines work
Ian Cordasco69e3c0a2016-09-26 12:53:14 -0500231 TLS_IP="DNS:$TLS_IP,IP:$TLS_IP"
Dean Troyerc83a7e12012-11-29 11:47:58 -0600232 fi
233 make_cert $INT_CA_DIR $DEVSTACK_CERT_NAME $DEVSTACK_HOSTNAME "$TLS_IP"
234
235 # Create a cert bundle
236 cat $INT_CA_DIR/private/$DEVSTACK_CERT_NAME.key $INT_CA_DIR/$DEVSTACK_CERT_NAME.crt $INT_CA_DIR/cacert.pem >$DEVSTACK_CERT
237 fi
238}
239
Dean Troyerc83a7e12012-11-29 11:47:58 -0600240# make_cert creates and signs a new certificate with the given commonName and CA
241# make_cert ca-dir cert-name "common-name" ["alt-name" ...]
Ian Wienandaee18c72014-02-21 15:35:08 +1100242function make_cert {
Dean Troyerc83a7e12012-11-29 11:47:58 -0600243 local ca_dir=$1
244 local cert_name=$2
245 local common_name=$3
246 local alt_names=$4
247
Rob Crittendenbe00e952016-03-24 18:09:22 -0400248 if [ "$common_name" != "$SERVICE_HOST" ]; then
249 if [[ -z "$alt_names" ]]; then
250 alt_names="DNS:$SERVICE_HOST"
251 else
252 alt_names="$alt_names,DNS:$SERVICE_HOST"
253 fi
Ian Cordasco69e3c0a2016-09-26 12:53:14 -0500254 if is_ipv4_address "$SERVICE_HOST" ; then
255 alt_names="$alt_names,IP:$SERVICE_HOST"
256 fi
Rob Crittendenbe00e952016-03-24 18:09:22 -0400257 fi
258
Stanislaw Pitucha2f69c6b2014-06-25 15:07:48 +0100259 # Only generate the certificate if it doesn't exist yet on the disk
260 if [ ! -r "$ca_dir/$cert_name.crt" ]; then
261 # Generate a signing request
262 $OPENSSL req \
263 -sha1 \
264 -newkey rsa \
265 -nodes \
266 -keyout $ca_dir/private/$cert_name.key \
267 -out $ca_dir/$cert_name.csr \
268 -subj "/O=${ORG_NAME}/OU=${ORG_UNIT_NAME} Servers/CN=${common_name}"
Dean Troyerc83a7e12012-11-29 11:47:58 -0600269
Stanislaw Pitucha2f69c6b2014-06-25 15:07:48 +0100270 if [[ -z "$alt_names" ]]; then
271 alt_names="DNS:${common_name}"
272 else
273 alt_names="DNS:${common_name},${alt_names}"
274 fi
275
276 # Sign the request valid for 1 year
277 SUBJECT_ALT_NAME="$alt_names" \
278 $OPENSSL ca -config $ca_dir/signing.conf \
279 -extensions req_extensions \
280 -days 365 \
281 -notext \
282 -in $ca_dir/$cert_name.csr \
283 -out $ca_dir/$cert_name.crt \
284 -subj "/O=${ORG_NAME}/OU=${ORG_UNIT_NAME} Servers/CN=${common_name}" \
285 -batch
Dean Troyerc83a7e12012-11-29 11:47:58 -0600286 fi
Dean Troyerc83a7e12012-11-29 11:47:58 -0600287}
288
Dean Troyerc83a7e12012-11-29 11:47:58 -0600289# Make an intermediate CA to sign everything else
290# make_int_CA ca-dir signing-ca-dir
Ian Wienandaee18c72014-02-21 15:35:08 +1100291function make_int_CA {
Dean Troyerc83a7e12012-11-29 11:47:58 -0600292 local ca_dir=$1
293 local signing_ca_dir=$2
294
295 # Create the root CA
296 create_CA_base $ca_dir
297 create_CA_config $ca_dir 'Intermediate CA'
298 create_signing_config $ca_dir
299
Stanislaw Pitucha2f69c6b2014-06-25 15:07:48 +0100300 if [ ! -r "$ca_dir/cacert.pem" ]; then
301 # Create a signing certificate request
302 $OPENSSL req -config $ca_dir/ca.conf \
303 -sha1 \
304 -newkey rsa \
305 -nodes \
306 -keyout $ca_dir/private/cacert.key \
307 -out $ca_dir/cacert.csr \
308 -outform PEM
Dean Troyerc83a7e12012-11-29 11:47:58 -0600309
Stanislaw Pitucha2f69c6b2014-06-25 15:07:48 +0100310 # Sign the intermediate request valid for 1 year
311 $OPENSSL ca -config $signing_ca_dir/ca.conf \
312 -extensions ca_extensions \
313 -days 365 \
314 -notext \
315 -in $ca_dir/cacert.csr \
316 -out $ca_dir/cacert.pem \
317 -batch
318 fi
Dean Troyerc83a7e12012-11-29 11:47:58 -0600319}
320
321# Make a root CA to sign other CAs
322# make_root_CA ca-dir
Ian Wienandaee18c72014-02-21 15:35:08 +1100323function make_root_CA {
Dean Troyerc83a7e12012-11-29 11:47:58 -0600324 local ca_dir=$1
325
326 # Create the root CA
327 create_CA_base $ca_dir
328 create_CA_config $ca_dir 'Root CA'
329
Clark Boylan323b7262016-09-23 13:33:40 -0700330 if [ ! -r "$ca_dir/cacert.pem" ]; then
331 # Create a self-signed certificate valid for 5 years
332 $OPENSSL req -config $ca_dir/ca.conf \
333 -x509 \
334 -nodes \
335 -newkey rsa \
336 -days 21360 \
337 -keyout $ca_dir/private/cacert.key \
338 -out $ca_dir/cacert.pem \
339 -outform PEM
340 fi
Dean Troyerc83a7e12012-11-29 11:47:58 -0600341}
342
Rob Crittenden1987fcc2015-06-10 11:00:59 -0400343# If a non-system python-requests is installed then it will use the
344# built-in CA certificate store rather than the distro-specific
345# CA certificate store. Detect this and symlink to the correct
346# one. If the value for the CA is not rooted in /etc then we know
347# we need to change it.
348function fix_system_ca_bundle_path {
Sean Daguef3b2f4c2017-04-13 10:11:48 -0400349 if is_service_enabled tls-proxy; then
Ian Wienandada886d2015-10-07 14:06:26 +1100350 local capath
351 capath=$(python -c $'try:\n from requests import certs\n print certs.where()\nexcept ImportError: pass')
Rob Crittenden1987fcc2015-06-10 11:00:59 -0400352
353 if [[ ! $capath == "" && ! $capath =~ ^/etc/.* && ! -L $capath ]]; then
354 if is_fedora; then
355 sudo rm -f $capath
356 sudo ln -s /etc/pki/tls/certs/ca-bundle.crt $capath
357 elif is_ubuntu; then
358 sudo rm -f $capath
359 sudo ln -s /etc/ssl/certs/ca-certificates.crt $capath
Clark Boylan35649ae2017-05-27 17:52:55 -0700360 elif is_suse; then
361 sudo rm -f $capath
362 sudo ln -s /etc/ssl/ca-bundle.pem $capath
Rob Crittenden1987fcc2015-06-10 11:00:59 -0400363 else
364 echo "Don't know how to set the CA bundle, expect the install to fail."
365 fi
366 fi
367 fi
368}
369
Dean Troyerc83a7e12012-11-29 11:47:58 -0600370
Sean Daguef3b2f4c2017-04-13 10:11:48 -0400371# Only for compatibility, return if the tls-proxy is enabled
372function is_ssl_enabled_service {
373 return is_service_enabled tls-proxy
374}
375
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000376# Certificate Input Configuration
377# ===============================
378
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000379# Ensure that the certificates for a service are in place. This function does
380# not check that a service is SSL enabled, this should already have been
381# completed.
382#
383# The function expects to find a certificate, key and CA certificate in the
Dean Troyerdc97cb72015-03-28 08:20:50 -0500384# variables ``{service}_SSL_CERT``, ``{service}_SSL_KEY`` and ``{service}_SSL_CA``. For
385# example for keystone this would be ``KEYSTONE_SSL_CERT``, ``KEYSTONE_SSL_KEY`` and
386# ``KEYSTONE_SSL_CA``.
Rob Crittenden18d47782014-03-19 17:47:42 -0400387#
Dean Troyerdc97cb72015-03-28 08:20:50 -0500388# If it does not find these certificates then the DevStack-issued server
Rob Crittenden18d47782014-03-19 17:47:42 -0400389# certificate, key and CA certificate will be associated with the service.
390#
391# If only some of the variables are provided then the function will quit.
Ian Wienandaee18c72014-02-21 15:35:08 +1100392function ensure_certificates {
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000393 local service=$1
394
395 local cert_var="${service}_SSL_CERT"
396 local key_var="${service}_SSL_KEY"
397 local ca_var="${service}_SSL_CA"
398
399 local cert=${!cert_var}
400 local key=${!key_var}
401 local ca=${!ca_var}
402
Rob Crittenden18d47782014-03-19 17:47:42 -0400403 if [[ -z "$cert" && -z "$key" && -z "$ca" ]]; then
404 local cert="$INT_CA_DIR/$DEVSTACK_CERT_NAME.crt"
405 local key="$INT_CA_DIR/private/$DEVSTACK_CERT_NAME.key"
406 local ca="$INT_CA_DIR/ca-chain.pem"
407 eval ${service}_SSL_CERT=\$cert
408 eval ${service}_SSL_KEY=\$key
409 eval ${service}_SSL_CA=\$ca
410 return # the CA certificate is already in the bundle
411 elif [[ -z "$cert" || -z "$key" || -z "$ca" ]]; then
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000412 die $LINENO "Missing either the ${cert_var} ${key_var} or ${ca_var}" \
413 "variable to enable SSL for ${service}"
414 fi
415
416 cat $ca >> $SSL_BUNDLE_FILE
417}
418
Rob Crittenden18d47782014-03-19 17:47:42 -0400419# Enable the mod_ssl plugin in Apache
420function enable_mod_ssl {
421 echo "Enabling mod_ssl"
422
423 if is_ubuntu; then
424 sudo a2enmod ssl
Clark Boylan35649ae2017-05-27 17:52:55 -0700425 elif is_suse; then
426 sudo a2enmod ssl
427 sudo a2enflag SSL
Rob Crittenden18d47782014-03-19 17:47:42 -0400428 elif is_fedora; then
429 # Fedora enables mod_ssl by default
430 :
431 fi
432 if ! sudo `which httpd || which apache2ctl` -M | grep -w -q ssl_module; then
433 die $LINENO "mod_ssl is not enabled in apache2/httpd, please check for it manually and run stack.sh again"
434 fi
435}
436
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000437
Dean Troyerc83a7e12012-11-29 11:47:58 -0600438# Proxy Functions
439# ===============
440
Clark Boylancfb9f052016-11-29 10:43:05 -0800441function tune_apache_connections {
442 local tuning_file=$APACHE_SETTINGS_DIR/connection-tuning.conf
443 if ! [ -f $tuning_file ] ; then
444 sudo bash -c "cat > $tuning_file" << EOF
445# worker MPM
446# StartServers: initial number of server processes to start
447# MinSpareThreads: minimum number of worker threads which are kept spare
448# MaxSpareThreads: maximum number of worker threads which are kept spare
449# ThreadLimit: ThreadsPerChild can be changed to this maximum value during a
450# graceful restart. ThreadLimit can only be changed by stopping
451# and starting Apache.
452# ThreadsPerChild: constant number of worker threads in each server process
453# MaxClients: maximum number of simultaneous client connections
454# MaxRequestsPerChild: maximum number of requests a server process serves
455#
Clark Boylan8cf9acd2017-03-16 14:06:58 -0700456# We want to be memory thrifty so tune down apache to allow 256 total
457# connections. This should still be plenty for a dev env yet lighter than
458# apache defaults.
Clark Boylancfb9f052016-11-29 10:43:05 -0800459<IfModule mpm_worker_module>
460# Note that the next three conf values must be changed together.
461# MaxClients = ServerLimit * ThreadsPerChild
Clark Boylan8cf9acd2017-03-16 14:06:58 -0700462ServerLimit 8
Clark Boylancfb9f052016-11-29 10:43:05 -0800463ThreadsPerChild 32
Clark Boylan8cf9acd2017-03-16 14:06:58 -0700464MaxClients 256
465StartServers 2
466MinSpareThreads 32
467MaxSpareThreads 96
Clark Boylancfb9f052016-11-29 10:43:05 -0800468ThreadLimit 64
469MaxRequestsPerChild 0
470</IfModule>
471<IfModule mpm_event_module>
472# Note that the next three conf values must be changed together.
473# MaxClients = ServerLimit * ThreadsPerChild
Clark Boylan8cf9acd2017-03-16 14:06:58 -0700474ServerLimit 8
Clark Boylancfb9f052016-11-29 10:43:05 -0800475ThreadsPerChild 32
Clark Boylan8cf9acd2017-03-16 14:06:58 -0700476MaxClients 256
477StartServers 2
478MinSpareThreads 32
479MaxSpareThreads 96
Clark Boylancfb9f052016-11-29 10:43:05 -0800480ThreadLimit 64
481MaxRequestsPerChild 0
482</IfModule>
483EOF
484 restart_apache_server
485 fi
486}
487
Dean Troyerc83a7e12012-11-29 11:47:58 -0600488# Starts the TLS proxy for the given IP/ports
489# start_tls_proxy front-host front-port back-host back-port
Ian Wienandaee18c72014-02-21 15:35:08 +1100490function start_tls_proxy {
Gregory Haynes4b49e402016-08-31 18:19:51 -0700491 local b_service="$1-tls-proxy"
492 local f_host=$2
493 local f_port=$3
494 local b_host=$4
495 local b_port=$5
Dean Troyerc83a7e12012-11-29 11:47:58 -0600496
Clark Boylancfb9f052016-11-29 10:43:05 -0800497 tune_apache_connections
498
Gregory Haynes4b49e402016-08-31 18:19:51 -0700499 local config_file
500 config_file=$(apache_site_config_for $b_service)
501 local listen_string
502 # Default apache configs on ubuntu and centos listen on 80 and 443
503 # newer apache seems fine with duplicate listen directive but older
504 # apache does not so special case 80 and 443.
505 if [[ "$f_port" == "80" ]] || [[ "$f_port" == "443" ]]; then
506 listen_string=""
507 elif [[ "$f_host" == '*' ]] ; then
508 listen_string="Listen $f_port"
509 else
510 listen_string="Listen $f_host:$f_port"
511 fi
512 sudo bash -c "cat >$config_file" << EOF
513$listen_string
514
515<VirtualHost $f_host:$f_port>
516 SSLEngine On
517 SSLCertificateFile $DEVSTACK_CERT
518
Jordan Pittier43709252017-02-14 16:48:20 +0100519 # Disable KeepAlive to fix bug #1630664 a.k.a the
520 # ('Connection aborted.', BadStatusLine("''",)) error
521 KeepAlive Off
522
Gregory Haynes4b49e402016-08-31 18:19:51 -0700523 <Location />
Sean Daguea1446b92017-04-17 14:31:21 -0400524 ProxyPass http://$b_host:$b_port/ retry=0 nocanon
Gregory Haynes4b49e402016-08-31 18:19:51 -0700525 ProxyPassReverse http://$b_host:$b_port/
526 </Location>
Clark Boylan66ce5c22016-10-05 12:11:05 -0700527 ErrorLog $APACHE_LOG_DIR/tls-proxy_error.log
528 ErrorLogFormat "[%{u}t] [%-m:%l] [pid %P:tid %T] %7F: %E: [client\ %a] [frontend\ %A] %M% ,\ referer\ %{Referer}i"
529 LogLevel info
530 CustomLog $APACHE_LOG_DIR/tls-proxy_access.log common
531 LogFormat "%v %h %l %u %t \"%r\" %>s %b"
Gregory Haynes4b49e402016-08-31 18:19:51 -0700532</VirtualHost>
533EOF
Clark Boylan35649ae2017-05-27 17:52:55 -0700534 if is_suse ; then
535 sudo a2enflag SSL
536 fi
Gregory Haynes4b49e402016-08-31 18:19:51 -0700537 for mod in ssl proxy proxy_http; do
538 enable_apache_mod $mod
539 done
540 enable_apache_site $b_service
Ian Wienandf6a2d2c2017-04-26 10:50:29 +1000541 restart_apache_server
Dean Troyerc83a7e12012-11-29 11:47:58 -0600542}
Sean Dague584d90e2013-03-29 14:34:53 -0400543
Sean Daguef06455e2016-10-07 06:57:03 -0400544# Follow TLS proxy
545function follow_tls_proxy {
546 sudo touch /var/log/$APACHE_NAME/tls-proxy_error.log
547 tail_log tls-error /var/log/$APACHE_NAME/tls-proxy_error.log
548 sudo touch /var/log/$APACHE_NAME/tls-proxy_access.log
549 tail_log tls-proxy /var/log/$APACHE_NAME/tls-proxy_access.log
550}
Dean Troyercc6b4432013-04-08 15:38:03 -0500551
Stanislaw Pituchabd5dae02014-06-25 15:29:43 +0100552# Cleanup Functions
Dean Troyer3324f192014-09-18 09:26:39 -0500553# =================
Stanislaw Pituchabd5dae02014-06-25 15:29:43 +0100554
Gregory Haynes4b49e402016-08-31 18:19:51 -0700555# Stops the apache service. This should be done only after all services
Stanislaw Pituchabd5dae02014-06-25 15:29:43 +0100556# using tls configuration are down.
557function stop_tls_proxy {
Gregory Haynes4b49e402016-08-31 18:19:51 -0700558 stop_apache_server
Stanislaw Pituchabd5dae02014-06-25 15:29:43 +0100559}
560
Gregory Haynes4b49e402016-08-31 18:19:51 -0700561# Clean up the CA files
562# cleanup_CA
Stanislaw Pituchabd5dae02014-06-25 15:29:43 +0100563function cleanup_CA {
Gregory Haynes4b49e402016-08-31 18:19:51 -0700564 if is_fedora; then
565 sudo rm -f /usr/share/pki/ca-trust-source/anchors/devstack-chain.pem
566 sudo update-ca-trust
567 elif is_ubuntu; then
568 sudo rm -f /usr/local/share/ca-certificates/devstack-int.crt
569 sudo rm -f /usr/local/share/ca-certificates/devstack-root.crt
570 sudo update-ca-certificates
571 fi
572
Clark Boylan323b7262016-09-23 13:33:40 -0700573 rm -rf "$INT_CA_DIR" "$ROOT_CA_DIR" "$DEVSTACK_CERT"
Stanislaw Pituchabd5dae02014-06-25 15:29:43 +0100574}
575
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100576# Tell emacs to use shell-script-mode
577## Local variables:
578## mode: shell-script
579## End: