Skip to content

Commit e4f3ed3

Browse files
Merge pull request #8374 from bfournie/gcp-bootstrap-firewall-ssh
CORS-3297: Add GCP firewall rule to access bootstrap node via ssh
2 parents 13aca6a + 942227a commit e4f3ed3

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

pkg/infrastructure/gcp/clusterapi/clusterapi.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ func (p Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput)
144144
logrus.Debugf("publish strategy is set to external but api address is empty")
145145
}
146146

147+
if err := createBootstrapFirewallRules(ctx, in, *gcpCluster.Status.Network.SelfLink); err != nil {
148+
return fmt.Errorf("failed to add bootstrap firewall rule: %w", err)
149+
}
150+
147151
client, err := icgcp.NewClient(context.TODO())
148152
if err != nil {
149153
return err
@@ -222,7 +226,6 @@ func (p Provider) DestroyBootstrap(dir string) error {
222226
if err != nil {
223227
return err
224228
}
225-
226229
if err := gcp.DestroyStorage(context.Background(), metadata.ClusterID); err != nil {
227230
return fmt.Errorf("failed to destroy storage")
228231
}

pkg/infrastructure/gcp/clusterapi/firewallrules.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"google.golang.org/api/compute/v1"
99

1010
"github.com/openshift/installer/pkg/infrastructure/clusterapi"
11+
"github.com/openshift/installer/pkg/types"
1112
)
1213

1314
func getControlPlanePorts() []*compute.FirewallAllowed {
@@ -108,6 +109,20 @@ func getInternalNetworkPorts() []*compute.FirewallAllowed {
108109
}
109110
}
110111

112+
func getBootstrapSSHPorts() []*compute.FirewallAllowed {
113+
return []*compute.FirewallAllowed{
114+
{
115+
IPProtocol: "tcp",
116+
Ports: []string{
117+
"22", // SSH
118+
},
119+
},
120+
{
121+
IPProtocol: "icmp",
122+
},
123+
}
124+
}
125+
111126
// addFirewallRule creates the firewall rule and adds it the compute's firewalls.
112127
func addFirewallRule(ctx context.Context, name, network, projectID string, ports []*compute.FirewallAllowed, srcTags, targetTags, srcRanges []string) error {
113128
service, err := NewComputeService()
@@ -146,7 +161,7 @@ func addFirewallRule(ctx context.Context, name, network, projectID string, ports
146161
return nil
147162
}
148163

149-
// createFirewallRules creates the rules needed between tthe worker and master nodes.
164+
// createFirewallRules creates the rules needed between the worker and master nodes.
150165
func createFirewallRules(ctx context.Context, in clusterapi.InfraReadyInput, network string) error {
151166
projectID := in.InstallConfig.Config.Platform.GCP.ProjectID
152167
workerTag := fmt.Sprintf("%s-worker", in.InfraID)
@@ -189,3 +204,20 @@ func createFirewallRules(ctx context.Context, in clusterapi.InfraReadyInput, net
189204

190205
return err
191206
}
207+
208+
// createBootstrapFirewallRules creates the rules needed for the bootstrap node.
209+
func createBootstrapFirewallRules(ctx context.Context, in clusterapi.InfraReadyInput, network string) error {
210+
projectID := in.InstallConfig.Config.Platform.GCP.ProjectID
211+
firewallName := fmt.Sprintf("%s-bootstrap-in-ssh", in.InfraID)
212+
srcTags := []string{}
213+
bootstrapTag := fmt.Sprintf("%s-control-plane", in.InfraID)
214+
targetTags := []string{bootstrapTag}
215+
var srcRanges []string
216+
if in.InstallConfig.Config.Publish == types.ExternalPublishingStrategy {
217+
srcRanges = []string{"0.0.0.0/0"}
218+
} else {
219+
machineCIDR := in.InstallConfig.Config.Networking.MachineNetwork[0].CIDR.String()
220+
srcRanges = []string{machineCIDR}
221+
}
222+
return addFirewallRule(ctx, firewallName, network, projectID, getBootstrapSSHPorts(), srcTags, targetTags, srcRanges)
223+
}

0 commit comments

Comments
 (0)