diff --git a/integrations/access/pagerduty/app.go b/integrations/access/pagerduty/app.go index 5eadcc5147cd0..3b37fbb2c7b09 100644 --- a/integrations/access/pagerduty/app.go +++ b/integrations/access/pagerduty/app.go @@ -22,6 +22,7 @@ import ( "context" "errors" "fmt" + "slices" "strings" "time" @@ -140,8 +141,17 @@ func (a *App) run(ctx context.Context) error { if err != nil { return trace.Wrap(err) } - if err := a.accessMonitoringRules.InitAccessMonitoringRulesCache(ctx); err != nil { - return trace.Wrap(err) + + if len(acceptedWatchKinds) == 0 { + return trace.BadParameter("failed to initialize watcher for all the required resources: %+v", + watchKinds) + } + // Check if KindAccessMonitoringRule resources are being watched, + // the role the plugin is running as may not have access. + if slices.Contains(acceptedWatchKinds, types.KindAccessMonitoringRule) { + if err := a.accessMonitoringRules.InitAccessMonitoringRulesCache(ctx); err != nil { + return trace.Wrap(err, "initializing Access Monitoring Rule cache") + } } a.mainJob.SetReady(ok)