fix: improve WireGuard middleware to enforce policies based on cliet IP and Interface#110
Merged
Merged
Conversation
… IP and interface Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request enhances the WireGuard middleware logic and significantly expands test coverage to ensure correct policy enforcement for both proxy-based and interface-based scenarios. The main improvements include refactoring the interface-based middleware for clearer and more robust client IP and interface checks, and introducing comprehensive unit and integration tests for both middleware variants.
Middleware logic improvements:
WireGuardMiddlewareWithInterfaceto more robustly extract and validate the client IP, check for membership in the WireGuard subnet, and determine if the request arrived on the designated WireGuard interface. The logic now prioritizes headers likeX-Forwarded-For, handles edge cases, and improves debug logging for policy decisions. [1] [2] [3]Test coverage and reliability:
wireguard_test.gowith extensive test cases covering bothWireGuardMiddlewareWithProxyandWireGuardMiddlewareWithInterface, including scenarios with header precedence, subnet boundaries, invalid inputs, and real-world bug simulations. This ensures the middleware behaves as expected in a wide range of situations.Checklist
make test(or equivalent) locally and all tests passgit commit -s) with my real name and email<filename>.licensesidecarLICENSES/directoryType of Change
For more info, see Contributing Guidelines.