Skip to content

Commit eaf61bb

Browse files
committed
wip: replacing ALL sources
Signed-off-by: Richard Case <[email protected]>
1 parent ab3a129 commit eaf61bb

File tree

9 files changed

+73
-2
lines changed

9 files changed

+73
-2
lines changed

api/v1beta1/zz_generated.conversion.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/awscluster_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ type AWSLoadBalancerSpec struct {
252252
// PreserveClientIP lets the user control if preservation of client ips must be retained or not.
253253
// If this is enabled 6443 will be opened to 0.0.0.0/0.
254254
PreserveClientIP bool `json:"preserveClientIP,omitempty"`
255+
256+
// DefaultAllowedSourceCidrs is a list of allowed cidr blocks to allow as the source in the inbound rules for
257+
// the api server security group. If not supplied then it defaults to 0.0.0.0/0 for an IPv4 vpc or ::/o for
258+
// a IPv6 vpc. This is ignored if IngressRules are explicitly supplied.
259+
// +optional
260+
DefaultAllowedSourceCidrs []string `json:"defaultAllowedSourceCidrs,omitempty"`
255261
}
256262

257263
// AdditionalListenerSpec defines the desired state of an

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/infrastructure.cluster.x-k8s.io_awsclusters.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,14 @@ spec:
10791079
10801080
Defaults to false.
10811081
type: boolean
1082+
defaultAllowedSourceCidrs:
1083+
description: |-
1084+
DefaultAllowedSourceCidrs is a list of allowed cidr blocks to allow as the source in the inbound rules for
1085+
the api server security group. If not supplied then it defaults to 0.0.0.0/0 for an IPv4 vpc or ::/o for
1086+
a IPv6 vpc. This is ignored if IngressRules are explicitly supplied.
1087+
items:
1088+
type: string
1089+
type: array
10821090
disableHostsRewrite:
10831091
description: |-
10841092
DisableHostsRewrite disabled the hair pinning issue solution that adds the NLB's address as 127.0.0.1 to the hosts
@@ -1886,6 +1894,14 @@ spec:
18861894
18871895
Defaults to false.
18881896
type: boolean
1897+
defaultAllowedSourceCidrs:
1898+
description: |-
1899+
DefaultAllowedSourceCidrs is a list of allowed cidr blocks to allow as the source in the inbound rules for
1900+
the api server security group. If not supplied then it defaults to 0.0.0.0/0 for an IPv4 vpc or ::/o for
1901+
a IPv6 vpc. This is ignored if IngressRules are explicitly supplied.
1902+
items:
1903+
type: string
1904+
type: array
18891905
disableHostsRewrite:
18901906
description: |-
18911907
DisableHostsRewrite disabled the hair pinning issue solution that adds the NLB's address as 127.0.0.1 to the hosts

config/crd/bases/infrastructure.cluster.x-k8s.io_awsclustertemplates.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,14 @@ spec:
671671
672672
Defaults to false.
673673
type: boolean
674+
defaultAllowedSourceCidrs:
675+
description: |-
676+
DefaultAllowedSourceCidrs is a list of allowed cidr blocks to allow as the source in the inbound rules for
677+
the api server security group. If not supplied then it defaults to 0.0.0.0/0 for an IPv4 vpc or ::/o for
678+
a IPv6 vpc. This is ignored if IngressRules are explicitly supplied.
679+
items:
680+
type: string
681+
type: array
674682
disableHostsRewrite:
675683
description: |-
676684
DisableHostsRewrite disabled the hair pinning issue solution that adds the NLB's address as 127.0.0.1 to the hosts
@@ -1487,6 +1495,14 @@ spec:
14871495
14881496
Defaults to false.
14891497
type: boolean
1498+
defaultAllowedSourceCidrs:
1499+
description: |-
1500+
DefaultAllowedSourceCidrs is a list of allowed cidr blocks to allow as the source in the inbound rules for
1501+
the api server security group. If not supplied then it defaults to 0.0.0.0/0 for an IPv4 vpc or ::/o for
1502+
a IPv6 vpc. This is ignored if IngressRules are explicitly supplied.
1503+
items:
1504+
type: string
1505+
type: array
14901506
disableHostsRewrite:
14911507
description: |-
14921508
DisableHostsRewrite disabled the hair pinning issue solution that adds the NLB's address as 127.0.0.1 to the hosts

