From 5fc30acb1c6ba2751db4a97eae347d77d2212799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BB=D1=8C=D0=B5=D0=B2=20=D0=9D?= =?UTF-8?q?=D0=B8=D0=BA=D0=B8=D1=82=D0=B0?= Date: Mon, 16 Nov 2026 13:02:05 +0300 Subject: [PATCH] Advertise HTTP/1.1 for the actual loopback OTLP HTTP upstreams --- src/messenger/tls_gateway.py | 4 +++- student-tests/test_tls_boundary.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/messenger/tls_gateway.py b/src/messenger/tls_gateway.py index d1a7d4d..431f0db 100644 --- a/src/messenger/tls_gateway.py +++ b/src/messenger/tls_gateway.py @@ -39,7 +39,9 @@ def role(cert, allowed): def context(cfg): ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) - ctx.set_alpn_protocols(["http/1.1"] if cfg.get("http") else ["h2", "http/1.1"]) + # Every active HTTP upstream in this lab speaks HTTP/1.1 on loopback. + # Advertising h2 would make Go clients send HTTP/2 to a plaintext H1 port. + ctx.set_alpn_protocols(["http/1.1"]) ctx.minimum_version = ssl.TLSVersion.TLSv1_2 ctx.load_cert_chain(cfg["cert"], cfg["key"]) if cfg.get("allowed"): diff --git a/student-tests/test_tls_boundary.py b/student-tests/test_tls_boundary.py index d743585..fc17ea1 100644 --- a/student-tests/test_tls_boundary.py +++ b/student-tests/test_tls_boundary.py @@ -230,3 +230,13 @@ def test_revocation_existing_connection_before_next_command(tcp_boundary): except OSError: data = b"" assert data == b"" + + +def test_alpn_does_not_advertise_unsupported_http2(tcp_boundary): + context = client("lb") + context.set_alpn_protocols(["h2", "http/1.1"]) + with socket.create_connection(("127.0.0.1", tcp_boundary[0]), timeout=2) as raw: + with context.wrap_socket(raw, server_hostname="api") as conn: + assert conn.selected_alpn_protocol() == "http/1.1" + conn.sendall(b"http1-upstream") + assert conn.recv(1024) == b"http1-upstream"