cloudstack: IP address conflicts held by public IPs of virtual routers
ISSUE TYPE
- Bug Report
COMPONENT NAME
VR
CLOUDSTACK VERSION
4.17.2
Note: I believe this impacts releases 4.18 and 4.19 also as no relevant code changes have been made to VR code
CONFIGURATION
- Advanced zone
- Standard networking using virtual routers only
- /24 pool of “public” IPs available for the virtual routers
OS / ENVIRONMENT
Ubuntu Focal 20.04
SUMMARY
Our workflow makes it so public IPs can be assigned/unassigned/reassigned to different networks, possibly multiple times per day (mostly, but not only via https://github.com/apache/cloudstack-kubernetes-provider)
After a while, we started seeing that many unused IP addresses (according to ACS database) were actually answering to L2 ARPing. In parallel, some of our IPs are getting 2 different MACs from the ping:
ARPING XX.YY.25.156
60 bytes from 1e:00:fe:00:04:ac (XX.YY.25.156): index=0 time=306.714 usec
60 bytes from 1e:00:63:00:04:b5 (XX.YY.25.156): index=1 time=342.809 usec
Our investigation has shown these conflicts on around 10 ips in two of our /24 subnets, which looks too much to be a conicidence.
We have confirmed that both MAC addresses belong to alive and healthy virtual routers:
[cloud]> select instance_id from nics where mac_address="1e:00:63:00:04:b5";
+-------------+
| instance_id |
+-------------+
| 5654 |
+-------------+
1 row in set (0.010 sec)
[cloud]> select instance_id from nics where mac_address="1e:00:fe:00:04:ac";
+-------------+
| instance_id |
+-------------+
| 5624 |
+-------------+
1 row in set (0.007 sec)
These routers both correctly mount the IP addresses:
ip a | grep XX.YY.25.156
inet XX.YY.25.156/24 brd XX.YY.25.255 scope global secondary eth2
Inside the “databag” of the so called “illegitimate” router causing the conflict, we can see the IP declared (sometimes with flag add: true, sometimes with add: false):
# /etc/cloudstack/ips.json
{
"add": true,
"broadcast": "XX.YY.25.255",
"cidr": "XX.YY.25.156/24",
"device": "eth2",
"first_i_p": false,
"gateway": "XX.YY.25.1",
"is_private_gateway": false,
"netmask": "255.255.255.0",
"network": "XX.YY.25.0/24",
"new_nic": false,
"nic_dev_id": 2,
"nw_type": "public",
"one_to_one_nat": false,
"public_ip": "XX.YY.25.156",
"size": "24",
"source_nat": false,
"vif_mac_address": "1e:00:63:00:04:b5"
}
To my understanding, this file is read/merged whenever a new IP state change is requested; however it’s not merged properly on unassignment.
Obviously, deleting/recreating all the virtual routers would solve the issue as this cache would be cleared; however because this causes massive disruptions on the service we would like to make sure the root cause is fixed first.
STEPS TO REPRODUCE
No specific command line here, but I think trying to bounce a public IP between 2 guest routers (ofc inside separate VPCs if these are VPC networks) several time would results in this issue.
- Create 2 guest networks A and B
- Create 2 VMS, one inside network A, the other inside network B
- Associate an IP address to network A, and create a loadbalancer rule for some port of VM A (should also work with port-forwarding and static NAT)
- Release the IP, associate it to network B, and create a loadbalancer rule for some port of VM A (should also work with port-forwarding and static NAT)
- Repeat steps 3-4 until you get an IP address conflict (or until you see invalid entries in the databag)
EXPECTED RESULTS
The IP is properly garbage collected on the router that doesn’t hold it anymore
ACTUAL RESULTS
IP address conflcit
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 46 (32 by maintainers)
Hello @hsato03,
Thank you for the backport, I’ve tested the patch, this looks good, no more IP conflicts detected, and all rules still apply properly as before (as much as possible at least). I definitely see some NPEs now though, in case this is something you are trying to prevent, see examples below (might be out of scope for this issue).
Anyway thank you for the amazing work on this subject.
and
@DaanHoogland The issue I fixed in #9059 is not exactly the same as @vdombrovski reported.
@hsato03 @GutoVeronezi said they have reproduced the issue, let’s wait for their PR.
is the pipe symbol within the single quotes a problem in this command?
maybe try
instead?
@DaanHoogland yes correct, released after I wrote my comment, which means we will surely plan our tests now.
As for proof inside the DB, I’ve ran more tests, and I can most definitely introduce inconsistencies. For example, my last test got an IP with allocated=NULL but state=Allocated, which in practice means this ip is now unusable until I manually reset it in the database (it cannot be assigned, it cannot be released).
Note that all these cases are introduced without any modifications to my original test; I’m simply changing the timings of when I start test1.sh and test2.sh
I’ll run some more tests, and report any additional anomalies I find.
@DaanHoogland here is how I successfully reproduced the issue on our QA platform:
You were right, this is a timing issue. Here is the raw cmk code to reproduce:
Terminal 1:
Terminal 2:
Now I understand that handling concurrency isn’t really a priority for this project (see another issue from last year: https://github.com/apache/cloudstack/issues/7907)
However, with the introduction of more vectors of automation (Terraform, Kubernetes), I believe that these types of issues might become really common. In our case, the IP conflicts have impacted more than 10 IPs total on a pool of 400 IPs, which is 2.5%.
did a quick test, everything looks good this may need intensive testing to reproduce the issue
@DaanHoogland not sure if this helps, in /var/log/cloud.log I’m getting the same log repeated for all IPs:
Regarding DataBag logs specifically (again in /var/log/cloud.log), on some instances we are getting this WARNING, without any other explanation:
I will setup a “brute-force” type test case that mirrors what I’ve described in “Steps to reproduce” using either CMK or Terraform; I’ll let you know if I can get it to reproduce.
thanks @vdombrovski , this will (obviously) be hard to reproduce in a lab environment. the true/false flag of the databag should ensure that IPs are removed, so it not being merged properly on unassigment is the issue as you already stated.
Do you have further logging from the VR that would help identifying the culprit?
(I’ll try it in a lab env, but have little hope it will be reliably reproducible)