support attributes from request headers in DLS - #6310
Conversation
PR Code Analyzer ❗AI-powered 'Code-Diff-Analyzer' found issues on commit 551d00e. ⛔ Hard block: Issues at High severity or above will block this PR from merging.
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. |
PR Reviewer Guide 🔍(Review updated until commit 551d00e)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 551d00e Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 842817f
Suggestions up to commit 7e6cb3b
Suggestions up to commit 756f8d4
Suggestions up to commit f489388
Suggestions up to commit d86d247
|
1ead70c to
a0a03b4
Compare
|
Persistent review updated to latest commit a0a03b4 |
a0a03b4 to
b1dde53
Compare
|
Persistent review updated to latest commit b1dde53 |
b1dde53 to
956ae1e
Compare
|
Persistent review updated to latest commit 956ae1e |
956ae1e to
8fb20cf
Compare
|
Persistent review updated to latest commit 8fb20cf |
8fb20cf to
7d6694c
Compare
|
Persistent review updated to latest commit 7d6694c |
7d6694c to
67a2d5a
Compare
|
Persistent review updated to latest commit 67a2d5a |
|
thanks for the investigation @nibix! |
|
Persistent review updated to latest commit e8f9304 |
e8f9304 to
9fa7e22
Compare
|
Persistent review updated to latest commit 9fa7e22 |
9fa7e22 to
7d0b476
Compare
|
Persistent review updated to latest commit 7d0b476 |
|
odd that i'll have a look tomorrow |
nibix
left a comment
There was a problem hiding this comment.
I have rerun the tests, it looks like they are completely green now. Added just some minor nitpicks.
7d0b476 to
d86d247
Compare
awesome, thanks! i've incorporated fixes for your findings and rebased. the test runs fine locally => should be good now (i guess any CI failures will just be flaky tests again) |
|
Persistent review updated to latest commit d86d247 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6310 +/- ##
==========================================
+ Coverage 75.40% 75.46% +0.05%
==========================================
Files 456 457 +1
Lines 30255 30339 +84
Branches 4575 4585 +10
==========================================
+ Hits 22815 22896 +81
- Misses 5304 5312 +8
+ Partials 2136 2131 -5
🚀 New features to boost your workflow:
|
nibix
left a comment
There was a problem hiding this comment.
Thank you. I have added two more tiny remarks (sorry!), but still the current state is already approvable.
d86d247 to
f489388
Compare
|
Persistent review updated to latest commit f489388 |
|
Persistent review updated to latest commit 756f8d4 |
the plugin configuration and the authorization handling is always the same => these can be centralized in `GrpcHelpers` as well. Signed-off-by: Ralph Ursprung <Ralph.Ursprung@avaloq.com>
if one of the lists didn't contain any entries it'd just crash. now it causes a proper test failure, which is clearer. Signed-off-by: Ralph Ursprung <Ralph.Ursprung@avaloq.com>
756f8d4 to
7e6cb3b
Compare
|
CI builds failed due to an infrastructure issue (i rebased to try to trigger them again, but that led to the same problem). i've reported it on slack |
|
Retriggered the jobs ... |
|
Persistent review updated to latest commit 7e6cb3b |
|
The CI now seems to be completely stuck, some jobs just seem to be hanging. Unfortunately I cannot retrigger jobs in this state. Let's maybe wait a bit whether these will wake up again. Otherwise, @rursprung maybe force-push once again to retrigger the whole CI. |
with this it is now possible to specify request headers which should be
available as substitutions in DLS queries. both HTTP and gRPC headers
are supported.
the headers have to be configured under the config key
`plugins.security.unsupported.dls.allowed_request_headers`. this is a
map (the key doesn't matter) with the following content for each entry:
* `name`: the actual name of the gRPC / HTTP header (case-insensitive)
* `isMultiValue`: whether the header can have more than one value
(default: `false`)
* `validationRegex`: a regex to ensure that the header value cannot be
used for code injection into the DLS query
* `maxValueLength`: the maximum length each header value is allowed to
have (default: 256)
since DLS query substitution is pure string substitution and headers,
unlike other user attributes, are fully under the control of the caller
(and thus a potential attacker) the content must be carefully validated
to ensure that it does not pose a risk. for this the `validationRegex`
needs to be used - by default it rejects all content, thus it must be
configured explicitly. it should be configured to only allow explicitly
the patterns which are absolutely needed.
due to the risk associated with this feature it is currently being
treated as unsupported/experimental and will also not be documented.
if you, dear reader, stumble upon this PR / commit please beware: only
use this is if you are absolutely sure that you know what you are doing!
you have been warned!
the substitution is done using `${attr.header.[header name]}`, e.g.
`${attr.header.x-example-header}`.
if `isMultiValue` is set to `true` then the substitution will always
contain quotes around the values and has to be treated as a list, i.e.
you should enclose it in `[]`:
```
{ "terms": { "testfield": [${attr.header.x-example-header-mv}] } }
```
while if `isMultiValue` is set to `false` then the value will be added
verbatim and you need to quote it:
```
{ "term": { "testfield": "${attr.header.x-example-header}" } }
```
to prevent the risk of DOS attacks through the header forwarding both a
limit on the length of header values has been introduced (configurable
per header, see `maxValueLength`; default: 256 characters) as well as a
global limit on the amount of headers (see
`DlsRequestHeadersUtil#MAX_HEADER_COUNT`; arbitrarily set to 256) has
been introduced.
the config options can only be set via the config file (they are
intentionally not marked as `Dynamic`) so that it has to be a clear
decision to set this. this restriction can be lifted at a later point.
once opensearch-project#6311 is implemented the risk posed by this feature will go down
since then it will no longer be possible to modify the query with a
crafted request (which this feature tries to prevent by having the admin
specify a regex for the validation).
resolves opensearch-project#6265
Signed-off-by: Ralph Ursprung <Ralph.Ursprung@avaloq.com>
7e6cb3b to
842817f
Compare
|
Persistent review updated to latest commit 842817f |
done, though there are flaky tests again. final results: one
and one
in both cases the other matrix entries worked fine => these are flaky i checked the logs for
it seems that in some cases it either doesn't do the user setup correctly or uses it wrong - either way i think that's probably an issue with the test infrastructure code or with the gRPC code causing it to be flaky. re-running the test will probably make it pass |
I think I also saw that failure during previous test runs. I am going to check whether I can identify any issue that might be causing this. |
|
Persistent review updated to latest commit 551d00e |
Description
with this it is now possible to specify request headers which should be
available as substitutions in DLS queries. both HTTP and gRPC headers
are supported.
the headers have to be configured under the config key
plugins.security.unsupported.dls.allowed_request_headers. this is amap (the key doesn't matter) with the following content for each entry:
name: the actual name of the gRPC / HTTP header (case-insensitive)isMultiValue: whether the header can have more than one value(default:
false)validationRegex: a regex to ensure that the header value cannot beused for code injection into the DLS query
maxValueLength: the maximum length each header value is allowed tohave (default: 256)
since DLS query substitution is pure string substitution and headers,
unlike other user attributes, are fully under the control of the caller
(and thus a potential attacker) the content must be carefully validated
to ensure that it does not pose a risk. for this the
validationRegexneeds to be used - by default it rejects all content, thus it must be
configured explicitly. it should be configured to only allow explicitly
the patterns which are absolutely needed.
due to the risk associated with this feature it is currently being
treated as unsupported/experimental and will also not be documented.
if you, dear reader, stumble upon this PR / commit please beware: only
use this is if you are absolutely sure that you know what you are doing!
you have been warned!
the substitution is done using
${attr.header.[header name]}, e.g.${attr.header.x-example-header}.if
isMultiValueis set totruethen the substitution will alwayscontain quotes around the values and has to be treated as a list, i.e.
you should enclose it in
[]:while if
isMultiValueis set tofalsethen the value will be addedverbatim and you need to quote it:
to prevent the risk of DOS attacks through the header forwarding both a
limit on the length of header values has been introduced (configurable
per header, see
maxValueLength; default: 256 characters) as well as aglobal limit on the amount of headers (see
DlsRequestHeadersUtil#MAX_HEADER_COUNT; arbitrarily set to 256) hasbeen introduced.
the config options can only be set via the config file (they are
intentionally not marked as
Dynamic) so that it has to be a cleardecision to set this. this restriction can be lifted at a later point.
once #6311 is implemented the risk posed by this feature will go down
since then it will no longer be possible to modify the query with a
crafted request (which this feature tries to prevent by having the admin
specify a regex for the validation).
Issues Resolved
resolves #6265
Testing
integration tests, manual tests
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.