|
| 1 | +--- |
| 2 | +tags: |
| 3 | + - alerting |
| 4 | +--- |
| 5 | +# Alerting Access Control |
| 6 | + |
| 7 | +## Summary |
| 8 | + |
| 9 | +OpenSearch v3.5.0 introduces role-based access control for trigger execution context results in the Alerting plugin. A new cluster setting `plugins.alerting.notification_context_results_allowed_roles` allows administrators to restrict which user roles can include query results in notification message templates, preventing potential exposure of sensitive data through alert notifications. |
| 10 | + |
| 11 | +## Details |
| 12 | + |
| 13 | +### What's New in v3.5.0 |
| 14 | + |
| 15 | +This release adds a security enhancement to control access to monitor results in notification templates. When configuring alerting actions, users can include `ctx.results` in message templates to interpolate query results that triggered the alert. While useful, this could expose sensitive data through unencrypted notifications like email. |
| 16 | + |
| 17 | +### New Configuration Setting |
| 18 | + |
| 19 | +| Setting | Description | Default | |
| 20 | +|---------|-------------|---------| |
| 21 | +| `plugins.alerting.notification_context_results_allowed_roles` | List of user roles allowed to include results in notification templates | `[]` (empty - all roles allowed) | |
| 22 | + |
| 23 | +### Behavior |
| 24 | + |
| 25 | +```mermaid |
| 26 | +flowchart TB |
| 27 | + A[Trigger Execution] --> B{Setting Configured?} |
| 28 | + B -->|No| C[Include results in template context] |
| 29 | + B -->|Yes| D{Monitor roles intersect<br/>allowed roles?} |
| 30 | + D -->|Yes| C |
| 31 | + D -->|No| E[Return empty results in template context] |
| 32 | + C --> F[Notification sent with results] |
| 33 | + E --> G[Notification sent without results] |
| 34 | +``` |
| 35 | + |
| 36 | +- **Setting not configured (default)**: Original behavior preserved - all monitors can include results in notification templates |
| 37 | +- **Setting configured with roles**: Only monitors owned by users with at least one matching role can access results in templates |
| 38 | +- **No role intersection**: The `results` field in the template context returns an empty list |
| 39 | + |
| 40 | +### Technical Changes |
| 41 | + |
| 42 | +The implementation modifies the `TriggerExecutionContext` class hierarchy: |
| 43 | + |
| 44 | +| Class | Change | |
| 45 | +|-------|--------| |
| 46 | +| `TriggerExecutionContext` | Added `templateResults` property with role-based filtering logic | |
| 47 | +| `QueryLevelTriggerExecutionContext` | Updated to pass `ClusterSettings` and use `templateResults` | |
| 48 | +| `BucketLevelTriggerExecutionContext` | Updated to pass `ClusterSettings` and use `templateResults` | |
| 49 | +| `DocumentLevelTriggerExecutionContext` | Updated to pass `ClusterSettings` and use `templateResults` | |
| 50 | +| `AlertingSettings` | Added `NOTIFICATION_CONTEXT_RESULTS_ALLOWED_ROLES` setting | |
| 51 | + |
| 52 | +### Usage Example |
| 53 | + |
| 54 | +To restrict results access to only `admin` and `security_analyst` roles: |
| 55 | + |
| 56 | +```json |
| 57 | +PUT _cluster/settings |
| 58 | +{ |
| 59 | + "persistent": { |
| 60 | + "plugins.alerting.notification_context_results_allowed_roles": ["admin", "security_analyst"] |
| 61 | + } |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +With this setting, monitors created by users without these roles will have empty `results` in their notification templates, even if they use `{{ctx.results}}` in the message body. |
| 66 | + |
| 67 | +## Limitations |
| 68 | + |
| 69 | +- The setting applies cluster-wide and cannot be configured per-monitor |
| 70 | +- Existing monitors are affected immediately when the setting is changed |
| 71 | +- The setting only affects the `results` field in notification templates; other context fields remain accessible |
| 72 | +- Document-level monitors always return empty results in templates (by design, as they don't populate results in the execution context) |
| 73 | + |
| 74 | +## References |
| 75 | + |
| 76 | +### Pull Requests |
| 77 | + |
| 78 | +| PR | Description | Related Issue | |
| 79 | +|----|-------------|---------------| |
| 80 | +| [#1991](https://github.com/opensearch-project/alerting/pull/1991) | Access control for results in trigger execution context | [#1986](https://github.com/opensearch-project/alerting/issues/1986) | |
| 81 | + |
| 82 | +### Related Issues |
| 83 | + |
| 84 | +- [#1986](https://github.com/opensearch-project/alerting/issues/1986) - Feature request: Access control for using monitor results in email template |
0 commit comments