blob: f9ef554a6cc2429165b24b21658c988890e5cb21 [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
215 elif is_ubuntu; then
216 sudo cp $INT_CA_DIR/ca-chain.pem /usr/local/share/ca-certificates/devstack-int.crt
217 sudo cp $ROOT_CA_DIR/cacert.pem /usr/local/share/ca-certificates/devstack-root.crt
218 sudo update-ca-certificates
219 fi
220}
221
Dean Troyerca802172013-01-09 19:08:02 -0600222# Create an initial server cert
223# init_cert
224function init_cert {
Dean Troyerc83a7e12012-11-29 11:47:58 -0600225 if [[ ! -r $DEVSTACK_CERT ]]; then
226 if [[ -n "$TLS_IP" ]]; then
227 # Lie to let incomplete match routines work
Ian Cordasco69e3c0a2016-09-26 12:53:14 -0500228 TLS_IP="DNS:$TLS_IP,IP:$TLS_IP"
Dean Troyerc83a7e12012-11-29 11:47:58 -0600229 fi
230 make_cert $INT_CA_DIR $DEVSTACK_CERT_NAME $DEVSTACK_HOSTNAME "$TLS_IP"
231
232 # Create a cert bundle
233 cat $INT_CA_DIR/private/$DEVSTACK_CERT_NAME.key $INT_CA_DIR/$DEVSTACK_CERT_NAME.crt $INT_CA_DIR/cacert.pem >$DEVSTACK_CERT
234 fi
235}
236
Dean Troyerc83a7e12012-11-29 11:47:58 -0600237# make_cert creates and signs a new certificate with the given commonName and CA
238# make_cert ca-dir cert-name "common-name" ["alt-name" ...]
Ian Wienandaee18c72014-02-21 15:35:08 +1100239function make_cert {
Dean Troyerc83a7e12012-11-29 11:47:58 -0600240 local ca_dir=$1
241 local cert_name=$2
242 local common_name=$3
243 local alt_names=$4
244
Rob Crittendenbe00e952016-03-24 18:09:22 -0400245 if [ "$common_name" != "$SERVICE_HOST" ]; then
246 if [[ -z "$alt_names" ]]; then
247 alt_names="DNS:$SERVICE_HOST"
248 else
249 alt_names="$alt_names,DNS:$SERVICE_HOST"
250 fi
Ian Cordasco69e3c0a2016-09-26 12:53:14 -0500251 if is_ipv4_address "$SERVICE_HOST" ; then
252 alt_names="$alt_names,IP:$SERVICE_HOST"
253 fi
Rob Crittendenbe00e952016-03-24 18:09:22 -0400254 fi
255
Stanislaw Pitucha2f69c6b2014-06-25 15:07:48 +0100256 # Only generate the certificate if it doesn't exist yet on the disk
257 if [ ! -r "$ca_dir/$cert_name.crt" ]; then
258 # Generate a signing request
259 $OPENSSL req \
260 -sha1 \
261 -newkey rsa \
262 -nodes \
263 -keyout $ca_dir/private/$cert_name.key \
264 -out $ca_dir/$cert_name.csr \
265 -subj "/O=${ORG_NAME}/OU=${ORG_UNIT_NAME} Servers/CN=${common_name}"
Dean Troyerc83a7e12012-11-29 11:47:58 -0600266
Stanislaw Pitucha2f69c6b2014-06-25 15:07:48 +0100267 if [[ -z "$alt_names" ]]; then
268 alt_names="DNS:${common_name}"
269 else
270 alt_names="DNS:${common_name},${alt_names}"
271 fi
272
273 # Sign the request valid for 1 year
274 SUBJECT_ALT_NAME="$alt_names" \
275 $OPENSSL ca -config $ca_dir/signing.conf \
276 -extensions req_extensions \
277 -days 365 \
278 -notext \
279 -in $ca_dir/$cert_name.csr \
280 -out $ca_dir/$cert_name.crt \
281 -subj "/O=${ORG_NAME}/OU=${ORG_UNIT_NAME} Servers/CN=${common_name}" \
282 -batch
Dean Troyerc83a7e12012-11-29 11:47:58 -0600283 fi
Dean Troyerc83a7e12012-11-29 11:47:58 -0600284}
285
Dean Troyerc83a7e12012-11-29 11:47:58 -0600286# Make an intermediate CA to sign everything else
287# make_int_CA ca-dir signing-ca-dir
Ian Wienandaee18c72014-02-21 15:35:08 +1100288function make_int_CA {
Dean Troyerc83a7e12012-11-29 11:47:58 -0600289 local ca_dir=$1
290 local signing_ca_dir=$2
291
292 # Create the root CA
293 create_CA_base $ca_dir
294 create_CA_config $ca_dir 'Intermediate CA'
295 create_signing_config $ca_dir
296
Stanislaw Pitucha2f69c6b2014-06-25 15:07:48 +0100297 if [ ! -r "$ca_dir/cacert.pem" ]; then
298 # Create a signing certificate request
299 $OPENSSL req -config $ca_dir/ca.conf \
300 -sha1 \
301 -newkey rsa \
302 -nodes \
303 -keyout $ca_dir/private/cacert.key \
304 -out $ca_dir/cacert.csr \
305 -outform PEM
Dean Troyerc83a7e12012-11-29 11:47:58 -0600306
Stanislaw Pitucha2f69c6b2014-06-25 15:07:48 +0100307 # Sign the intermediate request valid for 1 year
308 $OPENSSL ca -config $signing_ca_dir/ca.conf \
309 -extensions ca_extensions \
310 -days 365 \
311 -notext \
312 -in $ca_dir/cacert.csr \
313 -out $ca_dir/cacert.pem \
314 -batch
315 fi
Dean Troyerc83a7e12012-11-29 11:47:58 -0600316}
317
318# Make a root CA to sign other CAs
319# make_root_CA ca-dir
Ian Wienandaee18c72014-02-21 15:35:08 +1100320function make_root_CA {
Dean Troyerc83a7e12012-11-29 11:47:58 -0600321 local ca_dir=$1
322
323 # Create the root CA
324 create_CA_base $ca_dir
325 create_CA_config $ca_dir 'Root CA'
326
Clark Boylan323b7262016-09-23 13:33:40 -0700327 if [ ! -r "$ca_dir/cacert.pem" ]; then
328 # Create a self-signed certificate valid for 5 years
329 $OPENSSL req -config $ca_dir/ca.conf \
330 -x509 \
331 -nodes \
332 -newkey rsa \
333 -days 21360 \
334 -keyout $ca_dir/private/cacert.key \
335 -out $ca_dir/cacert.pem \
336 -outform PEM
337 fi
Dean Troyerc83a7e12012-11-29 11:47:58 -0600338}
339
Rob Crittenden1987fcc2015-06-10 11:00:59 -0400340# If a non-system python-requests is installed then it will use the
341# built-in CA certificate store rather than the distro-specific
342# CA certificate store. Detect this and symlink to the correct
343# one. If the value for the CA is not rooted in /etc then we know
344# we need to change it.
345function fix_system_ca_bundle_path {
346 if is_service_enabled tls-proxy || [ "$USE_SSL" == "True" ]; then
Ian Wienandada886d2015-10-07 14:06:26 +1100347 local capath
348 capath=$(python -c $'try:\n from requests import certs\n print certs.where()\nexcept ImportError: pass')
Rob Crittenden1987fcc2015-06-10 11:00:59 -0400349
350 if [[ ! $capath == "" && ! $capath =~ ^/etc/.* && ! -L $capath ]]; then
351 if is_fedora; then
352 sudo rm -f $capath
353 sudo ln -s /etc/pki/tls/certs/ca-bundle.crt $capath
354 elif is_ubuntu; then
355 sudo rm -f $capath
356 sudo ln -s /etc/ssl/certs/ca-certificates.crt $capath
357 else
358 echo "Don't know how to set the CA bundle, expect the install to fail."
359 fi
360 fi
361 fi
362}
363
Dean Troyerc83a7e12012-11-29 11:47:58 -0600364
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000365# Certificate Input Configuration
366# ===============================
367
368# check to see if the service(s) specified are to be SSL enabled.
369#
370# Multiple services specified as arguments are ``OR``'ed together; the test
371# is a short-circuit boolean, i.e it returns on the first match.
372#
373# Uses global ``SSL_ENABLED_SERVICES``
Ian Wienandaee18c72014-02-21 15:35:08 +1100374function is_ssl_enabled_service {
Sean Daguef0bd8db2014-07-23 15:14:07 -0400375 local services=$@
376 local service=""
Rob Crittenden18d47782014-03-19 17:47:42 -0400377 if [ "$USE_SSL" == "False" ]; then
378 return 1
379 fi
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000380 for service in ${services}; do
381 [[ ,${SSL_ENABLED_SERVICES}, =~ ,${service}, ]] && return 0
382 done
383 return 1
384}
385
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000386# Ensure that the certificates for a service are in place. This function does
387# not check that a service is SSL enabled, this should already have been
388# completed.
389#
390# The function expects to find a certificate, key and CA certificate in the
Dean Troyerdc97cb72015-03-28 08:20:50 -0500391# variables ``{service}_SSL_CERT``, ``{service}_SSL_KEY`` and ``{service}_SSL_CA``. For
392# example for keystone this would be ``KEYSTONE_SSL_CERT``, ``KEYSTONE_SSL_KEY`` and
393# ``KEYSTONE_SSL_CA``.
Rob Crittenden18d47782014-03-19 17:47:42 -0400394#
Dean Troyerdc97cb72015-03-28 08:20:50 -0500395# If it does not find these certificates then the DevStack-issued server
Rob Crittenden18d47782014-03-19 17:47:42 -0400396# certificate, key and CA certificate will be associated with the service.
397#
398# If only some of the variables are provided then the function will quit.
Ian Wienandaee18c72014-02-21 15:35:08 +1100399function ensure_certificates {
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000400 local service=$1
401
402 local cert_var="${service}_SSL_CERT"
403 local key_var="${service}_SSL_KEY"
404 local ca_var="${service}_SSL_CA"
405
406 local cert=${!cert_var}
407 local key=${!key_var}
408 local ca=${!ca_var}
409
Rob Crittenden18d47782014-03-19 17:47:42 -0400410 if [[ -z "$cert" && -z "$key" && -z "$ca" ]]; then
411 local cert="$INT_CA_DIR/$DEVSTACK_CERT_NAME.crt"
412 local key="$INT_CA_DIR/private/$DEVSTACK_CERT_NAME.key"
413 local ca="$INT_CA_DIR/ca-chain.pem"
414 eval ${service}_SSL_CERT=\$cert
415 eval ${service}_SSL_KEY=\$key
416 eval ${service}_SSL_CA=\$ca
417 return # the CA certificate is already in the bundle
418 elif [[ -z "$cert" || -z "$key" || -z "$ca" ]]; then
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000419 die $LINENO "Missing either the ${cert_var} ${key_var} or ${ca_var}" \
420 "variable to enable SSL for ${service}"
421 fi
422
423 cat $ca >> $SSL_BUNDLE_FILE
424}
425
Rob Crittenden18d47782014-03-19 17:47:42 -0400426# Enable the mod_ssl plugin in Apache
427function enable_mod_ssl {
428 echo "Enabling mod_ssl"
429
430 if is_ubuntu; then
431 sudo a2enmod ssl
432 elif is_fedora; then
433 # Fedora enables mod_ssl by default
434 :
435 fi
436 if ! sudo `which httpd || which apache2ctl` -M | grep -w -q ssl_module; then
437 die $LINENO "mod_ssl is not enabled in apache2/httpd, please check for it manually and run stack.sh again"
438 fi
439}
440
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000441
Dean Troyerc83a7e12012-11-29 11:47:58 -0600442# Proxy Functions
443# ===============
444
Clark Boylancfb9f052016-11-29 10:43:05 -0800445function tune_apache_connections {
446 local tuning_file=$APACHE_SETTINGS_DIR/connection-tuning.conf
447 if ! [ -f $tuning_file ] ; then
448 sudo bash -c "cat > $tuning_file" << EOF
449# worker MPM
450# StartServers: initial number of server processes to start
451# MinSpareThreads: minimum number of worker threads which are kept spare
452# MaxSpareThreads: maximum number of worker threads which are kept spare
453# ThreadLimit: ThreadsPerChild can be changed to this maximum value during a
454# graceful restart. ThreadLimit can only be changed by stopping
455# and starting Apache.
456# ThreadsPerChild: constant number of worker threads in each server process
457# MaxClients: maximum number of simultaneous client connections
458# MaxRequestsPerChild: maximum number of requests a server process serves
459#
460# The apache defaults are too conservative if we want reliable tempest
461# testing. Bump these values up from ~400 max clients to 1024 max clients.
462<IfModule mpm_worker_module>
463# Note that the next three conf values must be changed together.
464# MaxClients = ServerLimit * ThreadsPerChild
465ServerLimit 32
466ThreadsPerChild 32
467MaxClients 1024
468StartServers 3
469MinSpareThreads 96
470MaxSpareThreads 192
471ThreadLimit 64
472MaxRequestsPerChild 0
473</IfModule>
474<IfModule mpm_event_module>
475# Note that the next three conf values must be changed together.
476# MaxClients = ServerLimit * ThreadsPerChild
477ServerLimit 32
478ThreadsPerChild 32
479MaxClients 1024
480StartServers 3
481MinSpareThreads 96
482MaxSpareThreads 192
483ThreadLimit 64
484MaxRequestsPerChild 0
485</IfModule>
486EOF
487 restart_apache_server
488 fi
489}
490
Dean Troyerc83a7e12012-11-29 11:47:58 -0600491# Starts the TLS proxy for the given IP/ports
492# start_tls_proxy front-host front-port back-host back-port
Ian Wienandaee18c72014-02-21 15:35:08 +1100493function start_tls_proxy {
Gregory Haynes4b49e402016-08-31 18:19:51 -0700494 local b_service="$1-tls-proxy"
495 local f_host=$2
496 local f_port=$3
497 local b_host=$4
498 local b_port=$5
Dean Troyerc83a7e12012-11-29 11:47:58 -0600499
Clark Boylancfb9f052016-11-29 10:43:05 -0800500 tune_apache_connections
501
Gregory Haynes4b49e402016-08-31 18:19:51 -0700502 local config_file
503 config_file=$(apache_site_config_for $b_service)
504 local listen_string
505 # Default apache configs on ubuntu and centos listen on 80 and 443
506 # newer apache seems fine with duplicate listen directive but older
507 # apache does not so special case 80 and 443.
508 if [[ "$f_port" == "80" ]] || [[ "$f_port" == "443" ]]; then
509 listen_string=""
510 elif [[ "$f_host" == '*' ]] ; then
511 listen_string="Listen $f_port"
512 else
513 listen_string="Listen $f_host:$f_port"
514 fi
515 sudo bash -c "cat >$config_file" << EOF
516$listen_string
517
518<VirtualHost $f_host:$f_port>
519 SSLEngine On
520 SSLCertificateFile $DEVSTACK_CERT
521
Jordan Pittier43709252017-02-14 16:48:20 +0100522 # Disable KeepAlive to fix bug #1630664 a.k.a the
523 # ('Connection aborted.', BadStatusLine("''",)) error
524 KeepAlive Off
525
Gregory Haynes4b49e402016-08-31 18:19:51 -0700526 <Location />
Jordan Pittierbc3d01c2017-02-14 15:35:59 +0000527 ProxyPass http://$b_host:$b_port/ retry=5 nocanon
Gregory Haynes4b49e402016-08-31 18:19:51 -0700528 ProxyPassReverse http://$b_host:$b_port/
529 </Location>
Clark Boylan66ce5c22016-10-05 12:11:05 -0700530 ErrorLog $APACHE_LOG_DIR/tls-proxy_error.log
531 ErrorLogFormat "[%{u}t] [%-m:%l] [pid %P:tid %T] %7F: %E: [client\ %a] [frontend\ %A] %M% ,\ referer\ %{Referer}i"
532 LogLevel info
533 CustomLog $APACHE_LOG_DIR/tls-proxy_access.log common
534 LogFormat "%v %h %l %u %t \"%r\" %>s %b"
Gregory Haynes4b49e402016-08-31 18:19:51 -0700535</VirtualHost>
536EOF
537 for mod in ssl proxy proxy_http; do
538 enable_apache_mod $mod
539 done
540 enable_apache_site $b_service
541 # Only a reload is required to pull in new vhosts
542 # Note that a restart reliably fails on centos7 and trusty
543 # because apache can't open port 80 because the old apache
544 # still has it open. Using reload fixes trusty but centos7
545 # still doesn't work.
546 reload_apache_server
Dean Troyerc83a7e12012-11-29 11:47:58 -0600547}
Sean Dague584d90e2013-03-29 14:34:53 -0400548
Sean Daguef06455e2016-10-07 06:57:03 -0400549# Follow TLS proxy
550function follow_tls_proxy {
551 sudo touch /var/log/$APACHE_NAME/tls-proxy_error.log
552 tail_log tls-error /var/log/$APACHE_NAME/tls-proxy_error.log
553 sudo touch /var/log/$APACHE_NAME/tls-proxy_access.log
554 tail_log tls-proxy /var/log/$APACHE_NAME/tls-proxy_access.log
555}
Dean Troyercc6b4432013-04-08 15:38:03 -0500556
Stanislaw Pituchabd5dae02014-06-25 15:29:43 +0100557# Cleanup Functions
Dean Troyer3324f192014-09-18 09:26:39 -0500558# =================
Stanislaw Pituchabd5dae02014-06-25 15:29:43 +0100559
Gregory Haynes4b49e402016-08-31 18:19:51 -0700560# Stops the apache service. This should be done only after all services
Stanislaw Pituchabd5dae02014-06-25 15:29:43 +0100561# using tls configuration are down.
562function stop_tls_proxy {
Gregory Haynes4b49e402016-08-31 18:19:51 -0700563 stop_apache_server
Stanislaw Pituchabd5dae02014-06-25 15:29:43 +0100564}
565
Gregory Haynes4b49e402016-08-31 18:19:51 -0700566# Clean up the CA files
567# cleanup_CA
Stanislaw Pituchabd5dae02014-06-25 15:29:43 +0100568function cleanup_CA {
Gregory Haynes4b49e402016-08-31 18:19:51 -0700569 if is_fedora; then
570 sudo rm -f /usr/share/pki/ca-trust-source/anchors/devstack-chain.pem
571 sudo update-ca-trust
572 elif is_ubuntu; then
573 sudo rm -f /usr/local/share/ca-certificates/devstack-int.crt
574 sudo rm -f /usr/local/share/ca-certificates/devstack-root.crt
575 sudo update-ca-certificates
576 fi
577
Clark Boylan323b7262016-09-23 13:33:40 -0700578 rm -rf "$INT_CA_DIR" "$ROOT_CA_DIR" "$DEVSTACK_CERT"
Stanislaw Pituchabd5dae02014-06-25 15:29:43 +0100579}
580
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100581# Tell emacs to use shell-script-mode
582## Local variables:
583## mode: shell-script
584## End: