Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation check for doc level query name during monitor creation #1506

Merged
merged 3 commits into from
Apr 12, 2024

Conversation

jowg-amazon
Copy link
Collaborator

@jowg-amazon jowg-amazon commented Apr 5, 2024

Issue #, if available:
PR related to: opensearch-project/common-utils#630
CI's will fail until common utils PR is merged in

Description of changes:
Adds validation check for doc level query name during monitor creation. Doc level query is restricted so that it may not start with: [_, +, -], contain .., or contain: [* ? < > | #]

CheckList:

  • Commits are signed per the DCO using --signoff

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.

Signed-off-by: Joanne Wang <jowg@amazon.com>
@@ -116,9 +122,11 @@ class RestIndexMonitorAction : BaseRestHandler() {
if (it !is DocumentLevelTrigger) {
throw IllegalArgumentException("Illegal trigger type, ${it.javaClass.name}, for document level monitor")
}
validateDocLevelQueryName(monitor)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like this is iterating through each trigger configured for the monitor, and then validating all of the query names during each iteration. Since queries are at the monitor level, not the trigger level, would it make sense to move this validation check out of the forEach loop?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes agreed, moved the validation outside the forEach loop

docLevelMonitorInput.queries.forEach { dlq ->
if (!dlq.name.matches(Regex(regex))) {
throw IllegalArgumentException(
"Doc level query name, ${dlq.name}, may only contain alphanumeric values and " +
Copy link
Collaborator

@AWSHurneyt AWSHurneyt Apr 8, 2024

Choose a reason for hiding this comment

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

We shouldn't return user input in error messages; so could we reword this error message to leave out ${dlq.name}?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reworded the error message to remove dlq.name

monitor.inputs.filterIsInstance<DocLevelMonitorInput>().forEach { docLevelMonitorInput ->
docLevelMonitorInput.queries.forEach { dlq ->
if (!dlq.name.matches(Regex(regex))) {
throw IllegalArgumentException(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just to confirm, does this end up throwing an IllegalArgumentException, or does it get wrapped in an AlertingException somewhere else? I believe IllegalArgumentException results in a 500 error, which we want to avoid.

Copy link
Collaborator

@AWSHurneyt AWSHurneyt Apr 8, 2024

Choose a reason for hiding this comment

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

Never mind, I see in your integ test that the expected error status is RestStatus.BAD_REQUEST, which is a 400 error; so the IllegalArgumentException must be getting caught, and wrapped somewhere else.

Signed-off-by: Joanne Wang <jowg@amazon.com>
@jowg-amazon
Copy link
Collaborator Author

Security tests have been failing in previous PRs
https://github.com/opensearch-project/alerting/actions/runs/8548149690/job/23421434894

@jowg-amazon jowg-amazon merged commit 636b43f into opensearch-project:main Apr 12, 2024
15 of 20 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 12, 2024
…#1506)

* add validation check for doc level query name during monitor creation

Signed-off-by: Joanne Wang <jowg@amazon.com>

* change to 0-256 chars

Signed-off-by: Joanne Wang <jowg@amazon.com>

* change validation message and move validation loc

Signed-off-by: Joanne Wang <jowg@amazon.com>

---------

Signed-off-by: Joanne Wang <jowg@amazon.com>
(cherry picked from commit 636b43f)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 12, 2024
…#1506)

* add validation check for doc level query name during monitor creation

Signed-off-by: Joanne Wang <jowg@amazon.com>

* change to 0-256 chars

Signed-off-by: Joanne Wang <jowg@amazon.com>

* change validation message and move validation loc

Signed-off-by: Joanne Wang <jowg@amazon.com>

---------

Signed-off-by: Joanne Wang <jowg@amazon.com>
(cherry picked from commit 636b43f)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
jowg-amazon pushed a commit that referenced this pull request Apr 13, 2024
…#1506) (#1511)

* add validation check for doc level query name during monitor creation



* change to 0-256 chars



* change validation message and move validation loc



---------


(cherry picked from commit 636b43f)

Signed-off-by: Joanne Wang <jowg@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>
jowg-amazon pushed a commit that referenced this pull request Apr 13, 2024
…#1506) (#1512)

* add validation check for doc level query name during monitor creation



* change to 0-256 chars



* change validation message and move validation loc



---------


(cherry picked from commit 636b43f)

Signed-off-by: Joanne Wang <jowg@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>
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 19, 2024
…#1506)

* add validation check for doc level query name during monitor creation

Signed-off-by: Joanne Wang <jowg@amazon.com>

* change to 0-256 chars

Signed-off-by: Joanne Wang <jowg@amazon.com>

* change validation message and move validation loc

Signed-off-by: Joanne Wang <jowg@amazon.com>

---------

Signed-off-by: Joanne Wang <jowg@amazon.com>
(cherry picked from commit 636b43f)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants