Repository navigation
[workspace] bazel/tap: Add tap2pcap, to convert Envoy socket tap traces to PCAP - #5627
Conversation
…envoyproxy#5622) A pure Python replacement for the `tap2pcap` tool of the Envoy API (`@envoy_api//tools:tap2pcap`), which shells out to `od` and to Wireshark's `text2pcap`, and is tested by comparing `tshark` output to a golden file. Neither tool is in the Envoy CI image, so that test only passes while its result is in the remote cache. `//tap:tap2pcap` writes the PCAP itself: a classic PCAP file with one TCP segment (dummy Ethernet and IPv4/IPv6 headers, real checksums, per-direction sequence numbers) for each read or write of a socket buffered trace. Payloads over what an IP packet can carry are split. The `tap2pcap` macro (`//tap:defs.bzl`) makes the binary from the caller's trace wrapper message, so this module does not depend on the Envoy API (which depends on this module): tap2pcap( name = "tap2pcap", message = "envoy.data.tap.v3.wrapper_pb2.TraceWrapper", proto = "//envoy/data/tap/v3:pkg_py_proto", ) Tested on the PCAP bytes (decoded back, with every length and checksum verified), and end to end on a binary made for a test proto with the fields of Envoy's, for text and binary traces. Signed-off-by: Ryan Northey <[email protected]> Backport note (workspace): picked as is, for the Envoy release branches that build with WORKSPACE (v1.37-v1.39), which have the same `tap2pcap_test` and the same CI image as `main` had. (cherry picked from commit 5f5e48b)
There was a problem hiding this comment.
🟡 Changes recommended
Unconditional protobuf loads reference a repository absent from WORKSPACE, causing CI build and test commands to fail during package loading before the new tests can run.
1 open issue
What changed in this PR
Backports tap2pcap to toolshed’s WORKSPACE line for Envoy release branches, enabling socket tap trace conversion without external Wireshark utilities.
Changes:
- Adds pure-Python PCAP generation with IPv4/IPv6 support, checksums, timestamps, and payload segmentation.
- Exposes a Bazel macro that uses the caller’s protobuf message, avoiding a dependency on Envoy’s API.
- Adds unit and binary integration tests for conversion and error handling.
| File | Description |
|---|---|
bazel/tap/tests/trace.proto |
Defines a minimal Envoy-compatible test schema. |
bazel/tap/tests/tap2pcap_test.py |
Tests packet generation, checksums, segmentation, and errors. |
bazel/tap/tests/tap2pcap_binary_test.py |
Tests text and binary conversion through the generated executable. |
bazel/tap/tests/socket.pb_text |
Supplies socket events with byte and string payloads. |
bazel/tap/tests/pcap.py |
Decodes generated packets and validates lengths and checksums. |
bazel/tap/tests/http.pb_text |
Supplies an unsupported trace for rejection testing. |
bazel/tap/tests/BUILD |
Defines test libraries, protobuf targets, and the test executable. |
bazel/tap/tap2pcap.py |
Implements trace parsing and PCAP generation. |
bazel/tap/defs.bzl |
Provides the caller-configurable tap2pcap macro. |
bazel/tap/BUILD |
Exposes the conversion library and macro definitions. |
Review effort: Balanced
| load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") | ||
| load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library") |
There was a problem hiding this comment.
This does not happen: the workspace CI of this PR loads and runs the package. test (workspace) runs bazel test --config=ci --config=rbe --config=bes //... //sysroot:sysroots with --noenable_bzlmod --enable_workspace (the branch's .bazelrc), and both //tap/tests:tap2pcap_test and //tap/tests:tap2pcap_binary_test pass there (job), as do the workspace build, gcc, macos and cross jobs. So @com_google_protobuf resolves in this branch's WORKSPACE setup; the note in toolchains/test/BUILD is out of date on that point. (bot assisted)
The WORKSPACE line of toolshed, with two backports: - envoyproxy/toolshed#5623 (0.4.13.post5): `cve_scan` does not need the scanner's `RunEnvironmentInfo`. With Bazel 7 an `sh_binary` does not provide it, so the CVE scan fails at analysis there (as it does on this branch, which is on Bazel 7.7.1, and did on `release/v1.38`). - envoyproxy/toolshed#5627 (0.4.13.post6): `tap2pcap` (`@envoy_toolshed//tap:defs.bzl`), for the next commit. Signed-off-by: Ryan Northey <[email protected]>
The `tap2pcap` tool (`@envoy_api//tools:tap2pcap`, from the traffic tapping docs) shelled out to `od` and to Wireshark's `text2pcap`, and its test compared `tshark` output to a golden file. The CI image has neither tool, so `@envoy_api//tools:tap2pcap_test` only passed while its result was in the remote cache: the API job reports "Executed 0 out of 5 tests". Anything that changes its action key runs it for real, and it fails with `FileNotFoundError: 'text2pcap'`, as on `@envoy_toolshed//tap:defs.bzl` (envoyproxy/toolshed#5622, in `envoy_toolshed` 0.5.24.envoy from envoyproxy#49389) writes the PCAP in Python and is tested there. This makes the tool from that, with the v3 trace wrapper (`envoy.data.tap.v3`, where the old tool read the frozen `v2alpha` one), and removes `tap2pcap.py`, its test, the two fixtures, and the test's line in `do_ci.sh api`. For users `bazel run @envoy_api//tools:tap2pcap <tap .pb/.pb_text> <pcap path>` is unchanged, and no longer needs Wireshark installed. Other differences, from the toolshed implementation: IPv6 traces are written with correct headers (a known issue of the `text2pcap` path), `as_string` bodies are read as well as `as_bytes`, and a trace that is not a socket buffered trace is an error. Risk Level: Low (a developer tool and its test) Testing: These changes ran in CI on envoyproxy#49376 against a pre-release of the toolshed module, with a temporary target that converted the old `tap2pcap_h2_ipv4.pb_text` fixture with the new tool; the API job passed. The toolshed output for that fixture was also checked with `tshark` by hand: the same six HTTP/2 frames, lengths and times as the old golden file. Nothing in Envoy runs the tool after this change. Docs Changes: N/A (the documented command is unchanged) Release Notes: N/A Signed-off-by: Ryan Northey <[email protected]> Backport note (release/v1.37): with `envoy_toolshed` 0.4.13.post6 (the WORKSPACE line, envoyproxy/toolshed#5627) for the rule. This branch has the same test and the same CI image as `main` had, so the same test that only passes from the cache. (cherry picked from commit c111365)
0.4.13.post5 has, backported to the WORKSPACE line (envoyproxy/toolshed#5623), a `cve_scan` that does not need the scanner's `RunEnvironmentInfo`. With Bazel 7 an `sh_binary` does not provide it, so the CVE scan failed at analysis there (as it does on `release/v1.38`); with Bazel 8 nothing changes. 0.4.13.post6 adds `tap2pcap` (`@envoy_toolshed//tap:defs.bzl`, envoyproxy/toolshed#5627), for the `tap2pcap` change that follows. Signed-off-by: Ryan Northey <[email protected]>
The `tap2pcap` tool (`@envoy_api//tools:tap2pcap`, from the traffic tapping docs) shelled out to `od` and to Wireshark's `text2pcap`, and its test compared `tshark` output to a golden file. The CI image has neither tool, so `@envoy_api//tools:tap2pcap_test` only passed while its result was in the remote cache: the API job reports "Executed 0 out of 5 tests". Anything that changes its action key runs it for real, and it fails with `FileNotFoundError: 'text2pcap'`, as on `@envoy_toolshed//tap:defs.bzl` (envoyproxy/toolshed#5622, in `envoy_toolshed` 0.5.24.envoy from envoyproxy#49389) writes the PCAP in Python and is tested there. This makes the tool from that, with the v3 trace wrapper (`envoy.data.tap.v3`, where the old tool read the frozen `v2alpha` one), and removes `tap2pcap.py`, its test, the two fixtures, and the test's line in `do_ci.sh api`. For users `bazel run @envoy_api//tools:tap2pcap <tap .pb/.pb_text> <pcap path>` is unchanged, and no longer needs Wireshark installed. Other differences, from the toolshed implementation: IPv6 traces are written with correct headers (a known issue of the `text2pcap` path), `as_string` bodies are read as well as `as_bytes`, and a trace that is not a socket buffered trace is an error. Risk Level: Low (a developer tool and its test) Testing: These changes ran in CI on envoyproxy#49376 against a pre-release of the toolshed module, with a temporary target that converted the old `tap2pcap_h2_ipv4.pb_text` fixture with the new tool; the API job passed. The toolshed output for that fixture was also checked with `tshark` by hand: the same six HTTP/2 frames, lengths and times as the old golden file. Nothing in Envoy runs the tool after this change. Docs Changes: N/A (the documented command is unchanged) Release Notes: N/A Signed-off-by: Ryan Northey <[email protected]> Backport note (release/v1.38): with `envoy_toolshed` 0.4.13.post6 (the WORKSPACE line, envoyproxy/toolshed#5627) for the rule. This branch has the same test and the same CI image as `main` had, so the same test that only passes from the cache. (cherry picked from commit c111365)
0.4.13.post5 has, backported to the WORKSPACE line (envoyproxy/toolshed#5623), a `cve_scan` that does not need the scanner's `RunEnvironmentInfo`. With Bazel 7 an `sh_binary` does not provide it, so the CVE scan failed at analysis there (as it does on `release/v1.38`); with Bazel 8 nothing changes. 0.4.13.post6 adds `tap2pcap` (`@envoy_toolshed//tap:defs.bzl`, envoyproxy/toolshed#5627), for the `tap2pcap` change that follows. Signed-off-by: Ryan Northey <[email protected]>
The `tap2pcap` tool (`@envoy_api//tools:tap2pcap`, from the traffic tapping docs) shelled out to `od` and to Wireshark's `text2pcap`, and its test compared `tshark` output to a golden file. The CI image has neither tool, so `@envoy_api//tools:tap2pcap_test` only passed while its result was in the remote cache: the API job reports "Executed 0 out of 5 tests". Anything that changes its action key runs it for real, and it fails with `FileNotFoundError: 'text2pcap'`, as on `@envoy_toolshed//tap:defs.bzl` (envoyproxy/toolshed#5622, in `envoy_toolshed` 0.5.24.envoy from envoyproxy#49389) writes the PCAP in Python and is tested there. This makes the tool from that, with the v3 trace wrapper (`envoy.data.tap.v3`, where the old tool read the frozen `v2alpha` one), and removes `tap2pcap.py`, its test, the two fixtures, and the test's line in `do_ci.sh api`. For users `bazel run @envoy_api//tools:tap2pcap <tap .pb/.pb_text> <pcap path>` is unchanged, and no longer needs Wireshark installed. Other differences, from the toolshed implementation: IPv6 traces are written with correct headers (a known issue of the `text2pcap` path), `as_string` bodies are read as well as `as_bytes`, and a trace that is not a socket buffered trace is an error. Risk Level: Low (a developer tool and its test) Testing: These changes ran in CI on envoyproxy#49376 against a pre-release of the toolshed module, with a temporary target that converted the old `tap2pcap_h2_ipv4.pb_text` fixture with the new tool; the API job passed. The toolshed output for that fixture was also checked with `tshark` by hand: the same six HTTP/2 frames, lengths and times as the old golden file. Nothing in Envoy runs the tool after this change. Docs Changes: N/A (the documented command is unchanged) Release Notes: N/A Signed-off-by: Ryan Northey <[email protected]> Backport note (release/v1.39): with `envoy_toolshed` 0.4.13.post6 (the WORKSPACE line, envoyproxy/toolshed#5627) for the rule. This branch has the same test and the same CI image as `main` had, so the same test that only passes from the cache. (cherry picked from commit c111365)
The WORKSPACE line of toolshed, with two backports: - envoyproxy/toolshed#5623 (0.4.13.post5): `cve_scan` does not need the scanner's `RunEnvironmentInfo`. With Bazel 7 an `sh_binary` does not provide it, so the CVE scan fails at analysis there (as it does on this branch, which is on Bazel 7.7.1, and did on `release/v1.38`). - envoyproxy/toolshed#5627 (0.4.13.post6): `tap2pcap` (`@envoy_toolshed//tap:defs.bzl`), for the next commit. Signed-off-by: Ryan Northey <[email protected]>
The `tap2pcap` tool (`@envoy_api//tools:tap2pcap`, from the traffic tapping docs) shelled out to `od` and to Wireshark's `text2pcap`, and its test compared `tshark` output to a golden file. The CI image has neither tool, so `@envoy_api//tools:tap2pcap_test` only passed while its result was in the remote cache: the API job reports "Executed 0 out of 5 tests". Anything that changes its action key runs it for real, and it fails with `FileNotFoundError: 'text2pcap'`, as on `@envoy_toolshed//tap:defs.bzl` (envoyproxy/toolshed#5622, in `envoy_toolshed` 0.5.24.envoy from #49389) writes the PCAP in Python and is tested there. This makes the tool from that, with the v3 trace wrapper (`envoy.data.tap.v3`, where the old tool read the frozen `v2alpha` one), and removes `tap2pcap.py`, its test, the two fixtures, and the test's line in `do_ci.sh api`. For users `bazel run @envoy_api//tools:tap2pcap <tap .pb/.pb_text> <pcap path>` is unchanged, and no longer needs Wireshark installed. Other differences, from the toolshed implementation: IPv6 traces are written with correct headers (a known issue of the `text2pcap` path), `as_string` bodies are read as well as `as_bytes`, and a trace that is not a socket buffered trace is an error. Risk Level: Low (a developer tool and its test) Testing: These changes ran in CI on #49376 against a pre-release of the toolshed module, with a temporary target that converted the old `tap2pcap_h2_ipv4.pb_text` fixture with the new tool; the API job passed. The toolshed output for that fixture was also checked with `tshark` by hand: the same six HTTP/2 frames, lengths and times as the old golden file. Nothing in Envoy runs the tool after this change. Docs Changes: N/A (the documented command is unchanged) Release Notes: N/A Signed-off-by: Ryan Northey <[email protected]> Backport note (release/v1.37): with `envoy_toolshed` 0.4.13.post6 (the WORKSPACE line, envoyproxy/toolshed#5627) for the rule. This branch has the same test and the same CI image as `main` had, so the same test that only passes from the cache. (cherry picked from commit c111365)
0.4.13.post5 has, backported to the WORKSPACE line (envoyproxy/toolshed#5623), a `cve_scan` that does not need the scanner's `RunEnvironmentInfo`. With Bazel 7 an `sh_binary` does not provide it, so the CVE scan failed at analysis there (as it does on `release/v1.38`); with Bazel 8 nothing changes. 0.4.13.post6 adds `tap2pcap` (`@envoy_toolshed//tap:defs.bzl`, envoyproxy/toolshed#5627), for the `tap2pcap` change that follows. Signed-off-by: Ryan Northey <[email protected]>
The `tap2pcap` tool (`@envoy_api//tools:tap2pcap`, from the traffic tapping docs) shelled out to `od` and to Wireshark's `text2pcap`, and its test compared `tshark` output to a golden file. The CI image has neither tool, so `@envoy_api//tools:tap2pcap_test` only passed while its result was in the remote cache: the API job reports "Executed 0 out of 5 tests". Anything that changes its action key runs it for real, and it fails with `FileNotFoundError: 'text2pcap'`, as on `@envoy_toolshed//tap:defs.bzl` (envoyproxy/toolshed#5622, in `envoy_toolshed` 0.5.24.envoy from #49389) writes the PCAP in Python and is tested there. This makes the tool from that, with the v3 trace wrapper (`envoy.data.tap.v3`, where the old tool read the frozen `v2alpha` one), and removes `tap2pcap.py`, its test, the two fixtures, and the test's line in `do_ci.sh api`. For users `bazel run @envoy_api//tools:tap2pcap <tap .pb/.pb_text> <pcap path>` is unchanged, and no longer needs Wireshark installed. Other differences, from the toolshed implementation: IPv6 traces are written with correct headers (a known issue of the `text2pcap` path), `as_string` bodies are read as well as `as_bytes`, and a trace that is not a socket buffered trace is an error. Risk Level: Low (a developer tool and its test) Testing: These changes ran in CI on #49376 against a pre-release of the toolshed module, with a temporary target that converted the old `tap2pcap_h2_ipv4.pb_text` fixture with the new tool; the API job passed. The toolshed output for that fixture was also checked with `tshark` by hand: the same six HTTP/2 frames, lengths and times as the old golden file. Nothing in Envoy runs the tool after this change. Docs Changes: N/A (the documented command is unchanged) Release Notes: N/A Signed-off-by: Ryan Northey <[email protected]> Backport note (release/v1.38): with `envoy_toolshed` 0.4.13.post6 (the WORKSPACE line, envoyproxy/toolshed#5627) for the rule. This branch has the same test and the same CI image as `main` had, so the same test that only passes from the cache. (cherry picked from commit c111365)
0.4.13.post5 has, backported to the WORKSPACE line (envoyproxy/toolshed#5623), a `cve_scan` that does not need the scanner's `RunEnvironmentInfo`. With Bazel 7 an `sh_binary` does not provide it, so the CVE scan failed at analysis there (as it does on `release/v1.38`); with Bazel 8 nothing changes. 0.4.13.post6 adds `tap2pcap` (`@envoy_toolshed//tap:defs.bzl`, envoyproxy/toolshed#5627), for the `tap2pcap` change that follows. Signed-off-by: Ryan Northey <[email protected]>
The `tap2pcap` tool (`@envoy_api//tools:tap2pcap`, from the traffic tapping docs) shelled out to `od` and to Wireshark's `text2pcap`, and its test compared `tshark` output to a golden file. The CI image has neither tool, so `@envoy_api//tools:tap2pcap_test` only passed while its result was in the remote cache: the API job reports "Executed 0 out of 5 tests". Anything that changes its action key runs it for real, and it fails with `FileNotFoundError: 'text2pcap'`, as on `@envoy_toolshed//tap:defs.bzl` (envoyproxy/toolshed#5622, in `envoy_toolshed` 0.5.24.envoy from #49389) writes the PCAP in Python and is tested there. This makes the tool from that, with the v3 trace wrapper (`envoy.data.tap.v3`, where the old tool read the frozen `v2alpha` one), and removes `tap2pcap.py`, its test, the two fixtures, and the test's line in `do_ci.sh api`. For users `bazel run @envoy_api//tools:tap2pcap <tap .pb/.pb_text> <pcap path>` is unchanged, and no longer needs Wireshark installed. Other differences, from the toolshed implementation: IPv6 traces are written with correct headers (a known issue of the `text2pcap` path), `as_string` bodies are read as well as `as_bytes`, and a trace that is not a socket buffered trace is an error. Risk Level: Low (a developer tool and its test) Testing: These changes ran in CI on #49376 against a pre-release of the toolshed module, with a temporary target that converted the old `tap2pcap_h2_ipv4.pb_text` fixture with the new tool; the API job passed. The toolshed output for that fixture was also checked with `tshark` by hand: the same six HTTP/2 frames, lengths and times as the old golden file. Nothing in Envoy runs the tool after this change. Docs Changes: N/A (the documented command is unchanged) Release Notes: N/A Signed-off-by: Ryan Northey <[email protected]> Backport note (release/v1.39): with `envoy_toolshed` 0.4.13.post6 (the WORKSPACE line, envoyproxy/toolshed#5627) for the rule. This branch has the same test and the same CI image as `main` had, so the same test that only passes from the cache. (cherry picked from commit c111365)

Backports #5622 (
bazel/tap:tap2pcap) to theworkspaceline, for the Envoy release branches that build with WORKSPACE (v1.37 - v1.39).Those branches have the same
@envoy_api//tools:tap2pcap_testand the same CI image asmainhad: the test shells out to Wireshark'stext2pcap, which the image does not have, so it only passes while its result is in the remote cache (the API job onrelease/v1.39reports "Executed 0 out of 5 tests"). envoyproxy/envoy#49392 fixed that onmainwith@envoy_toolshed//tap:defs.bzl, which this line does not have.Picked as is: the
tap2pcapmacro, the Python implementation (tap2pcap.py, unchanged frommain) and its tests. With this in a0.4.13.post6, envoyproxy/envoy#49392 can be picked to those branches.