Skip to content
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

iptables: use ISTIO_OUTPUT chain for DNS UDP rules #50915

Merged
merged 3 commits into from May 13, 2024

Conversation

eoinfennessy
Copy link
Contributor

@eoinfennessy eoinfennessy commented May 8, 2024

Please provide a description of this PR:

Fixes #50532

@eoinfennessy eoinfennessy requested a review from a team as a code owner May 8, 2024 13:40
@istio-policy-bot istio-policy-bot added area/dual-stack area/networking release-notes-none Indicates a PR that does not require release notes. labels May 8, 2024
@istio-testing istio-testing added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test labels May 8, 2024
@istio-testing
Copy link
Collaborator

Hi @eoinfennessy. Thanks for your PR.

I'm waiting for a istio member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@eoinfennessy
Copy link
Contributor Author

Hi @bleggett, do you think any further changes need to be made to address this issue?

@jewertow jewertow added the ok-to-test Set this label allow normal testing to take place for a PR not submitted by an Istio org member. label May 8, 2024
Copy link
Contributor

@costinm costinm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a good change but pretty risky - can you confirm the result by getting an iptables-save on a real pod ( the golden files are pretty fake - not sure why we use uid-owner 3 and 4, not something we'll have in practice ) ?

(long term): If you are interested in iptables and capture - I would save the capture in a doc, perhaps one capture from a pod with all iptables-related annotations plus ambient capture - and evaluate the differences and if we can merge the behavior. It is not clear at all why we need 2 different iptables code paths both operating on the pod - in the past ambient was in host namespace and it made sense.

@eoinfennessy
Copy link
Contributor Author

Thanks @costinm!

Golden files don't look right - ISTIO_OUTPUT is created 2x.

ISTIO_OUTPUT is created once in the nat table and once in the raw table (is this required because some of the rules created are added to the raw table?):

iptables -t nat -N ISTIO_OUTPUT
iptables -t raw -N ISTIO_OUTPUT
...
ip6tables -t nat -N ISTIO_OUTPUT
ip6tables -t raw -N ISTIO_OUTPUT

Also there is no jump from OUTPUT to ISTIO_OUTPUT showing up - maybe I missed it or was already there for the previous ISTIO_OUTPUT rule ? I don't remember how the jump is added - please check it doesn't have "-p tcp".

This jump is currently being created with -p tcp:

iptables -t nat -A OUTPUT -p tcp -j ISTIO_OUTPUT

Do we want to now create this without the -p tcp argument? Or create another jump with -p udp? I think I'm missing the jumps to the raw table too.

can you confirm the result by getting an iptables-save on a real pod ( the golden files are pretty fake - not sure why we use uid-owner 3 and 4, not something we'll have in practice ) - and compare it against what ambient does ?

Yes, I'll do some comparisons with between this and the current behavior for both sidecar and ambient.

@bleggett
Copy link
Contributor

bleggett commented May 8, 2024

I think it's a good change but pretty risky - can you confirm the result by getting an iptables-save on a real pod ( the golden files are pretty fake - not sure why we use uid-owner 3 and 4, not something we'll have in practice ) ?

+1 but we are using exactly the same library we use for real pods to generate the result we directly compare against the goldens - the inputs may be different in a real pod, but the rules/tables/chains will not be - that part is deterministic.

Copy link
Contributor

@bleggett bleggett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM conceptually and is a pretty straightforward rename.

We have decent testing around this, so if/when the tests pass, I am good. TY @eoinfennessy !

@@ -616,7 +616,7 @@ func HandleDNSUDP(
ext: ext,
ops: ops,
table: constants.NAT,
chain: constants.OUTPUT,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to insert the jump to the istio chain, since we are no longer using the default one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @bleggett! I've added the required jumps in the latest commit. The integration tests look OK now.

@eoinfennessy eoinfennessy requested a review from bleggett May 9, 2024 11:29
Copy link
Member

@hzxuzhonghu hzxuzhonghu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this one rule
-A OUTPUT -p udp -j ISTIO_OUTPUT

I am not sure i can get what really it fix here

@eoinfennessy
Copy link
Contributor Author

with this one rule
-A OUTPUT -p udp -j ISTIO_OUTPUT

I am not sure i can get what really it fix here

Hi @hzxuzhonghu, this jump is required because all UDP rules have been moved from the main OUTPUT chain to the ISTIO_OUTPUT chain.

Copy link
Contributor

@bleggett bleggett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! ty @eoinfennessy!

@istio-testing istio-testing merged commit b2e7ae0 into istio:master May 13, 2024
28 checks passed
@howardjohn
Copy link
Member

with this one rule
-A OUTPUT -p udp -j ISTIO_OUTPUT
I am not sure i can get what really it fix here

Hi @hzxuzhonghu, this jump is required because all UDP rules have been moved from the main OUTPUT chain to the ISTIO_OUTPUT chain.

Shouldn't we conditionally jump? Like only for dport 53/sport 15053?

@bleggett
Copy link
Contributor

bleggett commented May 13, 2024

with this one rule
-A OUTPUT -p udp -j ISTIO_OUTPUT
I am not sure i can get what really it fix here

Hi @hzxuzhonghu, this jump is required because all UDP rules have been moved from the main OUTPUT chain to the ISTIO_OUTPUT chain.

Shouldn't we conditionally jump? Like only for dport 53/sport 15053?

The existing rules (now moved to the custom chain) only apply if the traffic meets those reqs (is udp/ports, etc) so it amounts to the same thing.

Putting a rule in a custom chain and jumping to it doesn't change rule evaluation over how they would work in the primary/default chain (where they were before) - if they would all have been skipped in the main chain, they are still all skipped in the secondary chain.

If we checked before the jump we would effectively be checking the same properties 2x for every relevant packet. Jumps are supposed to be pretty dumb and have virtually zero cost, they're just pointers - organizational conveniences for the user.

@eoinfennessy eoinfennessy deleted the iptables-cleanup-chains branch May 14, 2024 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dual-stack area/networking ok-to-test Set this label allow normal testing to take place for a PR not submitted by an Istio org member. release-notes-none Indicates a PR that does not require release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sidecar iptables - istio-specific rules should only be inserted into custom chains
8 participants