Skip to content

Commit fba7008

Browse files
committed
policy: Add NetworkPolicyResourcesDiscoveryService
Add new cilium/versioned.h generic container for transactional selector updates. Add a new NetworkPolicyResourceDiscoveryService that implements delta updates for policies and selectors, and where policies refer to selectors by their resource name. NPRDS adds a top-level oneof wrapper that wraps either a Selector or a NetworkPolicy. NetworkPolicy definition is shared with NPDS, but PortNetworkPolicyRule adds a new selectors field that is only used with NPRDS. Store the latest desired ConfigSource in the policy map and use it for: - initial policy map subscription - re-subscription when connection under current subscription is terminated - a healthy network policy stream is not disrupted This should work for Cilium Agent upgrades and downgrades, as the agent expresses the desired mode, and listens for both. Clear the resource map on a first update on a new stream. This fixes NACK cases where further updates on the stream would have IP collisions with resources that were kept from the previous stream. Stream generation accounting has to be shared between NPDS and NPRDS streams, so that the handoff works as designed, but no other xDS protocols (e.g., NPHDS) should interfere with the stream generation accounting. Solve this by defining the stream generation number as a static member of NetworkPolicyMapImpl and updating it from the already established transport connected/closed callbacks. Switch to delta mode eagerly when we have evidence that the agent is capable, but switch to SotW mode only when xDS stream transport had failed to connect or closes. Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
1 parent d9ea6bd commit fba7008

14 files changed

Lines changed: 5604 additions & 246 deletions

cilium/BUILD

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ envoy_cc_library(
2828
],
2929
)
3030

31+
envoy_cc_library(
32+
name = "versioned_lib",
33+
hdrs = ["versioned.h"],
34+
repository = "@envoy",
35+
deps = [
36+
"@com_google_absl//absl/container:flat_hash_map",
37+
"@com_google_absl//absl/container:flat_hash_set",
38+
"@envoy//source/common/common:assert_lib",
39+
],
40+
)
41+
3142
envoy_cc_library(
3243
name = "network_policy_lib",
3344
srcs = [
@@ -45,6 +56,7 @@ envoy_cc_library(
4556
"//cilium:conntrack_lib",
4657
"//cilium:grpc_subscription_lib",
4758
"//cilium:ipcache_lib",
59+
"//cilium:versioned_lib",
4860
"//cilium/api:npds_cc_proto",
4961
"@envoy//envoy/singleton:manager_interface",
5062
"@envoy//source/common/common:logger_lib",

cilium/api/npds.proto

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import "validate/validate.proto";
1717
// [#protodoc-title: Network policy management and NPDS]
1818

1919
// Each resource name is a network policy identifier.
20+
// Deprecated: This service will be removed when Cilium 1.20 is the oldest supported release.
2021
service NetworkPolicyDiscoveryService {
2122
option (envoy.annotations.resource).type = "cilium.NetworkPolicy";
2223

@@ -33,6 +34,32 @@ service NetworkPolicyDiscoveryService {
3334
}
3435
}
3536

37+
// Policy and selector resource names are exact-match identifiers in delta NPDS.
38+
service NetworkPolicyResourceDiscoveryService {
39+
option (envoy.annotations.resource).type = "cilium.NetworkPolicyResource";
40+
41+
rpc DeltaNetworkPolicyResources(stream envoy.service.discovery.v3.DeltaDiscoveryRequest)
42+
returns (stream envoy.service.discovery.v3.DeltaDiscoveryResponse) {
43+
}
44+
}
45+
46+
// A delta NPDS resource that carries either an endpoint policy or a shared selector.
47+
message NetworkPolicyResource {
48+
oneof resource {
49+
NetworkPolicy policy = 1;
50+
Selector selector = 2;
51+
}
52+
}
53+
54+
// A shared set of remote identities referenced by selector resource name.
55+
// Unlike the old state-of-the-world remote identity lists, an empty selector
56+
// matches nothing.
57+
message Selector {
58+
// The set of numeric remote security IDs selected by this selector.
59+
// If empty, this selector selects no remote identities.
60+
repeated uint32 remote_identities = 1;
61+
}
62+
3663
// A network policy that is enforced by a filter on the network flows to/from
3764
// associated hosts.
3865
message NetworkPolicy {
@@ -153,6 +180,12 @@ message PortNetworkPolicyRule {
153180
// Optional. If not specified, any remote host is matched by this predicate.
154181
repeated uint32 remote_policies = 7;
155182

183+
// Optional selector resource names that can be resolved to shared remote
184+
// policy sets in delta NPDS.
185+
// Selector references are matched by exact selector resource name.
186+
// Optional. If not specified, any remote host is matched by this predicate.
187+
repeated string selectors = 11;
188+
156189
// Optional downstream TLS context. If present, the incoming connection must
157190
// be a TLS connection.
158191
TLSContext downstream_tls_context = 3;

cilium/bpf_metadata.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ Config::Config(const ::cilium::BpfMetadata& config,
285285
[&context, config_source = config_source_] {
286286
return std::make_shared<Cilium::NetworkPolicyMap>(context, config_source, true);
287287
});
288+
// update desired config source on the map
289+
npmap_->setConfigSource(config_source_);
288290
}
289291
}
290292

cilium/grpc_subscription.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ TypeUrlToServiceMap* buildTypeUrlToServiceMap() {
8787
// https://www.mail-archive.com/protobuf@googlegroups.com/msg04540.html.
8888
for (absl::string_view name : {
8989
"cilium.NetworkPolicyDiscoveryService",
90-
//"cilium.NetworkPolicyResourceDiscoveryService",
90+
"cilium.NetworkPolicyResourceDiscoveryService",
9191
"cilium.NetworkPolicyHostsDiscoveryService",
9292
}) {
9393
const auto* service_desc =

0 commit comments

Comments
 (0)