-
Notifications
You must be signed in to change notification settings - Fork 286
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
Fix multitency config update #2758
Fix multitency config update #2758
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2758 +/- ##
============================================
+ Coverage 61.31% 61.34% +0.03%
+ Complexity 3408 3386 -22
============================================
Files 272 265 -7
Lines 18846 18789 -57
Branches 3295 3296 +1
============================================
- Hits 11555 11527 -28
+ Misses 5690 5664 -26
+ Partials 1601 1598 -3
|
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.
Hi @willyborankin , thank you for putting this together. This PR looks good, and especially for the testing coverage! I left some minor questions/reviews just for my understanding.
|
||
private final static Set<String> ACCEPTABLE_DEFAULT_TENANTS = ImmutableSet.of( | ||
ConfigConstants.TENANCY_GLOBAL_TENANT_DEFAULT_NAME, | ||
ConfigConstants.TENANCY_GLOBAL_TENANT_NAME, |
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.
Are the L63 and L64 are the 2 case sensitive name for global tenants? Like 'global' vs 'Global'?
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.
AFAIU they are not not, will change and add equalsIgnoreCase
private final Header asUser = encodeBasicHeader("kirk", "kirk"); | ||
private final Header onUserTenant = new BasicHeader("securitytenant", "__user__"); | ||
private static final Header AS_REST_API_USER = encodeBasicHeader("rest_api_access", "rest_api_access"); | ||
private static final Header AS_ADMIN_USER = encodeBasicHeader("admin", "admin"); |
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 for my information, is there any reason for renaming this? Cuz I saw the asUser
still remains the same.
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.
Yes since configuration can be changed only by user which has access to REST API (I just want to highlight it)
@@ -156,3 +156,9 @@ user_tenant_parameters_substitution: | |||
attributes: | |||
attribute1: "tenant_parameters_substitution" | |||
description: "PR# 819 / Issue#817" | |||
rest_api_access: |
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.
Nit: probably user_rest_api_access
?
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.
sure :-)
public class MultiTenancyConfigApiTest extends AbstractRestApiUnitTest { | ||
|
||
private static final Header ADMIN_FULL_ACCESS_USER = encodeBasicHeader("admin_all_access", "admin_all_access"); | ||
private static final Header USER_NO_REST_API_ACCESS = encodeBasicHeader("admin", "admin"); |
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.
Is this means that it is the admin user but without the all_access
or only the rest_api_access
?
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.
Yes by default admin
has full access to the cluster and indices but not to the REST API.
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.
Thank you for the contribution @willyborankin! This approach brings this API in line with other security APIs and reduces the amount of code for this feature.
import static org.opensearch.security.dlic.rest.support.Utils.addRoutesPrefix; | ||
|
||
|
||
public class MultiTenancyConfigApiAction extends AbstractApiAction { |
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.
This greatly simplifies this down to a single class that extends AbstractApiAction. Great work!
} | ||
|
||
@Test | ||
public void testForbiddenAccess() throws Exception { |
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.
Thank you for adding this test. I agree that this should behave like all of the other security admin APIs.
@@ -2,6 +2,8 @@ | |||
_meta: | |||
type: "roles" | |||
config_version: 2 | |||
security_rest_api_access: |
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.
For anyone wondering what's special about this role and how it gets restapi access, its one of the roles specified in the demo configuration for restapi access here: https://github.com/opensearch-project/security/blob/main/tools/install_demo_configuration.sh#L384
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.
A small addition from my side.
There are 3 types of admins in the plugin:
super admin
- has access to everything e.g. can change configuration like SSL reload, update config on each node, CRUD operations for nodes ds etc. This is leftovers from the past idea to have a dedicated node adminadmin
- has full access to cluster and indicesREST admin API
- "admin" which has access to change some plugin configuration like roles, roles mapping, internal users etc.
compare to other security frameworks the plugin idea is very very confusing and it is hard to support such config.
0b7c9b2
to
59e7a35
Compare
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.
Nicely done @willyborankin! This is a great improvement, readability and maintenance wise!
private final Header asAdminUser = encodeBasicHeader("admin", "admin"); | ||
private final Header asUser = encodeBasicHeader("kirk", "kirk"); | ||
private final Header onUserTenant = new BasicHeader("securitytenant", "__user__"); | ||
private static final Header AS_REST_API_USER = encodeBasicHeader("user_rest_api_access", "user_rest_api_access"); |
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.
nicely done!
assertThat(searchInUserTenantWithPrivateTenantEnabled.getStatusCode(), equalTo(HttpStatus.SC_OK)); | ||
assertThat(searchInUserTenantWithPrivateTenantEnabled.findValueInJson("hits.hits[0]._source.index-pattern.title"), equalTo("userIndex")); | ||
|
||
final HttpResponse disablePrivateTenantResponse = nonSslRestHelper().executePutRequest("/_plugins/_security/api/tenancy/config", "{\"private_tenant_enabled\": \"false\"}", asAdminUser); | ||
final HttpResponse disablePrivateTenantResponse = nonSslRestHelper().executePutRequest("/_plugins/_security/api/tenancy/config", "{\"private_tenant_enabled\": \"false\"}", AS_REST_API_USER); | ||
assertThat(disablePrivateTenantResponse.getStatusCode(), equalTo(HttpStatus.SC_OK)); | ||
assertThat(disablePrivateTenantResponse.findValueInJson("private_tenant_enabled"), equalTo("false")); | ||
|
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.
Should this test case also be added here:
final HttpResponse updateSettingResponse = nonSslRestHelper().executePutRequest("/_plugins/_security/api/tenancy/config", "{\"private_tenant_enabled\":false}", AS_USER);
assertThat(updateSettingResponse.getStatusCode(), equalTo(HttpStatus.SC_BAD_REQUEST));
assertThat(updateSettingResponse.findValueInJson("error.reason"), containsString("Private tenant can not be disabled if it is the default tenant."));
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.
It is end to end test and it tests what index dashboard should use for the auth use.
fac40fb
4b55714
to
6337959
Compare
Moved multi-tenancy to REST API implementation Signed-off-by: Andrey Pleskach <ples@aiven.io>
6337959
to
b7ed864
Compare
all tests now passed :-) |
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.
Thank you for taking the time to complete this. Looks good!
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.7 2.7
# Navigate to the new working tree
cd .worktrees/backport-2.7
# Create a new branch
git switch --create backport/backport-2758-to-2.7
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 94db5dbb0e2351b6d2b31b2a0969863acbad9ebe
# Push it to GitHub
git push --set-upstream origin backport/backport-2758-to-2.7
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.7 Then, create a pull request where the |
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.x 2.x
# Navigate to the new working tree
cd .worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-2758-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 94db5dbb0e2351b6d2b31b2a0969863acbad9ebe
# Push it to GitHub
git push --set-upstream origin backport/backport-2758-to-2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.x Then, create a pull request where the |
Since the auto bacporting failed, I will manually backport this. |
@RyanL1997, did you get a chance to manually backport this to 2.x yet? If not I can take care of it. |
Moved multi-tenancy to REST API implementation Signed-off-by: Andrey Pleskach <ples@aiven.io>
…s, and multi tenancy changes (#2737) * [Extensions] Generate auth tokens for service accounts (#2716) * Generate auth tokens for service accounts Signed-off-by: Stephen Crawford <steecraw@amazon.com> Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> * Security User Refactor (#2594) --------- Signed-off-by: Stephen Crawford <steecraw@amazon.com> Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> * Backport service account changes Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Update test Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Optimize imports Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Spotless Signed-off-by: Stephen Crawford <steecraw@amazon.com> * fix plugin Signed-off-by: Stephen Crawford <steecraw@amazon.com> * fix whitespace Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Fix multitency config update (#2758) Moved multi-tenancy to REST API implementation Signed-off-by: Andrey Pleskach <ples@aiven.io> * Remove SSLCertsAction Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Fix dependency Signed-off-by: Stephen Crawford <steecraw@amazon.com> * fix tenancy tests Signed-off-by: Stephen Crawford <steecraw@amazon.com> --------- Signed-off-by: Stephen Crawford <steecraw@amazon.com> Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> Signed-off-by: Andrey Pleskach <ples@aiven.io> Co-authored-by: Andrey Pleskach <ples@aiven.io>
…s, and multi tenancy changes (#2737) * [Extensions] Generate auth tokens for service accounts (#2716) * Generate auth tokens for service accounts Signed-off-by: Stephen Crawford <steecraw@amazon.com> Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> * Security User Refactor (#2594) --------- Signed-off-by: Stephen Crawford <steecraw@amazon.com> Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> * Backport service account changes Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Update test Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Optimize imports Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Spotless Signed-off-by: Stephen Crawford <steecraw@amazon.com> * fix plugin Signed-off-by: Stephen Crawford <steecraw@amazon.com> * fix whitespace Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Fix multitency config update (#2758) Moved multi-tenancy to REST API implementation Signed-off-by: Andrey Pleskach <ples@aiven.io> * Remove SSLCertsAction Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Fix dependency Signed-off-by: Stephen Crawford <steecraw@amazon.com> * fix tenancy tests Signed-off-by: Stephen Crawford <steecraw@amazon.com> --------- Signed-off-by: Stephen Crawford <steecraw@amazon.com> Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> Signed-off-by: Andrey Pleskach <ples@aiven.io> Co-authored-by: Andrey Pleskach <ples@aiven.io> (cherry picked from commit fa33fc5)
…s, and multi tenancy changes (#2737) (#2777) * [Extensions] Generate auth tokens for service accounts (#2716) * Generate auth tokens for service accounts Signed-off-by: Stephen Crawford <steecraw@amazon.com> Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> * Security User Refactor (#2594) --------- Signed-off-by: Stephen Crawford <steecraw@amazon.com> Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> * Backport service account changes Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Update test Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Optimize imports Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Spotless Signed-off-by: Stephen Crawford <steecraw@amazon.com> * fix plugin Signed-off-by: Stephen Crawford <steecraw@amazon.com> * fix whitespace Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Fix multitency config update (#2758) Moved multi-tenancy to REST API implementation Signed-off-by: Andrey Pleskach <ples@aiven.io> * Remove SSLCertsAction Signed-off-by: Stephen Crawford <steecraw@amazon.com> * Fix dependency Signed-off-by: Stephen Crawford <steecraw@amazon.com> * fix tenancy tests Signed-off-by: Stephen Crawford <steecraw@amazon.com> --------- Signed-off-by: Stephen Crawford <steecraw@amazon.com> Signed-off-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> Signed-off-by: Andrey Pleskach <ples@aiven.io> Co-authored-by: Andrey Pleskach <ples@aiven.io> (cherry picked from commit fa33fc5) Co-authored-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com>
Moved multi-tenancy to REST API implementation Signed-off-by: Andrey Pleskach <ples@aiven.io>
Moved multi-tenancy to REST API implementation Signed-off-by: Andrey Pleskach <ples@aiven.io> Signed-off-by: Maciej Mierzwa <dev.maciej.mierzwa@gmail.com>
Moved multi-tenancy to REST API implementation Signed-off-by: Andrey Pleskach <ples@aiven.io> Signed-off-by: Maciej Mierzwa <dev.maciej.mierzwa@gmail.com>
Moved multi-tenancy to REST API implementation Signed-off-by: Andrey Pleskach <ples@aiven.io>
Moved multi-tenancy to REST API implementation Signed-off-by: Andrey Pleskach <ples@aiven.io> Signed-off-by: Sam <samuel.costa@eliatra.com>
Description
The aim of this PR is to fix 2 issues with muti-tenancy:
security_rest_api_access
role.Issues Resolved
Closes #2769.
Check List
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.