Skip to content

Commit 596d495

Browse files
committed
test e2e workflow
1 parent 702ed92 commit 596d495

1 file changed

Lines changed: 128 additions & 0 deletions

File tree

‎.github/workflows/hub-e2e.yml‎

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,39 @@ jobs:
5353
with:
5454
node-version: 24
5555

56+
# Analysis only: capture uses tcpdump / the built-in Windows pktmon, not Npcap.
57+
- name: Install network diagnostics (Linux)
58+
if: runner.os == 'Linux'
59+
run: |
60+
sudo apt-get update -qq
61+
sudo env DEBIAN_FRONTEND=noninteractive apt-get install -y tcpdump tshark
62+
63+
- name: Prepare network diagnostics (macOS)
64+
if: runner.os == 'macOS'
65+
run: |
66+
curl --fail --location --retry 3 --output "$RUNNER_TEMP/wireshark.dmg" \
67+
'https://www.wireshark.org/download/osx/all-versions/Wireshark%204.6.4.dmg'
68+
echo "08150f79cfc5828820f991b6d944c68536db9595b1c3052982bbde79fb2053df $RUNNER_TEMP/wireshark.dmg" | shasum -a 256 --check
69+
mount="$RUNNER_TEMP/wireshark-mount"
70+
hdiutil attach "$RUNNER_TEMP/wireshark.dmg" -mountpoint "$mount" -readonly -nobrowse
71+
trap 'hdiutil detach "$mount"' EXIT
72+
ditto "$mount/Wireshark.app" "$RUNNER_TEMP/Wireshark.app"
73+
echo "$RUNNER_TEMP/Wireshark.app/Contents/MacOS" >> "$GITHUB_PATH"
74+
75+
- name: Install network diagnostics (Windows)
76+
if: runner.os == 'Windows'
77+
shell: pwsh
78+
run: |
79+
$installer = Join-Path $env:RUNNER_TEMP 'wireshark.exe'
80+
Invoke-WebRequest 'https://www.wireshark.org/download/win64/all-versions/Wireshark-4.6.4-x64.exe' -OutFile $installer
81+
if ((Get-FileHash $installer -Algorithm SHA256).Hash -ne '102017d8e99a75b57895cd2144e6a61dc335a8ff14c7a25bd83a55f8ea9ad77b') {
82+
throw 'Wireshark checksum mismatch'
83+
}
84+
# The silent installer does not install Npcap. Only offline analysis is needed.
85+
$process = Start-Process $installer -ArgumentList '/S', '/desktopicon=no' -Wait -PassThru
86+
if ($process.ExitCode -ne 0) { throw 'Wireshark installation failed' }
87+
"$env:ProgramFiles\Wireshark" >> $env:GITHUB_PATH
88+
5689
- name: Build Wizard CLI
5790
run: cargo build --locked --package wizard-cli
5891

