From 39bb332ecdc4565ef987d6e165bdd48c285f8a7d Mon Sep 17 00:00:00 2001 From: erfanara Date: Mon, 9 Nov 2026 01:24:50 +0330 Subject: [PATCH] add(proxyjail): first commit --- .gitignore | 1 + Cargo.lock | 836 +++++++++ Cargo.toml | 8 + README.md | 26 + apps/proxyjail-cli/Cargo.toml | 13 + apps/proxyjail-cli/src/main.rs | 50 + crates/proxyjail-core/Cargo.toml | 6 + crates/proxyjail-core/src/correlator.rs | 160 ++ crates/proxyjail-core/src/event.rs | 16 + crates/proxyjail-core/src/lib.rs | 7 + crates/proxyjail-ebpf/Cargo.toml | 17 + .../proxyjail-ebpf/bpf/bpf_sockopt_helpers.h | 21 + crates/proxyjail-ebpf/bpf/event.h | 47 + .../proxyjail-ebpf/bpf/redirect_cgroup.bpf.c | 176 ++ crates/proxyjail-ebpf/build.rs | 19 + crates/proxyjail-ebpf/src/lib.rs | 10 + crates/proxyjail-ebpf/src/libbpf.rs | 137 ++ crates/proxyjail-runtime/Cargo.toml | 7 + crates/proxyjail-runtime/src/lib.rs | 1 + .../src/std_runtime/config.rs | 40 + .../src/std_runtime/connection.rs | 51 + .../src/std_runtime/coordinator.rs | 108 ++ .../src/std_runtime/event_forwarder.rs | 34 + .../src/std_runtime/listener.rs | 48 + .../src/std_runtime/message.rs | 16 + .../proxyjail-runtime/src/std_runtime/mod.rs | 95 + .../src/std_runtime/relay.rs | 72 + docs/arch.excalidraw | 1560 +++++++++++++++++ docs/arch.svg | 4 + docs/decisions.md | 34 + docs/ideas.md | 14 + 31 files changed, 3634 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 README.md create mode 100644 apps/proxyjail-cli/Cargo.toml create mode 100644 apps/proxyjail-cli/src/main.rs create mode 100644 crates/proxyjail-core/Cargo.toml create mode 100644 crates/proxyjail-core/src/correlator.rs create mode 100644 crates/proxyjail-core/src/event.rs create mode 100644 crates/proxyjail-core/src/lib.rs create mode 100644 crates/proxyjail-ebpf/Cargo.toml create mode 100644 crates/proxyjail-ebpf/bpf/bpf_sockopt_helpers.h create mode 100644 crates/proxyjail-ebpf/bpf/event.h create mode 100644 crates/proxyjail-ebpf/bpf/redirect_cgroup.bpf.c create mode 100644 crates/proxyjail-ebpf/build.rs create mode 100644 crates/proxyjail-ebpf/src/lib.rs create mode 100644 crates/proxyjail-ebpf/src/libbpf.rs create mode 100644 crates/proxyjail-runtime/Cargo.toml create mode 100644 crates/proxyjail-runtime/src/lib.rs create mode 100644 crates/proxyjail-runtime/src/std_runtime/config.rs create mode 100644 crates/proxyjail-runtime/src/std_runtime/connection.rs create mode 100644 crates/proxyjail-runtime/src/std_runtime/coordinator.rs create mode 100644 crates/proxyjail-runtime/src/std_runtime/event_forwarder.rs create mode 100644 crates/proxyjail-runtime/src/std_runtime/listener.rs create mode 100644 crates/proxyjail-runtime/src/std_runtime/message.rs create mode 100644 crates/proxyjail-runtime/src/std_runtime/mod.rs create mode 100644 crates/proxyjail-runtime/src/std_runtime/relay.rs create mode 100644 docs/arch.excalidraw create mode 100644 docs/arch.svg create mode 100644 docs/decisions.md create mode 100644 docs/ideas.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..90460d2 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,836 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "android_system_properties" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae221649c9976a6f6c56ae1facf410f3ddb33cc661c4b7b61020a912d4237fbc" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" + +[[package]] +name = "anstyle-parse" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys", +] + +[[package]] +name = "anyhow" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" + +[[package]] +name = "autocfg" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" + +[[package]] +name = "bitflags" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" + +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] +name = "camino" +version = "1.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbbad30e4b4c14a39e3cc8aed085a12a327257c316619c93581e017bc52be591" +dependencies = [ + "serde_core", +] + +[[package]] +name = "cargo-platform" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e35af189006b9c0f00a064685c727031e3ed2d8020f7ba284d78cc2671bd36ea" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.19.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd5eb614ed4c27c5d706420e4320fbe3216ab31fa1c33cd8246ac36dae4479ba" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "cc" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ff2a8126fff0f8c839080d619675a585e61720bb12d2baceae45769fd66f155" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" + +[[package]] +name = "cfg_aliases" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" + +[[package]] +name = "chrono" +version = "0.4.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327" +dependencies = [ + "iana-time-zone", + "num-traits", + "windows-link", +] + +[[package]] +name = "clap" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa8876b300ab35ba921adea3dfd70157a46249b33f95c9084ae5709785478946" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0797fb7aeb1406c84efac526901f7ec3ead2124f946b494e72879d4b54704d" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9c751b79415d4e559e3d1fcf128e09e720eb673a06d26cf6f392d37d75b66e0" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 3.0.9", +] + +[[package]] +name = "clap_lex" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486" + +[[package]] +name = "colorchoice" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fastrand" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" + +[[package]] +name = "find-msvc-tools" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48" + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "libc", + "r-efi", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "js-sys" +version = "0.3.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dc09d2154098bbf4ef54eab6b117a3c24cbbffe94046b16ee6d6d4510584d3a" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20870f649af7073d53e38067b2a84312175d56ea15217e1b15bc83506ec50afb" + +[[package]] +name = "libbpf-cargo" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78da1f54d4070442b5911ea2ace04f0b102ef162a5f2aaaa51ba59b6dc3863fe" +dependencies = [ + "anyhow", + "cargo_metadata", + "clap", + "libbpf-rs", + "memmap2", + "serde", + "serde_json", + "tempfile", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "libbpf-rs" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffef943d6690772a293abe80412ca438c227867cac93448af2518166df1b1a7b" +dependencies = [ + "bitflags", + "libbpf-sys", + "libc", + "vsprintf", +] + +[[package]] +name = "libbpf-sys" +version = "1.7.0+v1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a109478760b2900aa2a6f2087e9d0de1d9c535b1758602af2845d5d2ccfaed7c" +dependencies = [ + "cc", + "nix", + "pkg-config", +] + +[[package]] +name = "libc" +version = "0.2.191" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" + +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + +[[package]] +name = "log" +version = "0.4.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "memmap2" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b0ca1155a9ecc25aa12e8313a119f32edf0255fea2f44839c4ac0a12b2ac157" +dependencies = [ + "libc", +] + +[[package]] +name = "nix" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf20d2fde8ff38632c426f1165ed7436270b44f199fc55284c38276f9db47c3d" +dependencies = [ + "bitflags", + "cfg-if", + "cfg_aliases", + "libc", +] + +[[package]] +name = "nu-ansi-term" +version = "0.50.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "pkg-config" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548" + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "proxyjail-cli" +version = "0.1.0" +dependencies = [ + "proxyjail-core", + "proxyjail-ebpf", + "proxyjail-runtime", +] + +[[package]] +name = "proxyjail-core" +version = "0.1.0" + +[[package]] +name = "proxyjail-ebpf" +version = "0.1.0" +dependencies = [ + "anyhow", + "libbpf-cargo", + "libbpf-rs", + "proxyjail-core", +] + +[[package]] +name = "proxyjail-runtime" +version = "0.1.0" +dependencies = [ + "proxyjail-core", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rustix" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" +dependencies = [ + "serde", + "serde_core", +] + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", +] + +[[package]] +name = "serde_json" +version = "1.0.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tempfile" +version = "3.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" +dependencies = [ + "fastrand", + "getrandom", + "once_cell", + "rustix", + "windows-sys", +] + +[[package]] +name = "thiserror" +version = "2.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", +] + +[[package]] +name = "thread_local" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad99c4c6d32803332c548b1af0540b357b3f5fc0be8f6c6bfe8b2e6ae784070" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319" +dependencies = [ + "chrono", + "nu-ansi-term", + "sharded-slab", + "thread_local", + "tracing-core", +] + +[[package]] +name = "unicode-ident" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "vsprintf" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aec2f81b75ca063294776b4f7e8da71d1d5ae81c2b1b149c8d89969230265d63" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0181c14ddd6c7b8b0b0132a5f1ea2f32be0d893cd3ea97b6e3b28886b8a3d1c" +dependencies = [ + "cfg-if", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e931a02a39abdbf66966fc35902b5ed58344750a70885bed4ebb3d8eaf28ed9" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ca4b54280e455bd831e33a6b8e734baf432fe63fbc35c42ac14ce67a043a53a" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 3.0.9", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b1f9c3798725016c6ee5f2f57869ec0831e8bbc0ab0310a86e787e97f41389e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..f1d57fc --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] +resolver = "2" +members = [ + "crates/proxyjail-core", + "crates/proxyjail-ebpf", + "crates/proxyjail-runtime", + "apps/proxyjail-cli", +] diff --git a/README.md b/README.md new file mode 100644 index 0000000..da1f8a1 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +## Build + +```bash +cargo check --workspace +cargo build --feature ebpf +``` + +Without the `ebpf` feature, the CLI starts the TCP runtime without an eBPF +event producer. This is useful for compiling and testing the runtime pieces, +but intercepted connections cannot be correlated or proxied. + +## Current behavior + +- eBPF events and accepted TCP sockets may arrive in either order. +- The coordinator stores unmatched items and expires them after + `pending_timeout`. +- A matched connection opens `original_destination` and relays bytes in both +directions. +- The blocking relay uses two OS threads per active proxied connection. +- The internal standard-library `mpsc::channel` is unbounded. Before production, + add queue limits, pending-item limits, and explicit overload behavior. +- The CLI currently does not implement child-process supervision or graceful + cancellation of the eBPF polling loop; those are application-lifecycle tasks + for a later iteration. + +The listener defaults to `127.0.0.1:10000`. diff --git a/apps/proxyjail-cli/Cargo.toml b/apps/proxyjail-cli/Cargo.toml new file mode 100644 index 0000000..578a1d6 --- /dev/null +++ b/apps/proxyjail-cli/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "proxyjail-cli" +version = "0.1.0" +edition = "2024" + +[features] +default = [] +ebpf = ["dep:proxyjail-ebpf", "proxyjail-ebpf/libbpf"] + +[dependencies] +proxyjail-core = { path = "../../crates/proxyjail-core" } +proxyjail-runtime = { path = "../../crates/proxyjail-runtime" } +proxyjail-ebpf = { path = "../../crates/proxyjail-ebpf", optional = true } diff --git a/apps/proxyjail-cli/src/main.rs b/apps/proxyjail-cli/src/main.rs new file mode 100644 index 0000000..43306fb --- /dev/null +++ b/apps/proxyjail-cli/src/main.rs @@ -0,0 +1,50 @@ +use std::{ + io, + net::SocketAddr, + sync::mpsc, + time::Duration, +}; + +use proxyjail_core::EbpfEvent; +use proxyjail_runtime::std_runtime::{self, StdRuntimeConfig}; + +#[cfg(feature = "ebpf")] +use std::{path::PathBuf, thread}; + +fn main() -> io::Result<()> { + let (event_tx, event_rx) = mpsc::channel::(); + + #[cfg(feature = "ebpf")] + { + let cgroup_path = std::env::var_os("PROXY_EBPF_CGROUP") + .map(PathBuf::from) + .unwrap_or_else(|| PathBuf::from("/sys/fs/cgroup/ebpf-demo")); + + let ebpf_config = proxyjail_ebpf::EbpfConfig { + cgroup_path, + ..proxyjail_ebpf::EbpfConfig::default() + }; + + thread::Builder::new() + .name("proxyjail-ebpf-poller".into()) + .spawn(move || { + if let Err(err) = proxyjail_ebpf::run(ebpf_config, event_tx) { + eprintln!("eBPF poller failed: {err:#}"); + } + })?; + } + + // Without the `ebpf` feature this CLI is useful for developing/testing + // the runtime, but it has no event producer and cannot match connections. + #[cfg(not(feature = "ebpf"))] + drop(event_tx); + + let config = StdRuntimeConfig { + listen_addr: SocketAddr::from(([127, 0, 0, 1], 10000)), + connect_timeout: Duration::from_secs(5), + pending_timeout: Duration::from_secs(10), + cleanup_interval: Duration::from_millis(250), + }; + + std_runtime::run(config, event_rx) +} diff --git a/crates/proxyjail-core/Cargo.toml b/crates/proxyjail-core/Cargo.toml new file mode 100644 index 0000000..f3ce6f8 --- /dev/null +++ b/crates/proxyjail-core/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "proxyjail-core" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/crates/proxyjail-core/src/correlator.rs b/crates/proxyjail-core/src/correlator.rs new file mode 100644 index 0000000..2ea9176 --- /dev/null +++ b/crates/proxyjail-core/src/correlator.rs @@ -0,0 +1,160 @@ +use std::{ + collections::HashMap, + net::SocketAddr, + time::{Duration, Instant}, +}; + +use crate::EbpfEvent; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum PendingSide { + EbpfEvent, + TcpConnection, +} + +pub struct MatchedConnection { + pub event: EbpfEvent, + pub stream: C, + pub peer_addr: SocketAddr, +} + +pub enum CorrelationOutcome { + /// The item was saved until its counterpart arrives. + Pending { + key: SocketAddr, + side: PendingSide, + }, + /// Both observations are now available. + Matched(MatchedConnection), + /// Another unmatched item with the same key was already pending. + /// The duplicate item is dropped. + Duplicate { + key: SocketAddr, + side: PendingSide, + }, +} + +struct Pending { + value: T, + since: Instant, +} + +pub struct Correlator { + pending_events: HashMap>, + pending_connections: HashMap>, +} + +impl Default for Correlator { + fn default() -> Self { + Self { + pending_events: HashMap::new(), + pending_connections: HashMap::new(), + } + } +} + +#[derive(Debug, Default)] +pub struct ExpiredItems { + pub events: Vec, + pub connections: Vec, +} + +impl Correlator { + pub fn on_event(&mut self, event: EbpfEvent) -> CorrelationOutcome { + let key = event.client; + + if let Some(pending) = self.pending_connections.remove(&key) { + return CorrelationOutcome::Matched(MatchedConnection { + event, + stream: pending.value, + peer_addr: key, + }); + } + + if self.pending_events.contains_key(&key) { + return CorrelationOutcome::Duplicate { + key, + side: PendingSide::EbpfEvent, + }; + } + + self.pending_events.insert( + key, + Pending { + value: event, + since: Instant::now(), + }, + ); + + CorrelationOutcome::Pending { + key, + side: PendingSide::EbpfEvent, + } + } + + pub fn on_connection( + &mut self, + stream: C, + peer_addr: SocketAddr, + ) -> CorrelationOutcome { + if let Some(pending) = self.pending_events.remove(&peer_addr) { + return CorrelationOutcome::Matched(MatchedConnection { + event: pending.value, + stream, + peer_addr, + }); + } + + if self.pending_connections.contains_key(&peer_addr) { + // `stream` is dropped here, closing the duplicate connection. + return CorrelationOutcome::Duplicate { + key: peer_addr, + side: PendingSide::TcpConnection, + }; + } + + self.pending_connections.insert( + peer_addr, + Pending { + value: stream, + since: Instant::now(), + }, + ); + + CorrelationOutcome::Pending { + key: peer_addr, + side: PendingSide::TcpConnection, + } + } + + /// Remove unmatched observations older than `ttl`. + /// Removing a pending TCP connection drops its stream. + pub fn expire(&mut self, now: Instant, ttl: Duration) -> ExpiredItems { + let mut expired = ExpiredItems::default(); + + self.pending_events.retain(|key, pending| { + let keep = now.duration_since(pending.since) < ttl; + if !keep { + expired.events.push(*key); + } + keep + }); + + self.pending_connections.retain(|key, pending| { + let keep = now.duration_since(pending.since) < ttl; + if !keep { + expired.connections.push(*key); + } + keep + }); + + expired + } + + pub fn pending_counts(&self) -> (usize, usize) { + ( + self.pending_events.len(), + self.pending_connections.len(), + ) + } +} diff --git a/crates/proxyjail-core/src/event.rs b/crates/proxyjail-core/src/event.rs new file mode 100644 index 0000000..0fd45a0 --- /dev/null +++ b/crates/proxyjail-core/src/event.rs @@ -0,0 +1,16 @@ +use std::net::SocketAddr; + +/// A fully assembled observation of one outgoing connection. +/// +/// `client` must be the exact peer endpoint that the local TCP listener will +/// observe through `TcpStream::peer_addr()`. It is the correlation key. +/// `original_destination` is where the proxy should open the upstream socket. +/// +/// The eBPF layer should publish one `EbpfEvent` only after it has collected +/// enough information to populate both endpoints reliably. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct EbpfEvent { + pub pid_tgid: u64, + pub client: SocketAddr, + pub original_destination: SocketAddr, +} diff --git a/crates/proxyjail-core/src/lib.rs b/crates/proxyjail-core/src/lib.rs new file mode 100644 index 0000000..a21e035 --- /dev/null +++ b/crates/proxyjail-core/src/lib.rs @@ -0,0 +1,7 @@ +mod correlator; +mod event; + +pub use correlator::{ + CorrelationOutcome, Correlator, ExpiredItems, MatchedConnection, PendingSide, +}; +pub use event::EbpfEvent; diff --git a/crates/proxyjail-ebpf/Cargo.toml b/crates/proxyjail-ebpf/Cargo.toml new file mode 100644 index 0000000..3d78340 --- /dev/null +++ b/crates/proxyjail-ebpf/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "proxyjail-ebpf" +version = "0.1.0" +edition = "2024" + +[features] +default = [] +# Enable the libbpf loader after placing the generated redirect skeleton at +libbpf = ["dep:anyhow", "dep:libbpf-rs"] + +[dependencies] +proxyjail-core = { path = "../proxyjail-core" } +anyhow = { version = "1", optional = true } +libbpf-rs = { version = "0.27.2", optional = true } + +[build-dependencies] +libbpf-cargo = "0.27.2" diff --git a/crates/proxyjail-ebpf/bpf/bpf_sockopt_helpers.h b/crates/proxyjail-ebpf/bpf/bpf_sockopt_helpers.h new file mode 100644 index 0000000..11f3a09 --- /dev/null +++ b/crates/proxyjail-ebpf/bpf/bpf_sockopt_helpers.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include +#include + +int get_set_sk_priority(void *ctx) +{ + int prio; + + /* Verify that context allows calling bpf_getsockopt and + * bpf_setsockopt by reading and writing back socket + * priority. + */ + + if (bpf_getsockopt(ctx, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio))) + return 0; + if (bpf_setsockopt(ctx, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio))) + return 0; + + return 1; +} diff --git a/crates/proxyjail-ebpf/bpf/event.h b/crates/proxyjail-ebpf/bpf/event.h new file mode 100644 index 0000000..4b0c5bb --- /dev/null +++ b/crates/proxyjail-ebpf/bpf/event.h @@ -0,0 +1,47 @@ +#ifndef PROXY_EBPF_EVENT_H +#define PROXY_EBPF_EVENT_H + +#include + +/* + * Original destination metadata stored against the client socket. + * + * This storage is created in connect4 and retrieved later + * from the sockops callback. + */ +struct svc_addr { + __be32 addr; + __be16 port; + __u16 _pad; + __u64 pid_tgid; +}; + +/* + * Ring-buffer event. + * + * IMPORTANT: Keep this layout synchronized with the Rust parser. + * + * Total size: 24 bytes. + * + * Offset: + * 0 - 8: pid_tgid + * 8 - 12: client_ip4 + * 12 - 14: client_port + * 14 - 16: padding + * 16 - 20: original_ip4 + * 20 - 22: original_port + * 22 - 24: padding + */ +struct proxy_event { + __u64 pid_tgid; + + __be32 client_ip4; + __be16 client_port; + __u16 _pad0; + + __be32 original_ip4; + __be16 original_port; + __u16 _pad1; +}; + +#endif /* PROXY_EBPF_EVENT_H */ diff --git a/crates/proxyjail-ebpf/bpf/redirect_cgroup.bpf.c b/crates/proxyjail-ebpf/bpf/redirect_cgroup.bpf.c new file mode 100644 index 0000000..7f3a614 --- /dev/null +++ b/crates/proxyjail-ebpf/bpf/redirect_cgroup.bpf.c @@ -0,0 +1,176 @@ + +// SPDX-License-Identifier: GPL-2.0 + +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include "bpf_sockopt_helpers.h" +#include "event.h" + +char _license[] SEC("license") = "GPL"; + + +/* + * Per-socket metadata. + */ +struct { + __uint(type, BPF_MAP_TYPE_SK_STORAGE); + __uint(map_flags, BPF_F_NO_PREALLOC); + __type(key, int); + __type(value, struct svc_addr); +} service_mapping SEC(".maps"); + +/* + * Userspace event channel. + */ +struct { + __uint(type, BPF_MAP_TYPE_RINGBUF); + __uint(max_entries, 1 << 20); +} events SEC(".maps"); + + +/* + * Intercept outgoing IPv4 TCP connections. + * + * Preserve the original destination and redirect the connection + * to the local proxy listener. + */ +SEC("cgroup/connect4") +int connect4(struct bpf_sock_addr *ctx) +{ + struct svc_addr *orig; + + // This proxy currently handles TCP only. + if (ctx->type != SOCK_STREAM || + ctx->protocol != IPPROTO_TCP) + return 1; + + orig = bpf_sk_storage_get( + &service_mapping, + ctx->sk, + 0, + BPF_SK_STORAGE_GET_F_CREATE + ); + + // Fail closed if we cannot preserve the original destination. + if (!orig) + return 0; + + orig->addr = ctx->user_ip4; + orig->port = (__be16)ctx->user_port; + orig->pid_tgid = bpf_get_current_pid_tgid(); + orig->_pad = 0; + + // Redirect to local proxy. + ctx->user_ip4 = bpf_htonl(0x7f000001); + ctx->user_port = bpf_htons(10000); + + return 1; +} + + +/* + * Capture the actual local endpoint after TCP has allocated + * its source port. + * + * This callback runs for the outgoing TCP socket. + */ +SEC("sockops") +int proxy_sockops(struct bpf_sock_ops *skops) +{ + struct svc_addr *orig; + struct proxy_event *event; + + if (skops->op != BPF_SOCK_OPS_TCP_CONNECT_CB) + return 1; + + if (skops->family != AF_INET) + return 1; + + if (!skops->sk) + return 1; + + // Retrieve metadata saved by connect4. + orig = bpf_sk_storage_get( + &service_mapping, + skops->sk, + 0, + 0 + ); + + // Ignore connections that were not intercepted. + if (!orig) + return 1; + + event = bpf_ringbuf_reserve( + &events, + sizeof(*event), + 0 + ); + + /* + * SOCK_OPS callback return values cannot abort the connection. + * If the ring buffer is full, this event is lost. + */ + if (!event) + return 1; + + event->pid_tgid = orig->pid_tgid; + + // Local endpoint of the redirected client socket. + event->client_ip4 = skops->local_ip4; + + // SOCK_OPS local_port is host byte order. + // Store it in network byte order for userspace. + event->client_port = bpf_htons( + (__u16)skops->local_port + ); + + event->_pad0 = 0; + + // Original destination saved by connect4. + event->original_ip4 = orig->addr; + event->original_port = orig->port; + + event->_pad1 = 0; + + bpf_ringbuf_submit(event, 0); + + return 1; +} + + +/* + * Expose the original destination through getpeername(). + */ +SEC("cgroup/getpeername4") +int getpeername4(struct bpf_sock_addr *ctx) +{ + struct svc_addr *orig; + + if (!get_set_sk_priority(ctx)) + return 1; + + orig = bpf_sk_storage_get( + &service_mapping, + ctx->sk, + 0, + 0 + ); + + if (!orig) + return 1; + + ctx->user_ip4 = orig->addr; + ctx->user_port = orig->port; + + return 1; +} diff --git a/crates/proxyjail-ebpf/build.rs b/crates/proxyjail-ebpf/build.rs new file mode 100644 index 0000000..26d9953 --- /dev/null +++ b/crates/proxyjail-ebpf/build.rs @@ -0,0 +1,19 @@ +use std::{env, path::PathBuf}; + +use libbpf_cargo::SkeletonBuilder; + +fn main() { + let out_dir = PathBuf::from( + env::var_os("OUT_DIR").expect("OUT_DIR must be set") + ); + + let out = out_dir.join("redirect_cgroup.skel.rs"); + + SkeletonBuilder::new() + .source("bpf/redirect_cgroup.bpf.c") + .build_and_generate(&out) + .expect("failed to build BPF program and generate skeleton"); + + println!("cargo:rerun-if-changed=bpf/redirect_cgroup.bpf.c"); + println!("cargo:rerun-if-changed=bpf/bpf_sockopt_helpers.h"); +} \ No newline at end of file diff --git a/crates/proxyjail-ebpf/src/lib.rs b/crates/proxyjail-ebpf/src/lib.rs new file mode 100644 index 0000000..16b4696 --- /dev/null +++ b/crates/proxyjail-ebpf/src/lib.rs @@ -0,0 +1,10 @@ +//! eBPF event producer for the proxy workspace. +//! +//! The libbpf-backed loader is opt-in because it requires Linux, libbpf build +//! dependencies, and the generated `redirect_cgroup.skel.rs` skeleton. + +#[cfg(feature = "libbpf")] +mod libbpf; + +#[cfg(feature = "libbpf")] +pub use libbpf::{run, EbpfConfig}; diff --git a/crates/proxyjail-ebpf/src/libbpf.rs b/crates/proxyjail-ebpf/src/libbpf.rs new file mode 100644 index 0000000..deaa4e1 --- /dev/null +++ b/crates/proxyjail-ebpf/src/libbpf.rs @@ -0,0 +1,137 @@ +use std::{ + convert::TryInto, + fs::File, + net::{Ipv4Addr, SocketAddr, SocketAddrV4}, + os::fd::AsRawFd, + path::PathBuf, + sync::mpsc::Sender, + time::Duration, +}; + +use anyhow::{Context, Result}; +use libbpf_rs::{ + skel::{OpenSkel, SkelBuilder}, + RingBufferBuilder, +}; + +use proxyjail_core::EbpfEvent; + +// Generated from the BPF object named `redirect`. +mod redirect { + include!(concat!(env!("OUT_DIR"), "/redirect_cgroup.skel.rs")); +} + +use redirect::*; + +/// Configuration for the blocking libbpf ring-buffer poller. +#[derive(Debug, Clone)] +pub struct EbpfConfig { + /// Cgroup v2 directory to which the cgroup programs are attached. + pub cgroup_path: PathBuf, + /// Maximum time spent in one ring-buffer poll call before returning. + pub poll_interval: Duration, +} + +impl Default for EbpfConfig { + fn default() -> Self { + Self { + cgroup_path: PathBuf::from("/sys/fs/cgroup/ebpf-demo"), + poll_interval: Duration::from_millis(100), + } + } +} + +// ABI shared with the BPF program in bpf/event.h. +// C layout: u64, be32, be16, 2-byte padding, be32, be16, 2-byte tail padding. +const EVENT_SIZE: usize = 24; + +/// Load and attach the redirect programs, then publish decoded ring-buffer +/// events to the proxy runtime. +/// +/// This function blocks while polling the ring buffer. Run it on a dedicated +/// OS thread; do not call it from a latency-sensitive thread. +pub fn run(config: EbpfConfig, event_tx: Sender) -> Result<()> { + if config.poll_interval.is_zero() { + anyhow::bail!("poll_interval must be non-zero"); + } + + let builder = RedirectCgroupSkelBuilder::default(); + let mut open_object = std::mem::MaybeUninit::uninit(); + let open_skel = builder.open(&mut open_object)?; + let mut skel = open_skel.load()?; + + // Keep the cgroup file descriptor alive while the attached links exist. + let cgroup = File::open(&config.cgroup_path) + .with_context(|| format!("opening cgroup {}", config.cgroup_path.display()))?; + let cgroup_fd = cgroup.as_raw_fd(); + + let progs = &mut skel.progs; + let _connect4 = progs + .connect4 + .attach_cgroup(cgroup_fd) + .context("attaching connect4 cgroup program")?; + let _getpeername4 = progs + .getpeername4 + .attach_cgroup(cgroup_fd) + .context("attaching getpeername4 cgroup program")?; + let _sockops = progs + .proxy_sockops + .attach_cgroup(cgroup_fd) + .context("attaching sockops cgroup program")?; + + let mut ring_buffer_builder = RingBufferBuilder::new(); + ring_buffer_builder.add(&skel.maps.events, move |data| { + let Some(event) = parse_event(data) else { + eprintln!("Ignoring malformed eBPF event ({} bytes)", data.len()); + return 0; + }; + + match event_tx.send(event) { + Ok(()) => 0, + Err(err) => { + eprintln!("Proxy runtime receiver disconnected: {err}"); + // A negative callback result stops ring-buffer consumption. + -1 + } + } + })?; + + let ring_buffer = ring_buffer_builder.build()?; + + println!( + "eBPF programs attached to {}; polling ring buffer", + config.cgroup_path.display() + ); + + loop { + ring_buffer.poll(config.poll_interval)?; + } +} + +/// Decode the fixed-size event emitted by the BPF program. +/// +/// The source endpoint must be the endpoint visible to the proxy listener, +/// such that it matches `TcpStream::peer_addr()` exactly. +fn parse_event(data: &[u8]) -> Option { + if data.len() < EVENT_SIZE { + return None; + } + + let pid_tgid = u64::from_ne_bytes(data[0..8].try_into().ok()?); + + let client_ip = Ipv4Addr::from(<[u8; 4]>::try_from(&data[8..12]).ok()?); + let client_port = u16::from_be_bytes(data[12..14].try_into().ok()?); + + // Bytes 14..16 are ABI padding. + let original_ip = Ipv4Addr::from(<[u8; 4]>::try_from(&data[16..20]).ok()?); + let original_port = u16::from_be_bytes(data[20..22].try_into().ok()?); + + Some(EbpfEvent { + pid_tgid, + client: SocketAddr::V4(SocketAddrV4::new(client_ip, client_port)), + original_destination: SocketAddr::V4(SocketAddrV4::new( + original_ip, + original_port, + )), + }) +} diff --git a/crates/proxyjail-runtime/Cargo.toml b/crates/proxyjail-runtime/Cargo.toml new file mode 100644 index 0000000..753c716 --- /dev/null +++ b/crates/proxyjail-runtime/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "proxyjail-runtime" +version = "0.1.0" +edition = "2024" + +[dependencies] +proxyjail-core = { path = "../proxyjail-core" } diff --git a/crates/proxyjail-runtime/src/lib.rs b/crates/proxyjail-runtime/src/lib.rs new file mode 100644 index 0000000..63a95d3 --- /dev/null +++ b/crates/proxyjail-runtime/src/lib.rs @@ -0,0 +1 @@ +pub mod std_runtime; \ No newline at end of file diff --git a/crates/proxyjail-runtime/src/std_runtime/config.rs b/crates/proxyjail-runtime/src/std_runtime/config.rs new file mode 100644 index 0000000..58ad6a4 --- /dev/null +++ b/crates/proxyjail-runtime/src/std_runtime/config.rs @@ -0,0 +1,40 @@ +use std::{ + io, + net::SocketAddr, + time::Duration, +}; + +#[derive(Debug, Clone)] +pub struct StdRuntimeConfig { + pub listen_addr: SocketAddr, + pub connect_timeout: Duration, + pub pending_timeout: Duration, + pub cleanup_interval: Duration, +} + +impl Default for StdRuntimeConfig { + fn default() -> Self { + Self { + listen_addr: SocketAddr::from(([127, 0, 0, 1], 10000)), + connect_timeout: Duration::from_secs(5), + pending_timeout: Duration::from_secs(10), + cleanup_interval: Duration::from_millis(250), + } + } +} + +impl StdRuntimeConfig { + pub(super) fn validate(&self) -> io::Result<()> { + if self.connect_timeout.is_zero() + || self.pending_timeout.is_zero() + || self.cleanup_interval.is_zero() + { + return Err(io::Error::new( + io::ErrorKind::InvalidInput, + "timeouts and cleanup_interval must be non-zero", + )); + } + + Ok(()) + } +} \ No newline at end of file diff --git a/crates/proxyjail-runtime/src/std_runtime/connection.rs b/crates/proxyjail-runtime/src/std_runtime/connection.rs new file mode 100644 index 0000000..e227a42 --- /dev/null +++ b/crates/proxyjail-runtime/src/std_runtime/connection.rs @@ -0,0 +1,51 @@ +use std::{ + io, + net::TcpStream, + thread, + time::Duration, +}; + +use proxyjail_core::MatchedConnection; + +use super::relay; + +pub(super) fn dispatch( + matched: MatchedConnection, + connect_timeout: Duration, +) -> io::Result<()> { + let peer_addr = matched.peer_addr; + let destination = matched.event.original_destination; + let pid_tgid = matched.event.pid_tgid; + + thread::Builder::new() + .name(format!("proxyjail-connection-{peer_addr}")) + .spawn(move || { + println!( + "Matched client {peer_addr} (pid/tgid={pid_tgid}); connecting to {destination}" + ); + + match TcpStream::connect_timeout( + &destination, + connect_timeout, + ) { + Ok(upstream) => { + if let Err(err) = relay::relay( + matched.stream, + upstream, + ) { + eprintln!( + "Relay failed for {peer_addr} -> {destination}: {err}" + ); + } + } + + Err(err) => { + eprintln!( + "Upstream connection to {destination} failed: {err}" + ); + } + } + })?; + + Ok(()) +} \ No newline at end of file diff --git a/crates/proxyjail-runtime/src/std_runtime/coordinator.rs b/crates/proxyjail-runtime/src/std_runtime/coordinator.rs new file mode 100644 index 0000000..d525de2 --- /dev/null +++ b/crates/proxyjail-runtime/src/std_runtime/coordinator.rs @@ -0,0 +1,108 @@ +use std::{ + io, + net::TcpStream, + sync::mpsc::{Receiver, RecvTimeoutError}, + time::Instant, +}; + +use proxyjail_core::{ + CorrelationOutcome, + Correlator, + PendingSide, +}; + +use super::{ + config::StdRuntimeConfig, + connection, + message::RuntimeMessage, +}; + +pub(super) fn run( + config: &StdRuntimeConfig, + rx: Receiver, +) -> io::Result<()> { + let mut correlator: Correlator = Correlator::default(); + + loop { + match rx.recv_timeout(config.cleanup_interval) { + Ok(RuntimeMessage::EbpfEvent(event)) => { + let outcome = correlator.on_event(event); + handle_outcome(outcome, config)?; + } + + Ok(RuntimeMessage::AcceptedConnection { + stream, + peer_addr, + }) => { + let outcome = correlator.on_connection(stream, peer_addr); + handle_outcome(outcome, config)?; + } + + Ok(RuntimeMessage::ListenerFailed(message)) => { + return Err(io::Error::new( + io::ErrorKind::Other, + message, + )); + } + + Err(RecvTimeoutError::Timeout) => {} + + Err(RecvTimeoutError::Disconnected) => { + return Ok(()); + } + } + + // Expire unmatched observations. + let expired = correlator.expire( + Instant::now(), + config.pending_timeout, + ); + + for key in expired.events { + eprintln!( + "Timed out waiting for TCP connection matching eBPF event: {key}" + ); + } + + for key in expired.connections { + eprintln!( + "Timed out waiting for eBPF event matching TCP connection: {key}" + ); + } + } +} + +fn handle_outcome( + outcome: CorrelationOutcome, + config: &StdRuntimeConfig, +) -> io::Result<()> { + match outcome { + CorrelationOutcome::Pending { key, side } => { + match side { + PendingSide::EbpfEvent => { + println!( + "Waiting for TCP connection matching {key}" + ); + } + + PendingSide::TcpConnection => { + println!( + "Waiting for eBPF event matching {key}" + ); + } + } + } + + CorrelationOutcome::Duplicate { key, side } => { + eprintln!( + "Duplicate pending {side:?} for {key}; dropping duplicate" + ); + } + + CorrelationOutcome::Matched(matched) => { + connection::dispatch(matched, config.connect_timeout)?; + } + } + + Ok(()) +} \ No newline at end of file diff --git a/crates/proxyjail-runtime/src/std_runtime/event_forwarder.rs b/crates/proxyjail-runtime/src/std_runtime/event_forwarder.rs new file mode 100644 index 0000000..8e19db8 --- /dev/null +++ b/crates/proxyjail-runtime/src/std_runtime/event_forwarder.rs @@ -0,0 +1,34 @@ +use std::{ + sync::{ + atomic::{AtomicBool, Ordering}, + mpsc::{Receiver, RecvTimeoutError, Sender}, + Arc, + }, + time::Duration, +}; + +use proxyjail_core::EbpfEvent; + +use super::message::RuntimeMessage; + +const EVENT_RECV_INTERVAL: Duration = Duration::from_millis(100); + +pub(super) fn forward_events( + event_rx: Receiver, + tx: Sender, + stopping: Arc, +) { + while !stopping.load(Ordering::Acquire) { + match event_rx.recv_timeout(EVENT_RECV_INTERVAL) { + Ok(event) => { + if tx.send(RuntimeMessage::EbpfEvent(event)).is_err() { + break; + } + } + + Err(RecvTimeoutError::Timeout) => {} + + Err(RecvTimeoutError::Disconnected) => break, + } + } +} \ No newline at end of file diff --git a/crates/proxyjail-runtime/src/std_runtime/listener.rs b/crates/proxyjail-runtime/src/std_runtime/listener.rs new file mode 100644 index 0000000..8dd45c3 --- /dev/null +++ b/crates/proxyjail-runtime/src/std_runtime/listener.rs @@ -0,0 +1,48 @@ +use std::{ + io, + net::TcpListener, + sync::{ + atomic::{AtomicBool, Ordering}, + mpsc::Sender, + Arc, + }, + thread, + time::Duration, +}; + +use super::message::RuntimeMessage; + +const ACCEPT_RETRY_DELAY: Duration = Duration::from_millis(10); + +pub(super) fn accept_loop( + listener: TcpListener, + tx: Sender, + stopping: Arc, +) { + while !stopping.load(Ordering::Acquire) { + match listener.accept() { + Ok((stream, peer_addr)) => { + if tx + .send(RuntimeMessage::AcceptedConnection { + stream, + peer_addr, + }) + .is_err() + { + break; + } + } + + Err(err) if err.kind() == io::ErrorKind::WouldBlock => { + thread::sleep(ACCEPT_RETRY_DELAY); + } + + Err(err) => { + let _ = tx.send(RuntimeMessage::ListenerFailed( + err.to_string(), + )); + break; + } + } + } +} \ No newline at end of file diff --git a/crates/proxyjail-runtime/src/std_runtime/message.rs b/crates/proxyjail-runtime/src/std_runtime/message.rs new file mode 100644 index 0000000..0a96ee0 --- /dev/null +++ b/crates/proxyjail-runtime/src/std_runtime/message.rs @@ -0,0 +1,16 @@ +use std::{ + net::{SocketAddr, TcpStream}, +}; + +use proxyjail_core::EbpfEvent; + +pub(super) enum RuntimeMessage { + EbpfEvent(EbpfEvent), + + AcceptedConnection { + stream: TcpStream, + peer_addr: SocketAddr, + }, + + ListenerFailed(String), +} \ No newline at end of file diff --git a/crates/proxyjail-runtime/src/std_runtime/mod.rs b/crates/proxyjail-runtime/src/std_runtime/mod.rs new file mode 100644 index 0000000..e14e4e6 --- /dev/null +++ b/crates/proxyjail-runtime/src/std_runtime/mod.rs @@ -0,0 +1,95 @@ +mod config; +mod connection; +mod coordinator; +mod event_forwarder; +mod listener; +mod message; +mod relay; + +pub use config::StdRuntimeConfig; + +use std::{ + io, + net::TcpListener, + sync::{ + atomic::{AtomicBool, Ordering}, + mpsc::{self, Receiver}, + Arc, + }, + thread, +}; + +use proxyjail_core::EbpfEvent; + +pub fn run( + config: StdRuntimeConfig, + event_rx: Receiver, +) -> io::Result<()> { + config.validate()?; + + let listener = TcpListener::bind(config.listen_addr)?; + listener.set_nonblocking(true)?; + + println!("Proxy listener ready on {}", config.listen_addr); + + let (message_tx, message_rx) = mpsc::channel(); + let stopping = Arc::new(AtomicBool::new(false)); + + // Start TCP listener thread. + let accept_thread = { + let tx = message_tx.clone(); + let worker_stopping = Arc::clone(&stopping); + + thread::Builder::new() + .name("proxy-accept".into()) + .spawn(move || { + listener::accept_loop(listener, tx, worker_stopping); + })? + }; + + // Forward eBPF events to the coordinator. + let event_thread = { + let tx = message_tx.clone(); + let worker_stopping = Arc::clone(&stopping); + + match thread::Builder::new() + .name("proxy-event-forwarder".into()) + .spawn(move || { + event_forwarder::forward_events( + event_rx, + tx, + worker_stopping, + ); + }) + { + Ok(handle) => handle, + + Err(err) => { + stopping.store(true, Ordering::Release); + let _ = accept_thread.join(); + + return Err(err); + } + } + }; + + drop(message_tx); + + // Run coordinator on the current thread. + let result = coordinator::run(&config, message_rx); + + // Stop background workers. + stopping.store(true, Ordering::Release); + + let accept_join = accept_thread.join(); + let event_join = event_thread.join(); + + if accept_join.is_err() || event_join.is_err() { + return Err(io::Error::new( + io::ErrorKind::Other, + "a proxy runtime worker thread panicked", + )); + } + + result +} \ No newline at end of file diff --git a/crates/proxyjail-runtime/src/std_runtime/relay.rs b/crates/proxyjail-runtime/src/std_runtime/relay.rs new file mode 100644 index 0000000..fa036f1 --- /dev/null +++ b/crates/proxyjail-runtime/src/std_runtime/relay.rs @@ -0,0 +1,72 @@ +use std::{ + io::{self, copy}, + net::{Shutdown, TcpStream}, + thread, +}; + +pub(super) fn relay( + client: TcpStream, + upstream: TcpStream, +) -> io::Result<()> { + client.set_nodelay(true)?; + upstream.set_nodelay(true)?; + + let mut client_reader = client.try_clone()?; + let mut upstream_writer = upstream.try_clone()?; + + let mut client_writer = client; + let mut upstream_reader = upstream; + + // Client -> Upstream + let upload_thread = thread::Builder::new() + .name("proxyjail-client-to-upstream".into()) + .spawn(move || { + match copy( + &mut client_reader, + &mut upstream_writer, + ) { + Ok(bytes_copied) => { + upstream_writer.shutdown(Shutdown::Write)?; + Ok(bytes_copied) + } + + Err(err) => { + let _ = client_reader.shutdown(Shutdown::Both); + let _ = upstream_writer.shutdown(Shutdown::Both); + + Err(err) + } + } + })?; + + // Upstream -> Client + let download_result = copy( + &mut upstream_reader, + &mut client_writer, + ); + + match &download_result { + Ok(_) => { + let _ = client_writer.shutdown(Shutdown::Write); + } + + Err(_) => { + let _ = client_writer.shutdown(Shutdown::Both); + let _ = upstream_reader.shutdown(Shutdown::Both); + } + } + + let upload_result = upload_thread + .join() + .map_err(|_| { + io::Error::new( + io::ErrorKind::Other, + "upload relay thread panicked", + ) + })?; + + download_result?; + upload_result?; + + Ok(()) +} \ No newline at end of file diff --git a/docs/arch.excalidraw b/docs/arch.excalidraw new file mode 100644 index 0000000..b5f61f9 --- /dev/null +++ b/docs/arch.excalidraw @@ -0,0 +1,1560 @@ +{ + "type": "excalidraw", + "version": 2, + "source": "https://excalidraw.com", + "elements": [ + { + "id": "HMcX_Ukzj2KWGJQUNnpU6", + "type": "rectangle", + "x": 1806.287051798387, + "y": 1137.8869810407828, + "width": 129, + "height": 114, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#b2f2bb", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a0", + "roundness": { + "type": 3 + }, + "seed": 1658161794, + "version": 58, + "versionNonce": 704198914, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "_FvKW3BlAJkQ2n4Iwfd02" + } + ], + "updated": 1793965537376, + "created": 1793964621174, + "link": null, + "locked": false + }, + { + "id": "_FvKW3BlAJkQ2n4Iwfd02", + "type": "text", + "x": 1841.3703857675032, + "y": 1184.8869810407828, + "width": 58.83333206176758, + "height": 20, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a1", + "roundness": null, + "seed": 1766741598, + "version": 39, + "versionNonce": 655557918, + "isDeleted": false, + "boundElements": [], + "updated": 1793965481775, + "created": 1793964622841, + "link": null, + "locked": false, + "text": "process", + "fontSize": 16, + "baseFontSize": null, + "fontFamily": 5, + "textAlign": "center", + "verticalAlign": "middle", + "containerId": "HMcX_Ukzj2KWGJQUNnpU6", + "originalText": "process", + "autoResize": true, + "lineHeight": 1.25, + "labelPosition": null + }, + { + "id": "gpm55JqsfzT8LAxwQV8SV", + "type": "rectangle", + "x": 1814.287051798387, + "y": 693.8869810407828, + "width": 129, + "height": 114, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#b2f2bb", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a11", + "roundness": { + "type": 3 + }, + "seed": 610910978, + "version": 122, + "versionNonce": 704816642, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "SdgeX6Ic45YmtecoaRF2q" + } + ], + "updated": 1793965675779, + "created": 1793965672262, + "link": null, + "locked": false + }, + { + "id": "SdgeX6Ic45YmtecoaRF2q", + "type": "text", + "x": 1849.3703857675032, + "y": 740.8869810407828, + "width": 58.83333206176758, + "height": 20, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a12", + "roundness": null, + "seed": 771625666, + "version": 103, + "versionNonce": 1954715074, + "isDeleted": false, + "boundElements": [], + "updated": 1793965675779, + "created": 1793965672262, + "link": null, + "locked": false, + "text": "process", + "fontSize": 16, + "baseFontSize": null, + "fontFamily": 5, + "textAlign": "center", + "verticalAlign": "middle", + "containerId": "gpm55JqsfzT8LAxwQV8SV", + "originalText": "process", + "autoResize": true, + "lineHeight": 1.25, + "labelPosition": null + }, + { + "id": "f2Pdgt2AJvBoZKFtjqQTQ", + "type": "rectangle", + "x": 1816.287051798387, + "y": 1147.8869810407828, + "width": 129, + "height": 114, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#b2f2bb", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a14", + "roundness": { + "type": 3 + }, + "seed": 1469095006, + "version": 60, + "versionNonce": 1002413278, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "POlnbbCrMdwlvUWTg4R9v" + } + ], + "updated": 1793965539343, + "created": 1793965539343, + "link": null, + "locked": false + }, + { + "id": "POlnbbCrMdwlvUWTg4R9v", + "type": "text", + "x": 1851.3703857675032, + "y": 1194.8869810407828, + "width": 58.83333206176758, + "height": 20, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a18", + "roundness": null, + "seed": 1379491998, + "version": 41, + "versionNonce": 389785602, + "isDeleted": false, + "boundElements": [], + "updated": 1793965539343, + "created": 1793965539343, + "link": null, + "locked": false, + "text": "process", + "fontSize": 16, + "baseFontSize": null, + "fontFamily": 5, + "textAlign": "center", + "verticalAlign": "middle", + "containerId": "f2Pdgt2AJvBoZKFtjqQTQ", + "originalText": "process", + "autoResize": true, + "lineHeight": 1.25, + "labelPosition": null + }, + { + "id": "avKDGTBNUYqS7WofIjP7n", + "type": "rectangle", + "x": 1824.287051798387, + "y": 703.8869810407828, + "width": 129, + "height": 114, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#b2f2bb", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a18V", + "roundness": { + "type": 3 + }, + "seed": 1743940226, + "version": 124, + "versionNonce": 284069250, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "co76uYDJN9x1OfkWsrO3B" + } + ], + "updated": 1793965675779, + "created": 1793965672262, + "link": null, + "locked": false + }, + { + "id": "co76uYDJN9x1OfkWsrO3B", + "type": "text", + "x": 1859.3703857675032, + "y": 750.8869810407828, + "width": 58.83333206176758, + "height": 20, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a19", + "roundness": null, + "seed": 1493551682, + "version": 105, + "versionNonce": 1954909506, + "isDeleted": false, + "boundElements": [], + "updated": 1793965675779, + "created": 1793965672262, + "link": null, + "locked": false, + "text": "process", + "fontSize": 16, + "baseFontSize": null, + "fontFamily": 5, + "textAlign": "center", + "verticalAlign": "middle", + "containerId": "avKDGTBNUYqS7WofIjP7n", + "originalText": "process", + "autoResize": true, + "lineHeight": 1.25, + "labelPosition": null + }, + { + "id": "5pyEznqCrM7uhWmyNKJfC", + "type": "rectangle", + "x": 1826.287051798387, + "y": 1157.8869810407828, + "width": 129, + "height": 114, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#b2f2bb", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a1A", + "roundness": { + "type": 3 + }, + "seed": 558829442, + "version": 63, + "versionNonce": 819060034, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "tLpK2xFukWVkPuFnY62Lp" + }, + { + "id": "u0BQydpDg_1TyrrRH6LoL", + "type": "arrow" + } + ], + "updated": 1793965562377, + "created": 1793965539993, + "link": null, + "locked": false + }, + { + "id": "tLpK2xFukWVkPuFnY62Lp", + "type": "text", + "x": 1861.3703857675032, + "y": 1204.8869810407828, + "width": 58.83333206176758, + "height": 20, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a1C", + "roundness": null, + "seed": 1770377026, + "version": 43, + "versionNonce": 1590415902, + "isDeleted": false, + "boundElements": [], + "updated": 1793965539993, + "created": 1793965539993, + "link": null, + "locked": false, + "text": "process", + "fontSize": 16, + "baseFontSize": null, + "fontFamily": 5, + "textAlign": "center", + "verticalAlign": "middle", + "containerId": "5pyEznqCrM7uhWmyNKJfC", + "originalText": "process", + "autoResize": true, + "lineHeight": 1.25, + "labelPosition": null + }, + { + "id": "vIy5wwXVQ-dhLrzTuTvwc", + "type": "rectangle", + "x": 1834.287051798387, + "y": 713.8869810407828, + "width": 129, + "height": 114, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#b2f2bb", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a1CG", + "roundness": { + "type": 3 + }, + "seed": 1477915138, + "version": 127, + "versionNonce": 346461442, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "tFkvrIXjbCBUFzTHzzZvf" + }, + { + "id": "kAONHyyuP3W5SybMayecg", + "type": "arrow" + } + ], + "updated": 1793965675779, + "created": 1793965672262, + "link": null, + "locked": false + }, + { + "id": "tFkvrIXjbCBUFzTHzzZvf", + "type": "text", + "x": 1869.3703857675032, + "y": 760.8869810407828, + "width": 58.83333206176758, + "height": 20, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a1CV", + "roundness": null, + "seed": 136683970, + "version": 107, + "versionNonce": 1657840834, + "isDeleted": false, + "boundElements": [], + "updated": 1793965675779, + "created": 1793965672262, + "link": null, + "locked": false, + "text": "process", + "fontSize": 16, + "baseFontSize": null, + "fontFamily": 5, + "textAlign": "center", + "verticalAlign": "middle", + "containerId": "vIy5wwXVQ-dhLrzTuTvwc", + "originalText": "process", + "autoResize": true, + "lineHeight": 1.25, + "labelPosition": null + }, + { + "id": "hJGCEMEVcf0jxAlYxXaVg", + "type": "rectangle", + "x": 2367.287051798387, + "y": 1173.8869810407828, + "width": 138, + "height": 88, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#b2f2bb", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a1D", + "roundness": { + "type": 3 + }, + "seed": 1758614850, + "version": 177, + "versionNonce": 1272563532, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "fBsoDO20SfAbAr6JvXGzi" + } + ], + "updated": 1794173653738, + "created": 1793965571927, + "link": null, + "locked": false + }, + { + "id": "fBsoDO20SfAbAr6JvXGzi", + "type": "text", + "x": 2376.070384623094, + "y": 1187.8869810407828, + "width": 120.43333435058594, + "height": 60, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a1E", + "roundness": null, + "seed": 1947884802, + "version": 222, + "versionNonce": 1554997620, + "isDeleted": false, + "boundElements": [], + "updated": 1794173664188, + "created": 1793965571927, + "link": null, + "locked": false, + "text": "ProxyJail local\nsocket\n127.0.0.1:10000", + "fontSize": 16, + "baseFontSize": null, + "fontFamily": 5, + "textAlign": "center", + "verticalAlign": "middle", + "containerId": "hJGCEMEVcf0jxAlYxXaVg", + "originalText": "ProxyJail local socket\n127.0.0.1:10000", + "autoResize": true, + "lineHeight": 1.25, + "labelPosition": null + }, + { + "id": "PeWWAdRxmxmnwD4d2Di85", + "type": "rectangle", + "x": 2807.287051798387, + "y": 1164.8869810407828, + "width": 172, + "height": 114, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#b2f2bb", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a1E8", + "roundness": { + "type": 3 + }, + "seed": 1121041246, + "version": 413, + "versionNonce": 696029342, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "XcxhUc7NSOZ1uyMifIh8E" + }, + { + "id": "ycidrxup_yRmuyxqton5t", + "type": "arrow" + }, + { + "id": "LsZlW8-Vnaa2GerAyVvpK", + "type": "arrow" + } + ], + "updated": 1793968087660, + "created": 1793967630301, + "link": null, + "locked": false + }, + { + "id": "XcxhUc7NSOZ1uyMifIh8E", + "type": "text", + "x": 2839.445384623094, + "y": 1201.8869810407828, + "width": 107.68333435058594, + "height": 40, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a1EG", + "roundness": null, + "seed": 369008542, + "version": 498, + "versionNonce": 2113169410, + "isDeleted": false, + "boundElements": [], + "updated": 1793968104427, + "created": 1793967630301, + "link": null, + "locked": false, + "text": "Proxy Server\n(http,Socks5)", + "fontSize": 16, + "baseFontSize": null, + "fontFamily": 5, + "textAlign": "center", + "verticalAlign": "middle", + "containerId": "PeWWAdRxmxmnwD4d2Di85", + "originalText": "Proxy Server\n(http,Socks5)", + "autoResize": true, + "lineHeight": 1.25, + "labelPosition": null + }, + { + "id": "S5KGUeysC5eTlVjI58f7Y", + "type": "rectangle", + "x": 2384.287051798387, + "y": 710.8869810407828, + "width": 174, + "height": 114, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#b2f2bb", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a1EV", + "roundness": { + "type": 3 + }, + "seed": 1414535554, + "version": 182, + "versionNonce": 1811595714, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "LLLaocvBtnJPIPrSShrq1" + } + ], + "updated": 1793967604184, + "created": 1793965672262, + "link": null, + "locked": false + }, + { + "id": "LLLaocvBtnJPIPrSShrq1", + "type": "text", + "x": 2418.62871897368, + "y": 757.8869810407828, + "width": 105.31666564941406, + "height": 20, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a1F", + "roundness": null, + "seed": 1809160514, + "version": 209, + "versionNonce": 79406658, + "isDeleted": false, + "boundElements": [], + "updated": 1793968013109, + "created": 1793965672262, + "link": null, + "locked": false, + "text": "Dest IP:Port", + "fontSize": 16, + "baseFontSize": null, + "fontFamily": 5, + "textAlign": "center", + "verticalAlign": "middle", + "containerId": "S5KGUeysC5eTlVjI58f7Y", + "originalText": "Dest IP:Port", + "autoResize": true, + "lineHeight": 1.25, + "labelPosition": null + }, + { + "id": "bvj5D-R6RY5Q7iaAi_hs1", + "type": "rectangle", + "x": 3066.287051798387, + "y": 1166.8869810407828, + "width": 174, + "height": 114, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#b2f2bb", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a1FG", + "roundness": { + "type": 3 + }, + "seed": 1574460574, + "version": 279, + "versionNonce": 159774658, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "QDp_5lbVcl9UvCBoLs4eT" + }, + { + "id": "LsZlW8-Vnaa2GerAyVvpK", + "type": "arrow" + } + ], + "updated": 1793968133628, + "created": 1793968078043, + "link": null, + "locked": false + }, + { + "id": "QDp_5lbVcl9UvCBoLs4eT", + "type": "text", + "x": 3100.62871897368, + "y": 1213.8869810407828, + "width": 105.31666564941406, + "height": 20, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a1FV", + "roundness": null, + "seed": 1914640606, + "version": 305, + "versionNonce": 859156354, + "isDeleted": false, + "boundElements": [], + "updated": 1793968133628, + "created": 1793968078043, + "link": null, + "locked": false, + "text": "Dest IP:Port", + "fontSize": 16, + "baseFontSize": null, + "fontFamily": 5, + "textAlign": "center", + "verticalAlign": "middle", + "containerId": "bvj5D-R6RY5Q7iaAi_hs1", + "originalText": "Dest IP:Port", + "autoResize": true, + "lineHeight": 1.25, + "labelPosition": null + }, + { + "id": "zUgYstd5wvilbCE1xwmKf", + "type": "rectangle", + "x": 1699.287051798387, + "y": 1051.8869810407828, + "width": 484, + "height": 322.9999999999999, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a2", + "roundness": { + "type": 3 + }, + "seed": 649691202, + "version": 132, + "versionNonce": 34785602, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "ZL8sPEObMYjOb9pauchbF" + } + ], + "updated": 1793965648145, + "created": 1793965452574, + "link": null, + "locked": false + }, + { + "id": "ZL8sPEObMYjOb9pauchbF", + "type": "text", + "x": 1704.287051798387, + "y": 1056.8869810407828, + "width": 118.13333129882812, + "height": 45, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#b2f2bb", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a2V", + "roundness": null, + "seed": 1613034718, + "version": 35, + "versionNonce": 1965838594, + "isDeleted": false, + "boundElements": [], + "updated": 1793965648145, + "created": 1793965627944, + "link": null, + "locked": false, + "text": "Cgroup", + "fontSize": 36, + "baseFontSize": null, + "fontFamily": 5, + "textAlign": "left", + "verticalAlign": "top", + "containerId": "zUgYstd5wvilbCE1xwmKf", + "originalText": "Cgroup", + "autoResize": true, + "lineHeight": 1.25, + "labelPosition": null + }, + { + "id": "1abxIPlzoCdvhBr4FoYA6", + "type": "rectangle", + "x": 1707.287051798387, + "y": 607.8869810407828, + "width": 484, + "height": 322.9999999999999, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a2d", + "roundness": { + "type": 3 + }, + "seed": 1041572098, + "version": 196, + "versionNonce": 1113261058, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "IGDVB1c858Yj_FT1n0wil" + } + ], + "updated": 1793965675779, + "created": 1793965672262, + "link": null, + "locked": false + }, + { + "id": "IGDVB1c858Yj_FT1n0wil", + "type": "text", + "x": 1712.287051798387, + "y": 612.8869810407828, + "width": 118.13333129882812, + "height": 45, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#b2f2bb", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a2l", + "roundness": null, + "seed": 1988997314, + "version": 99, + "versionNonce": 1579103170, + "isDeleted": false, + "boundElements": [], + "updated": 1793965675779, + "created": 1793965672262, + "link": null, + "locked": false, + "text": "Cgroup", + "fontSize": 36, + "baseFontSize": null, + "fontFamily": 5, + "textAlign": "left", + "verticalAlign": "top", + "containerId": "1abxIPlzoCdvhBr4FoYA6", + "originalText": "Cgroup", + "autoResize": true, + "lineHeight": 1.25, + "labelPosition": null + }, + { + "id": "27snqBFziqv-RWuef1iAp", + "type": "text", + "x": 2274.287051798387, + "y": 1351.3869810407828, + "width": 451.3500061035156, + "height": 128.00000000000006, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a3", + "roundness": null, + "seed": 1002431070, + "version": 473, + "versionNonce": 291451892, + "isDeleted": false, + "boundElements": [], + "updated": 1794173705339, + "created": 1793965454741, + "link": null, + "locked": false, + "text": "ProxyJail", + "fontSize": 102.40000000000003, + "baseFontSize": null, + "fontFamily": 5, + "textAlign": "left", + "verticalAlign": "top", + "containerId": null, + "originalText": "ProxyJail", + "autoResize": true, + "lineHeight": 1.25, + "labelPosition": null + }, + { + "id": "ULK9wIxI8FPUXYlKGMIWR", + "type": "diamond", + "x": 1970.287051798387, + "y": 952.8869810407828, + "width": 253, + "height": 220, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#ffec99", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a5", + "roundness": { + "type": 2 + }, + "seed": 1159125918, + "version": 196, + "versionNonce": 208800798, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "w3oqi9FQX6OkzZlEqeyUC" + }, + { + "id": "71XQB6Po7o51oJjsB-gJO", + "type": "arrow" + } + ], + "updated": 1793967923624, + "created": 1793965501959, + "link": null, + "locked": false + }, + { + "id": "w3oqi9FQX6OkzZlEqeyUC", + "type": "text", + "x": 2051.9537197366194, + "y": 1012.8869810407828, + "width": 90.16666412353516, + "height": 100, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "transparent", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a5V", + "roundness": null, + "seed": 597793346, + "version": 250, + "versionNonce": 1190216652, + "isDeleted": false, + "boundElements": [], + "updated": 1794173646721, + "created": 1793965508492, + "link": null, + "locked": false, + "text": "eBPF\nAttached:\nRedirect All\nSockets to\nProxyJail", + "fontSize": 16, + "baseFontSize": null, + "fontFamily": 5, + "textAlign": "center", + "verticalAlign": "middle", + "containerId": "ULK9wIxI8FPUXYlKGMIWR", + "originalText": "eBPF Attached:\nRedirect All Sockets to ProxyJail", + "autoResize": true, + "lineHeight": 1.25, + "labelPosition": null + }, + { + "id": "u0BQydpDg_1TyrrRH6LoL", + "type": "arrow", + "x": 1961.2870517983868, + "y": 1214.9423310407828, + "width": 402.0000000000002, + "height": 2.9446499999999105, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#b2f2bb", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a8", + "roundness": null, + "seed": 1743582722, + "version": 32, + "versionNonce": 2000717378, + "isDeleted": false, + "boundElements": [], + "updated": 1793965563993, + "created": 1793965562377, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 402.0000000000002, + 2.9446499999999105 + ] + ], + "startBinding": { + "elementId": "5pyEznqCrM7uhWmyNKJfC", + "mode": "orbit", + "fixedPoint": [ + 1, + 0.5001 + ] + }, + "endBinding": null, + "startArrowhead": null, + "endArrowhead": "arrow", + "elbowed": false + }, + { + "id": "kAONHyyuP3W5SybMayecg", + "type": "arrow", + "x": 1969.2870517983868, + "y": 770.9423310407828, + "width": 402.0000000000002, + "height": 2.9446499999999105, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#b2f2bb", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "a9", + "roundness": null, + "seed": 1780715522, + "version": 96, + "versionNonce": 1725952770, + "isDeleted": false, + "boundElements": [], + "updated": 1793965675779, + "created": 1793965672262, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 402.0000000000002, + 2.9446499999999105 + ] + ], + "startBinding": { + "elementId": "vIy5wwXVQ-dhLrzTuTvwc", + "mode": "orbit", + "fixedPoint": [ + 1, + 0.5001 + ] + }, + "endBinding": null, + "startArrowhead": null, + "endArrowhead": "arrow", + "elbowed": false + }, + { + "id": "GJ0L-9sINIyZFQ08EtCPd", + "type": "ellipse", + "x": 2496.068301798387, + "y": 1114.5588560407828, + "width": 244.99999999999997, + "height": 205, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#ffec99", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "aA", + "roundness": { + "type": 2 + }, + "seed": 1609352414, + "version": 155, + "versionNonce": 1885253708, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "RVnqm6JVFhbNzacW7tCZn" + }, + { + "id": "ycidrxup_yRmuyxqton5t", + "type": "arrow" + }, + { + "id": "71XQB6Po7o51oJjsB-gJO", + "type": "arrow" + } + ], + "updated": 1794173682489, + "created": 1793967820672, + "link": null, + "locked": false + }, + { + "id": "RVnqm6JVFhbNzacW7tCZn", + "type": "text", + "x": 2538.789388278328, + "y": 1172.0804109691617, + "width": 159.31666564941406, + "height": 90, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#ffec99", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "aB", + "roundness": null, + "seed": 123259998, + "version": 156, + "versionNonce": 205178572, + "isDeleted": false, + "boundElements": [], + "updated": 1794173682489, + "created": 1793967823272, + "link": null, + "locked": false, + "text": "ProxyJail\nProcess", + "fontSize": 36, + "baseFontSize": null, + "fontFamily": 5, + "textAlign": "center", + "verticalAlign": "middle", + "containerId": "GJ0L-9sINIyZFQ08EtCPd", + "originalText": "ProxyJail Process", + "autoResize": true, + "lineHeight": 1.25, + "labelPosition": null + }, + { + "id": "ycidrxup_yRmuyxqton5t", + "type": "arrow", + "x": 2739.4593796969375, + "y": 1212.7138762954123, + "width": 61.827672101449934, + "height": 8.37204831328495, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#ffec99", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "aC", + "roundness": null, + "seed": 1289588098, + "version": 137, + "versionNonce": 827329868, + "isDeleted": false, + "boundElements": [], + "updated": 1794173682489, + "created": 1793967842239, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 61.827672101449934, + 8.37204831328495 + ] + ], + "startBinding": { + "elementId": "GJ0L-9sINIyZFQ08EtCPd", + "mode": "inside", + "fixedPoint": [ + 0.9934329710144928, + 0.47880497685185186 + ] + }, + "endBinding": { + "elementId": "PeWWAdRxmxmnwD4d2Di85", + "mode": "orbit", + "fixedPoint": [ + 0, + 0.5001 + ] + }, + "startArrowhead": null, + "endArrowhead": "arrow", + "elbowed": false + }, + { + "id": "71XQB6Po7o51oJjsB-gJO", + "type": "arrow", + "x": 2163.899624255583, + "y": 1003.5710066507326, + "width": 394.9320112254709, + "height": 117.42461972411081, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#ffec99", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "aD", + "roundness": { + "type": 2 + }, + "seed": 24907934, + "version": 195, + "versionNonce": 1090028492, + "isDeleted": false, + "boundElements": [ + { + "type": "text", + "id": "Nb2FA83aN0tmgtKjkfjBI" + } + ], + "updated": 1794173682489, + "created": 1793967916507, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 248.16867754280383, + 34.9253493900502 + ], + [ + 394.9320112254709, + 117.42461972411081 + ] + ], + "startBinding": { + "elementId": "ULK9wIxI8FPUXYlKGMIWR", + "mode": "orbit", + "fixedPoint": [ + 0.5001, + 0.18746672405007933 + ] + }, + "endBinding": { + "elementId": "GJ0L-9sINIyZFQ08EtCPd", + "mode": "orbit", + "fixedPoint": [ + 0.25637081053629085, + 0.03152916889898818 + ] + }, + "startArrowhead": null, + "endArrowhead": "arrow", + "elbowed": false + }, + { + "id": "Nb2FA83aN0tmgtKjkfjBI", + "type": "text", + "x": 2247.941579980512, + "y": 1008.3803805793132, + "width": 240.75, + "height": 40, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#ffec99", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "aE", + "roundness": null, + "seed": 1920701762, + "version": 71, + "versionNonce": 2121665950, + "isDeleted": false, + "boundElements": [], + "updated": 1793967975191, + "created": 1793967944874, + "link": null, + "locked": false, + "text": "Report Dst IP:Port to Parent\nProcess", + "fontSize": 16, + "baseFontSize": null, + "fontFamily": 5, + "textAlign": "center", + "verticalAlign": "middle", + "containerId": "71XQB6Po7o51oJjsB-gJO", + "originalText": "Report Dst IP:Port to Parent Process", + "autoResize": true, + "lineHeight": 1.25, + "labelPosition": 0.5 + }, + { + "id": "LsZlW8-Vnaa2GerAyVvpK", + "type": "arrow", + "x": 2985.2870517983874, + "y": 1222.0363120752654, + "width": 75, + "height": 1.7241379310346474, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#ffec99", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "aF", + "roundness": { + "type": 2 + }, + "seed": 560507870, + "version": 79, + "versionNonce": 1167617858, + "isDeleted": false, + "boundElements": [], + "updated": 1793968133628, + "created": 1793968087660, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 75, + 1.7241379310346474 + ] + ], + "startBinding": { + "elementId": "PeWWAdRxmxmnwD4d2Di85", + "mode": "orbit", + "fixedPoint": [ + 1, + 0.5001 + ] + }, + "endBinding": { + "elementId": "bvj5D-R6RY5Q7iaAi_hs1", + "mode": "orbit", + "fixedPoint": [ + 0, + 0.5001 + ] + }, + "startArrowhead": null, + "endArrowhead": "arrow", + "elbowed": false + }, + { + "id": "K0RvfdXCV_etgVHzzxwzc", + "type": "text", + "x": 2215.818301798387, + "y": 1188.2463560407828, + "width": 79.26667022705078, + "height": 20, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#ffec99", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "aG", + "roundness": null, + "seed": 943702402, + "version": 47, + "versionNonce": 586872194, + "isDeleted": false, + "boundElements": [], + "updated": 1793968320548, + "created": 1793968314665, + "link": null, + "locked": false, + "text": "TCP/UDP", + "fontSize": 16, + "baseFontSize": null, + "fontFamily": 5, + "textAlign": "left", + "verticalAlign": "top", + "containerId": null, + "originalText": "TCP/UDP", + "autoResize": true, + "lineHeight": 1.25, + "labelPosition": null + }, + { + "id": "T_MrgOcm4vHO-Sj4WCwse", + "type": "text", + "x": 2214.818301798387, + "y": 742.2463560407828, + "width": 79.26667022705078, + "height": 20, + "angle": 0, + "strokeColor": "#1971c2", + "backgroundColor": "#ffec99", + "fillStyle": "solid", + "strokeWidth": 2, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "index": "aH", + "roundness": null, + "seed": 628070494, + "version": 103, + "versionNonce": 1873013406, + "isDeleted": false, + "boundElements": [], + "updated": 1793968346466, + "created": 1793968340632, + "link": null, + "locked": false, + "text": "TCP/UDP", + "fontSize": 16, + "baseFontSize": null, + "fontFamily": 5, + "textAlign": "left", + "verticalAlign": "top", + "containerId": null, + "originalText": "TCP/UDP", + "autoResize": true, + "lineHeight": 1.25, + "labelPosition": null + } + ], + "appState": { + "gridSize": 20, + "gridStep": 5, + "gridModeEnabled": false, + "viewBackgroundColor": "#ffffff", + "lockedMultiSelections": {} + }, + "files": {} +} \ No newline at end of file diff --git a/docs/arch.svg b/docs/arch.svg new file mode 100644 index 0000000..440651b --- /dev/null +++ b/docs/arch.svg @@ -0,0 +1,4 @@ + + +processprocessprocessprocessprocessprocessProxyJail localsocket127.0.0.1:10000Proxy Server(http,Socks5)Dest IP:PortDest IP:PortCgroupCgroupProxyJaileBPFAttached:Redirect AllSockets toProxyJailProxyJailProcessReport Dst IP:Port to ParentProcessTCP/UDPTCP/UDP \ No newline at end of file diff --git a/docs/decisions.md b/docs/decisions.md new file mode 100644 index 0000000..c904eef --- /dev/null +++ b/docs/decisions.md @@ -0,0 +1,34 @@ +- why not using tokio? cause it's overkill. + +## eBPF event contract + +`proxyjail-core` defines the userspace event: + +```rust +pub struct EbpfEvent { + pub pid_tgid: u64, + pub client: SocketAddr, + pub original_destination: SocketAddr, +} +``` + +The ring-buffer ABI expected by `proxyjail-ebpf` is documented in +`crates/proxyjail-ebpf/bpf/event.h` and `crates/proxyjail-ebpf/bpf/README.md`. It is a +24-byte record: + +- `pid_tgid`: native-endian `u64` at offset 0 +- `client_ip`: network-order IPv4 at offset 8 +- `client_port`: network-order port at offset 12 +- 2 bytes padding +- `original_ip`: network-order IPv4 at offset 16 +- `original_port`: network-order port at offset 20 +- 2 bytes tail padding + +The `client` endpoint **must exactly match** the address returned by +`TcpStream::peer_addr()` on the accepted local TCP connection. The original +16-byte event containing only PID and original destination is not enough for +the matching strategy implemented here. Your BPF program must reliably +populate the client tuple before publishing the event. Do not assume the +source port is available in the initial cgroup `connect4` hook without +verifying the hook's socket state and the exact endpoint seen after any NAT or +redirection. diff --git a/docs/ideas.md b/docs/ideas.md new file mode 100644 index 0000000..6d1b099 --- /dev/null +++ b/docs/ideas.md @@ -0,0 +1,14 @@ +# Experiment phase journal +- let's start with cgroup and ebpf at first +- future cli: + +target: --pid 1234 | --cgroup | --netns | --container + │ + └─ container resolver (Docker/Podman API) → { pid, cgroup, netns } + │ +backend: LD_PRELOAD | eBPF cgroup/connect | nftables (TPROXY/REDIRECT) | TUN + +proxyjail attach --container my-app --chain work +proxyjail attach --netns /run/netns/vpn1 --chain tor +proxyjail run --chain work -- curl https://example.com # plain process, as before +proxyjail daemon --watch-label yourtool.profile # auto-capture labeled containers