Skip to content

Add IPv6 address of metadata service to sg rules#136

Open
sven-rosenzweig wants to merge 2 commits intostable/yoga-m3from
change_infrastructure_rules
Open

Add IPv6 address of metadata service to sg rules#136
sven-rosenzweig wants to merge 2 commits intostable/yoga-m3from
change_infrastructure_rules

Conversation

@sven-rosenzweig
Copy link
Contributor

So far only DHCPv6 and ICMPv6 traffic is refelcted in the default infrastructure rules of NSX-T. The IPv6 address of the metadata service requires clearing as well.

In order to reflect those changes in NSX-T, it requires a check if the rule configuration has changed. So far only creation of missing policies is supported.

@github-actions
Copy link

github-actions bot commented Mar 26, 2024

Name                                                                      Stmts   Miss  Cover
---------------------------------------------------------------------------------------------
networking_nsxv3/api/rpc.py                                                 233    110    53%
networking_nsxv3/common/config.py                                            16      0   100%
networking_nsxv3/common/constants.py                                         23      0   100%
networking_nsxv3/common/locking.py                                           35     11    69%
networking_nsxv3/common/synchronization.py                                  180     49    73%
networking_nsxv3/db/db.py                                                    94     19    80%
networking_nsxv3/extensions/nsxtoperations.py                               104     40    62%
networking_nsxv3/plugins/ml2/drivers/nsxv3/agent/agent.py                   162     52    68%
networking_nsxv3/plugins/ml2/drivers/nsxv3/agent/cli.py                     299    195    35%
networking_nsxv3/plugins/ml2/drivers/nsxv3/agent/client_nsx.py              187     49    74%
networking_nsxv3/plugins/ml2/drivers/nsxv3/agent/constants_nsx.py             7      0   100%
networking_nsxv3/plugins/ml2/drivers/nsxv3/agent/extensions/firewall.py      27      0   100%
networking_nsxv3/plugins/ml2/drivers/nsxv3/agent/provider.py                169     10    94%
networking_nsxv3/plugins/ml2/drivers/nsxv3/agent/provider_nsx_policy.py     783    111    86%
networking_nsxv3/plugins/ml2/drivers/nsxv3/agent/realization.py             203     33    84%
networking_nsxv3/plugins/ml2/drivers/nsxv3/driver.py                        129     74    43%
networking_nsxv3/prometheus/exporter.py                                      19      5    74%
networking_nsxv3/services/logapi/drivers/nsxv3/driver.py                     41      1    98%
networking_nsxv3/services/qos/drivers/nsxv3/qos.py                           34      4    88%
networking_nsxv3/services/trunk/drivers/nsxv3/trunk.py                       71      3    96%
---------------------------------------------------------------------------------------------
TOTAL                                                                      2816    766    73%

"display_name": "HTTP",
"source_groups": ["ANY"],
"destination_groups": ["169.254.169.254"],
"destination_groups": ["169.254.169.254", "fe80::a9fe:a9fe"],
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you like constants we have neutron_lib.constants.METADATA_V6_IP. There's also one for v4.

res = self.client.get(path=path)
if res.ok:
continue
if self._check_for_infrastructure_changes():
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is this method? I haven't found it in the source. Do you want to call _check_infrastructure_rules_for_updates() here?


def _check_infrastructure_rules_for_updates(self, policies_from_cfg, security_policies):
for rule_from_cfg in policies_from_cfg['rules']:
for rule_policy in sg_policy["rules"]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is sg_policy? is that security_policies but with a different name?

for rule_from_cfg in policies_from_cfg['rules']:
for rule_policy in sg_policy["rules"]:
if rule_policy['id'] == rule_from_cfg['id']:
shared_keys = set(rule.keys()).intersection(set(rule_policy.keys()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

[optional] I like using operators for set operations, but it depends of what you like yourself. For intersection you have the option of using &, so set(rule) & set(rule_policy) (the .keys() is implicit for dict-to-list-conversion but that's also a choice on how verbose you like to be, makes it more ovious that you're dealing with a dict).

if rule_policy['id'] == rule_from_cfg['id']:
shared_keys = set(rule.keys()).intersection(set(rule_policy.keys()))
diff = set(o for o in shared_keys if rule[o] != rule_policy[o])
LOG.info("Infrastructure rule %s has changed in %s - new rule %s" % (rule_from_cfg, diff, rule_from_cfg))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd pass the format attributes as arguments to LOG.info() instead of doing the formatting beforehand.

LOG.info("Infrastructure rule %s has changed in %s - new rule %s" % (rule_from_cfg, diff, rule_from_cfg))
return True
else:
LOG.info("New infrastructure rule found %s" % rule_from_cfg)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here for the Log args.

if res.ok:
continue
if self._check_for_infrastructure_changes():
self.client.put(path=path, data=policy).raise_for_status()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we update the default infra policy every time with the desired rules? What if the operator added his own rules? Is this the desired behaviour?

@sven-rosenzweig sven-rosenzweig force-pushed the change_infrastructure_rules branch 5 times, most recently from 0726ebd to 2b25bbd Compare July 4, 2024 10:36
@sven-rosenzweig sven-rosenzweig force-pushed the change_infrastructure_rules branch 3 times, most recently from 41e29c7 to 4bf2266 Compare July 4, 2024 13:18
Creating the default security policies (DHCP, ICMP and Metadata
allow), happens on driver start (in case they have not been realized so far).
Changing those was not supported.

Before starting the driver, it is now checked if the realized rules
differs from the rules defined in NSX-T constants. If a change is
detected, the rules defined in the NSX-T constants will be realized as
defined.
So far only DHCPv6 and ICMPv6 traffic is refelcted in the default
infrastructure rules of NSX-T. The IPv6 address of the metadata
service requires clearing as well.
@sven-rosenzweig sven-rosenzweig force-pushed the change_infrastructure_rules branch from 4bf2266 to e0afa85 Compare July 4, 2024 14:14

INFRA = "/policy/api/v1/infra"

class Ignore(set):
Copy link
Collaborator

Choose a reason for hiding this comment

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

[optional] Could get another name that denotes more what it does. IgnoreGivenKeys? DiffIgnoreKeys? You also could move it closer to where it's used scope wise, on the other hand maybe you'll need it some day and then you want it in that package directly accessible? Dunno. Both options make sense to me.


class Ignore(set):
def __contains__(self, key):
return set.__contains__(self, key[1])
Copy link
Collaborator

Choose a reason for hiding this comment

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

would super().__contains__(key[1]) work as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants