exec

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2019 License: Apache-2.0 Imports: 18 Imported by: 0

README

Security Response Automation

Setup automated actions to run on your security findings. You can use our predefined functions to auto-remediate findings as they come in or write and customize your own.

  • Automatically create a disk snapshot to enable future forensic investigations.
  • Revoke IAM grants that violate your desired policy.
  • Notify other systems such as Turbinia, PagerDuty, Slack or just send an email.

You can selectively control which resources are enforced by each function. Every action is logged and you can also run in dry_run mode where changes are not saved.

Note

This project is currently under development and is not yet ready for users. Stay tuned! If you do decide to use this library early and have any questions please reach out to tomfitzgerald@google.com for help.

Getting Started

This repository contains Cloud Functions to take automated actions on findings from Event Threat Detection and Security Health Analytics (SHA). For example, if SHA alerts you that a Google Cloud Storage bucket is open you may want to close it, or perhaps leave it alone if its meant to be public.

Configuration

Before installation we'll configure our automations, rename or copy empty-settings.json to settings.json. This is done because settings.json is ignored by Git so your changes are kept out of our repository and you don't accidently lose your changes. Within this file we'll restrict our automations to only take actions if the affected resource are within a set of resource IDs we declare. For example, you may want to revoke IAM grants in your development environment but in your prod environment you may want to monitor only.

  • For a full list of automations and their individual configurations see automations.
  • For each resource ID (folder, project, or organization) you configure below you'll also need to modify (main.tf)[/main.tf] so Terraform can grant the required permissions.

Each automation that considers resources will support the following resources:

Resources
  • Project IDs folder_ids: Take the action if the affected project ID is within this set.
  • Folder IDs project_ids: Take the action if the affected project ID has an ancestor of a folder ID within this set.
  • Organization ID organization_id: Take the action if the affected project ID is within this organization ID.

Each automation will check if it's affected project is within the configured resources and only take an action if there's a match. Setting an organization_id in a automation's configuration will allow every project within the organization to affected by that automation.

Example

In the automations documentation we see that this automation is configured in settings.json under the revoke_iam key. Within this key we'll fill out which projects will be enforced, in this example we'll specify a folder along with an allow list of expected domains.

{
  "revoke_grants": {
    "resources": {
      "folder_ids": ["670032686187"],
      "organization_id": "",
      "project_ids": []
    },
    "allow_domains": ["google.com", "googleplex.com"]
  }
}

Since we're using folders we'll also want to modify main.tf to inform Terraform which folders we're enforcing so the required roles are automatically granted. If you choose you can leave out this step but you must authorize the SRA service account to have the necessary roles to revoke the IAM grants. You could grant the account Project IAM Admin role on each project ID you want enforced then add the project IDs to the above project_ids key. You could also grant the role at the organization level and enter your organzation ID in the organization_id.

module "revoke_iam_grants" {
  source = "./terraform/automations/revoke-iam-grants"
  setup  = "${module.google-setup}"
  folder-ids = [
    "670032686187",
  ]
}
Installation

Following these instructions will deploy all automations. Before you get started be sure you have (at least) Go version 1.11 installed.

$ gcloud auth application-default login
$ terraform init

// Install all Functions.
$ terraform apply

// Install a single Function.
$ terraform apply --target module.revoke_iam_grants

TIP: Instead of entering variables every time you can create terraform.tfvars file and input key value pairs there, i.e. automation-project="aerial-jigsaw-235219".

If at any point you want to revert the changes we've made just run terraform destroy .

CSCC Notifications

Security Health Analytics requires CSCC notifications to be setup. This requires your account to be added to a early access group, please ping tomfitzgerald@google.com to be added. You can then create a new notification config that will send all CSCC findings to a Pub/Sub topic.

$ export PROJECT_ID=<YOUR_AUTOMATION_PROJECT_ID>
$ export SERVICE_ACCOUNT_EMAIL=automation-service-account@$PROJECT_ID.iam.gserviceaccount.com \
  ORGANIZATION_ID=<YOUR_ORGANIZATION_ID> \
  TOPIC_ID=cscc-notifications-topic

$ gcloud organizations add-iam-policy-binding $ORGANIZATION_ID \
  --member="serviceAccount:$SERVICE_ACCOUNT_EMAIL" \
  --role='roles/pubsub.admin'

$ go run ./local/cli/main.go \
  --command create \
  --org-id=$ORGANIZATION_ID \
  --topic=projects/$PROJECT_ID/topics/cscc-notifications-topic12w

// Note the output, specifically the generated `service_acount`:
//
// 2019/11/07 14:06:00 New NotificationConfig created: \
// name:"organizations/1037840971520/notificationConfigs/sampleConfigId"
// description:"Notifies active findings"
// event_type:FINDING pubsub_topic:"projects/ae-threat-detection/topics/cscc-notifications-topic"
// service_account:"service-459837319394@gcp-sa-scc-notification.iam.gserviceaccount.com"
// streaming_config:<filter:"state = \"ACTIVE\"" >
//
// Make sure to replace `SERVICE_ACCOUNT_FROM_ABOVE` with the generated service account.
gcloud beta pubsub topics add-iam-policy-binding projects/$PROJECT_ID/topics/$TOPIC_ID \
  --member="serviceAccount:<SERVICE_ACCOUNT_FROM_ABOVE>" \
  --role="roles/pubsub.publisher"

gcloud organizations remove-iam-policy-binding $ORGANIZATION_ID \
  --member="serviceAccount:$SERVICE_ACCOUNT_EMAIL" \
  --role='roles/pubsub.admin'
Reinstalling a Cloud Function

Terraform will create or destroy everything by default. To redeploy a single Cloud Function you can do:

$ zip -r ./deploy/functions.zip . -x *deploy* -x *.git* -x *.terraform*
$ terraform apply .

Then visit Cloud Console, Cloud Functions, click the Function name, edit then deploy.

Test
$ go test ./...
Logging

Each Cloud Function logs its actions to the below log location. This can be accessed by visiting StackDriver and clicking on the arrow on the right hand side then 'Convert to advanced filter'. Then paste in the below filter making sure to change the project ID to the project where your Cloud Functions are installed.

logName="projects/{{ project_id }}/logs/security-response-automation"

Documentation

Overview

Package exec is the entry point for security automation Cloud Functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseBucket

func CloseBucket(ctx context.Context, m pubsub.Message) error

CloseBucket will remove any public users from buckets found within the provided folders.

Permissions required

  • roles/viewer to retrieve ancestry.
  • roles/storeage.admin to modify buckets.

func CloseCloudSQL

func CloseCloudSQL(ctx context.Context, m pubsub.Message) error

CloseCloudSQL removes public IP for a Cloud SQL instance.

This Cloud Function will respond to Security Health Analytics **Public SQL Instance** findings from **SQL Scanner**. All public IP addresses of the affected instance will be deleted when this function is activated.

Permissions required

  • roles/cloudsql.editor to get instance data and delete access config.

func ClosePublicDataset

func ClosePublicDataset(ctx context.Context, m pubsub.Message) error

ClosePublicDataset removes public access of a BigQuery dataset.

This Cloud Function will respond to Security Health Analytics **Public Dataset** findings from **Dataset Scanner**. All public access of the affected dataset will be removed when this function is activated.

Permissions required

  • roles/bigquery.dataOwner to get and update dataset metadata.

func CloudSQLRequireSSL

func CloudSQLRequireSSL(ctx context.Context, m pubsub.Message) error

CloudSQLRequireSSL enables the SSL requirement for a Cloud SQL instance.

This Cloud Function will respond to Security Health Analytics **Public SQL Instance** findings from **SQL Scanner**. All public IP addresses of the affected instance will be deleted when this function is activated.

Permissions required

  • roles/cloudsql.editor to get instance data and delete access config.

func DisableDashboard

func DisableDashboard(ctx context.Context, m pubsub.Message) error

DisableDashboard will disable the Kubernetes dashboard addon.

This Cloud Function will respond to Security Health Analytics **Web UI Enabled** findings from **Container Scanner**. The Kubernetes dashboard addon will be disabled when this function is activated.

Permissions required

  • roles/container.clusterAdmin update cluster addon.

func EnableAuditLogs

func EnableAuditLogs(ctx context.Context, m pubsub.Message) error

EnableAuditLogs enables the Audit Logs to specific project

This Cloud Function will respond to Security Health Analytics **AUDIT_LOGGING_DISABLED** findings from **LOGGING_SCANNER**.

Permissions required

  • roles/resourcemanager.folderAdmin to get/update resource policy from projects in folder.
  • roles/editor to get/update resource policy to specific project.

func EnableBucketOnlyPolicy

func EnableBucketOnlyPolicy(ctx context.Context, m pubsub.Message) error

