Skip to content

Access control for results in trigger execution context#1991

Merged
AWSHurneyt merged 26 commits into
opensearch-project:mainfrom
cloud-gov:remove-alert-message-results
Jan 26, 2026
Merged

Access control for results in trigger execution context#1991
AWSHurneyt merged 26 commits into
opensearch-project:mainfrom
cloud-gov:remove-alert-message-results

Conversation

@markdboyd
Copy link
Copy Markdown
Contributor

@markdboyd markdboyd commented Nov 21, 2025

Description

This PR includes a few changes:

  • Adds a NOTIFICATION_CONTEXT_RESULTS_ALLOWED_ROLES setting to specify which user roles should have access to results from a trigger execution context
  • Adds a getter for a templateResults property of the TriggerExecutionContext to conditionally make templateResults empty if NOTIFICATION_CONTEXT_RESULTS_ALLOWED_ROLES is set AND the allowed roles do not intersect with the monitor's user roles
  • Update the asTemplateArg() method for trigger execution contexts to return templateResults as the value for the results property in mustache templates
  • Adds tests for each type of execution context to ensure that the visibility of templateResults is correct for different scenarios
  • Refactors code as necessary for compatibility with changes

Related Issues

Resolves #1986

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@markdboyd markdboyd force-pushed the remove-alert-message-results branch from ffeb432 to ae99a32 Compare November 21, 2025 17:22
@markdboyd markdboyd changed the title Conditionally remove results from trigger execution context Access control for results in from trigger execution context Nov 21, 2025
@markdboyd markdboyd changed the title Access control for results in from trigger execution context Access control for results in trigger execution context Nov 21, 2025
@markdboyd markdboyd force-pushed the remove-alert-message-results branch 2 times, most recently from 2594afd to 46f5991 Compare December 2, 2025 21:50
@markdboyd markdboyd force-pushed the remove-alert-message-results branch from 46f5991 to 9cd1067 Compare December 12, 2025 19:05
@cwperks
Copy link
Copy Markdown
Member

cwperks commented Dec 16, 2025

Thank you for this PR @markdboyd. I think it makes sense in the current paradigm to add a new cluster setting for this.

There is an ongoing effort to re-architect how plugins interface with security through a resource sharing framework based on ownership of a resource and access levels. This plugin has not been onboarded yet, but once targeted for onboarding I would also like to see if there is a convenient way to fit this into that model as well by provisioning different levels of access to the context to different users but that may involve introducing new transport actions.

Regardless, this change would work in both paradigms.

@@ -103,8 +103,10 @@ class AnomalyDetectionUtilsTests : OpenSearchTestCase() {
val searchSourceBuilder = SearchSourceBuilder()
addUserBackendRolesFilter(
User(
randomAlphaOfLength(5), null, listOf(randomAlphaOfLength(5)),
listOf(randomAlphaOfLength(5))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised this test did not need to be updated earlier. Has this repo been having failing tests?

Thanks for updating this!

Assert.assertTrue(templateResults.isEmpty())
}

fun `test results are excluded in document-level context even when allowed roles intersect monitor roles`() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my understanding, why is DocumentLevel context different from BucketLevel and QueryLevel?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For whatever reason, the DocumentLevelTriggerExecutionContext is coded to never pass along results when instantiating the context:

monitor, trigger, emptyList(), Instant.now(), Instant.now(),

You can see the third parameter there for the results is an emptyList(). So this context will never have results regardless of this new setting for controlling access that we're adding.

For the QueryLevelTriggerExecutionContext, you can see that the actual monitor results are passed along when instantiating the context:

monitor, trigger, monitorRunResult.inputResults.results, monitorRunResult.periodStart, monitorRunResult.periodEnd,

This behavior is the same for the BucketLevelTriggerExecutionContext

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like that's because the doc level monitor fires when a doc meets certain criteria, whereas bucket level monitor and query level trigger based on query results.

Is there any sensitive info that is present on doc level monitor that ought to be excluded?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to GPT-5.2 there is not:

You mostly get alert metadata and execution context, not query results or document contents.

I think it would have access to docId and index, but not _source

Copy link
Copy Markdown
Member

@cwperks cwperks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AWSHurneyt Could you also please review this? Thanks!

JasonTheMain and others added 6 commits December 17, 2025 10:51
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
…search-project#1939)

* changed the maven url in build.gradle

* url changed

---------

(cherry picked from commit 8b6afc3)

Signed-off-by: Riya Saxena <riysaxen@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
…ch-project#1946) (opensearch-project#1947)

(cherry picked from commit b87b2dd)

Signed-off-by: Peter Zhu <zhujiaxi@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
…rigger context

Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
…xts, not just the template arguments

Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
…in cluster settings to TriggerExecutionContext constructor

Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
…se when allowed roles are empty

Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
…tor user roles are included in allowed roles

Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
…gger contexts

Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
…context

Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
…ings

Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
…tting to distinguish between null for unset and an explicitly empty list

Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
…TS_ALLOWED_ROLES is not set

Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
…ON_CONTEXT_RESULTS_ALLOWED_ROLES is not set

Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
…esults as a template argument instead of as a context property

Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
@markdboyd markdboyd force-pushed the remove-alert-message-results branch from 9cd1067 to 7e7a84e Compare December 17, 2025 15:52
@cwperks
Copy link
Copy Markdown
Member

cwperks commented Jan 22, 2026

@AWSHurneyt Can we get another review on this? The CI checks are passing.

@AWSHurneyt AWSHurneyt merged commit 29907a3 into opensearch-project:main Jan 26, 2026
20 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Access control for using monitor results in email template

4 participants