GoogleCloudPlatform / terraform-google-network-forensics

Deploys Zeek on Google Cloud
https://registry.terraform.io/modules/GoogleCloudPlatform/network-forensics/google
Apache License 2.0
25 stars 11 forks source link
cft-terraform networking

Google Zeek Automation Module

Terraform Version

This module simplifies the deployment of Zeek so GCP customers can feed raw packets from VPC Packet Mirroring and produce rich security telemetry for threat detection and investigation in our Chronicle Security Platform.

Compatibility

This module is meant for use with Terraform v0.13.5 or above.

Examples

Examples of how to use these modules can be found in the examples folder.

Architecture

Architecture

Features

Pre-requisites

  1. Packer Image should exist before running terraform script.
  2. Terraform is installed on the machine where Terraform is executed.
  3. The Service Account you execute the module with has the right permissions.
  4. The Compute Engine APIs are active on the project you will launch the infrastructure on.
  5. User must create a GCS Bucket.
  6. If Mirror VPC is in a different project, then the user will have to do the manual network peering from Mirror VPC to Collector VPC, if they want to mirror traffic from that project VPC.
  7. If Mirror VPC is in a different project, then the user will have to add an egress firewall rule in the Mirror VPC for redirecting incoming traffic to Collector VPC.

Packer Image

There are two ways for using packer image:

Use Pre-Configured Image

Create Your Own Custom Image

IAM

Service account or user credentials with the following roles must be used to provision the resources of this module:

In addition to above roles, for Mirror VPCs residing in different projects than Collector VPC, the Service account email used for provisioning Collector VPC resources must be added as IAM Member to respective Mirror VPC project with the following role:

Enable APIs

In order to operate with the Service Account you must activate the following APIs on the project where the Service Account was created:

Usage

module "google_zeek_automation" {
  source                = "<link>/google_zeek_automation"
  gcp_project           = "collector_project-123"
  service_account_email = "service-account@collector-project-123.iam.gserviceaccount.com"

  collector_vpc_name    = "collector-vpc"
  subnets = [
    {
      mirror_vpc_network          = "projects/mirror-project-123/global/networks/test-mirror"
      collector_vpc_subnet_cidr   = "10.11.0.0/24"
      collector_vpc_subnet_region = "us-west1"
    },
  ]

  mirror_vpc_subnets = {
    "mirror-project-123--mirror_vpc_name--us-west1" = ["projects/mirror-project-123/regions/us-west1/subnetworks/subnet-01"]
  }

}

Note: For packet mirroring policy, it requires a mirror source to be specified before running the script. So, out of 3 variables: mirror_vpc_instances | mirror_vpc_tags| mirror_vpc_subnets, at least one of them should be specified while running the terraform script.

Then perform the following commands on the root folder:

Software Dependencies

Terraform and Plugins

Inputs

Name Description Type Default Required
gcp_project GCP Project ID where collector vpc will be provisioned. string n/a yes
golden_image This is name of zeek-fluentd packer image string "projects/zeekautomation/global/images/zeek-fluentd-golden-image-v1" no
collector_vpc_name This is name of collector vpc. string n/a yes
mirror_vpc_instances Mirror VPC Instances list to be mirrored.

(Note: Mirror VPC should reside in the same project as collector VPC because cross project referencing of instances is not allowed by GCP)
map(list(string)) {} no
mirror_vpc_subnets Mirror VPC Subnets list to be mirrored. map(list(string)) {} no
mirror_vpc_tags Mirror VPC Tags list to be mirrored. map(list(string)) {} no
service_account_email User's Service Account Email. string n/a yes
subnets The list of subnets being created
list(object({
mirror_vpc_network = string
collector_vpc_subnet_cidr = string
collector_vpc_subnet_region = string
}))
n/a yes

Outputs

Name Description
autoscaler_ids Autoscaler identifier for the resource with format projects/{{project}}/regions/{{region}}/autoscalers/{{name}}
collector_vpc_network_id The identifier of the VPC network with format projects/{{project}}/global/networks/{{name}}.
collector_vpc_subnets_ids Sub Network identifier for the resource with format projects/{{project}}/regions/{{region}}/subnetworks/{{name}}
forwarding_rule_ids Forwarding Rule identifier for the resource with format projects/{{project}}/regions/{{region}}/forwardingRules/{{name}}
health_check_id Health Check identifier for the resource with format projects/{{project}}/global/healthChecks/{{name}}
intance_group_ids Managed Instance Group identifier for the resource with format {{disk.name}}
intance_groups The full URL of the instance group created by the manager.
intance_template_ids Instance Templates identifier for the resource with format projects/{{project}}/global/instanceTemplates/{{name}}
loadbalancer_ids Internal Load Balancer identifier for the resource with format projects/{{project}}/regions/{{region}}/backendServices/{{name}}
packet_mirroring_policy_ids Packet Mirroring Policy identifier for the resource with format projects/{{project}}/regions/{{region}}/packetMirrorings/{{name}}

Specifying credentials

The Google Zeek Automation uses external scripts to perform a few tasks that are not implemented by Terraform providers. Because of this the Google Zeek Automation needs a copy of service account credentials to pass to these scripts. Credentials can be provided via two mechanisms:

  1. Explicitly passed to the Google Zeek Automation with the credentials variable. This approach typically uses the same credentials for the google provider and the Google Zeek Automation:

    provider "google" {
      credentials = "${file(var.credentials)}"
    }
    
    module "google_zeek_automation" {
      source = "<link>/google_zeek_automation"
    
      # other variables follow ...
    }
  2. Implicitly provided by the Application Default Credentials flow, which typically uses the GOOGLE_APPLICATION_CREDENTIALS environment variable:

    # `GOOGLE_APPLICATION_CREDENTIALS` must be set in the environment before Terraform is run.
    provider "google" {
     # Terraform will check the `GOOGLE_APPLICATION_CREDENTIALS` variable, so no `credentials`
     # value is needed here.
    }
    
    module "google_zeek_automation" {
      source = "<link>/google_zeek_automation"
    
      # Google Zeek Automation will also check the `GOOGLE_APPLICATION_CREDENTIALS` environment variable.
      # other variables follow ...
    }

Learn

Core concepts

Repo organisation

This repo has the following folder structure:

Contributions

Contributions to this repo are very welcome and appreciated! If you find a bug or want to add a new feature or even contribute an entirely new module, we are very happy to accept pull requests, provide feedback, and run your changes through our automated test suite.

Please see contributing guidelines for information on contributing to this module.

Troubleshooting