-
Notifications
You must be signed in to change notification settings - Fork 989
Description
Introduce a new cf pcap command that captures network traffic directly from running application container instances via SSH. This provides operators and developers with a native way to debug networking issues without needing to manually SSH into containers and perform the packet capture.
This is part of RFC0048.
Motivation
With the new cf-pcap feature in diego, app developers can perform packet captures themselves without privileged support from the operator (if enabled). Currently, this requires an understanding of the implementation details of these packet captures which should not be the case. The user should be able to perform packet captures through the same interface as all the other actions, hence a new CLI command. Since this a core feature of diego I opted for a built-in command as opposed to a plugin.
Proposed Changes
New command: cf pcap
cf pcap APP_NAME [--process PROCESS] [-i INDEX]
[-o OUTPUT_FILE] [--filter FILTER] [--interface INTERFACE]
[--snaplen SNAPLEN] [--skip-host-validation]
Flags:
| Flag | Default | Description |
|---|---|---|
--process |
web |
App process type to capture from |
-i, --app-instance-index |
all instances | Specific instance index (omit to capture from all running instances) |
-o, --output |
capture.pcap |
Output file path |
--filter |
(none) | BPF filter expression passed to cf-pcap |
--interface |
eth0 |
Network interface to capture on |
--snaplen |
0 (cf-pcap default) |
Snapshot length for captured packets |
-k, --skip-host-validation |
false |
Skip SSH host key validation |
Behavior:
- Requires an org and space to be targeted
- When
-iis omitted, captures from all instances simultaneously - Opens SSH connections to each target instance and runs
/tmp/lifecycle/cf-pcapremotely - Streams pcap-formatted data over SSH stdout, parses individual packets using
gopacket, and merges packets from all instances into a single output.pcapfile - Capture runs until the user presses Ctrl-C, at which point SIGINT is forwarded to the remote processes and the SSH sessions are torn down after a 5-second grace period
- Displays the output file path and size on completion
To allow merging the packet streams the github.com/gopacket/gopacket dependency needs to be added. I intend to only use the pure Go parts (no cgo) to keep building / installing the CLI simple.