Skip to content

Commit 5c1f930

Browse files
committed
refactor to use default source ranges
1 parent 2445b57 commit 5c1f930

File tree

7 files changed

+82
-31
lines changed

7 files changed

+82
-31
lines changed

Diff for: apis/gateway/v1beta1/loadbalancerconfig_types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ type SubnetConfiguration struct {
7373

7474
// SourceNatIPv6Prefix [Network LoadBalancer] The IPv6 prefix to use for source NAT. Specify an IPv6 prefix (/80 netmask) from the subnet CIDR block or auto_assigned to use an IPv6 prefix selected at random from the subnet CIDR block.
7575
// +optional
76-
SourceNatIPv6Prefix *string `json:"sourceNAT,omitempty"`
76+
SourceNatIPv6Prefix *string `json:"sourceNatIPv6Prefix,omitempty"`
7777
}
7878

7979
// +kubebuilder:validation:Enum=HTTP1Only;HTTP2Only;HTTP2Optional;HTTP2Preferred;None

Diff for: config/crd/gateway/gateway-crds.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ spec:
205205
description: privateIPv4Allocation [Network LoadBalancer] the
206206
private ipv4 address to assign to this subnet.
207207
type: string
208-
sourceNAT:
208+
sourceNatIPv6Prefix:
209209
description: SourceNatIPv6Prefix [Network LoadBalancer] The
210210
IPv6 prefix to use for source NAT. Specify an IPv6 prefix
211211
(/80 netmask) from the subnet CIDR block or auto_assigned

Diff for: config/crd/gateway/gateway.k8s.aws_loadbalancerconfigurations.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ spec:
206206
description: privateIPv4Allocation [Network LoadBalancer] the
207207
private ipv4 address to assign to this subnet.
208208
type: string
209-
sourceNAT:
209+
sourceNatIPv6Prefix:
210210
description: SourceNatIPv6Prefix [Network LoadBalancer] The
211211
IPv6 prefix to use for source NAT. Specify an IPv6 prefix
212212
(/80 netmask) from the subnet CIDR block or auto_assigned

Diff for: config/rbac/role.yaml

-24
Original file line numberDiff line numberDiff line change
@@ -194,43 +194,19 @@ rules:
194194
- get
195195
- patch
196196
- update
197-
- apiGroups:
198-
- gateway.networking.k8s.io
199-
resources:
200-
- gatewayclasses
201-
verbs:
202-
- get
203-
- list
204-
- watch
205-
- apiGroups:
206-
- gateway.networking.k8s.io
207-
resources:
208-
- gatewayclasses/finalizers
209-
verbs:
210-
- update
211-
- apiGroups:
212-
- gateway.networking.k8s.io
213-
resources:
214-
- gatewayclasses/status
215-
verbs:
216-
- get
217-
- patch
218-
- update
219197
- apiGroups:
220198
- gateway.networking.k8s.io
221199
resources:
222200
- gateways
223201
verbs:
224202
- get
225203
- list
226-
- patch
227204
- watch
228205
- apiGroups:
229206
- gateway.networking.k8s.io
230207
resources:
231208
- gateways/finalizers
232209
verbs:
233-
- patch
234210
- update
235211
- apiGroups:
236212
- gateway.networking.k8s.io

