Skip to content
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

Sanity query optimized #560

Merged
merged 31 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
773fb84
Optimized implementation of EquivalenceQuery.
tanyaveksler Jun 4, 2023
c5bf934
Added VacuityQuery and RedundancyQuery optimized implementation.
tanyaveksler Jun 20, 2023
aab6396
Added VacuityQuery and RedundancyQuery optimized implementation.
tanyaveksler Jun 20, 2023
54d3343
Ignoring 'complex function' lint error.
tanyaveksler Jun 11, 2023
adba6dd
Added VacuityQuery and RedundancyQuery optimized implementation.
tanyaveksler Jun 20, 2023
ab3a82e
Removed redundant method.
tanyaveksler Jun 13, 2023
c9393ee
Added VacuityQuery and RedundancyQuery optimized implementation.
tanyaveksler Jun 20, 2023
da98a3f
Fixed domain updating mechanism per rule (to avoid activating multipl…
tanyaveksler Jun 20, 2023
9cd810e
Fixed lint errors
tanyaveksler Jun 20, 2023
ac4f679
Enabled strongEquivalence optimized implementation.
tanyaveksler Jun 20, 2023
cbe8d1f
Implemented optimized ContainmentQuery.
tanyaveksler Jun 25, 2023
ac38097
Enabled optimized TwoContainmentQuery and PermitsQuery.
tanyaveksler Jun 25, 2023
6e632b5
Fixed small inaccuracy in handling host endpoints in optimized solution.
tanyaveksler Jun 27, 2023
af4c84f
Merge branch 'equivalence-based-queries-optmized' into containment-ba…
tanyaveksler Jun 27, 2023
a6ef67c
Implemented optimized InterferesQuery
tanyaveksler Jul 2, 2023
959d741
Merge with master
tanyaveksler Jul 9, 2023
3cd1578
Small improvement in print differences for two config queries
tanyaveksler Jul 9, 2023
951b40c
Merge branch 'master' into interferes-based-queries-optimized
tanyaveksler Jul 11, 2023
5b21d04
Optimized implementation of intersects and forbids queries.
tanyaveksler Jul 11, 2023
2b6b13b
Fixed bug in creation of optimized istio policy properties.
tanyaveksler Jul 11, 2023
3d840a4
Opened for optimized run those queries that do not call allowed_conne…
tanyaveksler Jul 11, 2023
a68de7e
Merge with master.
tanyaveksler Jul 16, 2023
22b8f2c
Implemented sanity query optimized.
tanyaveksler Jul 16, 2023
c2d5372
Merge branch 'master' into sanity-query-optimized
tanyaveksler Jul 25, 2023
2b80c86
Merge with master
tanyaveksler Jul 25, 2023
34e2bee
Merge remote-tracking branch 'origin/sanity-query-optimized' into san…
tanyaveksler Jul 25, 2023
26f07b7
Merge branch 'master' into sanity-query-optimized
tanyaveksler Jul 30, 2023
4121b88
Fixing lint error.
tanyaveksler Jul 30, 2023
b9ed39f
Fixing lint error.
tanyaveksler Jul 30, 2023
51ae5d2
merge with master
tanyaveksler Aug 6, 2023
60a40ff
merge with master
tanyaveksler Aug 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 32 additions & 19 deletions nca/NetworkConfig/NetworkConfigQuery.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def other_policy_containing_deny(self, self_policy, config_with_self_policy, lay
:param NetworkPolicy self_policy: The policy to check
:param NetworkConfig config_with_self_policy: A network config with self_policy as its single policy
:param NetworkLayerName layer_name: The layer name of the policy
:return: A policy containing self_policy's denied connections if exist, None otherwise
:return: A policy containing self_policy's denied connections if exists, None otherwise
:rtype: NetworkPolicy
"""
policies_list = self.config.policies_container.layers[layer_name].policies_list
Expand All @@ -471,26 +471,39 @@ def other_policy_containing_deny(self, self_policy, config_with_self_policy, lay
if not other_policy.has_deny_rules():
continue
config_with_other_policy = self.config.clone_with_just_one_policy(other_policy.full_name())
# calling get_all_peers_group does not require getting dnsEntry peers, since they are not relevant when computing
# deny connections
pods_to_compare = self.config.peer_container.get_all_peers_group()
pods_to_compare |= TwoNetworkConfigsQuery(self.config,
config_with_other_policy).disjoint_referenced_ip_blocks()
for pod1 in pods_to_compare:
for pod2 in pods_to_compare:
if isinstance(pod1, IpBlock) and isinstance(pod2, IpBlock):
continue
if pod1 == pod2:
continue # no way to prevent a pod from communicating with itself
_, _, _, self_deny_conns = config_with_self_policy.allowed_connections(pod1, pod2, layer_name)
_, _, _, other_deny_conns = config_with_other_policy.allowed_connections(pod1, pod2, layer_name)
if not self_deny_conns:
continue
if not self_deny_conns.contained_in(other_deny_conns):
return None
return other_policy
if self.config.optimized_run == 'false':
res = self.check_deny_containment_original(config_with_self_policy, config_with_other_policy, layer_name)
else:
res = self.check_deny_containment_optimized(config_with_self_policy, config_with_other_policy, layer_name)
if res:
return other_policy
return None

def check_deny_containment_original(self, config_with_self_policy, config_with_other_policy, layer_name):
# calling get_all_peers_group does not require getting dnsEntry peers, since they are not relevant when computing
# deny connections
pods_to_compare = self.config.peer_container.get_all_peers_group()
pods_to_compare |= TwoNetworkConfigsQuery(self.config, config_with_other_policy).disjoint_referenced_ip_blocks()
for pod1 in pods_to_compare:
for pod2 in pods_to_compare:
if isinstance(pod1, IpBlock) and isinstance(pod2, IpBlock):
continue
if pod1 == pod2:
continue # no way to prevent a pod from communicating with itself
_, _, _, self_deny_conns = config_with_self_policy.allowed_connections(pod1, pod2, layer_name)
_, _, _, other_deny_conns = config_with_other_policy.allowed_connections(pod1, pod2, layer_name)
if not self_deny_conns:
continue
if not self_deny_conns.contained_in(other_deny_conns):
return False
return True

@staticmethod
def check_deny_containment_optimized(config_with_self_policy, config_with_other_policy, layer_name):
self_props = config_with_self_policy.allowed_connections_optimized(layer_name)
other_props = config_with_other_policy.allowed_connections_optimized(layer_name)
return self_props.denied_conns.contained_in(other_props.denied_conns)

def other_rule_containing(self, self_policy, self_rule_index, is_ingress, layer_name):
"""
Search whether a given policy rule is contained in another policy rule
Expand Down
2 changes: 1 addition & 1 deletion nca/SchemeRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SchemeRunner(GenericYamlParser):

implemented_opt_queries = {'connectivityMap', 'equivalence', 'vacuity', 'redundancy', 'strongEquivalence',
'containment', 'twoWayContainment', 'permits', 'interferes', 'pairwiseInterferes',
'forbids', 'emptiness', 'disjointness', 'allCaptured'}
'forbids', 'emptiness', 'disjointness', 'allCaptured', 'sanity'}

def __init__(self, scheme_file_name, output_format=None, output_path=None, optimized_run='false'):
GenericYamlParser.__init__(self, scheme_file_name)
Expand Down
2 changes: 1 addition & 1 deletion tests/run_all_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def run_all_test_flow(self, all_results):
tmp_opt = [i for i in self.test_queries_obj.args_obj.args if '-opt=' in i]
opt = tmp_opt[0].split('=')[1] if tmp_opt else 'false'
if isinstance(self.test_queries_obj, CliQuery) and (opt == 'debug' or opt == 'true'):
implemented_opt_queries = {'--connectivity', '--equiv', '--permits', '--interferes', '--forbids'}
implemented_opt_queries = {'--connectivity', '--equiv', '--permits', '--interferes', '--forbids', '--sanity'}
# TODO - update/remove the optimization below when all queries are supported in optimized implementation
if not implemented_opt_queries.intersection(set(self.test_queries_obj.args_obj.args)):
print(f'Skipping {self.test_queries_obj.test_name} since it does not have optimized implementation yet')
Expand Down