support fallback values in DLS/FLS variables#6111
support fallback values in DLS/FLS variables#6111cwperks merged 2 commits intoopensearch-project:mainfrom
Conversation
6975101 to
43d3656
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6111 +/- ##
==========================================
+ Coverage 74.75% 74.78% +0.02%
==========================================
Files 447 447
Lines 28480 28470 -10
Branches 4331 4327 -4
==========================================
Hits 21291 21291
+ Misses 5193 5189 -4
+ Partials 1996 1990 -6
🚀 New features to boost your workflow:
|
43d3656 to
87f0013
Compare
PR Code Analyzer ❗AI-powered 'Code-Diff-Analyzer' found issues on commit 87f0013.
The table above displays the top 10 most important findings. Pull Requests Author(s): Please update your Pull Request according to the report above. Repository Maintainer(s): You can Thanks. |
|
the AI-analysis is wrong: without this is why i did it in the first place. security-wise i think this change is ok, we'll just have to document that |
PR Reviewer Guide 🔍(Review updated until commit 435abbf)Here are some key observations to aid the review process:
|
Given that the input is from admin and just not any API caller its fine. We couldn't certainly add better validation on Security APIs but not in the scope of this PR. |
PR Code Suggestions ✨Latest suggestions up to 435abbf
Previous suggestionsSuggestions up to commit 87f0013
|
this removes the manual string replacement and uses the existing functionality from `commons-text`. on its own this has no functional impact, however it enables us to implement opensearch-project#6110 with a single function call (will be done in the next commit). Signed-off-by: Ralph Ursprung <Ralph.Ursprung@avaloq.com>
if a user attribute is not defined then the system fails with an
exception. in 2.x this was silently ignored, allowing use-cases where
attributes were optional.
with this we now support fallbacks, thus it's now possible to e.g. write
`${attr.proxy.attr2:-foo}` so it prints "foo" if `attr2` is not defined
or even `${attr.proxy.attr2:-${attr.proxy.attr1}}` to fall back to the
value of `attr1` if `attr2` is not defined.
resolves opensearch-project#6110
Signed-off-by: Ralph Ursprung <Ralph.Ursprung@avaloq.com>
87f0013 to
435abbf
Compare
|
Persistent review updated to latest commit 435abbf |
|
rebased & incorporated @cwperks' slack feedback ( |
nibix
left a comment
There was a problem hiding this comment.
Look good to me!
IMHO, the whole attribute substitution is in a bad need of a complete redesign, but this is a good enhancement! 👍
|
thanks! btw, the CI failure is likely a false reject (it worked fine before and i only rebased). |
| retVal = orig.replace("${user.roles}", commaSeparatedRoles).replace("${user_roles}", commaSeparatedRoles); | ||
| } | ||
| return retVal; | ||
| final var stringSubstitutor = new StringSubstitutor(replacements).setEnableSubstitutionInVariables(true); |
There was a problem hiding this comment.
I think there are two concerns from my side:
- new failure mode with cycles (already brought here https://github.com/opensearch-project/security/pull/6111/changes#r3133408405)
- bringing a whole new library for simple string substitution (if we want to keep it simple) looks excessive to me
Do we want a full power of StringSubstitutor? May be we do, from other perspective keeping it very simple, non recursive, would be safer I believe.
There was a problem hiding this comment.
as said, i need the option "if A is not set fall back to B" where both A and B are attributes (in my case on the JWT).
in 2.x we solved this with two queries in a bool which worked because it just ignored the non-existent variable and this part then didn't match.
having the proper fallback will also be good for our performance (this is actually a TLQ we're doing, so doing it once instead of twice would be a big win)
as for bringing in a new library: it was already present as runtimeOnly - the only difference is that now i can also use it in this code base rather than it just being around at runtime for some other dependencies. so i don't see this is a big problem?
There was a problem hiding this comment.
as said, i need the option "if A is not set fall back to B" where both A and B are attributes (in my case on the JWT).
This part is fine, probably was not clearly articulated, +1 to have fallback, but StringSubstitutor will throw an exception on recursive substitution, whereas we could not push that as far by extending the existing manual substitution.
so i don't see this is a big problem?
you are actually very right, we bundle it even now, non issue
There was a problem hiding this comment.
but StringSubstitutor will throw an exception on recursive substitution, whereas we could not push that as far by extending the existing manual substitution.
ah, ok. this isn't a regression as this wasn't possible so far. and i think also a custom implementation would have to judge what to do after the first round of replacement. in the current implementation (with no fallback) it also raises an exception on finding a placeholder after having replaced the known ones:
and i think/hope that people will not write such complex replacement code in a DLS (then again: who knows? i'm to blame for even having TLQ support in DLS 😅) and if they do that they'll test it.
|
btw, talking of exceptions: there's but i'd strongly suggest that this is a follow-up cleanup |
Description
see the individual commit messages for details. basically this uses
StringSubstitutorfrom apache-commons text to re-create the existing behaviour (first commit) and also support fallbacks in the variables.if a user attribute is not defined then the system fails with an exception. in 2.x this was silently ignored, allowing use-cases where attributes were optional.
with this we now support fallbacks, thus it's now possible to e.g. write
${attr.proxy.attr2:-foo}so it prints "foo" ifattr2is not defined or even${attr.proxy.attr2:-${attr.proxy.attr1}}to fall back to the value ofattr1ifattr2is not defined.Issues Resolved
resolves #6110
Testing
unit testing
Check List
New Roles/Permissions have a corresponding security dashboards plugin PRAPI changes companion pull request createdBy 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.