Resolving communication issue between pods after enabling IPsec#1496
Resolving communication issue between pods after enabling IPsec#1496kmesh-bot merged 7 commits intokmesh-net:mainfrom
Conversation
Signed-off-by: aicee <hhbin2000@foxmail.com>
Signed-off-by: aicee <hhbin2000@foxmail.com>
Signed-off-by: aicee <hhbin2000@foxmail.com>
There was a problem hiding this comment.
Summary of Changes
Hello @zrggw, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request addresses a critical bug where inter-pod communication breaks down after IPsec is enabled. The core issue stemmed from how packets were handled post-decryption. By refining the BPF logic that processes traffic and explicitly marking decrypted packets, the system can now correctly route traffic that has undergone IPsec decryption, preventing packets from being dropped or misrouted.
Highlights
- Traffic Decryption Logic Refinement: Refactored the BPF traffic decryption marking logic to ensure correct handling of packets after IPsec decryption.
- Explicit Packet Marking: Introduced explicit marking for successfully decrypted packets (0xd0) and un-decrypted packets (0x0) within the BPF program, preventing misrouting.
- IPsec State Configuration: Configured the IPsec state creation to apply an output mark (0xd0) upon successful decryption, aligning with the BPF logic.
- Communication Issue Resolution: Resolved communication failures between pods when IPsec is enabled by ensuring proper packet flow and policy matching post-decryption.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Encrypted stream, Marked and sent to its true path, Pods now speak freely.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Pull Request Overview
This PR resolves a communication issue between pods after enabling IPsec by refactoring the traffic decrypt marking logic. The changes implement a new approach where ESP packets directly enter decryption and successfully decrypted packets are marked with 0xd0, while unencrypted packets get mark 0x0 to avoid matching policies.
- Refactored traffic decrypt marking logic in the BPF program to handle ESP protocol and decrypted packets differently
- Added OutputMark configuration to XFRM state creation for proper packet marking after decryption
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/controller/encryption/ipsec/ipsec_handler.go | Adds OutputMark configuration to XFRM state with value 0x00d0 |
| bpf/kmesh/general/tc_mark_decrypt.c | Refactors marking logic to handle ESP packets and check decryption status |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| } | ||
| nodeinfo = check_remote_manage_by_kmesh(ctx, &info, info.iph->saddr, info.ip6h->saddr.s6_addr32); | ||
| if (!nodeinfo) { | ||
| if (is_ipv4(&info)) { | ||
| protocol = info.iph->protocol; | ||
| } else if (is_ipv6(&info)) { | ||
| protocol = info.ip6h->nexthdr; | ||
| } else { | ||
| return TC_ACT_OK; | ||
| } |
There was a problem hiding this comment.
The removed nodeinfo check logic appears to be replaced without equivalent validation. Consider if the remote node management check is still needed or if this creates a security gap.
There was a problem hiding this comment.
Code Review
This pull request refactors the traffic decryption marking logic to resolve a communication issue between pods with IPsec enabled. It introduces an OutputMark on the XFRM state to mark decrypted packets and updates the tc_mark_decrypt BPF program to correctly handle these packets and reset marks for other traffic.
While the approach seems correct, I have identified a few areas for improvement:
- Broken Unit Test: The changes in
bpf/kmesh/general/tc_mark_decrypt.cwill likely cause the unit test intest/bpf_ut/tc_mark_decrypt_test.cto fail. The test still asserts the old behavior wherectx->markis set to0x00d0, whereas the new logic sets it to0for the tested scenario. It is critical to update the unit tests to match the new logic and ensure correctness. - Magic Numbers: The value
0x00d0is used as a magic number in both the Go code (ipsec_handler.go) and the BPF C code (tc_mark_decrypt.c). This makes the code hard to maintain and prone to errors. This value should be defined as a named constant and shared appropriately. I've left specific comments on this.
Signed-off-by: aicee <hhbin2000@foxmail.com>
Signed-off-by: aicee <hhbin2000@foxmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 7 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
| if (parser_tc_info(ctx, &info)) { | ||
| return TC_ACT_OK; | ||
| } | ||
| nodeinfo = check_remote_manage_by_kmesh(ctx, &info, info.iph->saddr, info.ip6h->saddr.s6_addr32); |
There was a problem hiding this comment.
You need to remove the related bpf map as well
There was a problem hiding this comment.
bpf map still need to be used in tc_mark_encrypt.c
Signed-off-by: aicee <hhbin2000@foxmail.com>
|
/assign @bitcoffeeiux |
|
/lgtm |
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hzxuzhonghu The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind bug
What this PR does / why we need it:
Refactored traffic decrypt marking logic.
Added OutputMark configuration in ipsec_handler.go
If the protocol is ESP, it directly enters the decryption phase to match the xfrm state and then re-enters ingress. If the packet is successfully decrypted, it will be marked as 0xd0. If the packet is not ESP protocol and has not been decrypted(mark != 0xd0), its mark will be set to 0x0, ensuring it does not match any policy and avoiding the issue described previously.
Which issue(s) this PR fixes:
Fixes #1481
Special notes for your reviewer:
Does this PR introduce a user-facing change?: