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 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.

FeatureEvent PollersEvent Handlers
MechanismPull-based (query audit logs)Push-based (Activity Log Alerts)
Default StateEnabledNot configured
LatencyConfigurable (default: every minute)Near real-time
Azure InfrastructureNoneAction Groups and Activity Log Alerts
ConfigurationMinimal, works out of the boxRequires 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 TypeGuideDescription
Event PollerEvent PollingSubscription-level event polling. Queries Azure Monitor audit logs for resource changes.
Management Group Event PollerManagement Group Event PollingDetects 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:

  1. An API is invoked in Azure, potentially making a change to a cloud resource.
  2. Azure writes the event to Azure Monitor.
  3. 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.
  4. The Guardrails raw event endpoint decodes the token and runs the action specified by the action type ID, typically running a provider router.
  5. The provider router verifies and filters the requests, creates events specific to that provider, and pushes them onto the event bus.
  6. 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.