pkg/cloud/scope/cluster.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,20 @@ func (s *ClusterScope) ControlPlaneEndpoint() clusterv1.APIEndpoint {
235235
// return []string{cloud.AnyIPv4CidrBlock}
236236
// }
237237

238+
// DefaultAllowedAPIServerSources returns the cidr blocks to be used as the default allowed sources in the api server
239+
// security group inbound rule. Defaults to 0.0.0.0/0 or ::/0
240+
func (s *ClusterScope) DefaultAllowedAPIServerSources(ipv6 bool) []string {
241+
if s.AWSCluster.Spec.ControlPlaneLoadBalancer == nil || len(s.AWSCluster.Spec.ControlPlaneLoadBalancer.DefaultAllowedSourceCidrs) == 0 {
242+
if ipv6 {
243+
return []string{cloud.AnyIPv6CidrBlock}
244+
} else {
245+
return []string{cloud.AnyIPv4CidrBlock}
246+
}
247+
}
248+
249+
return s.AWSCluster.Spec.ControlPlaneLoadBalancer.DefaultAllowedSourceCidrs
250+
}
251+
238252
// Bucket returns the cluster bucket configuration.
239253
func (s *ClusterScope) Bucket() *infrav1.S3Bucket {
240254
return s.AWSCluster.Spec.S3Bucket

pkg/cloud/scope/managedcontrolplane.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,15 @@ func (s *ManagedControlPlaneScope) SecurityGroupOverrides() map[infrav1.Security
243243
// return []string{cloud.AnyIPv4CidrBlock}
244244
// }
245245

246+
// DefaultAllowedAPIServerSources returns the cidr blocks to be used as the default allowed sources in the api server
247+
// security group inbound rule. Defaults to 0.0.0.0/0
248+
func (s *ManagedControlPlaneScope) DefaultAllowedAPIServerSources(ipv6 bool) []string {
249+
if ipv6 {
250+
return []string{cloud.AnyIPv6CidrBlock}
251+
}
252+
return []string{cloud.AnyIPv4CidrBlock}
253+
}
254+
246255
// Name returns the CAPI cluster name.
247256
func (s *ManagedControlPlaneScope) Name() string {
248257
return s.Cluster.Name

pkg/cloud/scope/sg.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,8 @@ type SGScope interface {
6262

6363
// NodePortIngressRuleCidrBlocks returns the CIDR blocks for the node NodePort ingress rules.
6464
NodePortIngressRuleCidrBlocks() []string
65+
66+
// DefaultAllowedAPIServerSources returns the cidr blocks to be used as the default allowed sources in the api server
67+
// security group inbound rule. Defaults to 0.0.0.0/0 for IPv4 and the equivalent for IPV6.
68+
DefaultAllowedAPIServerSources(ipv6 bool) []string
6569
}

pkg/cloud/services/securitygroup/securitygroups.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ func (s *Service) getIngressRuleToAllowAnyIPInTheAPIServer() infrav1.IngressRule
977977
Protocol: infrav1.SecurityGroupProtocolTCP,
978978
FromPort: int64(s.scope.APIServerPort()),
979979
ToPort: int64(s.scope.APIServerPort()),
980-
IPv6CidrBlocks: []string{cloud.AnyIPv6CidrBlock},
980+
IPv6CidrBlocks: s.scope.DefaultAllowedAPIServerSources(true),
981981
},
982982
}
983983
}
@@ -988,7 +988,7 @@ func (s *Service) getIngressRuleToAllowAnyIPInTheAPIServer() infrav1.IngressRule
988988
Protocol: infrav1.SecurityGroupProtocolTCP,
989989
FromPort: int64(s.scope.APIServerPort()),
990990
ToPort: int64(s.scope.APIServerPort()),
991-
CidrBlocks: []string{cloud.AnyIPv4CidrBlock},
991+
CidrBlocks: s.scope.DefaultAllowedAPIServerSources(false),
992992
},
993993
}
994994
}

0 commit comments

Comments
 (0)