support attributes from request headers in DLS#6310
Conversation
PR Code Analyzer ❗AI-powered 'Code-Diff-Analyzer' found issues on commit e8f9304.
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 e8f9304)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to e8f9304 Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit b1945ac
Suggestions up to commit 45bca69
Suggestions up to commit cc2b6e5
Suggestions up to commit 67a2d5a
Suggestions up to commit 7d6694c
|
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 |
|
i think that the test failures which are now still happening are flaky tests? i see nodes which become unreachable (but no clear error as to why and i've seen these errors in other PRs before) and i see gradle failing to download a gradle plugin (=> network issues) |
67a2d5a to
cc2b6e5
Compare
|
Persistent review updated to latest commit cc2b6e5 |
|
@rursprung Can you look into test failures: also, is there a reason for using |
ok, i can see the failure in my test: i don't do i can indeed reproduce that
as explained in the commit-msg & PR description this feature has some security implications and for now we want to keep it unsupported/experimental and gather some experience with it first, and maybe clean up some relevant functionality (e.g. how attribute substitution works) first before we stabilise it (if ever). |
cc2b6e5 to
45bca69
Compare
|
Persistent review updated to latest commit 45bca69 |
45bca69 to
b1945ac
Compare
|
Persistent review updated to latest commit b1945ac |
|
So, I had a look into the test failures in The changes in this PR has the effect that virtually any transport request carries the One example, generated by one test in This particular audit log message carried no headers before the change: This influences a condition in I do not really understand why the presence of But, this does not matter so much. Rather, IMHO we should avoid having any side effects of the feature when the feature is not in use. In this case, it is the presence of the empty valued transport header. We should strive to have such observable changes only when the feature is in use. Thus, I would recommend to modify the code to only write such headers when the settings reflect the use of it. |
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>
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>
b1945ac to
e8f9304
Compare
|
thanks for the investigation @nibix! |
|
Persistent review updated to latest commit e8f9304 |


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.