8000 egress-gateway: Add IPv6 support by syedazeez337 · Pull Request #39068 · cilium/cilium · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

egress-gateway: Add IPv6 support #39068

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

syedazeez337
Copy link
Contributor

egress-gateway: Add IPv6 support

Description

This PR adds IPv6 support to the egress gateway feature by introducing a new --enable-egress-gateway flag that enables egress gateway functionality for both IPv4 and IPv6. The existing --enable-ipv4-egress-gateway flag is marked as deprecated but still functional for backward compatibility.

Changes

  • Add a new --enable-egress-gateway flag that enables egress gateway for both IPv4 and IPv6
  • Properly mark the old flag as deprecated using flags.MarkDeprecated
  • Update the validation format for EgressIP from ipv4 to ip to support both IPv4 and IPv6 addresses
  • Update documentation to remove unnecessary IPv6 examples and comments
  • Update command reference documentation
  • Simplify example file

Testing

  • Ran unit tests for the affected packages
  • Verified that both flags can be set in the DaemonConfig struct
  • Ran make -C Documentation update-cmdref to update the command reference

Related Issues

Fixes #38957
Fixes #38962

Add a new `--enable-egress-gateway` flag that enables egress gateway for both IPv4 and IPv6, deprecating the IPv4-only `--enable-ipv4-egress-gateway` flag.

@syedazeez337 syedazeez337 requested review from a team as code owners April 22, 2025 02:39
@maintainer-s-little-helper
Copy link

Commit df54cf7 does not match "(?m)^Signed-off-by:".

Please follow instructions provided in https://docs.cilium.io/en/stable/contributing/development/contributing_guide/#developer-s-certificate-of-origin

@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-sign-off The author needs to add signoff to their commits before merge. label Apr 22, 2025
@syedazeez337 syedazeez337 requested a review from ysksuzuki April 22, 2025 02:39
@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Apr 22, 2025
@github-actions github-actions bot added cilium-cli This PR contains changes related with cilium-cli kind/community-contribution This was a contribution made by a community member. labels Apr 22, 2025
Copy link
Contributor
@zacharysarah zacharysarah left a comment

Choose a reason for hiding this comment

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

LGTM for docs

Copy link
Member
@joestringer joestringer left a comment

Choose a reason for hiding this comment

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

One minor change from a @cilium/docs-structure reviewer perspective.

Please also merge all the commits together and rebase against the tip of the main branch. The merge commit seems to be causing some confusion in the pull request.

@joestringer joestringer requested review from a team April 22, 2025 21:45
@joestringer joestringer added the release-note/major This PR introduces major new functionality to Cilium. label Apr 22, 2025
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Apr 22, 2025
Copy link
Member
@joestringer joestringer left a comment

Choose a reason for hiding this comment

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

The changes to docs look good to me 👍

@joestringer
Copy link
Member

/test

@joestringer
Copy link
Member

The egress gateway Go IPv6 tests are failing, looks related to the PR.

@syedazeez337
Copy link
Contributor Author
syedazeez337 commented Apr 30, 2025

When I ran the privileged tests for the egressgateway package with sudo -E PRIVILEGED_TESTS=1 go test -v ./pkg/egressgateway/..., three tests failed:

TestEgressGatewayManager - Failed with error: "mismatched gateway IP"
TestNodeSelector - Failed with error: "mismatched gateway IP"
TestEndpointDataStore - Failed with error: "mismatched gateway IP"
All three tests are failing with the same error message: "mismatched gateway IP".
If these tests are failing because of my code changes or a different issue altogether? I need some clarity and suggestions on this one.

cd /home/aze/Documents/cilium && ./test-ipv6-egress-gateway.sh
Testing IPv6 egress gateway support
Created test policy file
Validating policy with kubectl...
kubectl not found, skipping validation
Checking CRD schema for IPv6 support...
CRD schema supports IPv6 addresses
Checking IPv6 support in policy.go...
IPv6 support is implemented in policy.go
Checking mismatched IP families validation...
Mismatched IP families validation is implemented
Checking IPv6 tests...
IPv6 tests are implemented
All tests passed!
IPv6 egress gateway support is correctly implemented
sudo -E go test -v ./pkg/egressgateway/...
=== RUN   TestEgressGatewayCEGPParser
    manager_privileged_test.go:140: Set PRIVILEGED_TESTS to run this test
