-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Enhance API Key Querying #103192
Enhance API Key Querying #103192
Conversation
Hi @albertzaharovits, I've created a changelog YAML for you. |
ApiKeyAggregationsBuilder.verifyRequested(aggsBuilder, filteringAuthentication); | ||
searchSourceBuilder.aggregationsBuilder(aggsBuilder); |
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.
The above verifies & modifies the requested aggregation to:
- prohib scripts that can directly access the API Key docs
- rewrite the field names (because the query & agg use different field names from the document ones, in order to reflect the terminology that we use in the returned API Keys)
- rewrite queries to scope them to API Key docs only (and sometimes to the keys owned by the calling user only)
@@ -209,7 +208,6 @@ protected ValuesSourceAggregationBuilder( | |||
this.format = clone.format; | |||
this.missing = clone.missing; | |||
this.timeZone = clone.timeZone; | |||
this.config = clone.config; |
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.
Removed this unused bit, as it looked like one way to change the value source for the agg, and the point of this PR is to restrict that for API Keys aggs.
@@ -61,7 +61,7 @@ public abstract class FiltersAggregator extends BucketsAggregator { | |||
|
|||
public static class KeyedFilter implements Writeable, ToXContentFragment { | |||
private final String key; | |||
private final QueryBuilder filter; |
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.
Unfortunately, I had to make the filter here mutable, because the query for API Key aggs has to be modified to go only over API Key docs, and also optionally of a single user.
@@ -41,7 +41,7 @@ | |||
public class FilterAggregationBuilder extends AbstractAggregationBuilder<FilterAggregationBuilder> { | |||
public static final String NAME = "filter"; | |||
|
|||
private final QueryBuilder filter; |
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.
public static final String API_KEY_TYPE_RUNTIME_MAPPING_FIELD = "runtime_key_type"; | ||
private static final Map<String, Object> API_KEY_TYPE_RUNTIME_MAPPING = Map.of( | ||
API_KEY_TYPE_RUNTIME_MAPPING_FIELD, | ||
Map.of("type", "keyword", "script", Map.of("source", "emit(doc['type'].value ?: \"rest\");")) | ||
); |
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.
Keys created before 8.9 (#95714) don't have a type
field and they effectively work as "rest" types do post 8.9.
Adds support for the following to the Query API Key API:
type
as an allowed field to be queried (whose value can be set to eitherrest
orcross_cluster
)Closes: #101691