Skip to content

feat(mirror): Phase-1 local delivery β€” replay captured traffic to the local processΒ #5791

Description

@devantler

πŸ€– Generated by the Daily AI Assistant

Part of #4521 (Phase 1 β€” mirror-only). Next increment after #5702/#5703 (capture spec) and the capture session + workload mirror command landing.

Problem

ksail workload mirror <deployment> today resolves the target, injects the NET_RAW tap, streams the pcap over the exec channel, writes it to a file, and summarizes it. But mirror-only mode's headline promise β€” the locally-running service receives the mirrored traffic β€” is still unfulfilled: nothing delivers the captured requests to the developer's local port. The pcap file is forensics, not a dev bridge.

Proposed direction

Add a live replay sink to the capture session:

  • Parse the pcap stream as it arrives (gopacket/pcapgo are already embedded β€” pkg/svc/mirror/pcap.go, dep gopacket v1.6.1).
  • Reassemble inbound TCP payload streams addressed to the tap target's port (per-flow ordering; evaluate gopacket/reassembly vs a minimal per-flow sequencer β€” decide in the PR, smallest correct option wins).
  • Write each reconstructed inbound byte stream to a configurable local address via a new --to localhost:<port> flag, one local connection per mirrored flow, live (replay while capture runs, not post-hoc).
  • Read-only stays read-only: the local process's responses are read and discarded; nothing flows back into the cluster (the reverse tunnel is Phase 2 by design β€” see the [Repo Assist] [feature]: add local-remote service mirroring (Telepresence/mirrord-style dev bridge)Β #4521 design comment).

Acceptance criteria

  • ksail workload mirror <deployment> --to localhost:8080 replays mirrored inbound TCP payloads to the local address while the capture session runs; file output + summary keep working unchanged (--to is additive).
  • Pure in-process Go (client-go + gopacket) β€” no new external binary, per the package's native house rule.
  • Unit-tested with the existing CaptureExecutor stub feeding a synthetic pcap stream and a local net.Listener asserting the exact replayed bytes; error paths (unreachable local addr, malformed pcap) covered.
  • docs/src/content/docs/cli-flags/workload/workload-mirror.mdx regenerated + the mirror docs updated in the same PR.

Rough size: M β€” one focused PR (new replay.go + flag wiring + tests + docs).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    βœ… Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions