Skip to content

Commit 9526425

Browse files
Merge pull request openshift#8706 from barbacbd/capg-xpn-skip-firewall-creation
OCPBUGS-35262: Skip firewall rule creation if permission is missing
2 parents 35ac64a + 9f7e393 commit 9526425

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pkg/infrastructure/gcp/clusterapi/firewallrules.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@ import (
55
"fmt"
66
"time"
77

8+
"github.com/sirupsen/logrus"
89
"google.golang.org/api/compute/v1"
910

11+
gcpconfig "github.com/openshift/installer/pkg/asset/installconfig/gcp"
1012
"github.com/openshift/installer/pkg/infrastructure/clusterapi"
1113
"github.com/openshift/installer/pkg/types"
1214
)
1315

16+
const (
17+
// gcpFirewallPermission is the role/permission to create or skip the creation of
18+
// firewall rules for GCP during a xpn installation.
19+
gcpFirewallPermission = "compute.firewalls.create"
20+
)
21+
1422
func getEtcdPorts() []*compute.FirewallAllowed {
1523
return []*compute.FirewallAllowed{
1624
{
@@ -209,6 +217,25 @@ func deleteFirewallRule(ctx context.Context, name, projectID string) error {
209217

210218
// createFirewallRules creates the rules needed between the worker and master nodes.
211219
func createFirewallRules(ctx context.Context, in clusterapi.InfraReadyInput, network string) error {
220+
if projID := in.InstallConfig.Config.GCP.NetworkProjectID; projID != "" {
221+
client, err := gcpconfig.NewClient(context.Background())
222+
if err != nil {
223+
return fmt.Errorf("failed to create client during firewall rule creation: %w", err)
224+
}
225+
226+
permissions, err := client.GetProjectPermissions(ctx, projID, []string{
227+
gcpFirewallPermission,
228+
})
229+
if err != nil {
230+
return fmt.Errorf("failed to find project permissions during firewall creation: %w", err)
231+
}
232+
233+
if !permissions.Has(gcpFirewallPermission) {
234+
logrus.Warnf("failed to find permission %s, skipping firewall rule creation", gcpFirewallPermission)
235+
return nil
236+
}
237+
}
238+
212239
projectID := in.InstallConfig.Config.Platform.GCP.ProjectID
213240
if in.InstallConfig.Config.Platform.GCP.NetworkProjectID != "" {
214241
projectID = in.InstallConfig.Config.Platform.GCP.NetworkProjectID

0 commit comments

Comments
 (0)