Skip to content

Commit b5f332b

Browse files
committed
Merge remote-tracking branch 'es/main' into mergeSortedNumericField_3
2 parents 57e2996 + ceaa01a commit b5f332b

File tree

12 files changed

+167
-87
lines changed

12 files changed

+167
-87
lines changed

docs/changelog/126310.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 126310
2+
summary: Add Issuer to failed SAML Signature validation logs when available
3+
area: Security
4+
type: enhancement
5+
issues:
6+
- 111022

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,6 @@ tests:
357357
- class: org.elasticsearch.search.basic.SearchWithRandomDisconnectsIT
358358
method: testSearchWithRandomDisconnects
359359
issue: https://github.com/elastic/elasticsearch/issues/122707
360-
- class: org.elasticsearch.xpack.esql.qa.single_node.GenerativeIT
361-
method: test
362-
issue: https://github.com/elastic/elasticsearch/issues/126139
363360
- class: org.elasticsearch.snapshots.SharedClusterSnapshotRestoreIT
364361
method: testDeletionOfFailingToRecoverIndexShouldStopRestore
365362
issue: https://github.com/elastic/elasticsearch/issues/126204

server/src/main/java/org/elasticsearch/common/lucene/search/TopDocsAndMaxScore.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
/**
1515
* Wrapper around a {@link TopDocs} instance and the maximum score.
1616
*/
17-
// TODO: Remove this class when https://github.com/elastic/elasticsearch/issues/32981 is addressed.
1817
public final class TopDocsAndMaxScore {
1918

2019
public final TopDocs topDocs;
@@ -24,5 +23,4 @@ public TopDocsAndMaxScore(TopDocs topDocs, float maxScore) {
2423
this.topDocs = topDocs;
2524
this.maxScore = maxScore;
2625
}
27-
2826
}

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/generative/GenerativeRestTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public abstract class GenerativeRestTest extends ESRestTestCase {
4141
"Unbounded sort not supported yet",
4242
"The field names are too complex to process", // field_caps problem
4343
"must be \\[any type except counter types\\]", // TODO refine the generation of count()
44+
"mismatched input .* expecting", // identifier generator needs to be refined, this happens when an identifier is a reserved keyword
4445

4546
// warnings
4647
"Field '.*' shadowed by field at line .*",
@@ -52,10 +53,9 @@ public abstract class GenerativeRestTest extends ESRestTestCase {
5253
"only supports KEYWORD or TEXT values, found expression", // https://github.com/elastic/elasticsearch/issues/126017
5354
"token recognition error at: '``", // https://github.com/elastic/elasticsearch/issues/125870
5455
"Unknown column \\[.*\\]", // https://github.com/elastic/elasticsearch/issues/126026
55-
"Expected \\[.*\\] but was \\[.*\\]", // https://github.com/elastic/elasticsearch/issues/126030
56-
"trying to encode an unsupported data type value for TopN", // still https://github.com/elastic/elasticsearch/issues/126030 probably
57-
"Block cannot be cast to", // https://github.com/elastic/elasticsearch/issues/126036
5856
"optimized incorrectly due to missing references", // https://github.com/elastic/elasticsearch/issues/116781
57+
"No matches found for pattern", // https://github.com/elastic/elasticsearch/issues/126418
58+
"JOIN left field .* is incompatible with right field", // https://github.com/elastic/elasticsearch/issues/126419
5959
"The incoming YAML document exceeds the limit:" // still to investigate, but it seems to be specific to the test framework
6060
);
6161

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/CombineProjections.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private static List<NamedExpression> combineProjections(List<? extends NamedExpr
117117
// collect named expressions declaration in the lower list
118118
AttributeMap.Builder<NamedExpression> namedExpressionsBuilder = AttributeMap.builder();
119119
// while also collecting the alias map for resolving the source (f1 = 1, f2 = f1, etc..)
120-
AttributeMap.Builder<Expression> aliasesBuilder = AttributeMap.builder();
120+
AttributeMap.Builder<Expression> aliasesBuilder = AttributeMap.builder(lower.size());
121121
for (NamedExpression ne : lower) {
122122
// record the alias
123123
aliasesBuilder.put(ne.toAttribute(), Alias.unwrap(ne));
@@ -128,7 +128,7 @@ private static List<NamedExpression> combineProjections(List<? extends NamedExpr
128128
namedExpressionsBuilder.put(ne.toAttribute(), as.replaceChild(aliasesBuilder.build().resolve(child, child)));
129129
}
130130
}
131-
List<NamedExpression> replaced = new ArrayList<>();
131+
List<NamedExpression> replaced = new ArrayList<>(upper.size());
132132
var namedExpressions = namedExpressionsBuilder.build();
133133

134134
// replace any matching attribute with a lower alias (if there's a match)

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/Layout.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
package org.elasticsearch.xpack.esql.planner;
99

10+
import org.elasticsearch.common.util.Maps;
1011
import org.elasticsearch.xpack.esql.core.expression.NameId;
1112
import org.elasticsearch.xpack.esql.core.expression.NamedExpression;
1213
import org.elasticsearch.xpack.esql.core.type.DataType;
1314

1415
import java.util.ArrayList;
1516
import java.util.Collection;
1617
import java.util.Collections;
17-
import java.util.HashMap;
1818
import java.util.List;
1919
import java.util.Map;
2020
import java.util.Set;
@@ -65,7 +65,7 @@ class Builder {
6565
private final List<ChannelSet> channels;
6666

6767
public Builder() {
68-
channels = new ArrayList<>();
68+
this(new ArrayList<>());
6969
}
7070

7171
Builder(List<ChannelSet> channels) {
@@ -76,7 +76,7 @@ public Builder() {
7676
* Appends a new channel to the layout. The channel is mapped to one or more attribute ids.
7777
*/
7878
public Builder append(ChannelSet set) {
79-
if (set.nameIds.size() < 1) {
79+
if (set.nameIds.isEmpty()) {
8080
throw new IllegalArgumentException("Channel must be mapped to at least one id.");
8181
}
8282
channels.add(set);
@@ -104,7 +104,11 @@ public Builder append(Collection<? extends NamedExpression> attributes) {
104104
* Build a new {@link Layout}.
105105
*/
106106
public Layout build() {
107-
Map<NameId, ChannelAndType> layout = new HashMap<>();
107+
int size = 0;
108+
for (ChannelSet channel : channels) {
109+
size += channel.nameIds.size();
110+
}
111+
Map<NameId, ChannelAndType> layout = Maps.newHashMapWithExpectedSize(size);
108112
int numberOfChannels = 0;
109113
for (ChannelSet set : channels) {
110114
int channel = numberOfChannels++;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/LocalExecutionPlanner.java

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.elasticsearch.common.lucene.BytesRefs;
1212
import org.elasticsearch.common.settings.Settings;
1313
import org.elasticsearch.common.util.BigArrays;
14+
import org.elasticsearch.common.util.Maps;
1415
import org.elasticsearch.compute.Describable;
1516
import org.elasticsearch.compute.aggregation.AggregatorMode;
1617
import org.elasticsearch.compute.data.Block;
@@ -117,9 +118,6 @@
117118
import org.elasticsearch.xpack.esql.session.Configuration;
118119

119120
import java.util.ArrayList;
120-
import java.util.HashMap;
121-
import java.util.HashSet;
122-
import java.util.LinkedHashMap;
123121
import java.util.List;
124122
import java.util.Map;
125123
import java.util.Objects;
@@ -501,8 +499,8 @@ private PhysicalOperation planGrok(GrokExec grok, LocalExecutionPlannerContext c
501499
Layout.Builder layoutBuilder = source.layout.builder();
502500
List<Attribute> extractedFields = grok.extractedFields();
503501
layoutBuilder.append(extractedFields);
504-
Map<String, Integer> fieldToPos = new HashMap<>(extractedFields.size());
505-
Map<String, ElementType> fieldToType = new HashMap<>(extractedFields.size());
502+
Map<String, Integer> fieldToPos = Maps.newHashMapWithExpectedSize(extractedFields.size());
503+
Map<String, ElementType> fieldToType = Maps.newHashMapWithExpectedSize(extractedFields.size());
506504
ElementType[] types = new ElementType[extractedFields.size()];
507505
List<Attribute> extractedFieldsFromPattern = grok.pattern().extractedFields();
508506
for (int i = 0; i < extractedFields.size(); i++) {
@@ -559,7 +557,8 @@ private PhysicalOperation planEnrich(EnrichExec enrich, LocalExecutionPlannerCon
559557
private PhysicalOperation planRerank(RerankExec rerank, LocalExecutionPlannerContext context) {
560558
PhysicalOperation source = plan(rerank.child(), context);
561559

562-
Map<ColumnInfoImpl, EvalOperator.ExpressionEvaluator.Factory> rerankFieldsEvaluatorSuppliers = new LinkedHashMap<>();
560+
Map<ColumnInfoImpl, EvalOperator.ExpressionEvaluator.Factory> rerankFieldsEvaluatorSuppliers = Maps
561+
.newLinkedHashMapWithExpectedSize(rerank.rerankFields().size());
563562

564563
for (var rerankField : rerank.rerankFields()) {
565564
rerankFieldsEvaluatorSuppliers.put(
@@ -734,31 +733,13 @@ private PhysicalOperation planProject(ProjectExec project, LocalExecutionPlanner
734733
List<Integer> projectionList = new ArrayList<>(projections.size());
735734

736735
Layout.Builder layout = new Layout.Builder();
737-
Map<Integer, Layout.ChannelSet> inputChannelToOutputIds = new HashMap<>();
738-
for (int index = 0, size = projections.size(); index < size; index++) {
739-
NamedExpression ne = projections.get(index);
740-
741-
NameId inputId = null;
742-
if (ne instanceof Alias a) {
743-
inputId = ((NamedExpression) a.child()).id();
744-
} else {
745-
inputId = ne.id();
746-
}
736+
for (NamedExpression ne : projections) {
737+
NameId inputId = ne instanceof Alias a ? ((NamedExpression) a.child()).id() : ne.id();
747738
Layout.ChannelAndType input = source.layout.get(inputId);
748739
if (input == null) {
749740
throw new IllegalStateException("can't find input for [" + ne + "]");
750741
}
751-
Layout.ChannelSet channelSet = inputChannelToOutputIds.get(input.channel());
752-
if (channelSet == null) {
753-
channelSet = new Layout.ChannelSet(new HashSet<>(), input.type());
754-
channelSet.nameIds().add(ne.id());
755-
layout.append(channelSet);
756-
} else {
757-
channelSet.nameIds().add(ne.id());
758-
}
759-
if (channelSet.type() != input.type()) {
760-
throw new IllegalArgumentException("type mismatch for aliases");
761-
}
742+
layout.append(ne);
762743
projectionList.add(input.channel());
763744
}
764745

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private SamlAttributes authenticateResponse(Element element, Collection<String>
9393
}
9494
final boolean requireSignedAssertions;
9595
if (response.isSigned()) {
96-
validateSignature(response.getSignature());
96+
validateSignature(response.getSignature(), response.getIssuer());
9797
requireSignedAssertions = false;
9898
} else {
9999
requireSignedAssertions = true;
@@ -199,7 +199,7 @@ private List<Attribute> processAssertion(Assertion assertion, boolean requireSig
199199
}
200200
// Do not further process unsigned Assertions
201201
if (assertion.isSigned()) {
202-
validateSignature(assertion.getSignature());
202+
validateSignature(assertion.getSignature(), assertion.getIssuer());
203203
} else if (requireSignature) {
204204
throw samlException("Assertion [{}] is not signed, but a signature is required", assertion.getElementQName());
205205
}

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlLogoutRequestHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private Result parseLogout(LogoutRequest logoutRequest, boolean requireSignature
7373
throw samlException("Logout request is not signed");
7474
}
7575
} else {
76-
validateSignature(signature);
76+
validateSignature(signature, logoutRequest.getIssuer());
7777
}
7878

7979
checkIssuer(logoutRequest.getIssuer(), logoutRequest);

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlLogoutResponseHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void handle(boolean httpRedirect, String payload, Collection<String> allo
4545
if (logoutResponse.getSignature() == null) {
4646
throw samlException("LogoutResponse is not signed, but is required for HTTP-Post binding");
4747
}
48-
validateSignature(logoutResponse.getSignature());
48+
validateSignature(logoutResponse.getSignature(), logoutResponse.getIssuer());
4949
}
5050
checkInResponseTo(logoutResponse, allowedSamlRequestIds);
5151
checkStatus(logoutResponse.getStatus());

0 commit comments

Comments
 (0)