Real-Time Events
Guardrails needs to know when resources change in your GCP projects so it can update the CMDB, evaluate controls, and take enforcement actions. There are two mechanisms for delivering these change notifications. You choose one for each project.
Choosing the Right Mechanism
| Event Pollers | Event Handlers | |
|---|---|---|
| How it works | Guardrails periodically queries GCP Logging (Cloud Audit Logs) for recent API events. | Logging sinks and Pub/Sub deliver events to Guardrails in near real-time. |
| Latency | 1–10 minutes (configurable polling interval). | Near real-time (seconds). |
| Scalability | Limited. GCP Logging entries.list API has a rate limit of 1 call per second per project. As project count grows per service account, polling dominates API quota. | Excellent. Pub/Sub handles high event volumes natively. |
| GCP infrastructure | None. Guardrails uses existing Cloud Audit Log data via API. | Logging Sink, Pub/Sub Topic, Pub/Sub Subscription, and IAM policy per project. |
| Setup complexity | Lowest. Enabled by default, no GCP resources needed. | Moderate. Requires Pub/Sub and Logging APIs enabled, plus Guardrails deploys infrastructure via Terraform stacks. |
| Recommended for | Development environments, POCs, projects with very low activity. | Production environments. The recommended mechanism for all projects. |
| Status | Active (default for new projects). | Preferred. |
How They Relate
These two mechanisms are mutually exclusive. You should only have one active at a time for each project. If you enable event handlers, the event pollers stop running automatically. Event Handlers and Event Pollers should never be enabled at the same time. Duplicate event processing is highly undesirable.
The typical progression is:
- Start with Event Pollers, enabled by default when you connect a project. Works immediately with no setup.
- Upgrade to Event Handlers when you're ready for production-grade real-time events. This is the recommended configuration.
[!NOTE] Event pollers operate based on the value of the
GCP > Turbot > Event Handlerspolicy, not on the state of the Event Handler controls. When Event Handling is enabled, pollers stop running automatically. If event handler controls go into an error state, pollers still won't run. Resolve event handler issues as quickly as possible to avoid losing events.
GCP Logging Dependency
Both mechanisms depend on Cloud Audit Logs being active in your projects. GCP automatically logs Admin Activity audit logs, which capture resource creation, modification, and deletion events.
- Event Pollers: Directly query the Cloud Audit Logs
entries.listAPI. - Event Handlers: Cloud Audit Logs feed events through a Logging Sink to Pub/Sub, which delivers them to Guardrails.
Event Handler Architecture
The event handler infrastructure is configured by Guardrails Stacks (Terraform) in each project. These stacks create:
- Logging Sink: Filters API event messages and publishes them to a Pub/Sub topic.
- Pub/Sub Topic: Provides a data path between the Logging Sink and the Subscription.
- Pub/Sub Subscription: Forwards the events back to Guardrails for processing via HTTP push.
- Pub/Sub Topic IAM Policy: An IAM policy on the topic to allow the Logging Sink to publish.
Events flow through these components on their way to Guardrails:
- GCP Logging: User/API events originate here.
- Logging Sink: Events are filtered and directed to the Pub/Sub Topic.
- Pub/Sub Topic: Data path between the Logging Sink and the Subscription.
- Pub/Sub Subscription: Makes an HTTP call to pass event data to the Guardrails event ingestion endpoint.
- (Optional) API Gateway and Events Proxy: Enterprise customers with private ALBs may deploy an API Gateway. SaaS customers do not have this step.
- Guardrails ALB: Common entry point for events and API calls.
- Guardrails Events Container: Events are processed, triggering CMDB updates or control runs.
Guardrails Policies and Stacks
Guardrails uses Terraform to deploy the event handling infrastructure. The Terraform source is compiled from several inputs:
- Workspace configuration policies: Specify the HTTPS endpoint that event handlers point to, and the webhook secrets sent with each event.
- Event Handler configuration policies: Enable event handlers. Specify resource prefixes for Pub/Sub topics and Logging Sinks. Any policy in
GCP > Turbot > Event Handler > *. - Installed mods: Guardrails interrogates the list of mods and builds a Logging Sink filter to capture relevant events. See the Mods tab on the Admin page for a full list.
All inputs are compiled into the read-only GCP > Turbot > Event Handlers > Pub/Sub > Source and GCP > Turbot > Event Handlers > Logging > Source policy values. Looking at the "Depends On" tab of these Source policy values shows all dependent policies. Errors in any dependent policy may prevent event handlers from deploying properly.
Guides
| Guide | Description |
|---|---|
| Event Handlers | Set up push-based real-time event delivery (recommended for production). |
| Event Pollers | Configure polling frequency and lookback window. Enabled by default. |