@@ -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+
1422func 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.
211219func 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