-
Notifications
You must be signed in to change notification settings - Fork 25
Limit aproxy nftables redirection to egress traffic only #807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ snap install aproxy --edge | |
| snap set aproxy proxy={{ aproxy_address }} listen=:54969 | ||
| cat << EOF > /etc/nftables.conf | ||
| define default-ipv4 = $(ip route get $(ip route show 0.0.0.0/0 | grep -oP 'via \K\S+') | grep -oP 'src \K\S+') | ||
| define nics = { $(ip route show 0.0.0.0/0 | grep -oP 'dev \K\S+' | sort -u | sed 's/.*/"&"/' | paste -sd,) } | ||
| table ip aproxy | ||
| flush table ip aproxy | ||
| table ip aproxy { | ||
|
|
@@ -25,10 +26,12 @@ table ip aproxy { | |
| } | ||
| chain prerouting { | ||
| type nat hook prerouting priority dstnat; policy accept; | ||
| fib daddr oifname != \$nics return | ||
| ip daddr != @exclude tcp dport { {{ aproxy_redirect_ports }} } counter dnat to \$default-ipv4:54969 | ||
| } | ||
| chain output { | ||
| type nat hook output priority -100; policy accept; | ||
| oifname != \$nics return | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I tested this claim directly and it does not hold on the runner kernel (Ubuntu 24.04). Two findings:
This asymmetry is intentional: in |
||
| ip daddr != @exclude tcp dport { {{ aproxy_redirect_ports }} } counter dnat to \$default-ipv4:54969 | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,10 +100,12 @@ def runner_metrics_mock_fixture(monkeypatch: pytest.MonkeyPatch) -> MagicMock: | |
| } | ||
| chain prerouting { | ||
| type nat hook prerouting priority dstnat; policy accept; | ||
| fib daddr oifname != \\$nics return | ||
| ip daddr != @exclude tcp dport { 80, 443 } counter dnat to \\$default-ipv4:54969 | ||
| } | ||
| chain output { | ||
| type nat hook output priority -100; policy accept; | ||
| oifname != \\$nics return | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This depends on the |
||
| ip daddr != @exclude tcp dport { 80, 443 } counter dnat to \\$default-ipv4:54969 | ||
| } | ||
| } | ||
|
|
@@ -123,10 +125,12 @@ def runner_metrics_mock_fixture(monkeypatch: pytest.MonkeyPatch) -> MagicMock: | |
| } | ||
| chain prerouting { | ||
| type nat hook prerouting priority dstnat; policy accept; | ||
| fib daddr oifname != \\$nics return | ||
| ip daddr != @exclude tcp dport { 80, 443 } counter dnat to \\$default-ipv4:54969 | ||
| } | ||
| chain output { | ||
| type nat hook output priority -100; policy accept; | ||
| oifname != \\$nics return | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Same as the L108 thread: |
||
| ip daddr != @exclude tcp dport { 80, 443 } counter dnat to \\$default-ipv4:54969 | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I empirically tested this on Ubuntu 24.04 (iproute2 6.1.0) with two default routes configured. The pipeline does not fail under
set -e:ip route get <gw1> <gw2>returns exit 0 anddefine default-ipv4resolves to a valid address, so cloud-init is not broken.That said, the underlying point is fair: with multiple default routes the current expression silently uses the last gateway, which is non-deterministic. Adding
head -n1(orsort-ing by metric) is a reasonable robustness/determinism improvement even though it isn't a correctness bug.