Skip to content

Commit c8febae

Browse files
Merge pull request openshift#8462 from patrickdillon/OCPBUGS-34389-ssh-private
OCPBUGS-34389: aws/cluster: restrict SSH on private clusters
2 parents 185e41f + f846460 commit c8febae

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-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,

pkg/types/installconfig.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,3 +591,16 @@ func ClusterAPIFeatureGateEnabled(platform string, fgs featuregates.FeatureGate)
591591
return false
592592
}
593593
}
594+
595+
// PublicAPI indicates whether the API load balancer should be public
596+
// by inspecting the cluster and operator publishing strategies.
597+
func (c *InstallConfig) PublicAPI() bool {
598+
if c.Publish == ExternalPublishingStrategy {
599+
return true
600+
}
601+
602+
if op := c.OperatorPublishingStrategy; op != nil && strings.EqualFold(op.APIServer, "External") {
603+
return true
604+
}
605+
return false
606+
}

0 commit comments

Comments
 (0)