Skip to content

Commit a70cfff

Browse files
committed
[OVN] Allow logging all traffic related to an ACL
Before this patch, we would only get logged the client to server side of the communication. The OVN allow-related ACL option was implemented [0] so as to be able to log also the packets that are going from server to client. This patch implements the addition of that feature in Neutron and needs OVN version 22.03 or updated 21.12. [0] https://patchwork.ozlabs.org/project/ovn/patch/[email protected]/ Closes-Bug: #2003706 Change-Id: I72d061c333f53e07f6feedec032e2c0b06a61248 Signed-off-by: Elvira García <[email protected]> (cherry picked from commit f7e31b4)
1 parent 6ef9d23 commit a70cfff

File tree

4 files changed

+48
-13
lines changed

4 files changed

+48
-13
lines changed

neutron/services/logapi/drivers/ovn/driver.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# under the License.
1212

1313
from collections import namedtuple
14+
import random
1415

1516
from neutron_lib.api.definitions import portbindings
1617
from neutron_lib.callbacks import resources
@@ -38,6 +39,7 @@
3839

3940
log_cfg.register_log_driver_opts()
4041

42+
MAX_INT_LABEL = 2**32
4143
SUPPORTED_LOGGING_TYPES = [log_const.SECURITY_GROUP]
4244

4345

@@ -169,13 +171,20 @@ def _remove_acls_log(self, pgs, ovn_txn, log_name=None):
169171
if log_name:
170172
if acl.name and acl.name[0] != log_name:
171173
continue
174+
columns = {
175+
'log': False,
176+
'meter': [],
177+
'name': [],
178+
'severity': []
179+
}
180+
# TODO(egarciar): There wont be a need to check if label exists
181+
# once minimum version for OVN is >= 22.03
182+
if hasattr(acl, 'label'):
183+
columns['label'] = 0
184+
ovn_txn.add(self.ovn_nb.db_remove(
185+
"ACL", acl_uuid, 'options', 'log-related'))
172186
ovn_txn.add(self.ovn_nb.db_set(
173-
"ACL", acl_uuid,
174-
("log", False),
175-
("meter", []),
176-
("name", []),
177-
("severity", [])
178-
))
187+
"ACL", acl_uuid, *columns.items()))
179188
acl_changes += 1
180189
msg = "Cleared %d, Not found %d (out of %d visited) ACLs"
181190
if log_name:
@@ -191,13 +200,20 @@ def _set_acls_log(self, pgs, ovn_txn, actions_enabled, log_name):
191200
# skip acls used by a different network log
192201
if acl.name and acl.name[0] != log_name:
193202
continue
203+
columns = {
204+
'log': acl.action in actions_enabled,
205+
'meter': self.meter_name,
206+
'name': log_name,
207+
'severity': "info"
208+
}
209+
# TODO(egarciar): There wont be a need to check if label exists
210+
# once minimum version for OVN is >= 22.03
211+
if hasattr(acl, "label"):
212+
# Label needs to be an unsigned 32 bit number and not 0.
213+
columns["label"] = random.randrange(1, MAX_INT_LABEL)
214+
columns["options"] = {'log-related': "true"}
194215
ovn_txn.add(self.ovn_nb.db_set(
195-
"ACL", acl_uuid,
196-
("log", acl.action in actions_enabled),
197-
("meter", self.meter_name),
198-
("name", log_name),
199-
("severity", "info")
200-
))
216+
"ACL", acl_uuid, *columns.items()))
201217
acl_changes += 1
202218
LOG.info("Set %d (out of %d visited) ACLs for network log %s",
203219
acl_changes, acl_visits, log_name)

neutron/tests/functional/services/logapi/drivers/ovn/test_driver.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@ def _check_acl_log(self, sgr, is_enabled=True):
151151
acl = self._find_security_group_rule_row_by_id(sgr)
152152
self.assertIsNotNone(acl)
153153
self.assertEqual(is_enabled, acl.log)
154+
if hasattr(acl, "label"):
155+
# Here we compare if there is a name because the log can be
156+
# disabled but disabling a log would not take out the properties
157+
# attached to it.
158+
if acl.name:
159+
self.assertNotEqual(0, acl.label)
160+
self.assertEqual("true", acl.options.get("log-related"))
161+
else:
162+
self.assertEqual(0, acl.label)
163+
self.assertIsNone(acl.options.get("log-related"))
154164
return acl
155165

156166
def _check_acl_log_drop(self, is_enabled=True):

neutron/tests/unit/services/logapi/drivers/ovn/test_driver.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,10 @@ def test__remove_acls_log(self, m_info):
278278
self.assertEqual(len(pg_dict["acls"]), info_args[1])
279279
self.assertEqual(len(pg_dict["acls"]) - 2, info_args[2])
280280
self.assertEqual(len(pg_dict["acls"]), info_args[3])
281-
self.assertEqual(len(pg_dict["acls"]), self._nb_ovn.db_set.call_count)
281+
self.assertEqual(len(pg_dict["acls"]),
282+
self._nb_ovn.db_set.call_count)
283+
self.assertEqual(len(pg_dict["acls"]),
284+
self._nb_ovn.db_remove.call_count)
282285

283286
@mock.patch.object(ovn_driver.LOG, 'info')
284287
def test__remove_acls_log_missing_acls(self, m_info):
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
Neutron can record full connection using log-related feature introduced in
5+
OVN 21.12.
6+
For more info see `bug LP#<https://bugs.launchpad.net/neutron/+bug/2003706>`

0 commit comments

Comments
 (0)