Skip to content

Commit f846460

Browse files
committed
aws/cluster: restrict SSH on private clusters
Prior to this change, SSH was open to the public internet when installing on a private cluster. This restricts SSH to the machine network.
1 parent 4ae7799 commit f846460

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pkg/asset/manifests/aws/cluster.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/openshift/installer/pkg/asset/installconfig"
1515
"github.com/openshift/installer/pkg/asset/machines/aws"
1616
"github.com/openshift/installer/pkg/asset/manifests/capiutils"
17-
"github.com/openshift/installer/pkg/types"
1817
)
1918

2019
// BootstrapSSHDescription is the description for the
@@ -31,6 +30,11 @@ func GenerateClusterAssets(ic *installconfig.InstallConfig, clusterID *installco
3130
return nil, fmt.Errorf("failed to get user tags: %w", err)
3231
}
3332

33+
sshRuleCidr := []string{"0.0.0.0/0"}
34+
if !ic.Config.PublicAPI() {
35+
sshRuleCidr = []string{capiutils.CIDRFromInstallConfig(ic).String()}
36+
}
37+
3438
awsCluster := &capa.AWSCluster{
3539
ObjectMeta: metav1.ObjectMeta{
3640
Name: clusterID.InfraID,
@@ -142,7 +146,7 @@ func GenerateClusterAssets(ic *installconfig.InstallConfig, clusterID *installco
142146
Protocol: capa.SecurityGroupProtocolTCP,
143147
FromPort: 22,
144148
ToPort: 22,
145-
CidrBlocks: []string{"0.0.0.0/0"},
149+
CidrBlocks: sshRuleCidr,
146150
},
147151
},
148152
},
@@ -193,7 +197,7 @@ func GenerateClusterAssets(ic *installconfig.InstallConfig, clusterID *installco
193197
}
194198
awsCluster.SetGroupVersionKind(capa.GroupVersion.WithKind("AWSCluster"))
195199

196-
if ic.Config.Publish == types.ExternalPublishingStrategy {
200+
if ic.Config.PublicAPI() {
197201
awsCluster.Spec.SecondaryControlPlaneLoadBalancer = &capa.AWSLoadBalancerSpec{
198202
Name: ptr.To(clusterID.InfraID + "-ext"),
199203
LoadBalancerType: capa.LoadBalancerTypeNLB,

0 commit comments

Comments
 (0)