Diff for: pkg/gateway/model/model_build_security_group.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,25 @@ func (builder *securityGroupBuilderImpl) buildManagedSecurityGroupName(gw *gwv1.
177177
func (builder *securityGroupBuilderImpl) buildManagedSecurityGroupIngressPermissions(lbConf *elbv2gw.LoadBalancerConfiguration, routes map[int][]routeutils.RouteDescriptor, ipAddressType elbv2model.IPAddressType) []ec2model.IPPermission {
178178
var permissions []ec2model.IPPermission
179179

180-
var sourceRanges []string
180+
// Default to 0.0.0.0/0 and ::/0
181+
// If user specified actual ranges, then these values will be overridden.
182+
// TODO - Document this
183+
sourceRanges := []string{
184+
"0.0.0.0/0",
185+
"::/0",
186+
}
181187
var prefixes []string
182188
var enableICMP bool
183189

184-
if lbConf.Spec.SourceRanges != nil {
190+
if lbConf != nil && lbConf.Spec.SourceRanges != nil {
185191
sourceRanges = *lbConf.Spec.SourceRanges
186192
}
187193

188-
if lbConf.Spec.SecurityGroupPrefixes != nil {
194+
if lbConf != nil && lbConf.Spec.SecurityGroupPrefixes != nil {
189195
prefixes = *lbConf.Spec.SecurityGroupPrefixes
190196
}
191197

192-
if lbConf.Spec.EnableICMP {
198+
if lbConf != nil && lbConf.Spec.EnableICMP {
193199
enableICMP = true
194200
}
195201

Diff for: pkg/gateway/model/model_build_security_group_test.go

+64
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,31 @@ func Test_BuildSecurityGroups_BuildManagedSecurityGroupIngressPermissions(t *tes
325325
lbConf: &elbv2gw.LoadBalancerConfiguration{},
326326
expected: make([]ec2model.IPPermission, 0),
327327
},
328+
{
329+
name: "ipv4 - tcp - with default source ranges",
330+
lbConf: &elbv2gw.LoadBalancerConfiguration{
331+
Spec: elbv2gw.LoadBalancerConfigurationSpec{},
332+
},
333+
routes: map[int][]routeutils.RouteDescriptor{
334+
80: {
335+
&routeutils.MockRoute{
336+
Kind: routeutils.TCPRouteKind,
337+
},
338+
},
339+
},
340+
expected: []ec2model.IPPermission{
341+
{
342+
IPProtocol: "tcp",
343+
FromPort: awssdk.Int32(80),
344+
ToPort: awssdk.Int32(80),
345+
IPRanges: []ec2model.IPRange{
346+
{
347+
CIDRIP: "0.0.0.0/0",
348+
},
349+
},
350+
},
351+
},
352+
},
328353
{
329354
name: "ipv4 - tcp - with source range",
330355
lbConf: &elbv2gw.LoadBalancerConfiguration{
@@ -651,6 +676,45 @@ func Test_BuildSecurityGroups_BuildManagedSecurityGroupIngressPermissions(t *tes
651676
},
652677
},
653678
},
679+
{
680+
name: "ipv6 - with default source ranges",
681+
ipAddressType: elbv2model.IPAddressTypeDualStack,
682+
lbConf: &elbv2gw.LoadBalancerConfiguration{
683+
Spec: elbv2gw.LoadBalancerConfigurationSpec{},
684+
},
685+
routes: map[int][]routeutils.RouteDescriptor{
686+
80: {
687+
&routeutils.MockRoute{
688+
Kind: routeutils.TCPRouteKind,
689+
},
690+
&routeutils.MockRoute{
691+
Kind: routeutils.HTTPRouteKind,
692+
},
693+
},
694+
},
695+
expected: []ec2model.IPPermission{
696+
{
697+
IPProtocol: "tcp",
698+
FromPort: awssdk.Int32(80),
699+
ToPort: awssdk.Int32(80),
700+
IPRanges: []ec2model.IPRange{
701+
{
702+
CIDRIP: "0.0.0.0/0",
703+
},
704+
},
705+
},
706+
{
707+
IPProtocol: "tcp",
708+
FromPort: awssdk.Int32(80),
709+
ToPort: awssdk.Int32(80),
710+
IPv6Range: []ec2model.IPv6Range{
711+
{
712+
CIDRIPv6: "::/0",
713+
},
714+
},
715+
},
716+
},
717+
},
654718
{
655719
name: "ipv6 - with source range",
656720
ipAddressType: elbv2model.IPAddressTypeDualStack,

Diff for: pkg/gateway/routeutils/mock_route.go

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ type MockRoute struct {
99
Kind string
1010
}
1111

12+
func (m *MockRoute) GetBackendRefs() []gwv1.BackendRef {
13+
//TODO implement me
14+
panic("implement me")
15+
}
16+
1217
func (m *MockRoute) GetRouteNamespacedName() types.NamespacedName {
1318
//TODO implement me
1419
panic("implement me")

0 commit comments

Comments
 (0)