Commit f5d471c
committed
fix: Remove dependency on
Fixes #74
## Problem
httpjail failed when running inside Docker containers or minimal
environments that don't include the `iproute2` package (which provides
the `ip` command). This affected users running httpjail in:
- Minimal container images (Alpine, distroless, etc.)
- Container runtimes like sysbox-runc that provide CAP_SYS_ADMIN
but don't include iproute2
- Custom sandbox environments with limited userspace tools
## Solution
Replaced all `ip` command invocations with direct syscalls and netlink
operations using the `rtnetlink` and `nix` crates. The implementation now:
1. **Network namespace management**: Uses `unshare()` + bind-mount instead
of `ip netns add/del`
2. **Veth pair creation**: Uses rtnetlink instead of `ip link add`
3. **Interface configuration**: Uses rtnetlink for IP addresses and link
state instead of `ip addr` and `ip link set`
4. **Namespace execution**: Uses `setns()` + `fork()`/`exec()` instead of
`ip netns exec`
## Changes
### New Module: `src/jail/linux/netlink.rs`
- `create_netns()` / `delete_netns()`: Manage persistent namespaces
- `create_veth_pair()`: Create virtual ethernet pairs
- `move_link_to_netns()`: Move interfaces between namespaces
- `set_link_up()`: Configure link state
- `add_addr()`: Add IP addresses to interfaces
- `add_default_route()`: Add routing entries
- `execute_in_netns()`: Execute commands in namespaces with privilege dropping
- `get_handle_in_netns()`: Get netlink handle in a specific namespace
### Updated Files
- `src/jail/linux/resources.rs`: Use netlink functions for namespace/veth resources
- `src/jail/linux/mod.rs`: Use netlink for all network configuration and command execution
- `Cargo.toml`: Add dependencies: `rtnetlink`, `netlink-packet-route`, `futures`, `nix`
- `docs/guide/platform-support.md`: Document container support and removed `ip` dependency
## Testing
Built and tested successfully on Linux. The implementation:
- Maintains all existing functionality
- Works in environments without `iproute2`
- Still requires `nft` for nftables rules (documented requirement)
- Still requires CAP_SYS_ADMIN and CAP_NET_ADMIN (no change)
## Benefits
1. **Container compatibility**: Works in minimal images and sysbox-runc
2. **Smaller attack surface**: Fewer external dependencies
3. **Better error handling**: Direct syscall errors vs parsing command output
4. **Performance**: No process spawning overhead for network operations
5. **Maintainability**: Pure Rust implementation
## Breaking Changes
None. This is a drop-in replacement that maintains the same external behavior.
## Documentation
Updated platform support documentation to note that `iproute2` is no
longer required and added examples for running inside containers.ip command for container support1 parent 5afe807 commit f5d471c
6 files changed
Lines changed: 702 additions & 237 deletions
File tree
- docs/guide
- src/jail/linux
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
53 | 57 | | |
54 | 58 | | |
55 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
45 | 48 | | |
46 | 49 | | |
47 | 50 | | |
| |||
60 | 63 | | |
61 | 64 | | |
62 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
63 | 99 | | |
64 | 100 | | |
65 | 101 | | |
| |||
80 | 116 | | |
81 | 117 | | |
82 | 118 | | |
83 | | - | |
84 | | - | |
85 | 119 | | |
86 | 120 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
| 121 | + | |
| 122 | + | |
106 | 123 | | |
107 | 124 | | |
108 | 125 | | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
113 | 130 | | |
114 | 131 | | |
115 | 132 | | |
116 | 133 | | |
117 | | - | |
| 134 | + | |
118 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
119 | 140 | | |
120 | 141 | | |
121 | | - | |
| 142 | + | |
122 | 143 | | |
123 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
124 | 147 | | |
125 | | - | |
| 148 | + | |
126 | 149 | | |
127 | | - | |
| 150 | + | |
128 | 151 | | |
129 | | - | |
130 | | - | |
131 | | - | |
| 152 | + | |
132 | 153 | | |
133 | | - | |
| 154 | + | |
134 | 155 | | |
135 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
136 | 159 | | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
0 commit comments