diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c9b5e16..19b4713 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -757,6 +757,7 @@ jobs: eventing: "0" extras: "0" release_gates: "0" + worker_workspace: "1" - name: node-eventing suite: runtime examples: hello-nodejs @@ -923,6 +924,7 @@ jobs: LAMPYR_CI_RUNTIME_EXTRAS: ${{ matrix.extras }} LAMPYR_CI_RELEASE_GATES: ${{ matrix.release_gates }} LAMPYR_CI_MODE_CHECKS: ${{ matrix.mode_checks || 'all' }} + LAMPYR_CI_WORKER_WORKSPACE: ${{ matrix.worker_workspace || '0' }} LAMPYR_CLUSTER_INPUTS: ${{ github.workspace }}/build/cluster-inputs run: just test-kind-runtime-integration-prebuilt diff --git a/docs/cli/dev.md b/docs/cli/dev.md index 5291565..19ed121 100644 --- a/docs/cli/dev.md +++ b/docs/cli/dev.md @@ -230,6 +230,12 @@ python3 tests/contracts/test_worker_workspace.py \ --url https://YOUR_CLUSTER_INGRESS --host worker-api.default.YOUR_DOMAIN ``` +To also check processor and reused services through ingress, expose all three +services in `ingress.services`, redeploy them, and add `--direct-services`. +Each request uses its service hostname for TLS SNI, certificate checks, and +HTTP Host. An optional hostname port stays in HTTP Host, not TLS SNI. +`--url` sets the connection address and port; `--host` does not change them. + Only for a test cluster with a self-signed certificate, add `--insecure`. The runner checks fresh state, bindings, event content, explicit reuse and idle reset, errors, streaming, and client cancellation. The unchanged runner diff --git a/scripts/test-kind-integration.sh b/scripts/test-kind-integration.sh index e5dff6f..383c20d 100755 --- a/scripts/test-kind-integration.sh +++ b/scripts/test-kind-integration.sh @@ -199,6 +199,12 @@ if [[ "$suite" == "full" || "$suite" == "runtime" ]]; then rm -rf "$project/services/$service/.lampyr" sed -i 's/^ cpu: 250m$/ cpu: 10m/' "$project/services/$service/lampyr.yaml" done + if [[ "${LAMPYR_CI_WORKER_WORKSPACE:-0}" == 1 ]]; then + for service in api processor reused; do + cp -a "$repo_root/demos/local-worker-workspace/services/$service" \ + "$project/services/worker-$service" + done + fi expose_workspace_services "$project" "$repo_root/build/ly" build "$project" phase_done "build runtime examples" @@ -637,6 +643,26 @@ print(fiberd_grants.router_fibers_busy(sys.argv[2], sys.argv[3])) done } +run_worker_workspace_checks() { + local service + for service in worker-processor worker-reused worker-api; do + current_service=$service + "$repo_root/build/ly" deploy --context "$context" \ + --image "$images/$service:$tag" "$project/services/$service" + done + kubectl --context "$context" -n kourier-system get secret lampyr-kourier-tls \ + -o 'jsonpath={.data.tls\.crt}' | base64 --decode > "$project/ingress-trust.pem" + SSL_CERT_FILE="$project/ingress-trust.pem" \ + python3 "$repo_root/tests/contracts/test_worker_workspace.py" \ + --url "https://127.0.0.1:$https_port" \ + --host "worker-api.default.localhost:$https_port" \ + --direct-services + for service in worker-api worker-processor worker-reused; do + "$repo_root/build/ly" delete --context "$context" "$project/services/$service" + done + phase_done "verify worker workspace through trusted HTTPS ingress" +} + run_runtime_mode_checks() { reuse_dir="$project/services/reuse-mode" mkdir -p "$reuse_dir" @@ -809,6 +835,9 @@ fi if [[ "$suite" == "full" || "$suite" == "runtime" ]]; then run_runtime_checks + if [[ "${LAMPYR_CI_WORKER_WORKSPACE:-0}" == 1 ]]; then + run_worker_workspace_checks + fi fi if [[ "$runtime_extras" == 1 ]]; then diff --git a/scripts/tests/test_worker_workspace.py b/scripts/tests/test_worker_workspace.py index 43569d5..16cf10a 100644 --- a/scripts/tests/test_worker_workspace.py +++ b/scripts/tests/test_worker_workspace.py @@ -1,7 +1,9 @@ #!/usr/bin/env python3 import importlib.util +import json import pathlib +import sys import unittest from unittest import mock import urllib.parse @@ -17,6 +19,120 @@ class WorkerWorkspaceConnectionTests(unittest.TestCase): + def test_direct_requests_use_sibling_tls_identity(self): + cases = ( + ("https://worker-api.default.example.com:8443", None, ":8443"), + ("https://127.0.0.1:8443", "worker-api.default.example.com:9443", ":9443"), + ("https://127.0.0.1:8443", "worker-api.default.example.com", ""), + ) + for url, override, port in cases: + with self.subTest(host=override): + requests = self.run_contract(url, override) + for service, count in (("worker-processor", 2), ("worker-reused", 2)): + with self.subTest(service=service): + hostname = f"{service}.default.example.com" + direct = [ + request + for request in requests + if request["host"] == f"{hostname}{port}" + ] + self.assertEqual(len(direct), count) + for request in direct: + self.assertEqual( + request["address"], urllib.parse.urlsplit(url).hostname + ) + self.assertEqual(request["port"], 8443) + self.assertEqual(request["tls_hostname"], hostname) + + def test_direct_http_requests_keep_native_destination(self): + requests = self.run_contract("http://127.0.0.1:8080") + for service in ("worker-processor", "worker-reused"): + direct = [ + request + for request in requests + if request["host"] == f"{service}.default.localhost" + ] + self.assertEqual(len(direct), 2) + for request in direct: + self.assertEqual(request["address"], "127.0.0.1") + self.assertEqual(request["port"], 8080) + self.assertIsNone(request["tls_hostname"]) + + def run_contract(self, url, host=None): + replies = [ + {"count": 1, "fiberId": "root-1"}, + {"count": 1, "fiberId": "root-2"}, + {"kind": "http", "count": 1, "fiberId": "processor-1"}, + {"kind": "http", "count": 1, "fiberId": "processor-2"}, + { + "kind": "event", "id": "worker-demo", "count": 1, + "data": {"message": "hello from HTTP ingress"}, "fiberId": "event", + }, + {"count": 1, "fiberId": "reused"}, + {"count": 2, "fiberId": "reused"}, + {"count": 1, "fiberId": "reset"}, + None, None, None, None, + {"count": 1, "fiberId": "after-cancel"}, + ] + statuses = [200] * len(replies) + statuses[8:10] = [500, 502] + if url.startswith("http:"): + replies.append(None) + statuses.append(404) + replies.extend([ + {"kind": "http", "count": 1, "fiberId": "direct-processor-1"}, + {"kind": "http", "count": 1, "fiberId": "direct-processor-2"}, + {"count": 1}, + {"count": 2}, + ]) + statuses.extend([200] * 4) + responses = [] + for reply, status in zip(replies, statuses): + response = mock.Mock(status=status) + response.read.return_value = json.dumps(reply).encode() + response.getheader.return_value = None + responses.append(response) + responses[10].read.return_value = b"start\nend\n" + responses[10].getheader.return_value = "text/plain" + responses[11].readline.return_value = b"start\n" + requests = [] + context = CONTRACT.ssl.create_default_context() + + def send(connection, method, path, headers): + connection.connect() + requests.append({ + "address": connection.host, + "port": connection.port, + "host": headers["Host"], + "tls_hostname": ( + wrap_socket.call_args.kwargs["server_hostname"] + if isinstance(connection, CONTRACT.IngressHTTPSConnection) + else None + ), + }) + + argv = ["test_worker_workspace.py", "--url", url, "--direct-services"] + if host is not None: + argv.extend(["--host", host]) + with ( + mock.patch.object(sys, "argv", argv), + mock.patch.object(CONTRACT.ssl, "create_default_context", return_value=context), + mock.patch.object(context, "wrap_socket", return_value=mock.Mock()) as wrap_socket, + mock.patch.object(CONTRACT.http.client.HTTPConnection, "connect"), + mock.patch.object( + CONTRACT.http.client.HTTPConnection, "request", + autospec=True, side_effect=send, + ), + mock.patch.object( + CONTRACT.http.client.HTTPConnection, "getresponse", side_effect=responses, + ), + mock.patch.object(CONTRACT.time, "sleep"), + mock.patch.object(CONTRACT.time, "monotonic", side_effect=[0, 2]), + mock.patch("builtins.print"), + ): + CONTRACT.main() + return requests + def test_https_host_override_is_used_for_tls_identity(self): base = urllib.parse.urlsplit("https://127.0.0.1:8443") context = mock.Mock() diff --git a/tests/contracts/test_worker_workspace.py b/tests/contracts/test_worker_workspace.py index f7a15bb..b7538b1 100644 --- a/tests/contracts/test_worker_workspace.py +++ b/tests/contracts/test_worker_workspace.py @@ -59,11 +59,11 @@ def main(): assert base.scheme in ("http", "https") and base.hostname hostname = args.host or ("worker-api.default.localhost" if base.scheme == "http" else base.netloc) - def connect(): - return open_connection(base, hostname, args.insecure) + def connect(host=None): + return open_connection(base, host or hostname, args.insecure) def request(path, status=200, host=None, content_type=False): - connection = connect() + connection = connect(host) connection.request("GET", path, headers={"Host": host or hostname}) response = connection.getresponse() body = response.read()