[RFE] Add local-ip-prefix to Neutron metering label rules

Bug #1889431 reported by Rafael Weingartner on 2020-07-29
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
neutron
Wishlist
Rafael Weingartner

Bug Description

Problem Description
 =================
Neutron metering label rules have a parameter called "remote-ip-prefix", which would allow operators to filter traffic based on the remote IP address. However, since [1], its meaning was changed to the exact opposite, which makes a bit of confusion. Instead of matching on the remote prefix (towards the external interface), it matches the local prefix (towards the OS tenant network).

Ideally, to satisfy the use case presented in [1] (which was achieved by inverting the use of "remote-ip-prefix"), operators should be able to create rules based on local-ip-prefix and remote-ip-prefix.

[1] https://opendev.org/openstack/neutron/commit/92db1d4a2c49b1f675b6a9552a8cc5a417973b64

Proposed Change
 ===============
Therefore, we propose to introduce a new parameter in the Neutron metering rule API. This new parameter would be called "local_ip_prefix", representing the local IP of the traffic.

This change would also introduce a change in behavior of the "remote_ip_prefix", which would start to match the remote IP, instead of the local IP as it is doing since [1].

The "remote_ip_prefix" and "local_ip_prefix" could be used together, or only one of them can be defined. However, a metering rule must always have at least one of them (local_ip_prefix or remote_ip_prefix) defined.

## API JSON
Current JSON for "v2.0/metering/metering-label-rules" endpoint:
{
  "remote_ip_prefix": "0.0.0.0/0",
  "direction": "egress",
  "metering_label_id": "9ffd6512-9d2a-4dd2-9657-6a605126264d",
  "id": "f1694467-d866-4d8e-a8dc-18da516caedc",
  "excluded": false
}

Adding new attributes :
{
  "remote_ip_prefix": "0.0.0.0/0",
  "local_ip_prefix": "192.168.0.14/32",
  "direction": "egress",
  "metering_label_id": "9ffd6512-9d2a-4dd2-9657-6a605126264d",
  "id": "f1694467-d866-4d8e-a8dc-18da516caedc",
  "excluded": false
}

## Database table changes
Currently, the table "meteringlabelrules" is defined as:
+-------------------+--------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+--------------------------+------+-----+---------+-------+
| id | varchar(36) | NO | PRI | NULL | |
| direction | enum('ingress','egress') | YES | | NULL | |
| remote_ip_prefix | varchar(64) | YES | | NULL | |
| metering_label_id | varchar(36) | NO | MUL | NULL | |
| excluded | tinyint(1) | YES | | 0 | |
+-------------------+--------------------------+------+-----+---------+-------+

We would add a new field to it. Therefore, it would look like:
+-------------------+--------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+--------------------------+------+-----+---------+-------+
| id | varchar(36) | NO | PRI | NULL | |
| direction | enum('ingress','egress') | YES | | NULL | |
| remote_ip_prefix | varchar(64) | YES | | NULL | |
| local_ip_prefix | varchar(64) | YES | | NULL | |
| metering_label_id | varchar(36) | NO | MUL | NULL | |
| excluded | tinyint(1) | YES | | 0 | |
+-------------------+--------------------------+------+-----+---------+-------+

Moreover, during the upgrade process, the "remote_ip_prefix" would be set to "local_ip_prefix", and then we would set null in the "remote_ip_prefix" column. This is done to maintain compatibility with the changes introduced via [1].

## Neutron Metering agent changes
The IPtables driver in the metering agent will need to handle the new parameters "local_ip_prefix" and "remote_ip_prefix" properly. When building the IPtable rules the parameter "remote_ip_prefix" (if defined) will be used with the option "-d" (IPtables option) for egress rules and "-s" (IPtables option) for ingress rules. On the other hand, the parameter "local_ip_prefix" (if defined) will be used with option "-s"(IPtables option) for egress rules, and "-d"(IPtables option) for ingress rules.

## API impacts
People using the API to configure local IP prefixes via the "remote_ip_prefix" parameter would need to start using the "local_ip_prefix" parameter.

## Validations
To simplify validations, we propose to remove the overlapping IP_prefixes validations. The rationally behind this removal is that if the operator wants to somehow create rules that overlap, we should not be the ones blocking it.

We will implement the following validation:
* The remote IP prefix must be a valid IPv4 CIDR
* The local IP prefix must be a valid IPv4 CIDR
* Each metering label rule requires at least remote or local IP prefix to be informed. One can also use both.

## Foreseen tasks
- neutron_lib
-- add new attribute in api/definitions/metering.py
-- fix JSON of examples and documentation
-- YAML of documentation

- neutron
-- Add the new DB field in objects.metering.MeteringLabelRule and neutron/db/models/metering.MeteringLabelRule
-- DB script in neutron/db/migration/alembic_migrations/versions/victoria
--- add new field nullable
--- migration to fix the legacy data
-- Change execution flow in Neutron and Neutron meteting agent to use the new field.

- OpenStack SDK
-- add the new field

- OpenStack python client
-- add the new field

summary: - Add source-ip-prefix to Neutron metering label rules
+ Add local-ip-prefix to Neutron metering label rules
description: updated
description: updated
summary: - Add local-ip-prefix to Neutron metering label rules
+ [RFE] Add local-ip-prefix to Neutron metering label rules
description: updated
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron-lib (master)

Fix proposed to branch: master
Review: https://review.opendev.org/743828

Changed in neutron:
assignee: nobody → Rafael Weingartner (rafaelweingartner)
status: New → In Progress
Revision history for this message
Jonas Schäfer (ch-jssfr) wrote :

FTR, we tripped over the odd semantics of remote IP prefix and very much endorse this fix and extension of the metering feature. Thank you very much.

Revision history for this message
Slawek Kaplonski (slaweq) wrote :

Hi,

Thx for reporting this.
As this is (backward incompatible) API change, lets discuss that in the drivers team first.
I will add it to the agenda of the next drivers meeting which will be on Friday 31.07.2020.

Changed in neutron:
importance: Undecided → Wishlist
tags: added: api-ref metering rfe-triaged
description: updated
description: updated
description: updated
Revision history for this message
Slawek Kaplonski (slaweq) wrote :

We discussed that proposal on today's drivers meeting. We agreed to approve it but with proposing to add new parameters like "cloud_ip_prefix" and "peer_ip_prefix" (or something similar) and to not change current behaviour of the "remote_ip_prefix" attribute but only deprecate it.
Please propose spec with detailed description of the proposed changes and then we can move on with review of it and implementation.

tags: added: rfe-approved
removed: rfe-triaged
Revision history for this message
Rafael Weingartner (rafaelweingartner) wrote :

Thanks Slawek!
Spec proposed via: https://review.opendev.org/#/c/744702/

Revision history for this message
Slawek Kaplonski (slaweq) wrote :
Revision history for this message
Rafael Weingartner (rafaelweingartner) wrote :

Thanks!

Changed in neutron:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers