Set Up Firehose

The Guardrails Firehose generates an event stream of notifications sent to an AWS SNS topic. It's designed for streaming change events to downstream systems: data lakes, ticketing systems, and custom notification pipelines.

The Firehose answers the question "Can I get a stream of change events flowing through Guardrails?" It can't answer "How many controls are in ok?" or "How many storage buckets are in the environment?" For snapshots of environment state or bulk data extracts, use GraphQL or Steampipe.

[!NOTE] Only notifications created after Firehose configuration will be processed. There is no way to replay or resend historical notifications.

How It Works

Notification generated → Watch filter selects → Render template → Publish to AWS SNS → Downstream integrations
  1. As resources, controls, and policy settings change inside Guardrails, entries are added to the Notifications table.
  2. Watch filters select a subset of those notifications to send to the Firehose.
  3. Notifications pass through a Notification Template to prepare them for delivery.
  4. A background process publishes rendered notifications to the Firehose SNS topic.

Prerequisites

Step 1: Install the Firehose Mod

Install the firehose-aws-sns mod into your workspace if not already installed. See Install a Mod for instructions.

Step 2: Create AWS Resources

Create the following AWS resources. If you prefer Terraform, use the Firehose Terraform bootstrap.

  1. AWS SNS topic, in any account and region. All notifications will be forwarded to this topic.
  2. AWS IAM user, with publish-only access to the SNS topic. Use a dedicated user for Firehose (not shared with other services). The IAM policy should only grant sns:Publish to the Firehose topic ARN.
  3. Access key pair, for the IAM user.

Step 3: Configure Firehose Policies

Navigate to Policies and create policy settings for the following. These can ONLY be set at the Turbot (workspace root) level:

PolicyValue
Turbot > Firehose > AWS SNS > Notification TopicThe SNS topic ARN from Step 2.
Turbot > Firehose > AWS SNS > Notification Access KeyThe IAM user access key ID.
Turbot > Firehose > AWS SNS > Notification Secret KeyThe IAM user secret access key.

Step 4: Create Watches

Watches control which notifications flow through the Firehose. Without watches, no notifications are sent.

A watch specifies:

ParameterDescriptionCommon Value
actionThe action the watch takes on match (required).tmod:@turbot/firehose-aws-sns#/action/types/router
resourceThe resource scope for the watch (required).tmod:@turbot/turbot#/ (workspace root), a folder ID, or a cloud account ID.
filterA notification filter string (required).Varies by use case (see below).
favoriteA favorite to associate with the watch (optional).Varies.

Watch Filters

Watch filters determine which notifications match. See Notification Filters for the full filter syntax.

Supported Filter Pivots

KeywordValueExample
controlCategoryIdControl Category ID or AKAcontrolCategoryId:'tmod:@turbot/turbot#/control/categories/cmdbDiscovery'
controlCategoryLevelself and/or descendantcontrolCategoryLevel:self,descendant
controlTypeIdControl Type ID or AKAcontrolTypeId:'tmod:@turbot/aws-s3#/control/types/bucketVersioning'
controlTypeLevelself and/or descendantcontrolTypeLevel:self,descendant
levelself and/or descendantlevel:self
policyTypeIdPolicy Type ID or AKApolicyTypeId:'tmod:@turbot/aws-s3#/policy/types/bucketVersioning'
policyTypeLevelself and/or descendantpolicyTypeLevel:self,descendant
resourceCategoryIdResource Category ID or AKAresourceCategoryId:'tmod:@turbot/turbot#/resource/categories/storage'
resourceCategoryLevelself and/or descendantresourceCategoryLevel:self,descendant
resourceTypeIdResource Type ID or AKAresourceTypeId:'tmod:@turbot/aws-s3#/resource/types/bucket'
resourceTypeLevelself and/or descendantresourceTypeLevel:self
notificationTypeSee Supported Notification TypesnotificationType:active_grants_deleted

Supported Notification Types

ItemActionNotification TypeDescription
ActionNotifyaction_notifyA Guardrails action invokes a notify command during a run.
ControlChangecontrolAggregates both control_updated and control_notify.
ControlNotifycontrol_notifyA Guardrails control invokes a notify command during a run.
ControlUpdatedcontrol_updatedA control state change (e.g., ok → alarm).
FavoriteCreatedfavorite_createdA favorite is created for a resource.
FavoriteDeletedfavorite_deletedA favorite is deleted.
Grant ActivationCreatedactive_grants_createdA grant is activated.
Grant ActivationDeletedactive_grants_deletedA grant activation is deleted.
GrantCreatedgrant_createdA grant is created.
GrantDeletedgrant_deletedA grant is deleted.
Policy SettingCreatedpolicy_setting_createdA policy setting is created.
Policy SettingDeletedpolicy_setting_deletedA policy setting is deleted.
Policy SettingUpdatedpolicy_setting_updatedA policy setting is updated.
Policy ValueUpdatedpolicy_value_updatedA policy value is updated.
ResourceChangeresourceAggregates all resource_* notifications.
ResourceCreatedresource_createdA resource is created in Guardrails.
ResourceDeletedresource_deletedA resource is deleted.
ResourceUpdatedresource_updatedA resource is updated.

[!WARNING] Creating watches for notification types not listed above may cause system instability.

[!NOTE]

Common Filter Examples

Controls:

Resources:

Creating Filters Interactively

Manually constructing watch filter strings can be tedious. Instead, prototype your filters using the Activity report in the Guardrails console:

  1. Navigate to the Reports page and find the Activity Ledger report. The Firehose and Activity Ledger both examine the notifications table, so whatever rows show up in the report will match in the Firehose too.
  2. Customize the report filters to show exactly the notifications you want.
  3. Open the Developers tab on the report page and click one of the GraphQL queries.
  4. In the Query Variables section, find the filter value. This is the machine-generated filter string that matches your report.
  5. Copy the filter string into your watch configuration.

Step 5: Create Watches via Terraform or GraphQL

Terraform

resource "turbot_watch" "control_updates" {
  resource = "tmod:@turbot/turbot#/"
  action   = "tmod:@turbot/firehose-aws-sns#/action/types/router"
  filters  = [
    "level:self,descendant notificationType:control_updated"
  ]
}

GraphQL

Create a watch:

mutation CreateWatch($input: CreateWatchInput!) {
  createWatch(input: $input) {
    filters
    handler
    turbot {
      id
      resourceId
    }
  }
}
{
  "input": {
    "resource": "tmod:@turbot/turbot#/",
    "action": "tmod:@turbot/firehose-aws-sns#/action/types/router",
    "filters": ["level:self,descendant notificationType:control_updated"]
  }
}

List watches:

query MyWatches {
  watches(filter: "") {
    items {
      handler
      filters
      watchRules {
        metadata {
          filters
        }
      }
    }
  }
}

Delete a watch:

mutation DeleteMyWatch {
  deleteWatch(input: { id: "215276026059506" }) {
    handler
    filters
  }
}

Sample Notification

Below is a sample notification of type active_grants_deleted as it appears on the Firehose SNS topic:

{
  "notificationType": "active_grants_deleted",
  "actor": {
    "identity": {
      "picture": "https://www.gravatar.com/avatar/cb9ff8606c24daf9cda1d82615bd7a8e",
      "turbot": {
        "title": "Gary Anderson",
        "id": "186957187212252"
      },
      "title": "Gary Anderson"
    }
  },
  "turbot": {
    "id": "202473982728085",
    "createTimestamp": "2020-09-10T17:34:58.063Z"
  },
  "oldActiveGrant": {
    "grant": {
      "type": {
        "trunk": {
          "title": "Turbot"
        }
      },
      "level": {
        "trunk": {
          "title": "User > Metadata > ReadOnly"
        }
      },
      "resource": {
        "trunk": {
          "title": "Turbot"
        }
      },
      "identity": {
        "trunk": {
          "title": "Turbot > Goliath Federal Bank > Oscar Reyes"
        }
      }
    },
    "resource": {
      "trunk": {
        "title": "Turbot"
      }
    }
  }
}

Notification Templates

The Firehose uses Notification Templates to format events before publishing to SNS. Override the default templates via policies under Turbot > Firehose > AWS SNS > Notification Template > *. Each notification type has its own template.

The output is JSON by default but can be any format. Test template queries in the Developers > GraphQL Explorer before deploying.

[!NOTE] Notification templates cannot be made into calculated policies.

Troubleshooting

For reference, the data path:

Notification generated → Watch → Render template → Publish to SNS → Downstream integrations

Firehose Mod and Policies

IssueSolution
No notifications flowingIs the firehose-aws-sns mod installed without errors? Are the topic ARN, access key, and secret key policies set to correct values?
Mod installed but not workingCompare your setup against the Firehose Terraform bootstrap.

Watches

IssueSolution
No notifications matchingSet the watch to the broadest possible filter (e.g., all control_updated for all resources). This validates the data path. Refine later.
Filter not matching expected eventsPrototype the filter using the Activity Ledger report to eliminate typos.
Wrong scopeEnsure the watch is attached to the Turbot resource (tmod:@turbot/turbot#/), a folder, or a cloud account, not a control type or policy setting.
Easy testToggle a policy exception on a single resource from Check: Enabled to Check: Disabled and back to generate control_updated traffic.

SNS Topic and IAM User

IssueSolution
Messages not arriving on topicTest publishing to the topic using the AWS CLI with the Firehose IAM user credentials.
Subscription issuesEnable success/failure delivery logging on the SNS topic (disable after debugging in high-volume environments).
Topic permissionsVerify the IAM user has sns:Publish permission on the Firehose topic. No other permissions are needed.
Access key rotationPlan for regular access key rotation for the Firehose IAM user.

Downstream Integrations

IssueSolution
Lag between event and delivery30–60 seconds is typical. Up to 5 minutes under heavy load.
Events arriving but downstream not processingTest by manually publishing a message to the SNS topic and verifying the subscriber processes it.

Enterprise Customers

Check CloudWatch Logs at /aws/lambda/{turbot_prefix}_turbotfirehoseawssnssender-{hash} for publishing errors. SaaS customers should contact Guardrails Customer Success.

Next Steps