Skip to content

Commit b08bc22

Browse files
committed
policy: Use source pod's egress policy if available
Enforce source pod's egress policy, if available, i.e., when the source is a local pod, even in the north/south scenario, where the Ingress IP is used as the upstream source address. Signed-off-by: Jarno Rajahalme <[email protected]>
1 parent 66cb64b commit b08bc22

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

cilium/bpf_metadata.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -464,12 +464,16 @@ Config::extractSocketMetadata(Network::ConnectionSocket& socket) {
464464

465465
source_identity = new_source_identity;
466466

467-
// AllowAllEgressPolicy will be returned if no explicit Ingress policy exists
468-
policy = &getPolicy(ingress_ip_str);
467+
// Enforce the egress policy associated with the Ingress if source is not a local pod.
468+
// (otherwise keep the source pod's policy and pod_ip as the policy reference)
469+
if (policy->getEndpointID() == 0) {
470+
// AllowAllEgressPolicy will be returned if no explicit Ingress policy exists
471+
policy = &getPolicy(ingress_ip_str);
469472

470-
// Set Ingress source IP as pod_ip (In case of egress (how N/S L7 LB is implemented), the pod_ip
471-
// is the source IP)
472-
pod_ip = ingress_ip_str;
473+
// Set Ingress source IP as pod_ip (In case of egress (how N/S L7 LB is implemented), the
474+
// pod_ip is the source IP)
475+
pod_ip = ingress_ip_str;
476+
}
473477

474478
// Original source address is never used for north/south LB
475479
src_address = nullptr;

tests/metadata_config_test.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ TEST_F(MetadataConfigTest, EastWestL7LbMetadata) {
447447
}
448448

449449
// When original source is not configured to be used, east/west traffic takes the north/south path
450+
// but retains local pod's IP as the "policy name" it found.
450451
TEST_F(MetadataConfigTest, EastWestL7LbMetadataNoOriginalSource) {
451452
::cilium::BpfMetadata config{};
452453
config.set_is_l7lb(true);
@@ -465,7 +466,7 @@ TEST_F(MetadataConfigTest, EastWestL7LbMetadataNoOriginalSource) {
465466
EXPECT_EQ(false, policy_fs->ingress_);
466467
EXPECT_EQ(true, policy_fs->is_l7lb_);
467468
EXPECT_EQ(80, policy_fs->port_);
468-
EXPECT_EQ("10.1.1.42", policy_fs->pod_ip_);
469+
EXPECT_EQ("10.1.1.1", policy_fs->pod_ip_);
469470
EXPECT_EQ(0, policy_fs->ingress_source_identity_);
470471

471472
auto source_addresses_socket_option = socket_metadata->buildSourceAddressSocketOption();

0 commit comments

Comments
 (0)