-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Ingest Manager] Add namespace validation #75381
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3c09ab8
Add namespace validation on APIs and UI
jen-huang d236d4a
Add test coverage
jen-huang 4aa1f79
Fix imports
jen-huang 00d5d90
Fix schema
jen-huang 40cecb4
Merge remote-tracking branch 'upstream/master' into ingest/bug/74667
jen-huang 1e50244
Merge remote-tracking branch 'upstream/master' into ingest/bug/74667
jen-huang 5deb2d5
Rename to policy
jen-huang 848ced9
Fix typo
jen-huang 3210347
Merge remote-tracking branch 'upstream/master' into ingest/bug/74667
jen-huang dd62085
Merge remote-tracking branch 'upstream/master' into ingest/bug/74667
jen-huang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
x-pack/plugins/ingest_manager/common/services/is_valid_namespace.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import { isValidNamespace } from './is_valid_namespace'; | ||
|
||
describe('Ingest Manager - isValidNamespace', () => { | ||
it('returns true for valid namespaces', () => { | ||
expect(isValidNamespace('default')).toBe(true); | ||
expect(isValidNamespace('namespace-with-dash')).toBe(true); | ||
expect(isValidNamespace('123')).toBe(true); | ||
}); | ||
|
||
it('returns false for invalid namespaces', () => { | ||
expect(isValidNamespace('Default')).toBe(false); | ||
expect(isValidNamespace('namespace with spaces')).toBe(false); | ||
expect(isValidNamespace('foo/bar')).toBe(false); | ||
expect(isValidNamespace('foo\\bar')).toBe(false); | ||
expect(isValidNamespace('foo*bar')).toBe(false); | ||
expect(isValidNamespace('foo?bar')).toBe(false); | ||
expect(isValidNamespace('foo"bar')).toBe(false); | ||
expect(isValidNamespace('foo<bar')).toBe(false); | ||
expect(isValidNamespace('foo|bar')).toBe(false); | ||
expect(isValidNamespace('foo,bar')).toBe(false); | ||
expect(isValidNamespace('foo#bar')).toBe(false); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
x-pack/plugins/ingest_manager/common/services/is_valid_namespace.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
// Namespace string eventually becomes part of an index name. This method partially implements index name rules from | ||
// https://github.com/elastic/elasticsearch/blob/master/docs/reference/indices/create-index.asciidoc | ||
export function isValidNamespace(namespace: string) { | ||
return ( | ||
typeof namespace === 'string' && | ||
// Lowercase only | ||
namespace === namespace.toLowerCase() && | ||
// Cannot include \, /, *, ?, ", <, >, |, space character, comma, #, : | ||
/^[^\*\\/\?"<>|\s,#:]+$/.test(namespace) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a few cases missing which agent validates
.
but is not allowed to be equal to.
or..
-
,_
or+
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michalpristas I think the validation is incorrect,
This mean, type + dataset + namespace <= 255 bytes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what we do in agent is that we put 255 constraint on dataset, namespace and a product of concatenation, so eventaully we will fail when index > 255.
putting some not communicated constraint felt weird (such as 255/3 or some other math) so i used 255 on each part and result as well.
as namespace is created before configuration and can lead to different indexes based on dataset and type it would make sense to agree on some constraint which can be applied at the time of specifying namespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @jen-huang
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed up in #75846 (comment).