Skip to content

Commit 33ba734

Browse files
authored
Add Linux Local Redirect Mode (#206)
1 parent 3048206 commit 33ba734

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2532
-841
lines changed

.github/actions/setup/action.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: 'setup'
2+
description: 'checkout, setup rust and python'
3+
inputs:
4+
rust-version:
5+
description: 'Rust version'
6+
required: true
7+
default: 'stable'
8+
extra-targets:
9+
description: 'Extra Rust targets'
10+
toolchain-args:
11+
description: 'Extra args for `rustup toolchain`'
12+
runs:
13+
using: "composite"
14+
steps:
15+
- uses: mhils/workflows/setup-python@v12 # PyO3 wants recent Python on Windows.
16+
- run: rustup toolchain install ${{ inputs.rust-version }} --profile minimal ${{ inputs.toolchain-args }}
17+
shell: bash
18+
- run: rustup default ${{ inputs.rust-version }}
19+
shell: bash
20+
- if: inputs.extra-targets
21+
run: rustup target add ${{ inputs.extra-targets }}
22+
shell: bash
23+
- uses: mhils/workflows/rust-cache@v14
24+
- if: runner.os == 'Linux'
25+
run: cargo install --locked bpf-linker
26+
shell: bash

.github/python-version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.11
1+
3.12

.github/scripts/pin-versions.py

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
contents = (
1212
contents
1313
.replace(f"mitmproxy_windows", f"mitmproxy_windows=={version}")
14+
.replace(f"mitmproxy_linux", f"mitmproxy_linux=={version}")
1415
.replace(f"mitmproxy_macos", f"mitmproxy_macos=={version}")
1516
)
1617
pyproject_toml.write_text(contents)

.github/workflows/autofix.yml

+13-13
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ concurrency:
1111
cancel-in-progress: true
1212

1313
env:
14-
rust_clippy: "1.80" # MSRV
14+
MSRV: "1.80" # Minimum Supported Rust Version
1515

1616
jobs:
1717
protobuf:
1818
runs-on: macos-latest
1919
steps:
20-
- uses: actions/checkout@v4
20+
- uses: mhils/workflows/checkout@v12
2121
- run: brew install swift-protobuf
2222
- run: cargo install protoc-gen-prost
2323
- run: protoc --proto_path=./src/ipc/ mitmproxy_ipc.proto
2424
--prost_out=./src/ipc/
25+
--prost_opt="bytes=data"
2526
--swift_out=./mitmproxy-macos/redirector/ipc
2627
- run: cargo fmt --all
2728
- uses: autofix-ci/action@ff86a557419858bb967097bfc916833f5647fa8c
@@ -35,18 +36,17 @@ jobs:
3536
- os: macos-latest
3637
- os: ubuntu-latest
3738
steps:
38-
- uses: actions/checkout@v4
39-
- run: rustup toolchain install ${{ env.rust_clippy }} --profile minimal --component rustfmt --component clippy
40-
- run: rustup default ${{ env.rust_clippy }}
41-
- uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2.7.5
42-
timeout-minutes: 2
43-
continue-on-error: true
44-
# PyO3 wants recent Python on Windows.
45-
- uses: actions/setup-python@v5
39+
- uses: mhils/workflows/checkout@v12
40+
- uses: ./.github/actions/setup
4641
with:
47-
python-version-file: .github/python-version.txt
48-
49-
- run: cargo clippy --fix --allow-dirty --workspace
42+
rust-version: ${{ env.MSRV }}
43+
toolchain-args: --component rustfmt --component clippy
44+
45+
# We could run clippy on mitmproxy-linux-ebpf with
46+
# cargo +nightly clippy --workspace -- -C panic=abort -Zpanic_abort_tests
47+
# but that means we'd use nightly clippy, which may change its behavior (and thus break CI).
48+
# So we rather exempt mitmproxy-linux-ebpf from clippy lints.
49+
- run: cargo clippy --fix --allow-dirty --workspace --exclude mitmproxy-linux-ebpf
5050
- run: cargo fmt --all
5151
- run: git checkout src/ipc/mitmproxy_ipc.rs
5252

.github/workflows/ci.yml

+104-70
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,27 @@ jobs:
2222
matrix:
2323
include:
2424
- os: windows-latest
25-
rust: "1.80" # MSRV
26-
args: --exclude macos-certificate-truster
25+
rust: "1.80" # MSRV - can't use variables here.
26+
args: --exclude mitmproxy-linux-ebpf
2727
- os: macos-latest
28-
rust: "1.80"
29-
args: --exclude windows-redirector
28+
rust: "1.80" # MSRV - can't use variables here.
29+
args: --exclude mitmproxy-linux-ebpf
30+
- os: ubuntu-22.04
31+
rust: "1.80" # MSRV - can't use variables here.
32+
args: --exclude mitmproxy-linux-ebpf
3033
- os: ubuntu-latest
3134
rust: stable
32-
args: --exclude windows-redirector --exclude macos-certificate-truster
35+
args: --exclude mitmproxy-linux-ebpf
36+
- os: ubuntu-latest # old Ubuntu to test eBPF verifier compatibility
37+
rust: nightly
38+
args: --package mitmproxy-linux-ebpf
39+
env:
40+
RUSTFLAGS: ${{ matrix.rust == 'nightly' && '-Zpanic_abort_tests -C panic=abort' || '' }}
3341
steps:
34-
- uses: actions/checkout@v4
35-
- name: Set up Rust toolchain
36-
run: rustup toolchain install ${{ matrix.rust }} --profile minimal
37-
- uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2.7.5
38-
timeout-minutes: 2
39-
continue-on-error: true
40-
# PyO3 wants recent Python on Windows.
41-
- uses: actions/setup-python@v5
42+
- uses: mhils/workflows/checkout@v12
43+
- uses: ./.github/actions/setup
4244
with:
43-
python-version-file: .github/python-version.txt
45+
rust-version: ${{ matrix.rust }}
4446

4547
- name: Run "cargo check"
4648
# the action-rs/cargo action adds inline annotations for "cargo check" output
@@ -49,13 +51,19 @@ jobs:
4951
toolchain: ${{ matrix.rust }}
5052
command: check
5153
args: --workspace --verbose ${{ matrix.args }}
52-
- name: Run "cargo test"
54+
- if: matrix.rust != 'nightly' # XXX: weird errors here
55+
name: Run "cargo test"
5356
# the action-rs/cargo action adds inline annotations for "cargo test" output
5457
uses: actions-rs/cargo@9e120dd99b0fbad1c065f686657e914e76bd7b72
5558
with:
5659
toolchain: ${{ matrix.rust }}
5760
command: test
5861
args: --workspace --verbose ${{ matrix.args }}
62+
- if: matrix.os == 'ubuntu-22.04' # Test that eBPF loads
63+
run: cargo test --features root-tests
64+
working-directory: mitmproxy-linux
65+
env:
66+
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER: sudo -E
5967

6068
build:
6169
strategy:
@@ -69,33 +77,25 @@ jobs:
6977
- name: linux-arm64
7078
os: ubuntu-latest
7179
target: aarch64-unknown-linux-gnu
72-
args: --compatibility manylinux2014 --zig --target aarch64-unknown-linux-gnu
80+
args: --compatibility manylinux2014 --zig --target aarch64-unknown-linux-gnu -i 3.12
7381
- name: macos-universal
7482
os: macos-latest
7583
target: aarch64-apple-darwin x86_64-apple-darwin
7684
args: --target universal2-apple-darwin
7785
runs-on: ${{ matrix.os }}
7886
name: build mitmproxy-rs (${{ matrix.name }})
7987
steps:
80-
- uses: actions/checkout@v4
81-
- run: rustup toolchain install stable --profile minimal
82-
- run: rustup default stable
83-
- if: matrix.target
84-
run: rustup target add ${{ matrix.target }}
85-
- run: rustup show
86-
- uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2.7.5
87-
timeout-minutes: 2
88-
continue-on-error: true
89-
- uses: actions/setup-python@v5
88+
- uses: mhils/workflows/checkout@v12
89+
- uses: ./.github/actions/setup
9090
with:
91-
python-version-file: .github/python-version.txt
91+
extra-targets: ${{ matrix.target }}
9292

9393
- if: runner.os == 'Linux'
9494
name: Install maturin[zig] from PyPI
95-
uses: install-pinned/maturin-with-zig@4804d730717f28b7565e71e68e5c9fe8c4f9b089
95+
uses: install-pinned/maturin-with-zig@68c027568b7d08df7bc3c52476ae28d1d2d787f5
9696
- if: runner.os != 'Linux'
9797
name: Install maturin from PyPI
98-
uses: install-pinned/maturin@c8c3a8f7f2b2ecf1728c96824734c6c6afe7e3e8
98+
uses: install-pinned/maturin@b1e3f698dbd19f284d4363cb361f75b2fa04679c
9999

100100
- if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
101101
run: python .github/scripts/pin-versions.py
@@ -106,7 +106,7 @@ jobs:
106106
# ensure that sdist is building.
107107
# We do this here instead of a separate job because we don't want to wait for the entire matrix.
108108
- if: contains(matrix.args, 'sdist')
109-
run: pip install target/wheels/*.tar.gz
109+
run: pip install --no-dependencies target/wheels/*.tar.gz
110110

111111
- uses: actions/upload-artifact@v4
112112
with:
@@ -116,7 +116,7 @@ jobs:
116116
build-macos-app:
117117
runs-on: macos-latest
118118
steps:
119-
- uses: actions/checkout@v4
119+
- uses: mhils/workflows/checkout@v12
120120
- uses: actions/cache@v4
121121
id: cache-app
122122
with:
@@ -137,62 +137,96 @@ jobs:
137137
name: macos-app
138138
path: mitmproxy-macos/redirector/dist/
139139

140-
build-os-wheels:
141-
needs: build-macos-app
142-
strategy:
143-
matrix:
144-
include:
145-
- os: windows
146-
build-rust: --package windows-redirector
147-
- os: macos
148-
build-rust: --package macos-certificate-truster
149-
runs-on: ${{ matrix.os }}-latest
150-
name: build mitmproxy-${{ matrix.os }}
140+
build-windows-wheel:
141+
runs-on: windows-latest
142+
name: build mitmproxy-windows
151143
steps:
152-
- uses: actions/checkout@v4
153-
154-
# Build Rust
155-
- uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2.7.5
156-
timeout-minutes: 2
157-
continue-on-error: true
158-
- run: rustup toolchain install stable --profile minimal
159-
- run: rustup default stable
160-
- if: runner.os == 'macOS'
161-
run: rustup target add aarch64-apple-darwin x86_64-apple-darwin
162-
- if: runner.os == 'macOS'
163-
run: |
164-
cargo build --release ${{ matrix.build-rust }} --target x86_64-apple-darwin
165-
cargo build --release ${{ matrix.build-rust }} --target aarch64-apple-darwin
166-
lipo -create -output target/release/macos-certificate-truster target/x86_64-apple-darwin/release/macos-certificate-truster target/aarch64-apple-darwin/release/macos-certificate-truster
167-
- if: runner.os != 'macOS'
168-
run: cargo build --release ${{ matrix.build-rust }}
144+
- uses: mhils/workflows/checkout@v12
145+
- uses: ./.github/actions/setup
146+
- uses: install-pinned/build@aa7fb973fec4a5593736c5dc25b322120ca41a98
147+
148+
- run: cargo build --release --package windows-redirector
149+
150+
- run: python -m build --wheel ./mitmproxy-windows --outdir target/wheels/
151+
- uses: actions/upload-artifact@v4
152+
with:
153+
name: wheels-os-windows
154+
path: target/wheels
169155

156+
build-macos-wheel:
157+
name: build mitmproxy-macos
158+
needs: build-macos-app
159+
runs-on: macos-latest
160+
steps:
161+
- uses: mhils/workflows/checkout@v12
162+
- uses: ./.github/actions/setup
163+
with:
164+
extra-targets: aarch64-apple-darwin x86_64-apple-darwin
165+
- uses: install-pinned/build@aa7fb973fec4a5593736c5dc25b322120ca41a98
170166

171-
# Download macOS app
172-
- if: runner.os == 'macOS'
173-
uses: actions/download-artifact@v4
167+
- run: |
168+
cargo build --release --package macos-certificate-truster --target x86_64-apple-darwin
169+
cargo build --release --package macos-certificate-truster --target aarch64-apple-darwin
170+
lipo -create -output target/release/macos-certificate-truster target/x86_64-apple-darwin/release/macos-certificate-truster target/aarch64-apple-darwin/release/macos-certificate-truster
171+
- uses: actions/download-artifact@v4
174172
with:
175173
name: macos-app
176174
path: mitmproxy-macos/redirector/dist/
177175

178-
# Build & upload wheel
179-
- uses: actions/setup-python@v5
176+
- run: python -m build --wheel ./mitmproxy-macos --outdir target/wheels/
177+
- uses: actions/upload-artifact@v4
180178
with:
181-
python-version-file: .github/python-version.txt
182-
- name: Install build from PyPI
183-
uses: install-pinned/build@67059894d5ef2398af490c98fa8af8542d7b7008
184-
- run: python -m build --wheel ./mitmproxy-${{ matrix.os }} --outdir target/wheels/
179+
name: wheels-os-macos
180+
path: target/wheels
181+
182+
build-linux-wheel:
183+
name: build mitmproxy-${{ matrix.name }}
184+
strategy:
185+
matrix:
186+
include:
187+
- name: linux-x86_64
188+
args: --compatibility manylinux2014 --zig --sdist
189+
- name: linux-arm64
190+
target: aarch64-unknown-linux-gnu
191+
args: --compatibility manylinux2014 --zig --target aarch64-unknown-linux-gnu -i 3.12
192+
runs-on: ubuntu-latest
193+
steps:
194+
- uses: mhils/workflows/checkout@v12
195+
- uses: ./.github/actions/setup
196+
with:
197+
extra-targets: ${{ matrix.target }}
198+
- name: Install maturin[zig] from PyPI
199+
uses: install-pinned/maturin-with-zig@68c027568b7d08df7bc3c52476ae28d1d2d787f5
200+
201+
- run: maturin build --release ${{ matrix.args }}
202+
working-directory: ./mitmproxy-linux
203+
185204
- uses: actions/upload-artifact@v4
186205
with:
187-
name: wheels-os-${{ runner.os }}
206+
name: wheels-os-${{ matrix.name }}
207+
path: target/wheels
208+
209+
test-linux-wheel-sdist:
210+
needs: build-linux-wheel
211+
runs-on: ubuntu-latest
212+
steps:
213+
- uses: mhils/workflows/checkout@v12
214+
- uses: ./.github/actions/setup
215+
- uses: actions/download-artifact@v4
216+
with:
217+
name: wheels-os-linux-x86_64
188218
path: target/wheels
219+
- run: pip install --no-dependencies target/wheels/*.tar.gz
189220

190221
check:
191222
if: always()
192223
needs:
193224
- test
225+
- test-linux-wheel-sdist
194226
- build
195-
- build-os-wheels
227+
- build-windows-wheel
228+
- build-linux-wheel
229+
- build-macos-wheel
196230
uses: mhils/workflows/.github/workflows/alls-green.yml@main
197231
with:
198232
jobs: ${{ toJSON(needs) }}

.github/workflows/docs.yml

+7-11
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,16 @@ jobs:
1919
build:
2020
runs-on: ubuntu-latest
2121
steps:
22-
- uses: actions/checkout@v4
23-
- uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2.7.5
24-
timeout-minutes: 2
25-
continue-on-error: true
26-
- name: Install maturin[zig] from PyPI
27-
uses: install-pinned/maturin-with-zig@4804d730717f28b7565e71e68e5c9fe8c4f9b089
28-
- name: Install mypy from PyPI
29-
uses: install-pinned/mypy@acfb567eb55a86c12a58ca1d28cd3e183e6a6d63
30-
- name: Install pdoc from PyPI
31-
uses: install-pinned/pdoc@2e3e48c4027dad61fb97866e009e1e6b7da38209
22+
# TODO: This should ideally just reuse the main CI artifacts.
23+
- uses: mhils/workflows/checkout@v12
24+
- uses: ./.github/actions/setup
25+
- uses: install-pinned/maturin-with-zig@68c027568b7d08df7bc3c52476ae28d1d2d787f5
26+
- uses: install-pinned/mypy@2b552bed479e3f7065314667b670f7303619e989
27+
- uses: install-pinned/pdoc@fd9469ecb06f32b7012e07e449ce98b217bf1189
3228

3329
- run: maturin build
3430
working-directory: ./mitmproxy-rs
35-
- run: pip install --no-index --find-links target/wheels/ mitmproxy_rs
31+
- run: pip install --no-index --no-dependencies --find-links target/wheels/ mitmproxy_rs
3632

3733
- run: stubtest --allowlist mitmproxy-rs/stubtest-allowlist.txt --mypy-config-file mitmproxy-rs/pyproject.toml mitmproxy_rs
3834

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ re-run `maturin develop` and restart mitmproxy** for changes to apply.
2424
If you've followed the procedure above, you can run the basic test suite as follows:
2525

2626
```shell
27-
cargo test --workspace
27+
cargo test
2828
```
2929

3030
Please ensure that all patches are accompanied by matching changes in the test suite.

0 commit comments

Comments
 (0)