Use TLS proxy for Glance API's internal TLS
authorJuan Antonio Osorio Robles <jaosorior@redhat.com>
Thu, 8 Dec 2016 10:02:57 +0000 (12:02 +0200)
committerJuan Antonio Osorio Robles <jaosorior@redhat.com>
Mon, 23 Jan 2017 14:54:43 +0000 (14:54 +0000)
This uses the tls_proxy resource added in the previous commit [1] in
front of the Glance API server when internal TLS is enabled. Right
now values are passed quite manually, but a subsequent commit will use
t-h-t to pass the appropriate hieradata, and then we'll be able to clean
it up from here.

Note that the proxy is only deployed when internal TLS is enabled.

[1] I82243fd3acfe4f23aab373116b78e1daf9d08467

bp tls-via-certmonger
Depends-On: Id5dfb38852cf2420f4195a3c1cb98d5c47bbd45e

Change-Id: Id35a846d43ecae8903a0d58306d9803d5ea00bee

manifests/haproxy.pp
manifests/profile/base/glance/api.pp

index 043e01e..b8a27af 100644 (file)
@@ -919,6 +919,7 @@ class tripleo::haproxy (
             'set-header X-Forwarded-Proto http if !{ ssl_fc }'],
       },
       service_network   => $glance_api_network,
+      member_options    => union($haproxy_member_options, $internal_tls_member_options),
     }
   }
 
index 8945fff..6134a87 100644 (file)
 #   (Optional) The hostname of the node responsible for bootstrapping tasks
 #   Defaults to hiera('bootstrap_nodeid')
 #
+# [*certificates_specs*]
+#   (Optional) The specifications to give to certmonger for the certificate(s)
+#   it will create.
+#   Example with hiera:
+#     apache_certificates_specs:
+#       httpd-internal_api:
+#         hostname: <overcloud controller fqdn>
+#         service_certificate: <service certificate path>
+#         service_key: <service key path>
+#         principal: "haproxy/<overcloud controller fqdn>"
+#   Defaults to hiera('apache_certificate_specs', {}).
+#
+# [*enable_internal_tls*]
+#   (Optional) Whether TLS in the internal network is enabled or not.
+#   Defaults to hiera('enable_internal_tls', false)
+#
+# [*generate_service_certificates*]
+#   (Optional) Whether or not certmonger will generate certificates for
+#   HAProxy. This could be as many as specified by the $certificates_specs
+#   variable.
+#   Note that this doesn't configure the certificates in haproxy, it merely
+#   creates the certificates.
+#   Defaults to hiera('generate_service_certificate', false).
+#
 # [*glance_backend*]
 #   (Optional) Glance backend(s) to use.
 #   Defaults to downcase(hiera('glance_backend', 'swift'))
 #
+# [*glance_network*]
+#   (Optional) The network name where the glance endpoint is listening on.
+#   This is set by t-h-t.
+#   Defaults to hiera('glance_api_network', undef)
+#
 # [*glance_nfs_enabled*]
 #   (Optional) Whether to use NFS mount as 'file' backend storage location.
 #   Defaults to false
 # [*rabbit_port*]
 #   IP port for rabbitmq service
 #   Defaults to hiera('glance::notify::rabbitmq::rabbit_port', 5672)
-
+#
 class tripleo::profile::base::glance::api (
-  $bootstrap_node     = hiera('bootstrap_nodeid', undef),
-  $glance_backend     = downcase(hiera('glance_backend', 'swift')),
-  $glance_nfs_enabled = false,
-  $step               = hiera('step'),
-  $rabbit_hosts       = hiera('rabbitmq_node_names', undef),
-  $rabbit_port        = hiera('glance::notify::rabbitmq::rabbit_port', 5672),
+  $bootstrap_node                = hiera('bootstrap_nodeid', undef),
+  $certificates_specs            = hiera('apache_certificates_specs', {}),
+  $enable_internal_tls           = hiera('enable_internal_tls', false),
+  $generate_service_certificates = hiera('generate_service_certificates', false),
+  $glance_backend                = downcase(hiera('glance_backend', 'swift')),
+  $glance_network                = hiera('glance_api_network', undef),
+  $glance_nfs_enabled            = false,
+  $step                          = hiera('step'),
+  $rabbit_hosts                  = hiera('rabbitmq_node_names', undef),
+  $rabbit_port                   = hiera('glance::notify::rabbitmq::rabbit_port', 5672),
 ) {
+  if $enable_internal_tls and $generate_service_certificates {
+    ensure_resources('tripleo::certmonger::httpd', $certificates_specs)
+  }
 
   if $::hostname == downcase($bootstrap_node) {
     $sync_db = true
@@ -63,6 +99,27 @@ class tripleo::profile::base::glance::api (
   }
 
   if $step >= 4 or ($step >= 3 and $sync_db) {
+    if $enable_internal_tls {
+      if !$glance_network {
+        fail('glance_api_network is not set in the hieradata.')
+      }
+      $tls_certfile = $certificates_specs["httpd-${glance_network}"]['service_certificate']
+      $tls_keyfile = $certificates_specs["httpd-${glance_network}"]['service_key']
+
+      ::tripleo::tls_proxy { 'glance-api':
+        servername => hiera("fqdn_${glance_network}"),
+        ip         => hiera('glance::api::bind_host'),
+        port       => hiera('glance::api::bind_port'),
+        tls_cert   => $tls_certfile,
+        tls_key    => $tls_keyfile,
+        notify     => Class['::glance::api'],
+      }
+      # TODO(jaosorior): Remove this when we pass it via t-h-t
+      $bind_host = 'localhost'
+    } else {
+      # TODO(jaosorior): Remove this when we pass it via t-h-t
+      $bind_host = hiera('glance::api::bind_host')
+    }
     case $glance_backend {
         'swift': { $backend_store = 'glance.store.swift.Store' }
         'file': { $backend_store = 'glance.store.filesystem.Store' }
@@ -75,9 +132,11 @@ class tripleo::profile::base::glance::api (
     # TODO: notifications, scrubber, etc.
     include ::glance
     include ::glance::config
+    # TODO(jaosorior): Remove bind_host when we set it up conditionally in t-h-t
     class { '::glance::api':
-      stores  => $glance_store,
-      sync_db => $sync_db,
+      bind_host => $bind_host,
+      stores    => $glance_store,
+      sync_db   => $sync_db,
     }
     $rabbit_endpoints = suffix(any2array($rabbit_hosts), ":${rabbit_port}")
     class { '::glance::notify::rabbitmq' :