@@ -81,6 +114,44 @@ jobs:
81114
if (state?.status !== "found" || !(state.data.proxy_mode === "proxy_hub" || state.data.proxy_installed === true)) process.exit(1);
82115
' 2>> "$RUNNER_TEMP/wizard.log"
83116
117+
- name: Start network capture
118+
id: capture
119+
run: |
120+
umask 077
121+
mkdir -p "$RUNNER_TEMP/network-capture"
122+
cd "$RUNNER_TEMP/network-capture"
123+
tshark --version > analyzer.log 2>&1
124+
node -e '
125+
const filters = Object.values(require("node:os").networkInterfaces()).flat()
126+
.map(({ family, address }) => `${family === "IPv4" ? "ip" : "ipv6"}.src == ${address.split("%")[0]}`);
127+
if (!filters.length) throw new Error("No local network addresses");
128+
require("node:fs").writeFileSync("outgoing.filter", filters.join(" || "));
129+
'
130+
case "$RUNNER_OS" in
131+
Windows)
132+
pwsh -NoProfile -NonInteractive -Command '
133+
pktmon start --capture --comp nics --pkt-size 0 --file-name capture.etl
134+
if ($LASTEXITCODE -ne 0) { throw "Network capture failed to start" }
135+
' > capture.log 2>&1
136+
;;
137+
Linux|macOS)
138+
interface=any
139+
if [ "$RUNNER_OS" = macOS ]; then interface=pktap,all; fi
140+
# Save tcpdump's PID, not the sudo wrapper's. Drop privileges before writing packets.
141+
sudo -n sh -c 'echo $$; exec tcpdump "$@"' sh \
142+
-i "$interface" -n -s 0 -U -Z "$(id -un)" -w capture.pcapng > capture.pid 2> capture.log &
143+
ready=false
144+
for attempt in {1..100}; do
145+
if grep -q 'listening on' capture.log; then ready=true; break; fi
146+
sleep 0.1
147+
done
148+
if [ "$ready" != true ]; then
149+
echo '::error::Network capture failed to start.'
150+
exit 1
151+
fi
152+
;;
153+
esac
154+
84155
- name: Ask agent through Hub
85156
timeout-minutes: 5
86157
env:
@@ -116,3 +187,60 @@ jobs:
116187
exit 1
117188
fi
118189
echo 'Hub request succeeded: 42'
190+
191+
# Also runs when the agent fails. Capture covers the whole runner, not just its processes.
192+
- name: Stop capture and report network destinations
193+
if: ${{ always() && (steps.capture.outcome == 'success' || steps.capture.outcome == 'failure') }}
194+
timeout-minutes: 2
195+
run: |
196+
cd "$RUNNER_TEMP/network-capture"
197+
# Never upload packet captures: unexpected plaintext traffic could contain credentials.
198+
trap 'rm -f capture.pcapng capture.etl destinations.tsv' EXIT
199+
case "$RUNNER_OS" in
200+
Windows)
201+
pwsh -NoProfile -NonInteractive -Command '
202+
pktmon stop
203+
if ($LASTEXITCODE -ne 0) { throw "Network capture failed to stop" }
204+
pktmon etl2pcap capture.etl --out capture.pcapng
205+
if ($LASTEXITCODE -ne 0) { throw "Network capture conversion failed" }
206+
' > stop.log 2>&1
207+
;;
208+
Linux|macOS)
209+
read -r pid < capture.pid
210+
sudo -n kill -INT "$pid"
211+
stopped=false
212+
for attempt in {1..100}; do
213+
if ! sudo -n kill -0 "$pid" 2>/dev/null; then stopped=true; break; fi
214+
sleep 0.1
215+
done
216+
if [ "$stopped" != true ]; then
217+
sudo -n kill -TERM "$pid" || true
218+
echo '::error::Network capture did not stop cleanly.'
219+
exit 1
220+
fi
221+
sudo -n chown "$(id -u):$(id -g)" capture.pcapng
222+
chmod 600 capture.pcapng
223+
# tcpdump reports counters only with -w; no packet contents are printed.
224+
grep 'packets dropped by kernel' capture.log || true
225+
if grep -Eq '[1-9][0-9]* packets dropped by kernel' capture.log; then
226+
echo '::error::Network capture dropped packets.'
227+
exit 1
228+
fi
229+
;;
230+
esac
231+
# -n prevents analysis from making reverse-DNS requests. Export metadata only.
232+
tshark -n -2 -r capture.pcapng -Y "$(<outgoing.filter)" -T fields -E escape=y \
233+
-e ip.dst -e ipv6.dst -e tcp.dstport -e udp.dstport \
234+
-e dns.qry.name -e tls.handshake.extensions_server_name -e http.host \
235+
> destinations.tsv 2> analyzer.log
236+
if [ ! -s destinations.tsv ]; then
237+
echo '::error::No outgoing IP packets observed; network audit is inconclusive.'
238+
exit 1
239+
fi
240+
{
241+
printf '## Network audit: %s (%s)\n\n' "$AGENT" "$RUNNER_OS"
242+
printf 'Whole-runner traffic during the request; no process attribution or allowlist enforcement. Names may be absent. Windows: NIC capture only.\n\n'
243+
printf '```text\nIPv4\tIPv6\tTCP port\tUDP port\tDNS name\tTLS SNI\tHTTP Host\n'
244+
LC_ALL=C sort -u destinations.tsv
245+
printf '```\n'
246+
} | tee -a "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)