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

Added validations for indexPattern in autofollow API #1358

Closed
wants to merge 0 commits into from

Conversation

skumarp7
Copy link
Contributor

@skumarp7 skumarp7 commented Mar 22, 2024

Description

This PR adds validations for the indexPattern configured in autofollow API

Existing behavior of the autofollow API with invalid indexPattern:

  curl -Method POST -Uri "http://localhost:9201/_plugins/_replication/_autofollow?pretty"  -H @{'Content-Typ
e' = 'application/json'} -body '{"leader_alias":"leader", "name": "test", "pattern": "test/abcd"}'                   


StatusCode        : 200
StatusDescription : OK
Content           : {
                      "acknowledged" : true
                    }

Behaviour after adding validations on indexPattern:

curl -Method POST -Uri "http://localhost:9201/_plugins/_replication/_autofollow?pretty"  -H @{'Content-Typ
e' = 'application/json'} -body '{"leader_alias":"leader_sanjay", "name": "test", "pattern": "test/adfas"}'

curl : { "error" : { "root_cause" : [ { "type" : "action_request_validation_exception", "reason" : "Validation Failed: 1: Autofollow pattern: 
test/adfas must not contain the following characters [ , \", *, \\, <, |, ,, >, /, ?];" } ], "type" : "action_request_validation_exception", 
"reason" : "Validation Failed: 1: Autofollow pattern: test/adfas must not contain the following characters [ , \", *, \\, <, |, ,, >, /, ?];" },    
"status" : 400 }

Issues Resolved

#1034

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • 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.

@skumarp7
Copy link
Contributor Author

skumarp7 commented Apr 3, 2024

Hi All,

Please let me know if the above made changes are good to go. Feedback is much appreciated :)

@skumarp7
Copy link
Contributor Author

skumarp7 commented Apr 8, 2024

Hi @monusingh-1 , Any update ?

Copy link
Member

@ankitkala ankitkala left a comment

Choose a reason for hiding this comment

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

Thanks for taking out the time to contribute this fix @skumarp7

Have few minor comments on the PR. Rest LGTM.

* Validate the pattern against the rules that we have for indexPattern name.
*/

fun validatePattern(pattern: String?, validationException: ValidationException) {
Copy link
Member

Choose a reason for hiding this comment

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

Let's name this as validateAutofollowPattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -294,6 +294,32 @@ class UpdateAutoFollowPatternIT: MultiClusterRestTestCase() {
.hasMessageContaining(errorMsg)
}

fun `test auto follow should fail on indexPattern validation failure`() {
Copy link
Member

Choose a reason for hiding this comment

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

To ensure we're not regressing, Can you please add the tests for various valid patterns as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


fun validatePattern(pattern: String?, validationException: ValidationException) {

if (!Strings.validFileNameExcludingAstrix(pattern))
Copy link
Member

Choose a reason for hiding this comment

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

The characters in the pattern doesn't have to a valid filename right? Wanted to understand the how you arrived at this criteria.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have tried to adapt similar validations done in opensearch on indexPatterns at index template level where the index Pattern must not contain invalid filename characters.

reference: https://github.com/opensearch-project/OpenSearch/blob/main/server/src/main/java/org/opensearch/cluster/metadata/MetadataIndexTemplateService.java

@monusingh-1
Copy link
Collaborator

Enabled approval workflow

Copy link
Member

@ankitkala ankitkala left a comment

Choose a reason for hiding this comment

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

Thanks for

@monusingh-1
Copy link
Collaborator

Security tests have started to fail, investigating

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.

3 participants