cloudfoundry / cloudfoundry/cli

Add `cf pcap` command to facilitate multi-instance packet captures

Open
#3,738 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
1.9k
Forks
990
Avg merge
1d 7h
Merged PRs (30d)
8

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 -i is omitted, captures from all instances simultaneously
  • Opens SSH connections to each target instance and runs /tmp/lifecycle/cf-pcap remotely
  • Streams pcap-formatted data over SSH stdout, parses individual packets using gopacket, and merges packets from all instances into a single output .pcap file
  • 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with RFC0048 and the proposed cf pcap command interface, then inspect the CLI's existing command and SSH patterns. Evaluate the pure-Go github.com/gopacket/gopacket dependency and the /tmp/lifecycle/cf-pcap stream behavior. Done means the documented flags, multi-instance packet merging, Ctrl-C handling, and output reporting work as described.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli, networking
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.