EnableBucketOnlyPolicy Enable bucket only policy on a GCS bucket.

This Cloud Function will respond to Security Health Analytics **BUCKET_POLICY_ONLY_DISABLED** findings from **STORAGE_SCANNER**. Bucket only IAM policy will be enforced on the bucket.

Permissions required

  • roles/storage.admin to change the Bucket policy mode.

func IAMRevoke

func IAMRevoke(ctx context.Context, m pubsub.Message) error

IAMRevoke is the entry point for the IAM revoker Cloud Function.

This function will attempt to revoke the external members added to the policy if they match the provided list of disallowed domains. Additionally this method will only remove members if the project they were added to is within the specified folders. This configuration allows you to take a remediation action only on specific members and folders. For example, you may have a folder "development" where users can experiment without strict policies. However in your "production" folder you may want to revoke any grants that ETD finds as long as they match the domains you specify.

Permissions required

  • roles/resourcemanager.folderAdmin to revoke IAM grants.
  • roles/viewer to verify the affected project is within the enforced folder.

func OpenFirewall

func OpenFirewall(ctx context.Context, m pubsub.Message) error

OpenFirewall will remediate an open firewall.

Permissions required

  • roles/viewer to retrieve ancestry.
  • roles/compute.securityAdmin to modify firewall rules.

func RemoveNonOrganizationMembers

func RemoveNonOrganizationMembers(ctx context.Context, m pubsub.Message) error

RemoveNonOrganizationMembers removes all members that do not match the organization domain.

This Cloud Function will respond to Security Health Analytics **NON_ORG_IAM_MEMBER** findings from **IAM Scanner**. All user member types (user:) that do not correspond to the organization will be removed from policy binding.

Permissions required

  • roles/resourcemanager.organizationAdmin to get org info and policies and set policies.

func RemovePublicIP

func RemovePublicIP(ctx context.Context, m pubsub.Message) error

RemovePublicIP removes all the external IP addresses of a GCE instance.

This Cloud Function will respond to Security Health Analytics **Public IP Address** findings from **Compute Instance Scanner**. All public IP addresses of the affected instance will be deleted when this function is activated.

Permissions required

  • roles/compute.instanceAdmin.v1 to get instance data and delete access config.

func SnapshotDisk

func SnapshotDisk(ctx context.Context, m pubsub.Message) error

SnapshotDisk is the entry point for the auto creation of GCE snapshots Cloud Function.

Once a supported finding is received this Cloud Function will look for any existing disk snapshots for the affected instance. If there are recent snapshots then no action is taken. This is so we do not overwrite a recent snapshot. If we have not taken a snapshot recently, take a new snapshot for each disk within the instance.

Permissions required

  • roles/compute.instanceAdmin.v1 to manage disk snapshots.

func UpdatePassword

func UpdatePassword(ctx context.Context, m pubsub.Message) error

UpdatePassword updates the root password for a Cloud SQL instance.

This Cloud Function will respond to Security Health Analytics **SQL No Root Password** findings from **SQL Scanner**. The root user of the affected instance will be updated with a new password when this function is activated.

Permissions required

  • roles/cloudsql.admin to update a user password.

Types

This section is empty.

Directories

Path Synopsis
Package clients holds client libraries used by security automation Cloud Functions.
Package clients holds client libraries used by security automation Cloud Functions.
cscc/apiv1p1alpha1
Package securitycenter is an auto-generated package for the Cloud Security Command Center API.
Package securitycenter is an auto-generated package for the Cloud Security Command Center API.
stubs
Package stubs provides testable stubs for clients.
Package stubs provides testable stubs for clients.
cloudfunctions
iam/revoke
Package revoke provides the implementation of automated actions.
Package revoke provides the implementation of automated actions.
compiled
sha
Package protos is a generated protocol buffer package.
Package protos is a generated protocol buffer package.
sha/protos
Package sha is a generated protocol buffer package.
Package sha is a generated protocol buffer package.
local
cli command
This package will create a CSCC notification config that sends all active findings to the specified Pub/Sub topic.
This package will create a CSCC notification config that sends all active findings to the specified Pub/Sub topic.
debug command
Package main runs a Cloud Function locally.
Package main runs a Cloud Function locally.
providers
etd
sha
Package sha holds Security Health Analytics finding entities and functions
Package sha holds Security Health Analytics finding entities and functions
Package services holds commonly used methods used in security automation.
Package services holds commonly used methods used in security automation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL