Skip to content

Add manage_search_synonyms privilege#97853

Merged
carlosdelest merged 8 commits intoelastic:mainfrom
carlosdelest:carlosdelest/synonyms-manage-privilege
Jul 26, 2023
Merged

Add manage_search_synonyms privilege#97853
carlosdelest merged 8 commits intoelastic:mainfrom
carlosdelest:carlosdelest/synonyms-manage-privilege

Conversation

@carlosdelest
Copy link
Copy Markdown
Contributor

Adds a manage_search_synonyms privilege for synonyms related actions.

@carlosdelest carlosdelest added >non-issue Team:Enterprise Search Meta label for Enterprise Search team v8.10.0 labels Jul 20, 2023
reason: Introduced in 8.10.0

- do:
security.put_user:
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.

I wasn't able to use a roles.yml file / user setting for build.gradle. I'm sure I'm missing something, in the meanwhile adding users and roles via security API worked.

If you can help with another approach, that would be much appreciated 🙏

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.

Using APIs is fine. But it would be great if we pari the setup with a teardown part. Please see this file as an example.

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.

Done, thanks for the pointer!

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.

I created these tests in the core-rest-tests-with-security, as I haven't seen security related tests in the main rest-api-spec directory. Also, synonyms are part of the server module which has no security turned on by default on tests (as security is part of xpack).

Happy to move to a different directory structure if it makes more sense!

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 think it's fine to add it here. Again, if feature flag is still in play, we need to exclude this test for release builds. See this for an example.

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.

Included in the blacklist, thanks @ywangd !

@carlosdelest carlosdelest marked this pull request as ready for review July 20, 2023 18:39
@carlosdelest carlosdelest requested review from a team and mayya-sharipova July 20, 2023 18:39
@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label and removed Team:Enterprise Search Meta label for Enterprise Search team labels Jul 20, 2023
@mayya-sharipova mayya-sharipova added :Security/Security Security issues without another label :Search Relevance/Analysis How text is split into tokens and removed needs:triage Requires assignment of a team area label labels Jul 20, 2023
@elasticsearchmachine elasticsearchmachine added Team:Search Meta label for search team Team:Security Meta label for security team labels Jul 20, 2023
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-security (Team:Security)

@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-search (Team:Search)

Copy link
Copy Markdown
Member

@kderusso kderusso left a comment

Choose a reason for hiding this comment

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

Overall LGTM with one question

private static final Set<String> READ_SLM_PATTERN = Set.of(GetSnapshotLifecycleAction.NAME, GetStatusAction.NAME);

private static final Set<String> MANAGE_SEARCH_APPLICATION_PATTERN = Set.of("cluster:admin/xpack/application/search_application/*");
private static final Set<String> MANAGE_SEARCH_SYNONYMS_PATTERN = Set.of("cluster:admin/synonyms/*", "cluster:admin/synonyms_sets/*");
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.

We want to make sure that we have search in the pattern for future "manage search" privileges.

Also, does this synonyms need two different permission patterns? I would think that if you have the permission to manage synonym sets, you have the permission to manage synonym rules, and vice versa. Would it make sense to simplify this to just something like cluster:admin/search/synonyms?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need to add admin/synonym_rules/*?

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.

We want to make sure that we have search in the pattern for future "manage search" privileges.

Is that needed? I think we can use something like CROSS_CLUSTER_REPLICATION where we use a set of privileges, and we don't need explicit naming prefix...

I think it's better to omit the search prefix as that it's not a pattern I see in other constants, and we don't need to have it in order to create a manage_search privilege. Not a strong opinion though, happy to change it.

Also, does this synonyms need two different permission patterns? I would think that if you have the permission to manage synonym sets, you have the permission to manage synonym rules, and vice versa. Would it make sense to simplify this to just something like cluster:admin/search/synonyms?

We have three different action types, regarding synonyms, synonyms sets and synonym rules. As managing synonyms grant you access to both, that's the meaning of using the set of actions here.

Do we need to add admin/synonym_rules/*?
🤦 yes, thanks!

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.

@kderusso , @mayya-sharipova , anything else that you want addressed here? Hopefully my responses above and the changes to add admin/synonym_rules/* did address your concerns. Please LMK!

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 OK with this. Thank you!

@ioanatia ioanatia requested a review from ywangd July 24, 2023 08:19
Copy link
Copy Markdown
Member

@ywangd ywangd left a comment

Choose a reason for hiding this comment

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

Left a few comments. Thanks!

MANAGE_LOGSTASH_PIPELINES,
CANCEL_TASK,
MANAGE_SEARCH_APPLICATION,
MANAGE_SEARCH_SYNONYMS,
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.

Is the synonyms feature still behind a feature flag? If so, we need to gate the new privilege with the feature flag (see 3 lines below for an example).

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.

Updated, thanks for the catch and the example!

reason: Introduced in 8.10.0

- do:
security.put_user:
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.

Using APIs is fine. But it would be great if we pari the setup with a teardown part. Please see this file as an example.

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 think it's fine to add it here. Again, if feature flag is still in play, we need to exclude this test for release builds. See this for an example.

Comment on lines +99 to +109
"Create synonyms set - with manage_search_synonyms privilege":
- do:
headers: { Authorization: "Basic c3lub255bXMtdXNlcjpzeW5vbnltcy11c2VyLXBhc3N3b3Jk" } # synonyms-user
synonyms.put:
synonyms_set: test-synonyms
body:
synonyms_set:
- synonyms: "hello, hi"
id: "test-id"

- match: { result: "created" }
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 think we should have more tests for the synonyms-user to show it can excercise most (if not all) actions similar to how non-synonyms-user is tested?

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.

Makes sense. I've split into two test files, one for testing unprivileged access and another for privileged access. LMKWYT!

@carlosdelest carlosdelest requested a review from ywangd July 25, 2023 09:03
Copy link
Copy Markdown
Member

@kderusso kderusso left a comment

Choose a reason for hiding this comment

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

Nice work!

@@ -0,0 +1,111 @@
setup:
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.

Nice test organization 👍

Copy link
Copy Markdown
Member

@ywangd ywangd left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +20 to +33
- do:
security.put_user:
username: "non-synonyms-user"
body:
password: "non-synonyms-user-password"
roles : [ "non-synonyms-role" ]

- do:
security.put_role:
name: "non-synonyms-role"
body:
indices:
- names: ["*"]
privileges: [ "manage", "write", "read" ]
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.

Nit: I think these user non-synonyms user and role can be removed since we now split the tests into 2 files? The same goes for the teardown part.

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.

🤦 Removing them, thanks for the catch!

@carlosdelest
Copy link
Copy Markdown
Contributor Author

@elasticsearchmachine update branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>non-issue :Search Relevance/Analysis How text is split into tokens :Security/Security Security issues without another label Team:Search Meta label for search team Team:Security Meta label for security team v8.10.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants