Configuring Real-Time Events
Guardrails uses Azure Monitor events to keep up with Azure resources as they are created, destroyed, and modified. This allows policy enforcement in real time. There are two mechanisms for capturing these events:
- Event Pollers: pull-based, enabled by default
- Event Handlers: push-based, require additional configuration
Event Pollers or Event Handlers
Turbot Support recommends using Azure Pollers in all circumstances.
It is possible to configure both polling and event handlers, but they should never be enabled at the same time.
| Feature | Event Pollers | Event Handlers |
|---|---|---|
| Mechanism | Pull-based (query audit logs) | Push-based (Activity Log Alerts) |
| Default State | Enabled | Not configured |
| Latency | Configurable (default: every minute) | Near real-time |
| Azure Infrastructure | None | Action Groups and Activity Log Alerts |
| Configuration | Minimal, works out of the box | Requires mod installation and policy configuration |
Event Pollers
Guardrails Azure Event Pollers query Audit Logs (Azure Monitor) at regular intervals (every minute by default) for events inside the polling window (defaults to events in the last 10 minutes). They are enabled by default and require no additional configuration.
There are two types of event pollers:
| Poller Type | Guide | Description |
|---|---|---|
| Event Poller | Event Polling | Subscription-level event polling. Queries Azure Monitor audit logs for resource changes. |
| Management Group Event Poller | Management Group Event Polling | Detects changes in the management group hierarchy (new/updated/deleted subscriptions). Runs every 12 hours by default. |
Event Handlers
Guardrails Azure Event Handlers use a push-based mechanism and are responsible for sending Azure events back to Guardrails for processing.
The basic flow is:
- An API is invoked in Azure, potentially making a change to a cloud resource.
- Azure writes the event to Azure Monitor.
- The Event Handler (Activity Log Alert) is connected to Azure Monitor. As events are received, the Event Handler forwards them to the Guardrails event ingestion endpoint via an Action Group.
- The Guardrails raw event endpoint decodes the token and runs the action specified by the action type ID, typically running a provider router.
- The provider router verifies and filters the requests, creates events specific to that provider, and pushes them onto the event bus.
- A resource router picks up the event and takes the appropriate action (e.g., if the event is a resource creation, that resource is upserted into the database).
Event Handlers require the Microsoft Insights provider to be registered within the imported subscription. Attempting to configure event handlers without registering Microsoft Insights will result in errors and events not flowing back to Guardrails.
See the Event Handlers guide for configuration details.