--- SKIP: TestEgressGatewayCEGPParser (0.00s)
=== RUN   TestEgressGatewayManager
    manager_privileged_test.go:140: Set PRIVILEGED_TESTS to run this test
--- SKIP: TestEgressGatewayManager (0.00s)
=== RUN   TestNodeSelector
    manager_privileged_test.go:140: Set PRIVILEGED_TESTS to run this test
--- SKIP: TestNodeSelector (0.00s)
=== RUN   TestEndpointDataStore
    manager_privileged_test.go:140: Set PRIVILEGED_TESTS to run this test
--- SKIP: TestEndpointDataStore (0.00s)
=== RUN   TestCell
--- PASS: TestCell (0.00s)
=== RUN   TestParseIPv6EgressGatewayPolicy
--- PASS: TestParseIPv6EgressGatewayPolicy (0.00s)
=== RUN   TestDeriveFromPolicyGatewayConfigIPv6
--- PASS: TestDeriveFromPolicyGatewayConfigIPv6 (0.00s)
=== RUN   TestMismatchedIPFamilies
--- PASS: TestMismatchedIPFamilies (0.00s)
=== RUN   TestPolicyConfig_updateMatchedEndpointIDs
=== RUN   TestPolicyConfig_updateMatchedEndpointIDs/Test_updateMatchedEndpointIDs_with_endpoints_and_nodes
=== RUN   TestPolicyConfig_updateMatchedEndpointIDs/Test_updateMatchedEndpointIDs_endpoints_and_nodes_with_no_match
=== RUN   TestPolicyConfig_updateMatchedEndpointIDs/Test_updateMatchedEndpointIDs_endpoints_and_nodes_with_no_match_label
--- PASS: TestPolicyConfig_updateMatchedEndpointIDs (0.00s)
    --- PASS: TestPolicyConfig_updateMatchedEndpointIDs/Test_updateMatchedEndpointIDs_with_endpoints_and_nodes (0.00s)
    --- PASS: TestPolicyConfig_updateMatchedEndpointIDs/Test_updateMatchedEndpointIDs_endpoints_and_nodes_with_no_match (0.00s)
    --- PASS: TestPolicyConfig_updateMatchedEndpointIDs/Test_updateMatchedEndpointIDs_endpoints_and_nodes_with_no_match_label (0.00s)
PASS
ok      github.com/cilium/cilium/pkg/egressgateway(cached)

@maintainer-s-little-helper
Copy link

Commits df54cf7, 53a156e, 1f16fc0 do not match "(?m)^Signed-off-by:".

Please follow instructions provided in https://docs.cilium.io/en/stable/contributing/development/contributing_guide/#developer-s-certificate-of-origin

@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-sign-off The author needs to add signoff to their commits before merge. label Apr 30, 2025
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-sign-off The author needs to add signoff to their commits before merge. label Apr 30, 2025
@syedazeez337 syedazeez337 marked this pull request as draft April 30, 2025 04:09
This commit adds IPv6 support to the egress gateway feature. It includes:

1. A new flag `--enable-egress-gateway` that enables both IPv4 and IPv6 egress gateway
   functionality, while keeping the old `--enable-ipv4-egress-gateway` flag for
   backward compatibility.
2. Updates to the CRD schema to accept both IPv4 and IPv6 addresses.
3. Validation to reject policies with mismatched IP families.
4. Support for IPv6 egress IPs in policy configuration.
5. Tests for IPv6 egress gateway functionality.

Signed-off-by: Syed Azeez <syedazeez337@gmail.com>
Copy link
Contributor
@rgo3 rgo3 left a comment

Choose a reason for hiding this comment

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

Hey @syedazeez337,

Sorry for the long delay, I'm not requested as a reviewer on this PR so it slipped of my plate. Apologies for that.

Please see my comments below for a first round of review.

