Add filter by backend roles setting - #2034
Conversation
8589a08 to
a2932a3
Compare
| fun doUserBackendRolesMatchResource(userBackendRoles: List<String>, resourceBackendRoles: List<String>): Boolean { | ||
| if (filterByAccessStrategy == FilterByBackendRolesAccessStrategy.INTERSECT.strategy) { | ||
| return resourceBackendRoles.any { it in userBackendRoles } | ||
| } else if (filterByAccessStrategy == FilterByBackendRolesAccessStrategy.ALL.strategy) { |
There was a problem hiding this comment.
@markdboyd with the ALL strategy, what is the intended behavior when a user has all of the same backend roles but also some additional roles? With this implementation, it looks like a user with more roles would not match the resource.
If I'm understanding the use case correctly, are the below behaviors the intention?
user roles = [role1, role2, role3]andresource roles = [role1, role2, role3]should matchuser roles = [role1, role2, role3, role4, role5]andresource roles = [role1, role2, role3]should matchuser roles = [role1, role2, role3]andresource roles = [role1, role2, role3, role4, role5]should not match
There was a problem hiding this comment.
what is the intended behavior when a user has all of the same backend roles but also some additional roles
In this case with the ALL strategy, the user would not have access.
If I'm understanding the use case correctly, are the below behaviors the intention?
- user roles = [role1, role2, role3] and resource roles = [role1, role2, role3] should match
- user roles = [role1, role2, role3, role4, role5] and resource roles = [role1, role2, role3] should match
- user roles = [role1, role2, role3] and resource roles = [role1, role2, role3, role4, role5] should not match
For scenario 2, the behavior would also be not match and the user would not have access
Perhaps ALL would be better named MATCH_EXACTLY to specify this behavior?
There was a problem hiding this comment.
Ah thanks for clarifying. Yeah, EXACT makes sense in my mind given that additional context.
However, that intended behavior seems odd to me. Could you help me understand the use case for not permitting access to the resource when a user has more roles than are necessary?
There was a problem hiding this comment.
@AWSHurneyt - I thought more about this and I agree: ALL should provide access if the user roles contain all of the object backend roles, even if the user has additional roles. So for ALL, the user would have access in scenarios 1 and 2.
I added new logic to handle the ALL strategy. And I added EXACT as a separate strategy where the roles must match exactly with no additional roles
cb70999 to
fef3f4e
Compare
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
…s access strategy Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
…ckend roles Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
…mpare sorted lists Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
…tting Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
…omparing Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
|
@AWSHurneyt OK, I believe that I have added all of the requested tests |
|
@markdboyd I've rerun the failing security test a few times, but it still failing unfortunately. Could you take a look? |
|
@AWSHurneyt OK. I've run 5 of the failing tests from that workflow on my local machine, but none are failing so far. |
…oes not run with any information from the parent context & add comments to explain behavior Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
…access strategy is exact Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
|
@AWSHurneyt OK, I think I have resolved the test failures. The cause of the failures was the changes that I have made in the Initially, the problem was that I was having failures on tests acknowledging alerts when filtering by backend roles is enabled. Specifically, the code was returning this error: https://github.com/cloud-gov/opensearch-alerting/blob/dcb6f946bf12da4e9d6124db2f9fa7c059d1bf24/alerting/src/main/kotlin/org/opensearch/alerting/transport/SecureTransportAction.kt#L86-L92 I traced out the error to the fact that My initial fix was to pass along just the user information from the parent context manually: 16a21e3. But it seems that solution was not thread safe, so inspired by However, with that change, we started seeing several integration test failures related to acknowledging alerts. I believe that the problem with 4c908c0 is that it was including the user information from the parent context when invoking the So I have now refactored the code again to 298276a. The gist of the behavior is now:
With these changes, I believe that the code should function as expected when filtering by backend role is enabled or not. And that all tests should now pass. |
…t to get monitor operation Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
… when acknowledging an alert Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
… to acknowledge alerts Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
| val validator = FilterByBackendRolesAccessStrategyValidator() | ||
| validator.validate("all") | ||
| validator.validate("exact") | ||
| validator.validate("intersect") |
There was a problem hiding this comment.
Do we expect capitalized and mixed-case inputs to be valid (e.g., ALL, and aLl)?
There was a problem hiding this comment.
I made the validation case insensitive: 2412be4, however, does this change alone allow a capitalized input to be accepted and used by the system?
There was a problem hiding this comment.
@AWSHurneyt since this is a cluster setting, I believe adding mixed case here allows all these permutations for flexibility. Similar to a CLI program accepting y|Y|YES|yes for more flexibility.
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
| FilterByBackendRolesAccessStrategy.INTERSECT.strategy, | ||
| FilterByBackendRolesAccessStrategyValidator(), | ||
| Setting.Property.NodeScope, | ||
| Setting.Property.Dynamic |
There was a problem hiding this comment.
Same as alerting PR, let's add Setting.Property.Sensitive here.
| @Volatile private var indexTimeout = INDEX_TIMEOUT.get(settings) | ||
|
|
||
| @Volatile override var filterByEnabled = AlertingSettings.FILTER_BY_BACKEND_ROLES.get(settings) | ||
| @Volatile override var filterByAccessStrategy = AlertingSettings.FILTER_BY_BACKEND_ROLES_ACCESS_STRATEGY.get(settings) |
There was a problem hiding this comment.
I'm not an expert in this repo, but why must this be copied to all of these transport actions?
There was a problem hiding this comment.
@cwperks I think the reason this variable has to be copied into all of the transport actions is that filterByAccessStrategy is defined as a member on the SecureTransportAction interface which all of these actions implement: https://github.com/cloud-gov/opensearch-alerting/blob/2412be4a761f203a7cf1aac2a37321f3e6b7d1eb/alerting/src/main/kotlin/org/opensearch/alerting/transport/SecureTransportAction.kt#L42. So in order to satisfy the interface, all of the transport actions must include that member.
If I remove this line from the code then try to compile the plugin, I get this error:
Class 'TransportIndexAlertingCommentAction' is not abstract and does not implement abstract member:
var filterByAccessStrategy: String
| AlertingSettings.TENANT_ACCOUNT_ID_HEADER, | ||
| AlertingSettings.TENANT_RESOURCE_ID_HEADER | ||
| AlertingSettings.TENANT_RESOURCE_ID_HEADER, | ||
| AlertingSettings.FILTER_BY_BACKEND_ROLES_ACCESS_STRATEGY |
There was a problem hiding this comment.
nit: add this near related FILTER_BY_BACKEND_ROLES setting in this list.
| enableFilterBy() | ||
| putAlertMappings() | ||
|
|
||
| if (!isHttps()) { |
There was a problem hiding this comment.
btw I think you can add something like
at the top of the test suite to skip all tests if running ITs without security enabled.There was a problem hiding this comment.
@cwperks Not all of the tests in this file seem to require that https is enabled. Should they and then I can apply your suggested change?
…loser to AlertingSettings.FILTER_BY_BACKEND_ROLES in the plugin settings Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
…STRATEGY plugin setting Signed-off-by: Mark Boyd <mark.boyd@gsa.gov>
|
Related documentation changes: opensearch-project/documentation-website#12794 |
|
Confirmed with @cwperks offline that his comments have been addressed. Merging. |
Description
This PR adds a new plugin setting,
plugins.alerting.filter_by_backend_roles_access_strategy, which allows users to control how filtering by backend roles works to determine access to alerting objects (monitors). The options for this setting are:exact- Users have access to alerting objects if they have exactly the same (with no additional) backend roles as the user who created the objectintersect- Users have access to alerting objects if they share at least one backend role with the user who created the objectall- Users have access to alerting objects if their backend roles contain all of the backend roles of the user who created the objectRelated Issues
Resolves #1940
Check List
--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.