| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
import base64 |
| 16 |
import requests |
| 17 |
import socket |
| 18 |
import ssl |
| 19 |
import tempfile |
| 20 |
|
| 21 |
from cryptography.hazmat.primitives import serialization |
| 22 |
import httpx |
| 23 |
from OpenSSL.crypto import X509 |
| 24 |
from OpenSSL import SSL |
| 25 |
|
| 26 |
from oslo_log import log as logging |
| 27 |
from oslo_utils import uuidutils |
| 28 |
from tempest import config |
| 29 |
from tempest.lib.common.utils import data_utils |
| 30 |
from tempest.lib import decorators |
| 31 |
import testtools |
| 32 |
|
| 33 |
from octavia_tempest_plugin.common import barbican_client_mgr |
| 34 |
from octavia_tempest_plugin.common import cert_utils |
| 35 |
from octavia_tempest_plugin.common import constants as const |
| 36 |
from octavia_tempest_plugin.tests import test_base |
| 37 |
from octavia_tempest_plugin.tests import waiters |
| 38 |
|
| 39 |
CONF = config.CONF |
| 40 |
LOG = logging.getLogger(__name__) |
| 41 |
|
| 42 |
|
| 43 |
class TLSWithBarbicanTest(test_base.LoadBalancerBaseTestWithCompute): |
| 44 |
@classmethod |
| 45 |
def skip_checks(cls): |
| 46 |
super(TLSWithBarbicanTest, cls).skip_checks() |
| 47 |
if not CONF.loadbalancer_feature_enabled.terminated_tls_enabled: |
| 48 |
raise cls.skipException( |
| 49 |
'[loadbalancer-feature-enabled] "terminated_tls_enabled" is ' |
| 50 |
'False in the tempest configuration. TLS tests will be ' |
| 51 |
'skipped.') |
| 52 |
if not CONF.validation.run_validation: |
| 53 |
raise cls.skipException('Traffic tests will not work without ' |
| 54 |
'run_validation enabled.') |
| 55 |
if not getattr(CONF.service_available, 'barbican', False): |
| 56 |
raise cls.skipException('TLS with Barbican tests require the ' |
| 57 |
'barbican service.') |
| 58 |
|
| 59 |
@classmethod |
| 60 |
def _store_secret(cls, barbican_mgr, secret): |
| 61 |
new_secret_ref = barbican_mgr.store_secret(secret) |
| 62 |
cls.addClassResourceCleanup(barbican_mgr.delete_secret, |
| 63 |
new_secret_ref) |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
if not cls.mem_lb_client.is_version_supported( |
| 68 |
cls.api_version, '2.1'): |
| 69 |
user_list = cls.os_admin.users_v3_client.list_users( |
| 70 |
name=CONF.load_balancer.octavia_svc_username) |
| 71 |
msg = 'Only one user named "{0}" should exist, {1} found.'.format( |
| 72 |
CONF.load_balancer.octavia_svc_username, |
| 73 |
len(user_list['users'])) |
| 74 |
assert 1 == len(user_list['users']), msg |
| 75 |
barbican_mgr.add_acl(new_secret_ref, user_list['users'][0]['id']) |
| 76 |
return new_secret_ref |
| 77 |
|
| 78 |
@classmethod |
| 79 |
def _generate_load_certificate(cls, barbican_mgr, ca_cert, ca_key, name): |
| 80 |
new_cert, new_key = cert_utils.generate_server_cert_and_key( |
| 81 |
ca_cert, ca_key, name) |
| 82 |
|
| 83 |
LOG.debug('%s Cert: %s', name, new_cert.public_bytes( |
| 84 |
serialization.Encoding.PEM)) |
| 85 |
LOG.debug('%s private Key: %s', name, new_key.private_bytes( |
| 86 |
encoding=serialization.Encoding.PEM, |
| 87 |
format=serialization.PrivateFormat.TraditionalOpenSSL, |
| 88 |
encryption_algorithm=serialization.NoEncryption())) |
| 89 |
new_public_key = new_key.public_key() |
| 90 |
LOG.debug('%s public Key: %s', name, new_public_key.public_bytes( |
| 91 |
encoding=serialization.Encoding.PEM, |
| 92 |
format=serialization.PublicFormat.SubjectPublicKeyInfo)) |
| 93 |
|
| 94 |
|
| 95 |
pkcs12 = cert_utils.generate_pkcs12_bundle(new_cert, new_key) |
| 96 |
LOG.debug('%s PKCS12 bundle: %s', name, base64.b64encode(pkcs12)) |
| 97 |
|
| 98 |
new_secret_ref = cls._store_secret(barbican_mgr, pkcs12) |
| 99 |
|
| 100 |
return new_cert, new_key, new_secret_ref |
| 101 |
|
| 102 |
@classmethod |
| 103 |
def _load_pool_pki(cls): |
| 104 |
|
| 105 |
pkcs12 = cert_utils.generate_pkcs12_bundle(cls.member_client_cert, |
| 106 |
cls.member_client_key) |
| 107 |
LOG.debug('Pool client PKCS12 bundle: %s', base64.b64encode(pkcs12)) |
| 108 |
|
| 109 |
cls.pool_client_ref = cls._store_secret(cls.barbican_mgr, pkcs12) |
| 110 |
|
| 111 |
cls.pool_CA_ref = cls._store_secret( |
| 112 |
cls.barbican_mgr, |
| 113 |
cls.member_ca_cert.public_bytes(serialization.Encoding.PEM)) |
| 114 |
|
| 115 |
cls.pool_CRL_ref = cls._store_secret( |
| 116 |
cls.barbican_mgr, |
| 117 |
cls.member_crl.public_bytes(serialization.Encoding.PEM)) |
| 118 |
|
| 119 |
@classmethod |
| 120 |
def resource_setup(cls): |
| 121 |
"""Setup resources needed by the tests.""" |
| 122 |
super(TLSWithBarbicanTest, cls).resource_setup() |
| 123 |
|
| 124 |
|
| 125 |
cls.ca_cert, ca_key = cert_utils.generate_ca_cert_and_key() |
| 126 |
|
| 127 |
LOG.debug('CA Cert: %s', cls.ca_cert.public_bytes( |
| 128 |
serialization.Encoding.PEM)) |
| 129 |
LOG.debug('CA private Key: %s', ca_key.private_bytes( |
| 130 |
encoding=serialization.Encoding.PEM, |
| 131 |
format=serialization.PrivateFormat.TraditionalOpenSSL, |
| 132 |
encryption_algorithm=serialization.NoEncryption())) |
| 133 |
LOG.debug('CA public Key: %s', ca_key.public_key().public_bytes( |
| 134 |
encoding=serialization.Encoding.PEM, |
| 135 |
format=serialization.PublicFormat.SubjectPublicKeyInfo)) |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
cls.barbican_mgr = barbican_client_mgr.BarbicanClientManager( |
| 140 |
cls.os_roles_lb_member) |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
cls.server_uuid = uuidutils.generate_uuid() |
| 145 |
LOG.debug('Server (default) UUID: %s', cls.server_uuid) |
| 146 |
|
| 147 |
server_cert, server_key, cls.server_secret_ref = ( |
| 148 |
cls._generate_load_certificate(cls.barbican_mgr, cls.ca_cert, |
| 149 |
ca_key, cls.server_uuid)) |
| 150 |
|
| 151 |
|
| 152 |
cls.SNI1_uuid = uuidutils.generate_uuid() |
| 153 |
LOG.debug('SNI1 UUID: %s', cls.SNI1_uuid) |
| 154 |
|
| 155 |
SNI1_cert, SNI1_key, cls.SNI1_secret_ref = ( |
| 156 |
cls._generate_load_certificate(cls.barbican_mgr, cls.ca_cert, |
| 157 |
ca_key, cls.SNI1_uuid)) |
| 158 |
|
| 159 |
|
| 160 |
cls.SNI2_uuid = uuidutils.generate_uuid() |
| 161 |
LOG.debug('SNI2 UUID: %s', cls.SNI2_uuid) |
| 162 |
|
| 163 |
SNI2_cert, SNI2_key, cls.SNI2_secret_ref = ( |
| 164 |
cls._generate_load_certificate(cls.barbican_mgr, cls.ca_cert, |
| 165 |
ca_key, cls.SNI2_uuid)) |
| 166 |
|
| 167 |
|
| 168 |
cls.client_ca_cert, client_ca_key = ( |
| 169 |
cert_utils.generate_ca_cert_and_key()) |
| 170 |
|
| 171 |
cls.client_ca_cert_ref = cls._store_secret( |
| 172 |
cls.barbican_mgr, |
| 173 |
cls.client_ca_cert.public_bytes(serialization.Encoding.PEM)) |
| 174 |
|
| 175 |
|
| 176 |
cls.client_cn = uuidutils.generate_uuid() |
| 177 |
cls.client_cert, cls.client_key = ( |
| 178 |
cert_utils.generate_client_cert_and_key( |
| 179 |
cls.client_ca_cert, client_ca_key, cls.client_cn)) |
| 180 |
|
| 181 |
|
| 182 |
cls.revoked_client_cn = uuidutils.generate_uuid() |
| 183 |
cls.revoked_client_cert, cls.revoked_client_key = ( |
| 184 |
cert_utils.generate_client_cert_and_key( |
| 185 |
cls.client_ca_cert, client_ca_key, cls.revoked_client_cn)) |
| 186 |
|
| 187 |
|
| 188 |
cls.client_crl = cert_utils.generate_certificate_revocation_list( |
| 189 |
cls.client_ca_cert, client_ca_key, cls.revoked_client_cert) |
| 190 |
|
| 191 |
cls.client_crl_ref = cls._store_secret( |
| 192 |
cls.barbican_mgr, |
| 193 |
cls.client_crl.public_bytes(serialization.Encoding.PEM)) |
| 194 |
|
| 195 |
cls._load_pool_pki() |
| 196 |
|
| 197 |
|
| 198 |
lb_name = data_utils.rand_name("lb_member_lb1-tls") |
| 199 |
lb_kwargs = {const.PROVIDER: CONF.load_balancer.provider, |
| 200 |
const.NAME: lb_name} |
| 201 |
|
| 202 |
|
| 203 |
cls._setup_lb_network_kwargs(lb_kwargs, 4) |
| 204 |
|
| 205 |
lb = cls.mem_lb_client.create_loadbalancer(**lb_kwargs) |
| 206 |
cls.lb_id = lb[const.ID] |
| 207 |
cls.addClassResourceCleanup( |
| 208 |
cls.mem_lb_client.cleanup_loadbalancer, |
| 209 |
cls.lb_id, cascade=True) |
| 210 |
|
| 211 |
waiters.wait_for_status(cls.mem_lb_client.show_loadbalancer, |
| 212 |
cls.lb_id, const.PROVISIONING_STATUS, |
| 213 |
const.ACTIVE, |
| 214 |
CONF.load_balancer.lb_build_interval, |
| 215 |
CONF.load_balancer.lb_build_timeout) |
| 216 |
|
| 217 |
if CONF.validation.connect_method == 'floating': |
| 218 |
port_id = lb[const.VIP_PORT_ID] |
| 219 |
result = cls.lb_mem_float_ip_client.create_floatingip( |
| 220 |
floating_network_id=CONF.network.public_network_id, |
| 221 |
port_id=port_id) |
| 222 |
floating_ip = result['floatingip'] |
| 223 |
LOG.info('lb1_floating_ip: %s', floating_ip) |
| 224 |
cls.addClassResourceCleanup( |
| 225 |
waiters.wait_for_not_found, |
| 226 |
cls.lb_mem_float_ip_client.delete_floatingip, |
| 227 |
cls.lb_mem_float_ip_client.show_floatingip, |
| 228 |
floatingip_id=floating_ip['id']) |
| 229 |
cls.lb_vip_address = floating_ip['floating_ip_address'] |
| 230 |
else: |
| 231 |
cls.lb_vip_address = lb[const.VIP_ADDRESS] |
| 232 |
|
| 233 |
pool_name = data_utils.rand_name("lb_member_pool1-tls") |
| 234 |
pool_kwargs = { |
| 235 |
const.NAME: pool_name, |
| 236 |
const.PROTOCOL: const.HTTP, |
| 237 |
const.LB_ALGORITHM: cls.lb_algorithm, |
| 238 |
const.LOADBALANCER_ID: cls.lb_id, |
| 239 |
} |
| 240 |
pool = cls.mem_pool_client.create_pool(**pool_kwargs) |
| 241 |
cls.pool_id = pool[const.ID] |
| 242 |
|
| 243 |
cls.addClassResourceCleanup( |
| 244 |
cls.mem_pool_client.cleanup_pool, |
| 245 |
cls.pool_id, |
| 246 |
lb_client=cls.mem_lb_client, lb_id=cls.lb_id) |
| 247 |
|
| 248 |
waiters.wait_for_status(cls.mem_lb_client.show_loadbalancer, |
| 249 |
cls.lb_id, const.PROVISIONING_STATUS, |
| 250 |
const.ACTIVE, |
| 251 |
CONF.load_balancer.build_interval, |
| 252 |
CONF.load_balancer.build_timeout) |
| 253 |
|
| 254 |
|
| 255 |
member1_name = data_utils.rand_name("lb_member_member1-tls") |
| 256 |
member1_kwargs = { |
| 257 |
const.POOL_ID: cls.pool_id, |
| 258 |
const.NAME: member1_name, |
| 259 |
const.ADMIN_STATE_UP: True, |
| 260 |
const.ADDRESS: cls.webserver1_ip, |
| 261 |
const.PROTOCOL_PORT: 80, |
| 262 |
} |
| 263 |
if cls.lb_member_1_subnet: |
| 264 |
member1_kwargs[const.SUBNET_ID] = cls.lb_member_1_subnet[const.ID] |
| 265 |
|
| 266 |
member1 = cls.mem_member_client.create_member(**member1_kwargs) |
| 267 |
|
| 268 |
cls.addClassResourceCleanup( |
| 269 |
cls.mem_member_client.cleanup_member, |
| 270 |
member1[const.ID], cls.pool_id, |
| 271 |
lb_client=cls.mem_lb_client, lb_id=cls.lb_id) |
| 272 |
|
| 273 |
waiters.wait_for_status( |
| 274 |
cls.mem_lb_client.show_loadbalancer, cls.lb_id, |
| 275 |
const.PROVISIONING_STATUS, const.ACTIVE, |
| 276 |
CONF.load_balancer.check_interval, |
| 277 |
CONF.load_balancer.check_timeout) |
| 278 |
|
| 279 |
|
| 280 |
member2_name = data_utils.rand_name("lb_member_member2-tls") |
| 281 |
member2_kwargs = { |
| 282 |
const.POOL_ID: cls.pool_id, |
| 283 |
const.NAME: member2_name, |
| 284 |
const.ADMIN_STATE_UP: True, |
| 285 |
const.ADDRESS: cls.webserver2_ip, |
| 286 |
const.PROTOCOL_PORT: 80, |
| 287 |
} |
| 288 |
if cls.lb_member_2_subnet: |
| 289 |
member2_kwargs[const.SUBNET_ID] = cls.lb_member_2_subnet[const.ID] |
| 290 |
|
| 291 |
member2 = cls.mem_member_client.create_member(**member2_kwargs) |
| 292 |
|
| 293 |
cls.addClassResourceCleanup( |
| 294 |
cls.mem_member_client.cleanup_member, |
| 295 |
member2[const.ID], cls.pool_id, |
| 296 |
lb_client=cls.mem_lb_client, lb_id=cls.lb_id) |
| 297 |
|
| 298 |
waiters.wait_for_status( |
| 299 |
cls.mem_lb_client.show_loadbalancer, cls.lb_id, |
| 300 |
const.PROVISIONING_STATUS, const.ACTIVE, |
| 301 |
CONF.load_balancer.check_interval, |
| 302 |
CONF.load_balancer.check_timeout) |
| 303 |
|
| 304 |
@decorators.idempotent_id('887ece26-0f7b-4933-89ab-5bb00b106ee0') |
| 305 |
def test_basic_tls_traffic(self): |
| 306 |
|
| 307 |
listener_name = data_utils.rand_name("lb_member_listener1-tls") |
| 308 |
listener_kwargs = { |
| 309 |
const.NAME: listener_name, |
| 310 |
const.PROTOCOL: const.TERMINATED_HTTPS, |
| 311 |
const.PROTOCOL_PORT: '443', |
| 312 |
const.LOADBALANCER_ID: self.lb_id, |
| 313 |
const.DEFAULT_POOL_ID: self.pool_id, |
| 314 |
const.DEFAULT_TLS_CONTAINER_REF: self.server_secret_ref, |
| 315 |
} |
| 316 |
listener = self.mem_listener_client.create_listener(**listener_kwargs) |
| 317 |
self.listener_id = listener[const.ID] |
| 318 |
self.addCleanup( |
| 319 |
self.mem_listener_client.cleanup_listener, |
| 320 |
self.listener_id, |
| 321 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 322 |
|
| 323 |
waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 324 |
self.lb_id, const.PROVISIONING_STATUS, |
| 325 |
const.ACTIVE, |
| 326 |
CONF.load_balancer.build_interval, |
| 327 |
CONF.load_balancer.build_timeout) |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
self.check_members_balanced(self.lb_vip_address, protocol=const.HTTPS, |
| 332 |
HTTPS_verify=False, protocol_port=443) |
| 333 |
|
| 334 |
def _verify_cb(connection, x509, errno, errdepth, retcode): |
| 335 |
"""Callback for certificate validation.""" |
| 336 |
|
| 337 |
if errdepth != 0: |
| 338 |
return True |
| 339 |
if errno == 0: |
| 340 |
received_cn = x509.get_subject().commonName |
| 341 |
received_name = self._get_cert_name(received_cn) |
| 342 |
expected_cn = '{}.example.com'.format(self.server_uuid) |
| 343 |
msg = ('ERROR: Received certificate "{received_name}" with CN ' |
| 344 |
'{received_cn} is not the expected certificate ' |
| 345 |
'"default" with CN {expected_cn}.'.format( |
| 346 |
received_name=received_name, |
| 347 |
received_cn=received_cn, |
| 348 |
expected_cn=expected_cn)) |
| 349 |
|
| 350 |
self.assertEqual(expected_cn, received_cn, message=msg) |
| 351 |
else: |
| 352 |
LOG.error('Certificate with CN: %s failed validation with ' |
| 353 |
'OpenSSL verify errno %s', |
| 354 |
x509.get_subject().commonName, errno) |
| 355 |
return False |
| 356 |
return True |
| 357 |
|
| 358 |
try: |
| 359 |
context = SSL.Context(SSL.TLS_METHOD) |
| 360 |
except AttributeError: |
| 361 |
context = SSL.Context(SSL.SSLv23_METHOD) |
| 362 |
context.set_verify(SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT, |
| 363 |
_verify_cb) |
| 364 |
ca_store = context.get_cert_store() |
| 365 |
ca_store.add_cert(X509.from_cryptography(self.ca_cert)) |
| 366 |
sock = socket.socket() |
| 367 |
sock = SSL.Connection(context, sock) |
| 368 |
sock.connect((self.lb_vip_address, 443)) |
| 369 |
|
| 370 |
sock.do_handshake() |
| 371 |
|
| 372 |
@decorators.idempotent_id('dcf11f78-7af3-4832-b716-9a01648f439c') |
| 373 |
def test_mixed_http_https_traffic(self): |
| 374 |
|
| 375 |
listener_name = data_utils.rand_name("lb_member_listener1-tls") |
| 376 |
listener_kwargs = { |
| 377 |
const.NAME: listener_name, |
| 378 |
const.PROTOCOL: const.TERMINATED_HTTPS, |
| 379 |
const.PROTOCOL_PORT: '443', |
| 380 |
const.LOADBALANCER_ID: self.lb_id, |
| 381 |
const.DEFAULT_POOL_ID: self.pool_id, |
| 382 |
const.DEFAULT_TLS_CONTAINER_REF: self.server_secret_ref, |
| 383 |
} |
| 384 |
listener = self.mem_listener_client.create_listener(**listener_kwargs) |
| 385 |
self.listener_id = listener[const.ID] |
| 386 |
self.addCleanup( |
| 387 |
self.mem_listener_client.cleanup_listener, |
| 388 |
self.listener_id, |
| 389 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 390 |
|
| 391 |
waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 392 |
self.lb_id, const.PROVISIONING_STATUS, |
| 393 |
const.ACTIVE, |
| 394 |
CONF.load_balancer.build_interval, |
| 395 |
CONF.load_balancer.build_timeout) |
| 396 |
|
| 397 |
listener_name = data_utils.rand_name("lb_member_listener2-http-tls") |
| 398 |
listener_kwargs = { |
| 399 |
const.NAME: listener_name, |
| 400 |
const.PROTOCOL: const.HTTP, |
| 401 |
const.PROTOCOL_PORT: '80', |
| 402 |
const.LOADBALANCER_ID: self.lb_id, |
| 403 |
const.DEFAULT_POOL_ID: self.pool_id, |
| 404 |
} |
| 405 |
listener = self.mem_listener_client.create_listener(**listener_kwargs) |
| 406 |
self.listener2_id = listener[const.ID] |
| 407 |
self.addCleanup( |
| 408 |
self.mem_listener_client.cleanup_listener, |
| 409 |
self.listener2_id, |
| 410 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 411 |
|
| 412 |
waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 413 |
self.lb_id, const.PROVISIONING_STATUS, |
| 414 |
const.ACTIVE, |
| 415 |
CONF.load_balancer.build_interval, |
| 416 |
CONF.load_balancer.build_timeout) |
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
self.check_members_balanced(self.lb_vip_address, protocol=const.HTTPS, |
| 421 |
HTTPS_verify=False, protocol_port=443) |
| 422 |
|
| 423 |
|
| 424 |
self.check_members_balanced(self.lb_vip_address) |
| 425 |
|
| 426 |
@decorators.idempotent_id('08405802-4411-4454-b008-8607408f424a') |
| 427 |
def test_basic_tls_SNI_traffic(self): |
| 428 |
|
| 429 |
listener_name = data_utils.rand_name("lb_member_listener1-tls-sni") |
| 430 |
listener_kwargs = { |
| 431 |
const.NAME: listener_name, |
| 432 |
const.PROTOCOL: const.TERMINATED_HTTPS, |
| 433 |
const.PROTOCOL_PORT: '443', |
| 434 |
const.LOADBALANCER_ID: self.lb_id, |
| 435 |
const.DEFAULT_POOL_ID: self.pool_id, |
| 436 |
const.DEFAULT_TLS_CONTAINER_REF: self.server_secret_ref, |
| 437 |
const.SNI_CONTAINER_REFS: [self.SNI1_secret_ref, |
| 438 |
self.SNI2_secret_ref], |
| 439 |
} |
| 440 |
listener = self.mem_listener_client.create_listener(**listener_kwargs) |
| 441 |
self.listener_id = listener[const.ID] |
| 442 |
self.addCleanup( |
| 443 |
self.mem_listener_client.cleanup_listener, |
| 444 |
self.listener_id, |
| 445 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 446 |
|
| 447 |
waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 448 |
self.lb_id, const.PROVISIONING_STATUS, |
| 449 |
const.ACTIVE, |
| 450 |
CONF.load_balancer.build_interval, |
| 451 |
CONF.load_balancer.build_timeout) |
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
self.check_members_balanced(self.lb_vip_address, protocol=const.HTTPS, |
| 456 |
HTTPS_verify=False, protocol_port=443) |
| 457 |
|
| 458 |
def _verify_server_cb(connection, x509, errno, errdepth, retcode): |
| 459 |
return _verify_cb(connection, x509, errno, errdepth, retcode, |
| 460 |
name=self.server_uuid) |
| 461 |
|
| 462 |
def _verify_SNI1_cb(connection, x509, errno, errdepth, retcode): |
| 463 |
return _verify_cb(connection, x509, errno, errdepth, retcode, |
| 464 |
name=self.SNI1_uuid) |
| 465 |
|
| 466 |
def _verify_SNI2_cb(connection, x509, errno, errdepth, retcode): |
| 467 |
return _verify_cb(connection, x509, errno, errdepth, retcode, |
| 468 |
name=self.SNI2_uuid) |
| 469 |
|
| 470 |
def _verify_cb(connection, x509, errno, errdepth, retcode, name): |
| 471 |
"""Callback for certificate validation.""" |
| 472 |
|
| 473 |
if errdepth != 0: |
| 474 |
return True |
| 475 |
if errno == 0: |
| 476 |
received_cn = x509.get_subject().commonName |
| 477 |
received_name = self._get_cert_name(received_cn) |
| 478 |
expected_cn = '{}.example.com'.format(name) |
| 479 |
expected_name = self._get_cert_name(name) |
| 480 |
msg = ('ERROR: Received certificate "{received_name}" with CN ' |
| 481 |
'{received_cn} is not the expected certificate ' |
| 482 |
'"{expected_name}" with CN {expected_cn}.'.format( |
| 483 |
received_name=received_name, |
| 484 |
received_cn=received_cn, |
| 485 |
expected_name=expected_name, |
| 486 |
expected_cn=expected_cn)) |
| 487 |
|
| 488 |
self.assertEqual(expected_cn, received_cn, message=msg) |
| 489 |
else: |
| 490 |
LOG.error('Certificate with CN: %s failed validation with ' |
| 491 |
'OpenSSL verify errno %s', |
| 492 |
x509.get_subject().commonName, errno) |
| 493 |
return False |
| 494 |
return True |
| 495 |
|
| 496 |
|
| 497 |
try: |
| 498 |
context = SSL.Context(SSL.TLS_METHOD) |
| 499 |
except AttributeError: |
| 500 |
context = SSL.Context(SSL.SSLv23_METHOD) |
| 501 |
context.set_verify(SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT, |
| 502 |
_verify_server_cb) |
| 503 |
ca_store = context.get_cert_store() |
| 504 |
ca_store.add_cert(X509.from_cryptography(self.ca_cert)) |
| 505 |
sock = socket.socket() |
| 506 |
sock = SSL.Connection(context, sock) |
| 507 |
sock.connect((self.lb_vip_address, 443)) |
| 508 |
|
| 509 |
sock.do_handshake() |
| 510 |
|
| 511 |
|
| 512 |
try: |
| 513 |
context = SSL.Context(SSL.TLS_METHOD) |
| 514 |
except AttributeError: |
| 515 |
context = SSL.Context(SSL.TLSv1_2_METHOD) |
| 516 |
context.set_verify(SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT, |
| 517 |
_verify_server_cb) |
| 518 |
ca_store = context.get_cert_store() |
| 519 |
ca_store.add_cert(X509.from_cryptography(self.ca_cert)) |
| 520 |
sock = socket.socket() |
| 521 |
sock = SSL.Connection(context, sock) |
| 522 |
sock.set_tlsext_host_name('bogus.example.com'.encode()) |
| 523 |
sock.connect((self.lb_vip_address, 443)) |
| 524 |
|
| 525 |
sock.do_handshake() |
| 526 |
|
| 527 |
|
| 528 |
try: |
| 529 |
context = SSL.Context(SSL.TLS_METHOD) |
| 530 |
except AttributeError: |
| 531 |
context = SSL.Context(SSL.TLSv1_2_METHOD) |
| 532 |
context.set_verify(SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT, |
| 533 |
_verify_SNI1_cb) |
| 534 |
ca_store = context.get_cert_store() |
| 535 |
ca_store.add_cert(X509.from_cryptography(self.ca_cert)) |
| 536 |
sock = socket.socket() |
| 537 |
sock = SSL.Connection(context, sock) |
| 538 |
sock.set_tlsext_host_name( |
| 539 |
'{}.example.com'.format(self.SNI1_uuid).encode()) |
| 540 |
sock.connect((self.lb_vip_address, 443)) |
| 541 |
|
| 542 |
sock.do_handshake() |
| 543 |
|
| 544 |
|
| 545 |
try: |
| 546 |
context = SSL.Context(SSL.TLS_METHOD) |
| 547 |
except AttributeError: |
| 548 |
context = SSL.Context(SSL.SSLv23_METHOD) |
| 549 |
context.set_verify(SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT, |
| 550 |
_verify_SNI2_cb) |
| 551 |
ca_store = context.get_cert_store() |
| 552 |
ca_store.add_cert(X509.from_cryptography(self.ca_cert)) |
| 553 |
sock = socket.socket() |
| 554 |
sock = SSL.Connection(context, sock) |
| 555 |
sock.set_tlsext_host_name( |
| 556 |
'{}.example.com'.format(self.SNI2_uuid).encode()) |
| 557 |
sock.connect((self.lb_vip_address, 443)) |
| 558 |
|
| 559 |
sock.do_handshake() |
| 560 |
|
| 561 |
def _get_cert_name(self, lookup_string): |
| 562 |
if self.server_uuid in lookup_string: |
| 563 |
return 'default' |
| 564 |
elif self.SNI1_uuid in lookup_string: |
| 565 |
return 'SNI1' |
| 566 |
elif self.SNI2_uuid in lookup_string: |
| 567 |
return 'SNI2' |
| 568 |
else: |
| 569 |
return 'Unknown' |
| 570 |
|
| 571 |
@decorators.idempotent_id('bfac9bf4-8cd0-4519-8d99-5ad0c75abf5c') |
| 572 |
def test_basic_tls_SNI_multi_listener_traffic(self): |
| 573 |
"""Make sure certificates are only used on the correct listeners.""" |
| 574 |
|
| 575 |
listener_name = data_utils.rand_name("lb_member_listener1-tls-sni") |
| 576 |
listener_kwargs = { |
| 577 |
const.NAME: listener_name, |
| 578 |
const.PROTOCOL: const.TERMINATED_HTTPS, |
| 579 |
const.PROTOCOL_PORT: '443', |
| 580 |
const.LOADBALANCER_ID: self.lb_id, |
| 581 |
const.DEFAULT_POOL_ID: self.pool_id, |
| 582 |
const.DEFAULT_TLS_CONTAINER_REF: self.server_secret_ref, |
| 583 |
const.SNI_CONTAINER_REFS: [self.SNI1_secret_ref], |
| 584 |
} |
| 585 |
listener = self.mem_listener_client.create_listener(**listener_kwargs) |
| 586 |
self.listener_id = listener[const.ID] |
| 587 |
self.addCleanup( |
| 588 |
self.mem_listener_client.cleanup_listener, |
| 589 |
self.listener_id, |
| 590 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 591 |
|
| 592 |
waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 593 |
self.lb_id, const.PROVISIONING_STATUS, |
| 594 |
const.ACTIVE, |
| 595 |
CONF.load_balancer.build_interval, |
| 596 |
CONF.load_balancer.build_timeout) |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
self.check_members_balanced(self.lb_vip_address, protocol=const.HTTPS, |
| 601 |
HTTPS_verify=False, protocol_port=443) |
| 602 |
|
| 603 |
listener2_name = data_utils.rand_name("lb_member_listener2-tls-sni") |
| 604 |
listener2_kwargs = { |
| 605 |
const.NAME: listener2_name, |
| 606 |
const.PROTOCOL: const.TERMINATED_HTTPS, |
| 607 |
const.PROTOCOL_PORT: '8443', |
| 608 |
const.LOADBALANCER_ID: self.lb_id, |
| 609 |
const.DEFAULT_POOL_ID: self.pool_id, |
| 610 |
const.DEFAULT_TLS_CONTAINER_REF: self.SNI2_secret_ref, |
| 611 |
} |
| 612 |
listener2 = self.mem_listener_client.create_listener( |
| 613 |
**listener2_kwargs) |
| 614 |
self.listener2_id = listener2[const.ID] |
| 615 |
self.addCleanup( |
| 616 |
self.mem_listener_client.cleanup_listener, |
| 617 |
self.listener2_id, |
| 618 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 619 |
|
| 620 |
waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 621 |
self.lb_id, const.PROVISIONING_STATUS, |
| 622 |
const.ACTIVE, |
| 623 |
CONF.load_balancer.build_interval, |
| 624 |
CONF.load_balancer.build_timeout) |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
self.check_members_balanced(self.lb_vip_address, protocol=const.HTTPS, |
| 629 |
HTTPS_verify=False, protocol_port=8443) |
| 630 |
|
| 631 |
def _verify_server_cb(connection, x509, errno, errdepth, retcode): |
| 632 |
return _verify_cb(connection, x509, errno, errdepth, retcode, |
| 633 |
name=self.server_uuid) |
| 634 |
|
| 635 |
def _verify_SNI1_cb(connection, x509, errno, errdepth, retcode): |
| 636 |
return _verify_cb(connection, x509, errno, errdepth, retcode, |
| 637 |
name=self.SNI1_uuid) |
| 638 |
|
| 639 |
def _verify_SNI2_cb(connection, x509, errno, errdepth, retcode): |
| 640 |
return _verify_cb(connection, x509, errno, errdepth, retcode, |
| 641 |
name=self.SNI2_uuid) |
| 642 |
|
| 643 |
def _verify_cb(connection, x509, errno, errdepth, retcode, name): |
| 644 |
"""Callback for certificate validation.""" |
| 645 |
|
| 646 |
if errdepth != 0: |
| 647 |
return True |
| 648 |
if errno == 0: |
| 649 |
received_cn = x509.get_subject().commonName |
| 650 |
received_name = self._get_cert_name(received_cn) |
| 651 |
expected_cn = '{}.example.com'.format(name) |
| 652 |
expected_name = self._get_cert_name(name) |
| 653 |
msg = ('ERROR: Received certificate "{received_name}" with CN ' |
| 654 |
'{received_cn} is not the expected certificate ' |
| 655 |
'"{expected_name}" with CN {expected_cn}.'.format( |
| 656 |
received_name=received_name, |
| 657 |
received_cn=received_cn, |
| 658 |
expected_name=expected_name, |
| 659 |
expected_cn=expected_cn)) |
| 660 |
|
| 661 |
self.assertEqual(expected_cn, received_cn, message=msg) |
| 662 |
else: |
| 663 |
LOG.error('Certificate with CN: %s failed validation with ' |
| 664 |
'OpenSSL verify errno %s', |
| 665 |
x509.get_subject().commonName, errno) |
| 666 |
return False |
| 667 |
return True |
| 668 |
|
| 669 |
|
| 670 |
try: |
| 671 |
context = SSL.Context(SSL.TLS_METHOD) |
| 672 |
except AttributeError: |
| 673 |
context = SSL.Context(SSL.SSLv23_METHOD) |
| 674 |
context.set_verify(SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT, |
| 675 |
_verify_server_cb) |
| 676 |
ca_store = context.get_cert_store() |
| 677 |
ca_store.add_cert(X509.from_cryptography(self.ca_cert)) |
| 678 |
sock = socket.socket() |
| 679 |
sock = SSL.Connection(context, sock) |
| 680 |
sock.connect((self.lb_vip_address, 443)) |
| 681 |
|
| 682 |
sock.do_handshake() |
| 683 |
|
| 684 |
|
| 685 |
try: |
| 686 |
context = SSL.Context(SSL.TLS_METHOD) |
| 687 |
except AttributeError: |
| 688 |
context = SSL.Context(SSL.TLSv1_2_METHOD) |
| 689 |
context.set_verify(SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT, |
| 690 |
_verify_SNI1_cb) |
| 691 |
ca_store = context.get_cert_store() |
| 692 |
ca_store.add_cert(X509.from_cryptography(self.ca_cert)) |
| 693 |
sock = socket.socket() |
| 694 |
sock = SSL.Connection(context, sock) |
| 695 |
sock.set_tlsext_host_name( |
| 696 |
'{}.example.com'.format(self.SNI1_uuid).encode()) |
| 697 |
sock.connect((self.lb_vip_address, 443)) |
| 698 |
|
| 699 |
sock.do_handshake() |
| 700 |
|
| 701 |
|
| 702 |
try: |
| 703 |
context = SSL.Context(SSL.TLS_METHOD) |
| 704 |
except AttributeError: |
| 705 |
context = SSL.Context(SSL.SSLv23_METHOD) |
| 706 |
context.set_verify(SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT, |
| 707 |
_verify_server_cb) |
| 708 |
ca_store = context.get_cert_store() |
| 709 |
ca_store.add_cert(X509.from_cryptography(self.ca_cert)) |
| 710 |
sock = socket.socket() |
| 711 |
sock = SSL.Connection(context, sock) |
| 712 |
sock.set_tlsext_host_name( |
| 713 |
'{}.example.com'.format(self.SNI2_uuid).encode()) |
| 714 |
sock.connect((self.lb_vip_address, 443)) |
| 715 |
|
| 716 |
sock.do_handshake() |
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
try: |
| 721 |
context = SSL.Context(SSL.TLS_METHOD) |
| 722 |
except AttributeError: |
| 723 |
context = SSL.Context(SSL.SSLv23_METHOD) |
| 724 |
context.set_verify(SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT, |
| 725 |
_verify_SNI2_cb) |
| 726 |
ca_store = context.get_cert_store() |
| 727 |
ca_store.add_cert(X509.from_cryptography(self.ca_cert)) |
| 728 |
sock = socket.socket() |
| 729 |
sock = SSL.Connection(context, sock) |
| 730 |
sock.connect((self.lb_vip_address, 8443)) |
| 731 |
|
| 732 |
sock.do_handshake() |
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
try: |
| 737 |
context = SSL.Context(SSL.TLS_METHOD) |
| 738 |
except AttributeError: |
| 739 |
context = SSL.Context(SSL.SSLv23_METHOD) |
| 740 |
context.set_verify(SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT, |
| 741 |
_verify_SNI2_cb) |
| 742 |
ca_store = context.get_cert_store() |
| 743 |
ca_store.add_cert(X509.from_cryptography(self.ca_cert)) |
| 744 |
sock = socket.socket() |
| 745 |
sock = SSL.Connection(context, sock) |
| 746 |
sock.set_tlsext_host_name( |
| 747 |
'{}.example.com'.format(self.server_uuid).encode()) |
| 748 |
sock.connect((self.lb_vip_address, 8443)) |
| 749 |
|
| 750 |
sock.do_handshake() |
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
try: |
| 755 |
context = SSL.Context(SSL.TLS_METHOD) |
| 756 |
except AttributeError: |
| 757 |
context = SSL.Context(SSL.SSLv23_METHOD) |
| 758 |
context.set_verify(SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT, |
| 759 |
_verify_SNI2_cb) |
| 760 |
ca_store = context.get_cert_store() |
| 761 |
ca_store.add_cert(X509.from_cryptography(self.ca_cert)) |
| 762 |
sock = socket.socket() |
| 763 |
sock = SSL.Connection(context, sock) |
| 764 |
sock.set_tlsext_host_name( |
| 765 |
'{}.example.com'.format(self.SNI1_uuid).encode()) |
| 766 |
sock.connect((self.lb_vip_address, 8443)) |
| 767 |
|
| 768 |
sock.do_handshake() |
| 769 |
|
| 770 |
@decorators.idempotent_id('af6bb7d2-acbb-4f6e-861f-39a2a3f02331') |
| 771 |
def test_tls_client_auth_mandatory(self): |
| 772 |
if not self.mem_listener_client.is_version_supported( |
| 773 |
self.api_version, '2.8'): |
| 774 |
raise self.skipException('TLS client authentication ' |
| 775 |
'is only available on Octavia API ' |
| 776 |
'version 2.8 or newer.') |
| 777 |
LISTENER1_TCP_PORT = '443' |
| 778 |
listener_name = data_utils.rand_name( |
| 779 |
"lb_member_listener1-client-auth-mand") |
| 780 |
listener_kwargs = { |
| 781 |
const.NAME: listener_name, |
| 782 |
const.PROTOCOL: const.TERMINATED_HTTPS, |
| 783 |
const.PROTOCOL_PORT: LISTENER1_TCP_PORT, |
| 784 |
const.LOADBALANCER_ID: self.lb_id, |
| 785 |
const.DEFAULT_POOL_ID: self.pool_id, |
| 786 |
const.DEFAULT_TLS_CONTAINER_REF: self.server_secret_ref, |
| 787 |
const.CLIENT_AUTHENTICATION: const.CLIENT_AUTH_MANDATORY, |
| 788 |
const.CLIENT_CA_TLS_CONTAINER_REF: self.client_ca_cert_ref, |
| 789 |
const.CLIENT_CRL_CONTAINER_REF: self.client_crl_ref, |
| 790 |
} |
| 791 |
listener = self.mem_listener_client.create_listener(**listener_kwargs) |
| 792 |
self.listener_id = listener[const.ID] |
| 793 |
self.addCleanup( |
| 794 |
self.mem_listener_client.cleanup_listener, |
| 795 |
self.listener_id, |
| 796 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 797 |
|
| 798 |
waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 799 |
self.lb_id, const.PROVISIONING_STATUS, |
| 800 |
const.ACTIVE, |
| 801 |
CONF.load_balancer.build_interval, |
| 802 |
CONF.load_balancer.build_timeout) |
| 803 |
|
| 804 |
|
| 805 |
self.assertRaises( |
| 806 |
requests.exceptions.SSLError, |
| 807 |
requests.get, |
| 808 |
'https://{0}:{1}'.format(self.lb_vip_address, LISTENER1_TCP_PORT), |
| 809 |
timeout=12, verify=False) |
| 810 |
|
| 811 |
|
| 812 |
with tempfile.NamedTemporaryFile(buffering=0) as cert_file: |
| 813 |
cert_file.write(self.revoked_client_cert.public_bytes( |
| 814 |
serialization.Encoding.PEM)) |
| 815 |
with tempfile.NamedTemporaryFile(buffering=0) as key_file: |
| 816 |
key_file.write(self.revoked_client_key.private_bytes( |
| 817 |
serialization.Encoding.PEM, |
| 818 |
serialization.PrivateFormat.TraditionalOpenSSL, |
| 819 |
serialization.NoEncryption())) |
| 820 |
self.assertRaises( |
| 821 |
requests.exceptions.SSLError, requests.get, |
| 822 |
'https://{0}:{1}'.format(self.lb_vip_address, |
| 823 |
LISTENER1_TCP_PORT), |
| 824 |
timeout=12, verify=False, cert=(cert_file.name, |
| 825 |
key_file.name)) |
| 826 |
|
| 827 |
|
| 828 |
with tempfile.NamedTemporaryFile(buffering=0) as cert_file: |
| 829 |
cert_file.write(self.client_cert.public_bytes( |
| 830 |
serialization.Encoding.PEM)) |
| 831 |
with tempfile.NamedTemporaryFile(buffering=0) as key_file: |
| 832 |
key_file.write(self.client_key.private_bytes( |
| 833 |
serialization.Encoding.PEM, |
| 834 |
serialization.PrivateFormat.TraditionalOpenSSL, |
| 835 |
serialization.NoEncryption())) |
| 836 |
response = requests.get( |
| 837 |
'https://{0}:{1}'.format(self.lb_vip_address, |
| 838 |
LISTENER1_TCP_PORT), |
| 839 |
timeout=12, verify=False, cert=(cert_file.name, |
| 840 |
key_file.name)) |
| 841 |
self.assertEqual(200, response.status_code) |
| 842 |
|
| 843 |
@decorators.idempotent_id('42d696bf-e7f5-44f0-9331-4a5e01d69ef3') |
| 844 |
def test_tls_client_auth_optional(self): |
| 845 |
if not self.mem_listener_client.is_version_supported( |
| 846 |
self.api_version, '2.8'): |
| 847 |
raise self.skipException('TLS client authentication ' |
| 848 |
'is only available on Octavia API ' |
| 849 |
'version 2.8 or newer.') |
| 850 |
LISTENER1_TCP_PORT = '443' |
| 851 |
listener_name = data_utils.rand_name( |
| 852 |
"lb_member_listener1-client-auth-optional") |
| 853 |
listener_kwargs = { |
| 854 |
const.NAME: listener_name, |
| 855 |
const.PROTOCOL: const.TERMINATED_HTTPS, |
| 856 |
const.PROTOCOL_PORT: LISTENER1_TCP_PORT, |
| 857 |
const.LOADBALANCER_ID: self.lb_id, |
| 858 |
const.DEFAULT_POOL_ID: self.pool_id, |
| 859 |
const.DEFAULT_TLS_CONTAINER_REF: self.server_secret_ref, |
| 860 |
const.CLIENT_AUTHENTICATION: const.CLIENT_AUTH_OPTIONAL, |
| 861 |
const.CLIENT_CA_TLS_CONTAINER_REF: self.client_ca_cert_ref, |
| 862 |
const.CLIENT_CRL_CONTAINER_REF: self.client_crl_ref, |
| 863 |
} |
| 864 |
listener = self.mem_listener_client.create_listener(**listener_kwargs) |
| 865 |
self.listener_id = listener[const.ID] |
| 866 |
self.addCleanup( |
| 867 |
self.mem_listener_client.cleanup_listener, |
| 868 |
self.listener_id, |
| 869 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 870 |
|
| 871 |
waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 872 |
self.lb_id, const.PROVISIONING_STATUS, |
| 873 |
const.ACTIVE, |
| 874 |
CONF.load_balancer.build_interval, |
| 875 |
CONF.load_balancer.build_timeout) |
| 876 |
|
| 877 |
|
| 878 |
response = requests.get( |
| 879 |
'https://{0}:{1}'.format(self.lb_vip_address, LISTENER1_TCP_PORT), |
| 880 |
timeout=12, verify=False) |
| 881 |
self.assertEqual(200, response.status_code) |
| 882 |
|
| 883 |
|
| 884 |
with tempfile.NamedTemporaryFile(buffering=0) as cert_file: |
| 885 |
cert_file.write(self.revoked_client_cert.public_bytes( |
| 886 |
serialization.Encoding.PEM)) |
| 887 |
with tempfile.NamedTemporaryFile(buffering=0) as key_file: |
| 888 |
key_file.write(self.revoked_client_key.private_bytes( |
| 889 |
serialization.Encoding.PEM, |
| 890 |
serialization.PrivateFormat.TraditionalOpenSSL, |
| 891 |
serialization.NoEncryption())) |
| 892 |
self.assertRaises( |
| 893 |
requests.exceptions.SSLError, requests.get, |
| 894 |
'https://{0}:{1}'.format(self.lb_vip_address, |
| 895 |
LISTENER1_TCP_PORT), |
| 896 |
timeout=12, verify=False, cert=(cert_file.name, |
| 897 |
key_file.name)) |
| 898 |
|
| 899 |
|
| 900 |
with tempfile.NamedTemporaryFile(buffering=0) as cert_file: |
| 901 |
cert_file.write(self.client_cert.public_bytes( |
| 902 |
serialization.Encoding.PEM)) |
| 903 |
with tempfile.NamedTemporaryFile(buffering=0) as key_file: |
| 904 |
key_file.write(self.client_key.private_bytes( |
| 905 |
serialization.Encoding.PEM, |
| 906 |
serialization.PrivateFormat.TraditionalOpenSSL, |
| 907 |
serialization.NoEncryption())) |
| 908 |
response = requests.get( |
| 909 |
'https://{0}:{1}'.format(self.lb_vip_address, |
| 910 |
LISTENER1_TCP_PORT), |
| 911 |
timeout=12, verify=False, cert=(cert_file.name, |
| 912 |
key_file.name)) |
| 913 |
self.assertEqual(200, response.status_code) |
| 914 |
|
| 915 |
@decorators.idempotent_id('13271ce6-f9f7-4017-a017-c2fc390b9438') |
| 916 |
def test_tls_multi_listener_client_auth(self): |
| 917 |
"""Test client authentication in a multi-listener LB. |
| 918 |
|
| 919 |
Validates that certificates and CRLs don't get cross configured |
| 920 |
between multiple listeners on the same load balancer. |
| 921 |
""" |
| 922 |
if not self.mem_listener_client.is_version_supported( |
| 923 |
self.api_version, '2.8'): |
| 924 |
raise self.skipException('TLS client authentication ' |
| 925 |
'is only available on Octavia API ' |
| 926 |
'version 2.8 or newer.') |
| 927 |
|
| 928 |
client2_ca_cert, client2_ca_key = ( |
| 929 |
cert_utils.generate_ca_cert_and_key()) |
| 930 |
|
| 931 |
client2_ca_cert_ref = self._store_secret( |
| 932 |
self.barbican_mgr, |
| 933 |
client2_ca_cert.public_bytes(serialization.Encoding.PEM)) |
| 934 |
|
| 935 |
|
| 936 |
client2_cn = uuidutils.generate_uuid() |
| 937 |
client2_cert, client2_key = ( |
| 938 |
cert_utils.generate_client_cert_and_key( |
| 939 |
client2_ca_cert, client2_ca_key, client2_cn)) |
| 940 |
|
| 941 |
|
| 942 |
revoked_client2_cn = uuidutils.generate_uuid() |
| 943 |
revoked_client2_cert, revoked_client2_key = ( |
| 944 |
cert_utils.generate_client_cert_and_key( |
| 945 |
client2_ca_cert, client2_ca_key, revoked_client2_cn)) |
| 946 |
|
| 947 |
|
| 948 |
client2_crl = cert_utils.generate_certificate_revocation_list( |
| 949 |
client2_ca_cert, client2_ca_key, revoked_client2_cert) |
| 950 |
|
| 951 |
client2_crl_ref = self._store_secret( |
| 952 |
self.barbican_mgr, |
| 953 |
client2_crl.public_bytes(serialization.Encoding.PEM)) |
| 954 |
|
| 955 |
LISTENER1_TCP_PORT = '443' |
| 956 |
listener_name = data_utils.rand_name( |
| 957 |
"lb_member_listener1-multi-list-client-auth") |
| 958 |
listener_kwargs = { |
| 959 |
const.NAME: listener_name, |
| 960 |
const.PROTOCOL: const.TERMINATED_HTTPS, |
| 961 |
const.PROTOCOL_PORT: LISTENER1_TCP_PORT, |
| 962 |
const.LOADBALANCER_ID: self.lb_id, |
| 963 |
const.DEFAULT_POOL_ID: self.pool_id, |
| 964 |
const.DEFAULT_TLS_CONTAINER_REF: self.server_secret_ref, |
| 965 |
const.CLIENT_AUTHENTICATION: const.CLIENT_AUTH_MANDATORY, |
| 966 |
const.CLIENT_CA_TLS_CONTAINER_REF: self.client_ca_cert_ref, |
| 967 |
const.CLIENT_CRL_CONTAINER_REF: self.client_crl_ref, |
| 968 |
} |
| 969 |
listener = self.mem_listener_client.create_listener(**listener_kwargs) |
| 970 |
self.listener_id = listener[const.ID] |
| 971 |
self.addCleanup( |
| 972 |
self.mem_listener_client.cleanup_listener, |
| 973 |
self.listener_id, |
| 974 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 975 |
|
| 976 |
waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 977 |
self.lb_id, const.PROVISIONING_STATUS, |
| 978 |
const.ACTIVE, |
| 979 |
CONF.load_balancer.build_interval, |
| 980 |
CONF.load_balancer.build_timeout) |
| 981 |
|
| 982 |
LISTENER2_TCP_PORT = '8443' |
| 983 |
listener_name = data_utils.rand_name( |
| 984 |
"lb_member_listener2-multi-list-client-auth") |
| 985 |
listener_kwargs = { |
| 986 |
const.NAME: listener_name, |
| 987 |
const.PROTOCOL: const.TERMINATED_HTTPS, |
| 988 |
const.PROTOCOL_PORT: LISTENER2_TCP_PORT, |
| 989 |
const.LOADBALANCER_ID: self.lb_id, |
| 990 |
const.DEFAULT_POOL_ID: self.pool_id, |
| 991 |
const.DEFAULT_TLS_CONTAINER_REF: self.server_secret_ref, |
| 992 |
const.CLIENT_AUTHENTICATION: const.CLIENT_AUTH_MANDATORY, |
| 993 |
const.CLIENT_CA_TLS_CONTAINER_REF: client2_ca_cert_ref, |
| 994 |
const.CLIENT_CRL_CONTAINER_REF: client2_crl_ref, |
| 995 |
} |
| 996 |
listener2 = self.mem_listener_client.create_listener(**listener_kwargs) |
| 997 |
self.listener2_id = listener2[const.ID] |
| 998 |
self.addCleanup( |
| 999 |
self.mem_listener_client.cleanup_listener, |
| 1000 |
self.listener2_id, |
| 1001 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 1002 |
|
| 1003 |
waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 1004 |
self.lb_id, const.PROVISIONING_STATUS, |
| 1005 |
const.ACTIVE, |
| 1006 |
CONF.load_balancer.build_interval, |
| 1007 |
CONF.load_balancer.build_timeout) |
| 1008 |
|
| 1009 |
|
| 1010 |
self.assertRaises( |
| 1011 |
requests.exceptions.SSLError, |
| 1012 |
requests.get, |
| 1013 |
'https://{0}:{1}'.format(self.lb_vip_address, LISTENER1_TCP_PORT), |
| 1014 |
timeout=12, verify=False) |
| 1015 |
|
| 1016 |
|
| 1017 |
self.assertRaises( |
| 1018 |
requests.exceptions.SSLError, |
| 1019 |
requests.get, |
| 1020 |
'https://{0}:{1}'.format(self.lb_vip_address, LISTENER2_TCP_PORT), |
| 1021 |
timeout=12, verify=False) |
| 1022 |
|
| 1023 |
|
| 1024 |
with tempfile.NamedTemporaryFile(buffering=0) as cert_file: |
| 1025 |
cert_file.write(self.revoked_client_cert.public_bytes( |
| 1026 |
serialization.Encoding.PEM)) |
| 1027 |
with tempfile.NamedTemporaryFile(buffering=0) as key_file: |
| 1028 |
key_file.write(self.revoked_client_key.private_bytes( |
| 1029 |
serialization.Encoding.PEM, |
| 1030 |
serialization.PrivateFormat.TraditionalOpenSSL, |
| 1031 |
serialization.NoEncryption())) |
| 1032 |
self.assertRaises( |
| 1033 |
requests.exceptions.SSLError, requests.get, |
| 1034 |
'https://{0}:{1}'.format(self.lb_vip_address, |
| 1035 |
LISTENER1_TCP_PORT), |
| 1036 |
timeout=12, verify=False, cert=(cert_file.name, |
| 1037 |
key_file.name)) |
| 1038 |
|
| 1039 |
|
| 1040 |
with tempfile.NamedTemporaryFile(buffering=0) as cert_file: |
| 1041 |
cert_file.write(revoked_client2_cert.public_bytes( |
| 1042 |
serialization.Encoding.PEM)) |
| 1043 |
with tempfile.NamedTemporaryFile(buffering=0) as key_file: |
| 1044 |
key_file.write(revoked_client2_key.private_bytes( |
| 1045 |
serialization.Encoding.PEM, |
| 1046 |
serialization.PrivateFormat.TraditionalOpenSSL, |
| 1047 |
serialization.NoEncryption())) |
| 1048 |
self.assertRaises( |
| 1049 |
requests.exceptions.SSLError, requests.get, |
| 1050 |
'https://{0}:{1}'.format(self.lb_vip_address, |
| 1051 |
LISTENER2_TCP_PORT), |
| 1052 |
timeout=12, verify=False, cert=(cert_file.name, |
| 1053 |
key_file.name)) |
| 1054 |
|
| 1055 |
|
| 1056 |
with tempfile.NamedTemporaryFile(buffering=0) as cert_file: |
| 1057 |
cert_file.write(self.client_cert.public_bytes( |
| 1058 |
serialization.Encoding.PEM)) |
| 1059 |
with tempfile.NamedTemporaryFile(buffering=0) as key_file: |
| 1060 |
key_file.write(self.client_key.private_bytes( |
| 1061 |
serialization.Encoding.PEM, |
| 1062 |
serialization.PrivateFormat.TraditionalOpenSSL, |
| 1063 |
serialization.NoEncryption())) |
| 1064 |
response = requests.get( |
| 1065 |
'https://{0}:{1}'.format(self.lb_vip_address, |
| 1066 |
LISTENER1_TCP_PORT), |
| 1067 |
timeout=12, verify=False, cert=(cert_file.name, |
| 1068 |
key_file.name)) |
| 1069 |
self.assertEqual(200, response.status_code) |
| 1070 |
|
| 1071 |
|
| 1072 |
with tempfile.NamedTemporaryFile(buffering=0) as cert_file: |
| 1073 |
cert_file.write(client2_cert.public_bytes( |
| 1074 |
serialization.Encoding.PEM)) |
| 1075 |
with tempfile.NamedTemporaryFile(buffering=0) as key_file: |
| 1076 |
key_file.write(client2_key.private_bytes( |
| 1077 |
serialization.Encoding.PEM, |
| 1078 |
serialization.PrivateFormat.TraditionalOpenSSL, |
| 1079 |
serialization.NoEncryption())) |
| 1080 |
response = requests.get( |
| 1081 |
'https://{0}:{1}'.format(self.lb_vip_address, |
| 1082 |
LISTENER2_TCP_PORT), |
| 1083 |
timeout=12, verify=False, cert=(cert_file.name, |
| 1084 |
key_file.name)) |
| 1085 |
self.assertEqual(200, response.status_code) |
| 1086 |
|
| 1087 |
|
| 1088 |
with tempfile.NamedTemporaryFile(buffering=0) as cert_file: |
| 1089 |
cert_file.write(self.client_cert.public_bytes( |
| 1090 |
serialization.Encoding.PEM)) |
| 1091 |
with tempfile.NamedTemporaryFile(buffering=0) as key_file: |
| 1092 |
key_file.write(self.client_key.private_bytes( |
| 1093 |
serialization.Encoding.PEM, |
| 1094 |
serialization.PrivateFormat.TraditionalOpenSSL, |
| 1095 |
serialization.NoEncryption())) |
| 1096 |
self.assertRaises( |
| 1097 |
requests.exceptions.SSLError, |
| 1098 |
requests.get, 'https://{0}:{1}'.format(self.lb_vip_address, |
| 1099 |
LISTENER2_TCP_PORT), |
| 1100 |
timeout=12, verify=False, cert=(cert_file.name, |
| 1101 |
key_file.name)) |
| 1102 |
|
| 1103 |
|
| 1104 |
with tempfile.NamedTemporaryFile(buffering=0) as cert_file: |
| 1105 |
cert_file.write(client2_cert.public_bytes( |
| 1106 |
serialization.Encoding.PEM)) |
| 1107 |
with tempfile.NamedTemporaryFile(buffering=0) as key_file: |
| 1108 |
key_file.write(client2_key.private_bytes( |
| 1109 |
serialization.Encoding.PEM, |
| 1110 |
serialization.PrivateFormat.TraditionalOpenSSL, |
| 1111 |
serialization.NoEncryption())) |
| 1112 |
self.assertRaises( |
| 1113 |
requests.exceptions.SSLError, |
| 1114 |
requests.get, 'https://{0}:{1}'.format(self.lb_vip_address, |
| 1115 |
LISTENER1_TCP_PORT), |
| 1116 |
timeout=12, verify=False, cert=(cert_file.name, |
| 1117 |
key_file.name)) |
| 1118 |
|
| 1119 |
|
| 1120 |
with tempfile.NamedTemporaryFile(buffering=0) as cert_file: |
| 1121 |
cert_file.write(self.revoked_client_cert.public_bytes( |
| 1122 |
serialization.Encoding.PEM)) |
| 1123 |
with tempfile.NamedTemporaryFile(buffering=0) as key_file: |
| 1124 |
key_file.write(self.revoked_client_key.private_bytes( |
| 1125 |
serialization.Encoding.PEM, |
| 1126 |
serialization.PrivateFormat.TraditionalOpenSSL, |
| 1127 |
serialization.NoEncryption())) |
| 1128 |
self.assertRaises( |
| 1129 |
requests.exceptions.SSLError, |
| 1130 |
requests.get, 'https://{0}:{1}'.format(self.lb_vip_address, |
| 1131 |
LISTENER2_TCP_PORT), |
| 1132 |
timeout=12, verify=False, cert=(cert_file.name, |
| 1133 |
key_file.name)) |
| 1134 |
|
| 1135 |
|
| 1136 |
with tempfile.NamedTemporaryFile(buffering=0) as cert_file: |
| 1137 |
cert_file.write(revoked_client2_cert.public_bytes( |
| 1138 |
serialization.Encoding.PEM)) |
| 1139 |
with tempfile.NamedTemporaryFile(buffering=0) as key_file: |
| 1140 |
key_file.write(revoked_client2_key.private_bytes( |
| 1141 |
serialization.Encoding.PEM, |
| 1142 |
serialization.PrivateFormat.TraditionalOpenSSL, |
| 1143 |
serialization.NoEncryption())) |
| 1144 |
self.assertRaises( |
| 1145 |
requests.exceptions.SSLError, |
| 1146 |
requests.get, 'https://{0}:{1}'.format(self.lb_vip_address, |
| 1147 |
LISTENER1_TCP_PORT), |
| 1148 |
timeout=12, verify=False, cert=(cert_file.name, |
| 1149 |
key_file.name)) |
| 1150 |
|
| 1151 |
@decorators.idempotent_id('19bade6f-302f-45dc-b316-553f1dfff49c') |
| 1152 |
def test_alpn_tls_traffic(self): |
| 1153 |
"""Test ALPN protocol negotiation""" |
| 1154 |
s_protos = c_protos = ['http/1.1'] |
| 1155 |
expected = 'http/1.1' |
| 1156 |
self._test_alpn_tls_traffic(s_protos, c_protos, expected) |
| 1157 |
|
| 1158 |
@decorators.idempotent_id('ee0d15a3-05b7-498d-9b2f-280d4896e597') |
| 1159 |
def test_alpn_fallback_tls_traffic(self): |
| 1160 |
"""Test ALPN protocol negotiation fallback""" |
| 1161 |
s_protos = ['http/1.0', 'http/1.1'] |
| 1162 |
c_protos = ['bogus', 'h2', 'http/1.1'] |
| 1163 |
expected = 'http/1.1' |
| 1164 |
self._test_alpn_tls_traffic(s_protos, c_protos, expected) |
| 1165 |
|
| 1166 |
@decorators.idempotent_id('56f4274a-ebd9-42f7-b897-baebc4b8eb5b') |
| 1167 |
def test_alpn_proto_not_supported_tls_traffic(self): |
| 1168 |
"""Test failed ALPN protocol negotiation""" |
| 1169 |
s_protos = ['http/1.1', 'http/1.0'] |
| 1170 |
c_protos = ['h2'] |
| 1171 |
expected = None |
| 1172 |
self._test_alpn_tls_traffic(s_protos, c_protos, expected) |
| 1173 |
|
| 1174 |
def _test_alpn_tls_traffic(self, s_protos, c_protos, expected_proto): |
| 1175 |
"""Test ALPN protocols between client and load balancer. |
| 1176 |
|
| 1177 |
:param s_protos: ALPN protocols the load balancer accepts during the |
| 1178 |
SSL/TLS handshake. |
| 1179 |
:type s_protos: list of str |
| 1180 |
:param c_protos: ALPN protocols the client advertise during SSL/TLS the |
| 1181 |
handshake. |
| 1182 |
:type c_protos: list of str |
| 1183 |
:param expected_proto: the expected ALPN protocol selected during the |
| 1184 |
SSL/TLS handshake. Setting to ``None`` means |
| 1185 |
parties could not agree on ALPN protocol. |
| 1186 |
:type expected_proto: str |
| 1187 |
:raises self.skipException: ALPN support not available prior to v2.20. |
| 1188 |
""" |
| 1189 |
if not self.mem_listener_client.is_version_supported( |
| 1190 |
self.api_version, '2.20'): |
| 1191 |
raise self.skipException('ALPN protocols are only available on ' |
| 1192 |
'Octavia API version 2.20 or newer.') |
| 1193 |
listener_name = data_utils.rand_name("lb_member_listener1-tls-alpn") |
| 1194 |
listener_kwargs = { |
| 1195 |
const.NAME: listener_name, |
| 1196 |
const.PROTOCOL: const.TERMINATED_HTTPS, |
| 1197 |
const.PROTOCOL_PORT: '443', |
| 1198 |
const.LOADBALANCER_ID: self.lb_id, |
| 1199 |
const.DEFAULT_POOL_ID: self.pool_id, |
| 1200 |
const.DEFAULT_TLS_CONTAINER_REF: self.server_secret_ref, |
| 1201 |
const.ALPN_PROTOCOLS: s_protos, |
| 1202 |
} |
| 1203 |
listener = self.mem_listener_client.create_listener(**listener_kwargs) |
| 1204 |
self.listener_id = listener[const.ID] |
| 1205 |
self.addCleanup( |
| 1206 |
self.mem_listener_client.cleanup_listener, |
| 1207 |
self.listener_id, |
| 1208 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 1209 |
|
| 1210 |
waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 1211 |
self.lb_id, const.PROVISIONING_STATUS, |
| 1212 |
const.ACTIVE, |
| 1213 |
CONF.load_balancer.build_interval, |
| 1214 |
CONF.load_balancer.build_timeout) |
| 1215 |
|
| 1216 |
context = ssl.SSLContext(ssl.PROTOCOL_TLS) |
| 1217 |
context.set_alpn_protocols(c_protos) |
| 1218 |
s = socket.socket() |
| 1219 |
ssl_sock = context.wrap_socket(s) |
| 1220 |
ssl_sock.connect((self.lb_vip_address, 443)) |
| 1221 |
selected_proto = ssl_sock.selected_alpn_protocol() |
| 1222 |
|
| 1223 |
self.assertEqual(expected_proto, selected_proto) |
| 1224 |
|
| 1225 |
def _test_http_versions_tls_traffic(self, http_version, alpn_protos, |
| 1226 |
hsts: bool = False): |
| 1227 |
if not self.mem_listener_client.is_version_supported( |
| 1228 |
self.api_version, '2.20'): |
| 1229 |
raise self.skipException('ALPN protocols are only available on ' |
| 1230 |
'Octavia API version 2.20 or newer.') |
| 1231 |
listener_name = data_utils.rand_name("lb_member_listener1-tls-alpn") |
| 1232 |
listener_kwargs = { |
| 1233 |
const.NAME: listener_name, |
| 1234 |
const.PROTOCOL: const.TERMINATED_HTTPS, |
| 1235 |
const.PROTOCOL_PORT: '443', |
| 1236 |
const.LOADBALANCER_ID: self.lb_id, |
| 1237 |
const.DEFAULT_POOL_ID: self.pool_id, |
| 1238 |
const.DEFAULT_TLS_CONTAINER_REF: self.server_secret_ref, |
| 1239 |
const.ALPN_PROTOCOLS: alpn_protos, |
| 1240 |
} |
| 1241 |
if self.mem_listener_client.is_version_supported( |
| 1242 |
self.api_version, '2.27'): |
| 1243 |
listener_kwargs[const.HSTS_MAX_AGE] = 100 if hsts else None |
| 1244 |
listener_kwargs[const.HSTS_INCLUDE_SUBDOMAINS] = hsts |
| 1245 |
listener_kwargs[const.HSTS_PRELOAD] = hsts |
| 1246 |
|
| 1247 |
listener = self.mem_listener_client.create_listener(**listener_kwargs) |
| 1248 |
self.listener_id = listener[const.ID] |
| 1249 |
self.addCleanup( |
| 1250 |
self.mem_listener_client.cleanup_listener, |
| 1251 |
self.listener_id, |
| 1252 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 1253 |
|
| 1254 |
waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 1255 |
self.lb_id, const.PROVISIONING_STATUS, |
| 1256 |
const.ACTIVE, |
| 1257 |
CONF.load_balancer.build_interval, |
| 1258 |
CONF.load_balancer.build_timeout) |
| 1259 |
context = ssl.create_default_context(cadata=self.ca_cert.public_bytes( |
| 1260 |
serialization.Encoding.PEM).decode('utf-8')) |
| 1261 |
context.check_hostname = False |
| 1262 |
|
| 1263 |
url = 'https://%s:%s' % (self.lb_vip_address, 443) |
| 1264 |
client_kwargs = { |
| 1265 |
'verify': context |
| 1266 |
} |
| 1267 |
if http_version == 'HTTP/2': |
| 1268 |
client_kwargs['http1'] = False |
| 1269 |
client_kwargs['http2'] = True |
| 1270 |
client = httpx.Client(**client_kwargs) |
| 1271 |
r = client.get(url) |
| 1272 |
self.assertEqual(http_version, r.http_version) |
| 1273 |
if hsts: |
| 1274 |
self.assertIn('strict-transport-security', r.headers) |
| 1275 |
self.assertEqual('max-age=100; includeSubDomains; preload;', |
| 1276 |
r.headers['strict-transport-security']) |
| 1277 |
else: |
| 1278 |
self.assertNotIn('strict-transport-security', r.headers) |
| 1279 |
|
| 1280 |
@decorators.idempotent_id('9965828d-24af-4fa0-91ae-21c6bc47ab4c') |
| 1281 |
def test_http_2_tls_traffic(self): |
| 1282 |
self._test_http_versions_tls_traffic('HTTP/2', ['h2', 'http/1.1']) |
| 1283 |
|
| 1284 |
@decorators.idempotent_id('a0dff0f2-d53e-497c-9ded-dca64e82991f') |
| 1285 |
def test_http_1_1_tls_traffic(self): |
| 1286 |
self._test_http_versions_tls_traffic( |
| 1287 |
'HTTP/1.1', ['http/1.1', 'http/1.0']) |
| 1288 |
|
| 1289 |
@decorators.idempotent_id('7436c6b7-44be-4544-a40b-31d2b7b2ad0b') |
| 1290 |
def test_http_1_1_tls_hsts_traffic(self): |
| 1291 |
if not self.mem_listener_client.is_version_supported( |
| 1292 |
self.api_version, '2.27'): |
| 1293 |
raise self.skipException('HSTS is only available on ' |
| 1294 |
'Octavia API version 2.27 or newer.') |
| 1295 |
self._test_http_versions_tls_traffic( |
| 1296 |
'HTTP/1.1', ['http/1.1', 'http/1.0'], hsts=True) |
| 1297 |
|
| 1298 |
@decorators.idempotent_id('ee0faf71-d11e-4323-8673-e5e15779749b') |
| 1299 |
def test_pool_reencryption(self): |
| 1300 |
if not self.mem_listener_client.is_version_supported( |
| 1301 |
self.api_version, '2.8'): |
| 1302 |
raise self.skipException('Pool re-encryption is only available on ' |
| 1303 |
'Octavia API version 2.8 or newer.') |
| 1304 |
pool_name = data_utils.rand_name("lb_member_pool1-tls-reencrypt") |
| 1305 |
pool_kwargs = { |
| 1306 |
const.NAME: pool_name, |
| 1307 |
const.PROTOCOL: const.HTTP, |
| 1308 |
const.LB_ALGORITHM: self.lb_algorithm, |
| 1309 |
const.LOADBALANCER_ID: self.lb_id, |
| 1310 |
const.TLS_ENABLED: True |
| 1311 |
} |
| 1312 |
pool = self.mem_pool_client.create_pool(**pool_kwargs) |
| 1313 |
pool_id = pool[const.ID] |
| 1314 |
|
| 1315 |
self.addClassResourceCleanup( |
| 1316 |
self.mem_pool_client.cleanup_pool, |
| 1317 |
pool_id, |
| 1318 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 1319 |
|
| 1320 |
waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 1321 |
self.lb_id, const.PROVISIONING_STATUS, |
| 1322 |
const.ACTIVE, |
| 1323 |
CONF.load_balancer.build_interval, |
| 1324 |
CONF.load_balancer.build_timeout) |
| 1325 |
|
| 1326 |
|
| 1327 |
member1_name = data_utils.rand_name("lb_member_member1-tls-reencrypt") |
| 1328 |
member1_kwargs = { |
| 1329 |
const.POOL_ID: pool_id, |
| 1330 |
const.NAME: member1_name, |
| 1331 |
const.ADMIN_STATE_UP: True, |
| 1332 |
const.ADDRESS: self.webserver1_ip, |
| 1333 |
const.PROTOCOL_PORT: 443, |
| 1334 |
} |
| 1335 |
if self.lb_member_1_subnet: |
| 1336 |
member1_kwargs[const.SUBNET_ID] = self.lb_member_1_subnet[const.ID] |
| 1337 |
|
| 1338 |
member1 = self.mem_member_client.create_member(**member1_kwargs) |
| 1339 |
|
| 1340 |
self.addClassResourceCleanup( |
| 1341 |
self.mem_member_client.cleanup_member, |
| 1342 |
member1[const.ID], pool_id, |
| 1343 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 1344 |
|
| 1345 |
waiters.wait_for_status( |
| 1346 |
self.mem_lb_client.show_loadbalancer, self.lb_id, |
| 1347 |
const.PROVISIONING_STATUS, const.ACTIVE, |
| 1348 |
CONF.load_balancer.check_interval, |
| 1349 |
CONF.load_balancer.check_timeout) |
| 1350 |
|
| 1351 |
|
| 1352 |
member2_name = data_utils.rand_name("lb_member_member2-tls-reencrypt") |
| 1353 |
member2_kwargs = { |
| 1354 |
const.POOL_ID: pool_id, |
| 1355 |
const.NAME: member2_name, |
| 1356 |
const.ADMIN_STATE_UP: True, |
| 1357 |
const.ADDRESS: self.webserver2_ip, |
| 1358 |
const.PROTOCOL_PORT: 443, |
| 1359 |
} |
| 1360 |
if self.lb_member_2_subnet: |
| 1361 |
member2_kwargs[const.SUBNET_ID] = self.lb_member_2_subnet[const.ID] |
| 1362 |
|
| 1363 |
member2 = self.mem_member_client.create_member(**member2_kwargs) |
| 1364 |
|
| 1365 |
self.addClassResourceCleanup( |
| 1366 |
self.mem_member_client.cleanup_member, |
| 1367 |
member2[const.ID], pool_id, |
| 1368 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 1369 |
|
| 1370 |
waiters.wait_for_status( |
| 1371 |
self.mem_lb_client.show_loadbalancer, self.lb_id, |
| 1372 |
const.PROVISIONING_STATUS, const.ACTIVE, |
| 1373 |
CONF.load_balancer.check_interval, |
| 1374 |
CONF.load_balancer.check_timeout) |
| 1375 |
|
| 1376 |
listener_name = data_utils.rand_name( |
| 1377 |
"lb_member_listener1-tls-reencrypt") |
| 1378 |
listener_kwargs = { |
| 1379 |
const.NAME: listener_name, |
| 1380 |
const.PROTOCOL: const.HTTP, |
| 1381 |
const.PROTOCOL_PORT: '84', |
| 1382 |
const.LOADBALANCER_ID: self.lb_id, |
| 1383 |
const.DEFAULT_POOL_ID: pool_id, |
| 1384 |
} |
| 1385 |
listener = self.mem_listener_client.create_listener(**listener_kwargs) |
| 1386 |
self.listener_id = listener[const.ID] |
| 1387 |
|
| 1388 |
self.addCleanup( |
| 1389 |
self.mem_listener_client.cleanup_listener, |
| 1390 |
self.listener_id, |
| 1391 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 1392 |
|
| 1393 |
waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 1394 |
self.lb_id, const.PROVISIONING_STATUS, |
| 1395 |
const.ACTIVE, |
| 1396 |
CONF.load_balancer.build_interval, |
| 1397 |
CONF.load_balancer.build_timeout) |
| 1398 |
|
| 1399 |
|
| 1400 |
self.check_members_balanced(self.lb_vip_address, protocol=const.HTTP, |
| 1401 |
protocol_port=84) |
| 1402 |
|
| 1403 |
|
| 1404 |
pool_update_kwargs = { |
| 1405 |
const.CA_TLS_CONTAINER_REF: self.client_ca_cert_ref |
| 1406 |
} |
| 1407 |
|
| 1408 |
self.mem_pool_client.update_pool(pool_id, **pool_update_kwargs) |
| 1409 |
|
| 1410 |
waiters.wait_for_status( |
| 1411 |
self.mem_lb_client.show_loadbalancer, self.lb_id, |
| 1412 |
const.PROVISIONING_STATUS, const.ACTIVE, |
| 1413 |
CONF.load_balancer.check_interval, |
| 1414 |
CONF.load_balancer.check_timeout) |
| 1415 |
waiters.wait_for_status( |
| 1416 |
self.mem_pool_client.show_pool, pool_id, |
| 1417 |
const.PROVISIONING_STATUS, const.ACTIVE, |
| 1418 |
CONF.load_balancer.check_interval, |
| 1419 |
CONF.load_balancer.check_timeout) |
| 1420 |
|
| 1421 |
url = 'http://{0}:84'.format(self.lb_vip_address) |
| 1422 |
self.validate_URL_response(url, expected_status_code=503) |
| 1423 |
|
| 1424 |
|
| 1425 |
pool_update_kwargs = { |
| 1426 |
const.CA_TLS_CONTAINER_REF: self.pool_CA_ref |
| 1427 |
} |
| 1428 |
|
| 1429 |
self.mem_pool_client.update_pool(pool_id, **pool_update_kwargs) |
| 1430 |
|
| 1431 |
waiters.wait_for_status( |
| 1432 |
self.mem_lb_client.show_loadbalancer, self.lb_id, |
| 1433 |
const.PROVISIONING_STATUS, const.ACTIVE, |
| 1434 |
CONF.load_balancer.check_interval, |
| 1435 |
CONF.load_balancer.check_timeout) |
| 1436 |
waiters.wait_for_status( |
| 1437 |
self.mem_pool_client.show_pool, pool_id, |
| 1438 |
const.PROVISIONING_STATUS, const.ACTIVE, |
| 1439 |
CONF.load_balancer.check_interval, |
| 1440 |
CONF.load_balancer.check_timeout) |
| 1441 |
|
| 1442 |
self.check_members_balanced(self.lb_vip_address, protocol=const.HTTP, |
| 1443 |
protocol_port=84) |
| 1444 |
|
| 1445 |
|
| 1446 |
pool_update_kwargs = { |
| 1447 |
const.CRL_CONTAINER_REF: self.pool_CRL_ref |
| 1448 |
} |
| 1449 |
|
| 1450 |
self.mem_pool_client.update_pool(pool_id, **pool_update_kwargs) |
| 1451 |
|
| 1452 |
waiters.wait_for_status( |
| 1453 |
self.mem_lb_client.show_loadbalancer, self.lb_id, |
| 1454 |
const.PROVISIONING_STATUS, const.ACTIVE, |
| 1455 |
CONF.load_balancer.check_interval, |
| 1456 |
CONF.load_balancer.check_timeout) |
| 1457 |
waiters.wait_for_status( |
| 1458 |
self.mem_pool_client.show_pool, pool_id, |
| 1459 |
const.PROVISIONING_STATUS, const.ACTIVE, |
| 1460 |
CONF.load_balancer.check_interval, |
| 1461 |
CONF.load_balancer.check_timeout) |
| 1462 |
|
| 1463 |
self.check_members_balanced(self.lb_vip_address, protocol=const.HTTP, |
| 1464 |
protocol_port=84, traffic_member_count=1) |
| 1465 |
|
| 1466 |
@decorators.idempotent_id('11b67c96-a553-4b47-9fc6-4c3d7a2a10ce') |
| 1467 |
def test_pool_reencryption_client_authentication(self): |
| 1468 |
if not self.mem_listener_client.is_version_supported( |
| 1469 |
self.api_version, '2.8'): |
| 1470 |
raise self.skipException('Pool re-encryption is only available on ' |
| 1471 |
'Octavia API version 2.8 or newer.') |
| 1472 |
pool_name = data_utils.rand_name("lb_member_pool1-tls-client-auth") |
| 1473 |
pool_kwargs = { |
| 1474 |
const.NAME: pool_name, |
| 1475 |
const.PROTOCOL: const.HTTP, |
| 1476 |
const.LB_ALGORITHM: self.lb_algorithm, |
| 1477 |
const.LOADBALANCER_ID: self.lb_id, |
| 1478 |
const.TLS_ENABLED: True |
| 1479 |
} |
| 1480 |
|
| 1481 |
|
| 1482 |
if self.mem_listener_client.is_version_supported( |
| 1483 |
self.api_version, '2.24'): |
| 1484 |
pool_kwargs[const.ALPN_PROTOCOLS] = ['http/1.0', 'http/1.1'] |
| 1485 |
|
| 1486 |
pool = self.mem_pool_client.create_pool(**pool_kwargs) |
| 1487 |
pool_id = pool[const.ID] |
| 1488 |
|
| 1489 |
self.addClassResourceCleanup( |
| 1490 |
self.mem_pool_client.cleanup_pool, |
| 1491 |
pool_id, |
| 1492 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 1493 |
|
| 1494 |
waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 1495 |
self.lb_id, const.PROVISIONING_STATUS, |
| 1496 |
const.ACTIVE, |
| 1497 |
CONF.load_balancer.build_interval, |
| 1498 |
CONF.load_balancer.build_timeout) |
| 1499 |
|
| 1500 |
hm_name = data_utils.rand_name("lb_member_hm1-tls-client-auth") |
| 1501 |
hm_kwargs = { |
| 1502 |
const.POOL_ID: pool_id, |
| 1503 |
const.NAME: hm_name, |
| 1504 |
const.TYPE: const.HEALTH_MONITOR_HTTPS, |
| 1505 |
const.HTTP_METHOD: const.GET, |
| 1506 |
const.URL_PATH: '/', |
| 1507 |
const.EXPECTED_CODES: '200', |
| 1508 |
const.DELAY: 1, |
| 1509 |
const.TIMEOUT: 1, |
| 1510 |
const.MAX_RETRIES: 1, |
| 1511 |
const.MAX_RETRIES_DOWN: 1, |
| 1512 |
const.ADMIN_STATE_UP: True, |
| 1513 |
} |
| 1514 |
hm = self.mem_healthmonitor_client.create_healthmonitor(**hm_kwargs) |
| 1515 |
self.addCleanup( |
| 1516 |
self.mem_healthmonitor_client.cleanup_healthmonitor, |
| 1517 |
hm[const.ID], |
| 1518 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 1519 |
|
| 1520 |
waiters.wait_for_status( |
| 1521 |
self.mem_lb_client.show_loadbalancer, self.lb_id, |
| 1522 |
const.PROVISIONING_STATUS, const.ACTIVE, |
| 1523 |
CONF.load_balancer.build_interval, |
| 1524 |
CONF.load_balancer.build_timeout) |
| 1525 |
hm = waiters.wait_for_status( |
| 1526 |
self.mem_healthmonitor_client.show_healthmonitor, |
| 1527 |
hm[const.ID], const.PROVISIONING_STATUS, |
| 1528 |
const.ACTIVE, |
| 1529 |
CONF.load_balancer.build_interval, |
| 1530 |
CONF.load_balancer.build_timeout) |
| 1531 |
|
| 1532 |
|
| 1533 |
member1_name = data_utils.rand_name( |
| 1534 |
"lb_member_member1-tls-client-auth") |
| 1535 |
member1_kwargs = { |
| 1536 |
const.POOL_ID: pool_id, |
| 1537 |
const.NAME: member1_name, |
| 1538 |
const.ADMIN_STATE_UP: True, |
| 1539 |
const.ADDRESS: self.webserver1_ip, |
| 1540 |
const.PROTOCOL_PORT: 9443, |
| 1541 |
} |
| 1542 |
if self.lb_member_1_subnet: |
| 1543 |
member1_kwargs[const.SUBNET_ID] = self.lb_member_1_subnet[const.ID] |
| 1544 |
|
| 1545 |
member1 = self.mem_member_client.create_member(**member1_kwargs) |
| 1546 |
|
| 1547 |
self.addCleanup( |
| 1548 |
self.mem_member_client.cleanup_member, |
| 1549 |
member1[const.ID], pool_id=pool_id, |
| 1550 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 1551 |
|
| 1552 |
waiters.wait_for_status( |
| 1553 |
self.mem_lb_client.show_loadbalancer, self.lb_id, |
| 1554 |
const.PROVISIONING_STATUS, const.ACTIVE, |
| 1555 |
CONF.load_balancer.check_interval, |
| 1556 |
CONF.load_balancer.check_timeout) |
| 1557 |
|
| 1558 |
|
| 1559 |
member2_name = data_utils.rand_name( |
| 1560 |
"lb_member_member2-tls-client-auth") |
| 1561 |
member2_kwargs = { |
| 1562 |
const.POOL_ID: pool_id, |
| 1563 |
const.NAME: member2_name, |
| 1564 |
const.ADMIN_STATE_UP: True, |
| 1565 |
const.ADDRESS: self.webserver2_ip, |
| 1566 |
const.PROTOCOL_PORT: 9443, |
| 1567 |
} |
| 1568 |
if self.lb_member_2_subnet: |
| 1569 |
member2_kwargs[const.SUBNET_ID] = self.lb_member_2_subnet[const.ID] |
| 1570 |
|
| 1571 |
member2 = self.mem_member_client.create_member(**member2_kwargs) |
| 1572 |
|
| 1573 |
self.addCleanup( |
| 1574 |
self.mem_member_client.cleanup_member, |
| 1575 |
member2[const.ID], pool_id=pool_id, |
| 1576 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 1577 |
|
| 1578 |
waiters.wait_for_status( |
| 1579 |
self.mem_lb_client.show_loadbalancer, self.lb_id, |
| 1580 |
const.PROVISIONING_STATUS, const.ACTIVE, |
| 1581 |
CONF.load_balancer.check_interval, |
| 1582 |
CONF.load_balancer.check_timeout) |
| 1583 |
|
| 1584 |
listener_name = data_utils.rand_name( |
| 1585 |
"lb_member_listener1-tls-client-auth") |
| 1586 |
listener_kwargs = { |
| 1587 |
const.NAME: listener_name, |
| 1588 |
const.PROTOCOL: const.HTTP, |
| 1589 |
const.PROTOCOL_PORT: '85', |
| 1590 |
const.LOADBALANCER_ID: self.lb_id, |
| 1591 |
const.DEFAULT_POOL_ID: pool_id, |
| 1592 |
} |
| 1593 |
listener = self.mem_listener_client.create_listener(**listener_kwargs) |
| 1594 |
self.listener_id = listener[const.ID] |
| 1595 |
|
| 1596 |
self.addCleanup( |
| 1597 |
self.mem_listener_client.cleanup_listener, |
| 1598 |
self.listener_id, |
| 1599 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 1600 |
|
| 1601 |
waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 1602 |
self.lb_id, const.PROVISIONING_STATUS, |
| 1603 |
const.ACTIVE, |
| 1604 |
CONF.load_balancer.build_interval, |
| 1605 |
CONF.load_balancer.build_timeout) |
| 1606 |
|
| 1607 |
|
| 1608 |
url = 'http://{0}:85'.format(self.lb_vip_address) |
| 1609 |
self.validate_URL_response(url, expected_status_code=503) |
| 1610 |
|
| 1611 |
|
| 1612 |
pool_update_kwargs = { |
| 1613 |
const.TLS_CONTAINER_REF: self.pool_client_ref |
| 1614 |
} |
| 1615 |
|
| 1616 |
self.mem_pool_client.update_pool(pool_id, **pool_update_kwargs) |
| 1617 |
|
| 1618 |
waiters.wait_for_status( |
| 1619 |
self.mem_lb_client.show_loadbalancer, self.lb_id, |
| 1620 |
const.PROVISIONING_STATUS, const.ACTIVE, |
| 1621 |
CONF.load_balancer.check_interval, |
| 1622 |
CONF.load_balancer.check_timeout) |
| 1623 |
waiters.wait_for_status( |
| 1624 |
self.mem_pool_client.show_pool, pool_id, |
| 1625 |
const.PROVISIONING_STATUS, const.ACTIVE, |
| 1626 |
CONF.load_balancer.check_interval, |
| 1627 |
CONF.load_balancer.check_timeout) |
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
waiters.wait_for_status( |
| 1632 |
self.mem_member_client.show_member, member1[const.ID], |
| 1633 |
const.OPERATING_STATUS, const.ONLINE, |
| 1634 |
CONF.load_balancer.check_interval, |
| 1635 |
CONF.load_balancer.check_timeout, error_ok=True, pool_id=pool_id) |
| 1636 |
waiters.wait_for_status( |
| 1637 |
self.mem_member_client.show_member, member2[const.ID], |
| 1638 |
const.OPERATING_STATUS, const.ONLINE, |
| 1639 |
CONF.load_balancer.check_interval, |
| 1640 |
CONF.load_balancer.check_timeout, error_ok=True, pool_id=pool_id) |
| 1641 |
|
| 1642 |
self.check_members_balanced(self.lb_vip_address, protocol=const.HTTP, |
| 1643 |
protocol_port=85) |
| 1644 |
|
| 1645 |
@decorators.idempotent_id('d3e4c5fe-1726-49e4-b0b0-7a5a47749fc9') |
| 1646 |
def test_basic_h2_listener_http_listener_pool_reencryption(self): |
| 1647 |
"""Test both h2 and HTTP traffic on the same load balancer. |
| 1648 |
|
| 1649 |
In this test we deploy the following Octavia resources: |
| 1650 |
HTTPS_TERMINATED listener with h2 alpn protocols |
| 1651 |
HTTP listener |
| 1652 |
HTTP pool with both h2 alpn protocols and backend re-encryption |
| 1653 |
|
| 1654 |
we send both h2 and http traffic from a client to the load balancer vip |
| 1655 |
and we make sure h2 traffic was negotiated when it was sent on 443 port |
| 1656 |
:raises self.skipException: ALPN support for pools not available prior |
| 1657 |
to v2.24. |
| 1658 |
""" |
| 1659 |
if not self.mem_listener_client.is_version_supported( |
| 1660 |
self.api_version, '2.24'): |
| 1661 |
raise self.skipException('ALPN protocols are only available on ' |
| 1662 |
'pools in Octavia API version 2.24 or' |
| 1663 |
' newer.') |
| 1664 |
pool_name = data_utils.rand_name("lb_member_pool1-tls-alpn") |
| 1665 |
pool_kwargs = { |
| 1666 |
const.NAME: pool_name, |
| 1667 |
const.PROTOCOL: const.HTTP, |
| 1668 |
const.LB_ALGORITHM: self.lb_algorithm, |
| 1669 |
const.LOADBALANCER_ID: self.lb_id, |
| 1670 |
const.TLS_ENABLED: True, |
| 1671 |
const.ALPN_PROTOCOLS: ['h2', 'http/1.1'], |
| 1672 |
} |
| 1673 |
|
| 1674 |
pool = self.mem_pool_client.create_pool(**pool_kwargs) |
| 1675 |
pool_id = pool[const.ID] |
| 1676 |
|
| 1677 |
self.addCleanup( |
| 1678 |
self.mem_pool_client.cleanup_pool, |
| 1679 |
pool_id, |
| 1680 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 1681 |
|
| 1682 |
waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 1683 |
self.lb_id, const.PROVISIONING_STATUS, |
| 1684 |
const.ACTIVE, |
| 1685 |
CONF.load_balancer.build_interval, |
| 1686 |
CONF.load_balancer.build_timeout) |
| 1687 |
|
| 1688 |
|
| 1689 |
member1_name = data_utils.rand_name("lb_member_member1-tls-reencrypt") |
| 1690 |
member1_kwargs = { |
| 1691 |
const.POOL_ID: pool_id, |
| 1692 |
const.NAME: member1_name, |
| 1693 |
const.ADMIN_STATE_UP: True, |
| 1694 |
const.ADDRESS: self.webserver1_ip, |
| 1695 |
const.PROTOCOL_PORT: 443, |
| 1696 |
} |
| 1697 |
if self.lb_member_1_subnet: |
| 1698 |
member1_kwargs[const.SUBNET_ID] = self.lb_member_1_subnet[const.ID] |
| 1699 |
|
| 1700 |
member1 = self.mem_member_client.create_member(**member1_kwargs) |
| 1701 |
|
| 1702 |
self.addCleanup( |
| 1703 |
self.mem_member_client.cleanup_member, |
| 1704 |
member1[const.ID], pool_id=pool_id, |
| 1705 |
lb_client=self.mem_lb_client, |
| 1706 |
lb_id=self.lb_id) |
| 1707 |
|
| 1708 |
waiters.wait_for_status( |
| 1709 |
self.mem_lb_client.show_loadbalancer, self.lb_id, |
| 1710 |
const.PROVISIONING_STATUS, const.ACTIVE, |
| 1711 |
CONF.load_balancer.check_interval, |
| 1712 |
CONF.load_balancer.check_timeout) |
| 1713 |
|
| 1714 |
|
| 1715 |
member2_name = data_utils.rand_name("lb_member_member2-tls-reencrypt") |
| 1716 |
member2_kwargs = { |
| 1717 |
const.POOL_ID: pool_id, |
| 1718 |
const.NAME: member2_name, |
| 1719 |
const.ADMIN_STATE_UP: True, |
| 1720 |
const.ADDRESS: self.webserver2_ip, |
| 1721 |
const.PROTOCOL_PORT: 443, |
| 1722 |
} |
| 1723 |
if self.lb_member_2_subnet: |
| 1724 |
member2_kwargs[const.SUBNET_ID] = self.lb_member_2_subnet[const.ID] |
| 1725 |
|
| 1726 |
member2 = self.mem_member_client.create_member(**member2_kwargs) |
| 1727 |
|
| 1728 |
self.addCleanup( |
| 1729 |
self.mem_member_client.cleanup_member, |
| 1730 |
member2[const.ID], pool_id=pool_id, |
| 1731 |
lb_client=self.mem_lb_client, |
| 1732 |
lb_id=self.lb_id) |
| 1733 |
|
| 1734 |
waiters.wait_for_status( |
| 1735 |
self.mem_lb_client.show_loadbalancer, self.lb_id, |
| 1736 |
const.PROVISIONING_STATUS, const.ACTIVE, |
| 1737 |
CONF.load_balancer.check_interval, |
| 1738 |
CONF.load_balancer.check_timeout) |
| 1739 |
|
| 1740 |
listener_name = data_utils.rand_name( |
| 1741 |
"lb_member_listener1-tls-terminated-alpn") |
| 1742 |
listener_kwargs = { |
| 1743 |
const.NAME: listener_name, |
| 1744 |
const.PROTOCOL: const.TERMINATED_HTTPS, |
| 1745 |
const.PROTOCOL_PORT: '443', |
| 1746 |
const.LOADBALANCER_ID: self.lb_id, |
| 1747 |
const.DEFAULT_POOL_ID: pool_id, |
| 1748 |
const.DEFAULT_TLS_CONTAINER_REF: self.server_secret_ref, |
| 1749 |
const.ALPN_PROTOCOLS: ['h2', 'http/1.1'] |
| 1750 |
} |
| 1751 |
listener = self.mem_listener_client.create_listener(**listener_kwargs) |
| 1752 |
|
| 1753 |
self.addCleanup( |
| 1754 |
self.mem_listener_client.cleanup_listener, |
| 1755 |
listener[const.ID], |
| 1756 |
lb_client=self.mem_lb_client, |
| 1757 |
lb_id=self.lb_id) |
| 1758 |
|
| 1759 |
waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 1760 |
self.lb_id, const.PROVISIONING_STATUS, |
| 1761 |
const.ACTIVE, |
| 1762 |
CONF.load_balancer.build_interval, |
| 1763 |
CONF.load_balancer.build_timeout) |
| 1764 |
|
| 1765 |
listener_name = data_utils.rand_name( |
| 1766 |
"lb_member_listener1-http") |
| 1767 |
listener_kwargs = { |
| 1768 |
const.NAME: listener_name, |
| 1769 |
const.PROTOCOL: const.HTTP, |
| 1770 |
const.PROTOCOL_PORT: 80, |
| 1771 |
const.LOADBALANCER_ID: self.lb_id, |
| 1772 |
const.DEFAULT_POOL_ID: pool_id, |
| 1773 |
} |
| 1774 |
listener = self.mem_listener_client.create_listener(**listener_kwargs) |
| 1775 |
self.listener_id = listener[const.ID] |
| 1776 |
self.addCleanup( |
| 1777 |
self.mem_listener_client.cleanup_listener, |
| 1778 |
self.listener_id, |
| 1779 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 1780 |
|
| 1781 |
waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 1782 |
self.lb_id, const.PROVISIONING_STATUS, |
| 1783 |
const.ACTIVE, |
| 1784 |
CONF.load_balancer.build_interval, |
| 1785 |
CONF.load_balancer.build_timeout) |
| 1786 |
|
| 1787 |
context = ssl.SSLContext(ssl.PROTOCOL_TLS) |
| 1788 |
context.set_alpn_protocols(['h2', 'http/1.1']) |
| 1789 |
s = socket.socket() |
| 1790 |
ssl_sock = context.wrap_socket(s) |
| 1791 |
ssl_sock.connect((self.lb_vip_address, 443)) |
| 1792 |
selected_proto = ssl_sock.selected_alpn_protocol() |
| 1793 |
self.assertEqual('h2', selected_proto) |
| 1794 |
|
| 1795 |
|
| 1796 |
self.check_members_balanced(self.lb_vip_address, protocol=const.HTTPS, |
| 1797 |
HTTPS_verify=False, protocol_port=443) |
| 1798 |
|
| 1799 |
|
| 1800 |
self.check_members_balanced(self.lb_vip_address) |
| 1801 |
|
| 1802 |
@decorators.idempotent_id('7d9dcae6-3e2c-4eae-9bfb-1ef0d00aa530') |
| 1803 |
@testtools.skipUnless( |
| 1804 |
CONF.loadbalancer_feature_enabled.prometheus_listener_enabled, |
| 1805 |
'PROMETHEUS listener tests are disabled in the tempest configuration.') |
| 1806 |
def test_tls_prometheus_client_auth_mandatory(self): |
| 1807 |
if not self.mem_listener_client.is_version_supported( |
| 1808 |
self.api_version, '2.25'): |
| 1809 |
raise self.skipException('Prometheus listeners are only available ' |
| 1810 |
'on Octavia API version 2.25 or newer.') |
| 1811 |
LISTENER1_TCP_PORT = '9443' |
| 1812 |
listener_name = data_utils.rand_name( |
| 1813 |
"lb_member_listener1-prometheus-client-auth-mand") |
| 1814 |
listener_kwargs = { |
| 1815 |
const.NAME: listener_name, |
| 1816 |
const.PROTOCOL: const.PROMETHEUS, |
| 1817 |
const.PROTOCOL_PORT: LISTENER1_TCP_PORT, |
| 1818 |
const.LOADBALANCER_ID: self.lb_id, |
| 1819 |
const.DEFAULT_TLS_CONTAINER_REF: self.server_secret_ref, |
| 1820 |
const.CLIENT_AUTHENTICATION: const.CLIENT_AUTH_MANDATORY, |
| 1821 |
const.CLIENT_CA_TLS_CONTAINER_REF: self.client_ca_cert_ref, |
| 1822 |
const.CLIENT_CRL_CONTAINER_REF: self.client_crl_ref, |
| 1823 |
} |
| 1824 |
listener = self.mem_listener_client.create_listener(**listener_kwargs) |
| 1825 |
self.listener_id = listener[const.ID] |
| 1826 |
self.addCleanup( |
| 1827 |
self.mem_listener_client.cleanup_listener, |
| 1828 |
self.listener_id, |
| 1829 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 1830 |
|
| 1831 |
waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 1832 |
self.lb_id, const.PROVISIONING_STATUS, |
| 1833 |
const.ACTIVE, |
| 1834 |
CONF.load_balancer.build_interval, |
| 1835 |
CONF.load_balancer.build_timeout) |
| 1836 |
|
| 1837 |
|
| 1838 |
self.assertRaises( |
| 1839 |
requests.exceptions.SSLError, |
| 1840 |
requests.get, |
| 1841 |
'https://{0}:{1}'.format(self.lb_vip_address, LISTENER1_TCP_PORT), |
| 1842 |
timeout=12, verify=False) |
| 1843 |
|
| 1844 |
|
| 1845 |
with tempfile.NamedTemporaryFile(buffering=0) as cert_file: |
| 1846 |
cert_file.write(self.revoked_client_cert.public_bytes( |
| 1847 |
serialization.Encoding.PEM)) |
| 1848 |
with tempfile.NamedTemporaryFile(buffering=0) as key_file: |
| 1849 |
key_file.write(self.revoked_client_key.private_bytes( |
| 1850 |
serialization.Encoding.PEM, |
| 1851 |
serialization.PrivateFormat.TraditionalOpenSSL, |
| 1852 |
serialization.NoEncryption())) |
| 1853 |
self.assertRaises( |
| 1854 |
requests.exceptions.SSLError, requests.get, |
| 1855 |
'https://{0}:{1}'.format(self.lb_vip_address, |
| 1856 |
LISTENER1_TCP_PORT), |
| 1857 |
timeout=12, verify=False, cert=(cert_file.name, |
| 1858 |
key_file.name)) |
| 1859 |
|
| 1860 |
|
| 1861 |
with tempfile.NamedTemporaryFile(buffering=0) as cert_file: |
| 1862 |
cert_file.write(self.client_cert.public_bytes( |
| 1863 |
serialization.Encoding.PEM)) |
| 1864 |
with tempfile.NamedTemporaryFile(buffering=0) as key_file: |
| 1865 |
key_file.write(self.client_key.private_bytes( |
| 1866 |
serialization.Encoding.PEM, |
| 1867 |
serialization.PrivateFormat.TraditionalOpenSSL, |
| 1868 |
serialization.NoEncryption())) |
| 1869 |
response = requests.get( |
| 1870 |
'https://{0}:{1}'.format(self.lb_vip_address, |
| 1871 |
LISTENER1_TCP_PORT), |
| 1872 |
timeout=12, verify=False, cert=(cert_file.name, |
| 1873 |
key_file.name)) |
| 1874 |
self.assertEqual(200, response.status_code) |