// TODO: deprecate --enable-ipv4-egress-gateway, create new --enable-egress-gateway
if !dcfg.EnableIPv4EgressGateway {
// Check if either IPv4 or IPv6 egress gateway is enabled
if !dcfg.EnableIPv4EgressGateway && !dcfg.EnableEgressGateway {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think here we can still just have one daemon config value. However you should add some code in pkg/option/config.go, to make sure the config value is set correctly depending on how users set the option configs flag. I would fdo this with the following steps:

  1. Rename DaemonConfig.EnableIPv4EgressGateway to DaemonConfig.EnableEgressGateway
  2. Set DaemonConfig.EnableEgressGateway to true if either of the option flags enable-ipv4-egress-gateway or enable-egress-gateway is set to true. You can access them through viper.

This way we can keep most of the code the same, we added a new option flag, deprecated the old one but nothing for existing users will change if they keep running with enable-ipv4-egress-gateway after an upgrade.

@@ -198,10 +198,19 @@ func NewEgressGatewayManager(p Params) (out struct {
return out, errors.New("egress gateway is not supported in combination with the CiliumEndpointSlice feature")
}

// TODO: refactor config checks for both ipv4 and ipv6, and derive whether the environment supports egress gateway policies for either protocol
Copy link
Contributor

Choose a reason for hiding this comment

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

I think for now we should keep this code as is, and keep the TODO comment. We can tackle this independently after this PR. That's why I created two separate issues. Making sure we do this correctly is important so that we don't break existing deployments. For example you suggested change could potentially break an existing user-deployment that uses ipv4 egress gateway policies, has ipv6 enabled as well but sets dcfg.EnableIPv6Masquerade to false deliberately. For such users cilium would suddenly fail after an upgrade, without them having changed a thing. This should be avoided.

So let's stick to deprecating the old option flag and enabling users to use the egressIP field in this PR.

@@ -359,6 +366,28 @@ func ParseCEGP(cegp *v2.CiliumEgressGatewayPolicy) (*PolicyConfig, error) {
}
}

// Check for mismatched IP families
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this code could be a bit less verbose and can be run earlier in this function. I would propose to add something like the following, right after we have collected all the destination CIDRs:

Suggested change
// Check for mismatched IP families
for _, cidr := range dstCidrList {
if cidr.Addr().Is6() && policyGwc.egressIP.IsValid() && policyGwc.egressIP.Is4() {
return nil, fmt.Errorf("mismatched IP families: IPv4 egress IP with IPv6 destination CIDRs")
}
if cidr.Addr().Is4() && policyGwc.egressIP.IsValid() && policyGwc.egressIP.Is6() {
return nil, fmt.Errorf("mismatched IP families: IPv6 egress IP with IPv4 destination CIDRs")
}
}

@@ -1671,6 +1674,7 @@ type DaemonConfig struct {

EnableBPFClockProbe bool
EnableIPv4EgressGateway bool
Copy link
Contributor

Choose a reason for hiding this comment

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

As I suggested above, I think we can remove this daemon config parameter.

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of adding a new ipv6 only test file, please see the TestEgressGatewayCEGPParser function in manager_privileged_test.go and add the needed test cases there.

Copy link
Contributor

Choose a reason for hiding this comment

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

This file is code-generated I believe, to make any changes here you'll have to change pkg/k8s/apis/cilium.io/v2/cegp_types.go.

default route.
format: ipv4
format: ip
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you certain that ip is a valid format parameter? I can't find it in the OpenAPI v3 spec?

@rgo3 rgo3 mentioned this pull request Jun 4, 2025
8 tasks
@joestringer joestringer added the dont-merge/wait-until-release Freeze window for current release is blocking non-bugfix PRs label Jun 20, 2025
@joestringer joestringer removed the dont-merge/wait-until-release Freeze window for current release is blocking non-bugfix PRs label Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cilium-cli This PR contains changes related with cilium-cli kind/community-contribution This was a contribution made by a community member. release-note/major This PR introduces major new functionality to Cilium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support setting egress IP for IPv6 egress gateway policies Replace --enable-ipv4-egress-gateway with --enable-egress-gateway
4 participants
0