OpenMCF logoOpenMCF

Loading...

GCP Firewall Rule

Deploys a GCP compute firewall rule (google_compute_firewall) with an action + rules abstraction for allow/deny traffic control, supporting INGRESS/EGRESS directions, CIDR-based source/destination filtering, network tags, service account targeting, priority, logging, and a disabled toggle.

What Gets Created

When you deploy a GcpFirewallRule resource, OpenMCF provisions:

  • Firewall Rule — a google_compute_firewall resource in the specified VPC network with allow or deny blocks generated from the action and rules fields

Prerequisites

  • GCP credentials configured via environment variables or OpenMCF provider config
  • An existing GCP project — referenced via projectId
  • An existing VPC network — referenced via network (name or self-link)
  • Compute Engine API enabled (compute.googleapis.com) on the target project
  • IAM permissions — roles/compute.securityAdmin or roles/compute.networkAdmin on the target project

Quick Start

Create a file firewall.yaml:

apiVersion: gcp.openmcf.org/v1
kind: GcpFirewallRule
metadata:
  name: allow-web
  labels:
    openmcf.org/provisioner: pulumi
    pulumi.openmcf.org/organization: my-org
    pulumi.openmcf.org/project: my-project
    pulumi.openmcf.org/stack.name: dev.GcpFirewallRule.allow-web
spec:
  projectId:
    value: my-gcp-project-123
  network:
    value: my-vpc
  ruleName: allow-http-https
  direction: INGRESS
  action: ALLOW
  rules:
    - protocol: tcp
      ports:
        - "80"
        - "443"
  sourceRanges:
    - "0.0.0.0/0"
  targetTags:
    - web-server

Deploy:

openmcf apply -f firewall.yaml

This creates an INGRESS firewall rule that allows HTTP and HTTPS traffic from any source to instances tagged web-server in the my-vpc network.

Configuration Reference

Required Fields

FieldTypeDescriptionValidation
projectIdStringValueOrRefGCP project ID where the firewall rule is created. Can reference a GcpProject resource.Required
networkStringValueOrRefVPC network name or self-link URL. Can reference a GcpVpc resource.Required
ruleNamestringName of the firewall rule in GCP.1-63 chars, lowercase letters/numbers/hyphens
directionstringTraffic direction: INGRESS or EGRESS.Required
actionstringAction when traffic matches: ALLOW or DENY.Required
rulesGcpFirewallProtocolPort[]Protocol and port combinations to match.Min 1 item
rules[].protocolstringIP protocol: tcp, udp, icmp, esp, ah, sctp, ipip, all, or an IANA protocol number.Required
rules[].portsstring[]Ports or port ranges (e.g., "80", "8000-9000"). Only applicable for tcp or udp. Omit for other protocols.—

Optional Fields

FieldTypeDefaultDescription
priorityint321000Rule priority (0-65535). Lower = higher priority.
descriptionstring""Human-readable description.
sourceRangesstring[]—Source CIDRs for INGRESS rules.
destinationRangesstring[]—Destination CIDRs for EGRESS rules.
sourceTagsstring[]—Source instance network tags (INGRESS). Mutually exclusive with service account fields.
targetTagsstring[]—Target instance network tags. Mutually exclusive with service account fields.
sourceServiceAccountsstring[]—Source service accounts for INGRESS (max 10). Mutually exclusive with tag fields.
targetServiceAccountsstring[]—Target service accounts (max 10). Mutually exclusive with tag fields.
disabledboolfalseWhen true, rule exists but is not enforced.
logConfig.metadatastring—Enables logging. Must be EXCLUDE_ALL_METADATA or INCLUDE_ALL_METADATA.

Examples

Basic INGRESS ALLOW for Web Traffic

apiVersion: gcp.openmcf.org/v1
kind: GcpFirewallRule
metadata:
  name: allow-web
  labels:
    openmcf.org/provisioner: pulumi
    pulumi.openmcf.org/organization: my-org
    pulumi.openmcf.org/project: my-project
    pulumi.openmcf.org/stack.name: dev.GcpFirewallRule.allow-web
spec:
  projectId:
    value: my-gcp-project-123
  network:
    value: my-vpc
  ruleName: allow-http-https
  direction: INGRESS
  action: ALLOW
  rules:
    - protocol: tcp
      ports:
        - "80"
        - "443"
  sourceRanges:
    - "0.0.0.0/0"
  targetTags:
    - web-server

INGRESS ALLOW for SSH via IAP

apiVersion: gcp.openmcf.org/v1
kind: GcpFirewallRule
metadata:
  name: allow-iap-ssh
  labels:
    openmcf.org/provisioner: pulumi
    pulumi.openmcf.org/organization: my-org
    pulumi.openmcf.org/project: my-project
    pulumi.openmcf.org/stack.name: dev.GcpFirewallRule.allow-iap-ssh
spec:
  projectId:
    value: my-gcp-project-123
  network:
    value: my-vpc
  ruleName: allow-iap-ssh
  direction: INGRESS
  action: ALLOW
  rules:
    - protocol: tcp
      ports:
        - "22"
  sourceRanges:
    - "35.235.240.0/20"
  description: Allow SSH from Google IAP tunnel IP range

EGRESS DENY All (Restrictive Baseline)

apiVersion: gcp.openmcf.org/v1
kind: GcpFirewallRule
metadata:
  name: deny-all-egress
  labels:
    openmcf.org/provisioner: pulumi
    pulumi.openmcf.org/organization: my-org
    pulumi.openmcf.org/project: my-project
    pulumi.openmcf.org/stack.name: prod.GcpFirewallRule.deny-all-egress
spec:
  projectId:
    value: my-prod-project-456
  network:
    value: prod-vpc
  ruleName: deny-all-egress
  direction: EGRESS
  action: DENY
  rules:
    - protocol: all
  priority: 65534
  destinationRanges:
    - "0.0.0.0/0"
  description: Deny all outbound traffic by default

Stack Outputs

After deployment, the following outputs are available in status.outputs:

OutputTypeDescription
firewall_self_linkstringFull self-link URI of the firewall rule (e.g., projects/my-project/global/firewalls/allow-http-https)
firewall_namestringName of the firewall rule as it exists in GCP
creation_timestampstringRFC 3339 timestamp of when the firewall rule was created

Related Components

  • GcpVpc — provides the VPC network that firewall rules are attached to
  • GcpProject — provides the GCP project and enables the Compute Engine API
  • GcpSubnetwork — creates subnets within the VPC
  • GcpGkeCluster — deploys GKE clusters that benefit from firewall rules for node traffic control

Next article

GCP GCS Bucket

GCP GCS Bucket Deploys a Google Cloud Storage bucket with full control over storage class, access model, lifecycle management, encryption, CORS, static website hosting, and IAM bindings. The bucket is created in the specified GCP project and location with Uniform Bucket-Level Access enabled by default. What Gets Created When you deploy a GcpGcsBucket resource, OpenMCF provisions: GCS Bucket — a Cloud Storage bucket in the specified project and location, with labels, storage class, and access...
Read next article
Presets
3 ready-to-deploy configurationsView presets →