Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .testcoverage.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Coverage threshold gate for the capture-sidecar module.
# Enforced by `make cover-go-check` via go-test-coverage/v2.
# Enforced in CI by Gameplane's shared go-component.yaml workflow (go-test-coverage/v2).
#
# The capture-sidecar is an optional ephemeral container that captures and
# records network traffic from game pods via AF_PACKET sockets and PCAPNG
Expand Down
22 changes: 22 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# capture-sidecar — AI assistant guide

This repository holds the optional AF_PACKET/BPF network capture sidecar and node diagnostic worker behind the NetworkCapture CRD. It is a split component of [GameplanePanel/Gameplane](https://github.com/GameplanePanel/Gameplane), checked out there as the `capture-sidecar/` submodule. What it does and its contracts: [`specs.md`](specs.md).

## How it fits into Gameplane

- **Own Go module**, not part of Gameplane's `go.work`. Build and test from this repository's root: `go build ./...` (inside a Gameplane checkout, prefix `GOWORK=off`).
- **CI** is `.github/workflows/ci.yaml`, a thin caller of Gameplane's shared [`go-component.yaml`](https://github.com/GameplanePanel/Gameplane/blob/master/.github/workflows/go-component.yaml), pinned by SHA: lint with Gameplane's root `.golangci.yml` and `.hadolint.yaml` (no copy here), race tests on amd64 and arm64 with the `.testcoverage.yml` gate, govulncheck, and an image build. Dependabot runs in this repository.
- **Images** `capture-sidecar` (`Dockerfile`, built by `make image-capture-sidecar`) are built and published from the Gameplane repository root: the Dockerfiles copy `capture-sidecar/...` from that build context.
- **Callers live in Gameplane:** paths such as `operator/`, `api/`, `charts/`, `docs/` and `web/` in `specs.md` and code comments refer to that repository.
- **Shipping a change:** PR to `main` here → after it merges, bump the `capture-sidecar` pointer in Gameplane (`git -C capture-sidecar checkout <merged sha on main>`, `git add capture-sidecar`) in a Gameplane PR. A user-visible change gets its `changelog/unreleased/` entry in that Gameplane PR.

## Rules

Gameplane's [`AGENTS.md`](https://github.com/GameplanePanel/Gameplane/blob/master/AGENTS.md) core rules apply here. The ones that matter most in this repository:

- **CI verifies:** locally only compile checks (`go build ./...`); never run test or lint suites locally.
- **Fix, don't silence:** no `//nolint` and no per-repository `.golangci.yml`; `_test.go` files are exempt from `errcheck`/`gosec`/`unparam` through the shared config.
- **Go errors:** wrap with `%w`.
- **Tests:** never delete or weaken a test without the maintainer's explicit sign-off; fix the code.
- **Git:** signed commits (`git commit -s`), conventional prefixes (`feat:`, `fix:`, `chore:`, `docs:` …), one branch per unit of work, never amend pushed commits; delete the branch after merge.
- **Docs:** keep `specs.md` in step with behaviour changes in the same PR.
1 change: 1 addition & 0 deletions CLAUDE.md
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# capture-sidecar

> This repository is checked out as the `capture-sidecar/` submodule of [GameplanePanel/Gameplane](https://github.com/GameplanePanel/Gameplane). Paths such as `docs/`, `operator/`, `api/`, `charts/` and `web/` below refer to that repository.

The **capture-sidecar** [optional] records a game server's network traffic to
PCAPNG for diagnostics. The operator adds it to a GameServer's pod when packet
capture is enabled and drives it through the NetworkCapture CRD; the dashboard
starts, stops and downloads captures through the API.

- **Sidecar mode** (`/capture-sidecar`): AF_PACKET capture with a compiled BPF
filter, controlled over an mTLS-only HTTP server (client certificates required;
never plain HTTP) on port 9091, with hard duration and size limits and a volume
budget (the operator expires old captures).
- **Node diagnostic worker** (`/capture-tool --node-worker`): a separate,
operator-created Job that enters one exact container's network namespace;
`--artifacts-only` serves the finished files without capture privileges.

The full contract (endpoints, limits, identity checks, security boundary) is in
[`specs.md`](specs.md); the threat model is in Gameplane's
[`docs/security.md`](https://github.com/GameplanePanel/Gameplane/blob/master/docs/security.md).

## Building and testing

This is its own Go module, outside Gameplane's `go.work`:

```sh
go build ./... # inside a Gameplane checkout: GOWORK=off go build ./...
go test -race ./...
```

CI (`.github/workflows/ci.yaml`) runs Gameplane's shared `go-component.yaml`
workflow: lint, race tests with the `.testcoverage.yml` gate, govulncheck and the
image build. The image is built and published from the Gameplane repository root
(`make image-capture-sidecar`), because the Dockerfile copies
`capture-sidecar/...` from that build context. Contributor rules:
[`AGENTS.md`](AGENTS.md).
6 changes: 3 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ func main() {
// and TLS 1.2 minimum, from auth.ServerTLS). This is the sidecar's only
// authentication boundary: on a plaintext listener anything that can reach
// the pod network could start captures and download another server's
// packet data, so svcutil.RunHTTP - which is HTTP-only - must not be used
// here. Empty file arguments make ListenAndServeTLS use the certificates
// already in server.TLSConfig, matching agent/cmd/main.go.
// packet data, so a plain-HTTP server must not be used here. Empty file
// arguments make ListenAndServeTLS use the certificates already in
// server.TLSConfig, matching Gameplane's agent/cmd/main.go.
errCh := make(chan error, 1)
go func() {
if err := server.ListenAndServeTLS("", ""); err != nil && !errors.Is(err, http.ErrServerClosed) {
Expand Down
9 changes: 5 additions & 4 deletions specs.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# capture-sidecar — Specification

> This repository is checked out as the `capture-sidecar/` submodule of [GameplanePanel/Gameplane](https://github.com/GameplanePanel/Gameplane). Paths such as `docs/`, `operator/`, `api/`, `charts/` and `web/` below refer to that repository.

**Status:** pre-v1 (v0.4.1), Phase 2 Foundational (implementation complete)
**Module / command:** `github.com/GameplanePanel/gameplane/capture-sidecar`
**Dependencies (current):** stdlib + external libraries for packet capture and filtering (github.com/gopacket/gopacket v1.7.2, github.com/packetcap/go-pcap, golang.org/x/net)
Expand Down Expand Up @@ -130,7 +132,7 @@ The module declares the following external dependencies in `go.mod`:
- `github.com/packetcap/go-pcap v0.0.0-20260731105150-c86974bbfbcd` — BPF filter compilation and validation
- `golang.org/x/net` — Networking utilities (bundled by gopacket)

This module does not depend on `svcutil`: its control server is served over mTLS via `ListenAndServeTLS` with client-certificate verification, and `RunHTTP` only serves plain HTTP (`ListenAndServe`) — a plaintext listener would remove the sidecar's only authentication boundary (see the comment at `cmd/main.go:80-86`).
The control server is served over mTLS via `ListenAndServeTLS` with client-certificate verification and never over plain HTTP: a plaintext listener would remove the sidecar's only authentication boundary (see the comment above `server.ListenAndServeTLS` in `cmd/main.go`).

## External Interface / Configuration (Phase 2 Design)

Expand Down Expand Up @@ -316,11 +318,10 @@ Both items previously listed here as "planned" are implemented; kept as a sectio

### Test Commands (Phase 2)

Run via the workspace root Makefile or isolated:
Run from this repository's root (CI runs the same through Gameplane's shared `go-component.yaml` workflow):

```sh
make test-go # Runs all Go tests, including capture-sidecar
cd capture-sidecar && go test ./... # Isolated run
go test -race ./...
```

### Key Test Cases (Phase 2)
Expand Down
4 changes: 2 additions & 2 deletions system-deps.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ component = "capture-sidecar"
name = "go"
kind = "toolchain"
version = "go"
reason = "Compiles and tests the capture-sidecar module (go.work:3-21; inventory 2.1)."
reason = "Compiles and tests the capture-sidecar module."

[[dep]]
name = "golangci-lint"
kind = "cli"
version = "golangci_lint"
reason = "make lint-go runs golangci-lint in this module (Makefile:302-305; GO_MODULES at Makefile:43)."
reason = "golangci-lint runs on this module with Gameplane's root .golangci.yml (shared go-component.yaml workflow)."
Loading