How-to
Detect policy changes
Goal
Run application code when the policy is updated by another swarm member (or by an external system).
Subscribe to the PolicyChanged event
client.Authorization.PolicyChanged += (sender, args) =>
{
logger.LogInformation(
"Policy reloaded: {Reason} at {Timestamp}",
args.Reason, args.TimestampUtc);
// Refresh any cached authorization decisions in your application
}; Force a reload
If you have reason to believe the policy is stale (for example, after a cloud event), force a reload:
await client.Authorization.ReloadAsync();
// Triggers PolicyChanged event with reason "manual-reload" Notify from outside the SDK
If your application has its own change-detection mechanism (an S3 EventBridge webhook, an Azure Event Grid notification, an Open Policy Agent bundle push), call:
await client.Authorization.NotifyPolicyChangedAsync("s3-event-bridge");
// SDK reloads the policy and raises PolicyChanged with that reason See also
- Share a policy across machines How-to
- The scaling model (swarm) Concept