@@ -1393,8 +1393,10 @@ func (lbaas *LbaasV2) buildListenerCreateOpt(port corev1.ServicePort, svcConf *s
1393
1393
listenerCreateOpt .Protocol = listeners .ProtocolHTTP
1394
1394
}
1395
1395
1396
- if len (svcConf .allowedCIDR ) > 0 {
1397
- listenerCreateOpt .AllowedCIDRs = svcConf .allowedCIDR
1396
+ if openstackutil .IsOctaviaFeatureSupported (lbaas .lb , openstackutil .OctaviaFeatureVIPACL , lbaas .opts .LBProvider ) {
1397
+ if len (svcConf .allowedCIDR ) > 0 {
1398
+ listenerCreateOpt .AllowedCIDRs = svcConf .allowedCIDR
1399
+ }
1398
1400
}
1399
1401
return listenerCreateOpt
1400
1402
}
@@ -1751,18 +1753,19 @@ func (lbaas *LbaasV2) checkService(service *corev1.Service, nodes []*corev1.Node
1751
1753
svcConf .timeoutTCPInspect = getIntFromServiceAnnotation (service , ServiceAnnotationLoadBalancerTimeoutTCPInspect , 0 )
1752
1754
}
1753
1755
1754
- var listenerAllowedCIDRs []string
1755
1756
sourceRanges , err := GetLoadBalancerSourceRanges (service , svcConf .preferredIPFamily )
1756
1757
if err != nil {
1757
1758
return fmt .Errorf ("failed to get source ranges for loadbalancer service %s: %v" , serviceName , err )
1758
1759
}
1759
1760
if openstackutil .IsOctaviaFeatureSupported (lbaas .lb , openstackutil .OctaviaFeatureVIPACL , lbaas .opts .LBProvider ) {
1760
1761
klog .V (4 ).Info ("LoadBalancerSourceRanges is suppported" )
1761
- listenerAllowedCIDRs = sourceRanges .StringSlice ()
1762
+ svcConf .allowedCIDR = sourceRanges .StringSlice ()
1763
+ } else if lbaas .opts .LBProvider == "ovn" && lbaas .opts .ManageSecurityGroups {
1764
+ klog .V (4 ).Info ("LoadBalancerSourceRanges will be enforced on the SG created and attached to LB members" )
1765
+ svcConf .allowedCIDR = sourceRanges .StringSlice ()
1762
1766
} else {
1763
- klog .Warning ("LoadBalancerSourceRanges is ignored" )
1767
+ klog .Warning ("LoadBalancerSourceRanges are ignored" )
1764
1768
}
1765
- svcConf .allowedCIDR = listenerAllowedCIDRs
1766
1769
1767
1770
if openstackutil .IsOctaviaFeatureSupported (lbaas .lb , openstackutil .OctaviaFeatureFlavors , lbaas .opts .LBProvider ) {
1768
1771
svcConf .flavorID = getStringFromServiceAnnotation (service , ServiceAnnotationLoadBalancerFlavorID , lbaas .opts .FlavorID )
@@ -2009,7 +2012,7 @@ func (lbaas *LbaasV2) ensureOctaviaLoadBalancer(ctx context.Context, clusterName
2009
2012
status := lbaas .createLoadBalancerStatus (service , svcConf , addr )
2010
2013
2011
2014
if lbaas .opts .ManageSecurityGroups {
2012
- err := lbaas .ensureSecurityGroup (clusterName , service , nodes , loadbalancer , svcConf . preferredIPFamily , svcConf . lbMemberSubnetID )
2015
+ err := lbaas .ensureAndUpdateOctaviaSecurityGroup (clusterName , service , nodes , svcConf )
2013
2016
if err != nil {
2014
2017
return status , fmt .Errorf ("failed when reconciling security groups for LB service %v/%v: %v" , service .Namespace , service .Name , err )
2015
2018
}
@@ -2070,14 +2073,6 @@ func (lbaas *LbaasV2) ensureSecurityRule(sgRuleCreateOpts rules.CreateOpts) erro
2070
2073
return nil
2071
2074
}
2072
2075
2073
- // ensureSecurityGroup ensures security group exist for specific loadbalancer service.
2074
- // Creating security group for specific loadbalancer service when it does not exist.
2075
- func (lbaas * LbaasV2 ) ensureSecurityGroup (clusterName string , apiService * corev1.Service , nodes []* corev1.Node ,
2076
- loadbalancer * loadbalancers.LoadBalancer , preferredIPFamily corev1.IPFamily , memberSubnetID string ) error {
2077
-
2078
- return lbaas .ensureAndUpdateOctaviaSecurityGroup (clusterName , apiService , nodes , memberSubnetID )
2079
- }
2080
-
2081
2076
func (lbaas * LbaasV2 ) updateOctaviaLoadBalancer (ctx context.Context , clusterName string , service * corev1.Service , nodes []* corev1.Node ) error {
2082
2077
svcConf := new (serviceConfig )
2083
2078
var err error
@@ -2140,7 +2135,7 @@ func (lbaas *LbaasV2) updateOctaviaLoadBalancer(ctx context.Context, clusterName
2140
2135
}
2141
2136
2142
2137
if lbaas .opts .ManageSecurityGroups {
2143
- err := lbaas .updateSecurityGroup (clusterName , service , nodes , svcConf . lbMemberSubnetID )
2138
+ err := lbaas .ensureAndUpdateOctaviaSecurityGroup (clusterName , service , nodes , svcConf )
2144
2139
if err != nil {
2145
2140
return fmt .Errorf ("failed to update Security Group for loadbalancer service %s: %v" , serviceName , err )
2146
2141
}
@@ -2204,7 +2199,7 @@ func getRulesToCreateAndDelete(wantedRules []rules.CreateOpts, existingRules []r
2204
2199
}
2205
2200
2206
2201
// ensureAndUpdateOctaviaSecurityGroup handles the creation and update of the security group and the securiry rules for the octavia load balancer
2207
- func (lbaas * LbaasV2 ) ensureAndUpdateOctaviaSecurityGroup (clusterName string , apiService * corev1.Service , nodes []* corev1.Node , memberSubnetID string ) error {
2202
+ func (lbaas * LbaasV2 ) ensureAndUpdateOctaviaSecurityGroup (clusterName string , apiService * corev1.Service , nodes []* corev1.Node , svcConf * serviceConfig ) error {
2208
2203
// get service ports
2209
2204
ports := apiService .Spec .Ports
2210
2205
if len (ports ) == 0 {
@@ -2238,16 +2233,23 @@ func (lbaas *LbaasV2) ensureAndUpdateOctaviaSecurityGroup(clusterName string, ap
2238
2233
}
2239
2234
2240
2235
mc := metrics .NewMetricContext ("subnet" , "get" )
2241
- subnet , err := subnets .Get (lbaas .network , memberSubnetID ).Extract ()
2236
+ subnet , err := subnets .Get (lbaas .network , svcConf . lbMemberSubnetID ).Extract ()
2242
2237
if mc .ObserveRequest (err ) != nil {
2243
2238
return fmt .Errorf (
2244
- "failed to find subnet %s from openstack: %v" , memberSubnetID , err )
2239
+ "failed to find subnet %s from openstack: %v" , svcConf . lbMemberSubnetID , err )
2245
2240
}
2246
2241
2247
2242
etherType := rules .EtherType4
2248
2243
if netutils .IsIPv6CIDRString (subnet .CIDR ) {
2249
2244
etherType = rules .EtherType6
2250
2245
}
2246
+ cidrs := []string {subnet .CIDR }
2247
+ if lbaas .opts .LBProvider == "ovn" {
2248
+ // OVN keeps the source IP of the incoming traffic. This means that we cannot just open the LB range, but we
2249
+ // need to open for the whole world. This can be restricted by using the service.spec.loadBalancerSourceRanges.
2250
+ // svcConf.allowedCIDR will give us the ranges calculated by GetLoadBalancerSourceRanges() earlier.
2251
+ cidrs = svcConf .allowedCIDR
2252
+ }
2251
2253
2252
2254
existingRules , err := getSecurityGroupRules (lbaas .network , rules.ListOpts {SecGroupID : lbSecGroupID })
2253
2255
if err != nil {
@@ -2260,6 +2262,8 @@ func (lbaas *LbaasV2) ensureAndUpdateOctaviaSecurityGroup(clusterName string, ap
2260
2262
wantedRules := make ([]rules.CreateOpts , 0 , len (ports )+ 1 )
2261
2263
2262
2264
if apiService .Spec .HealthCheckNodePort != 0 {
2265
+ // TODO(dulek): How should this work with OVN…? Do we need to allow all?
2266
+ // Probably the traffic goes from the compute node?
2263
2267
wantedRules = append (wantedRules ,
2264
2268
rules.CreateOpts {
2265
2269
Direction : rules .DirIngress ,
@@ -2277,17 +2281,19 @@ func (lbaas *LbaasV2) ensureAndUpdateOctaviaSecurityGroup(clusterName string, ap
2277
2281
if port .NodePort == 0 { // It's 0 when AllocateLoadBalancerNodePorts=False
2278
2282
continue
2279
2283
}
2280
- wantedRules = append (wantedRules ,
2281
- rules.CreateOpts {
2282
- Direction : rules .DirIngress ,
2283
- Protocol : rules .RuleProtocol (port .Protocol ),
2284
- EtherType : etherType ,
2285
- RemoteIPPrefix : subnet .CIDR ,
2286
- SecGroupID : lbSecGroupID ,
2287
- PortRangeMin : int (port .NodePort ),
2288
- PortRangeMax : int (port .NodePort ),
2289
- },
2290
- )
2284
+ for _ , cidr := range cidrs {
2285
+ wantedRules = append (wantedRules ,
2286
+ rules.CreateOpts {
2287
+ Direction : rules .DirIngress ,
2288
+ Protocol : rules .RuleProtocol (port .Protocol ),
2289
+ EtherType : etherType ,
2290
+ RemoteIPPrefix : cidr ,
2291
+ SecGroupID : lbSecGroupID ,
2292
+ PortRangeMin : int (port .NodePort ),
2293
+ PortRangeMax : int (port .NodePort ),
2294
+ },
2295
+ )
2296
+ }
2291
2297
}
2292
2298
2293
2299
toCreate , toDelete := getRulesToCreateAndDelete (wantedRules , existingRules )
@@ -2321,11 +2327,6 @@ func (lbaas *LbaasV2) ensureAndUpdateOctaviaSecurityGroup(clusterName string, ap
2321
2327
return nil
2322
2328
}
2323
2329
2324
- // updateSecurityGroup updating security group for specific loadbalancer service.
2325
- func (lbaas * LbaasV2 ) updateSecurityGroup (clusterName string , apiService * corev1.Service , nodes []* corev1.Node , memberSubnetID string ) error {
2326
- return lbaas .ensureAndUpdateOctaviaSecurityGroup (clusterName , apiService , nodes , memberSubnetID )
2327
- }
2328
-
2329
2330
// EnsureLoadBalancerDeleted deletes the specified load balancer
2330
2331
func (lbaas * LbaasV2 ) EnsureLoadBalancerDeleted (ctx context.Context , clusterName string , service * corev1.Service ) error {
2331
2332
mc := metrics .NewMetricContext ("loadbalancer" , "delete" )
0 commit comments