Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/139596.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 139596
summary: "CPS: Copy existing resolved index expressions when constructing a new `SearchRequest`\
\ from an existing one"
area: CCS
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ private SearchRequest(
this.waitForCheckpointsTimeout = searchRequest.waitForCheckpointsTimeout;
this.forceSyntheticSource = searchRequest.forceSyntheticSource;
this.projectRouting = searchRequest.projectRouting;
this.resolvedIndexExpressions = searchRequest.resolvedIndexExpressions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a quick unit test for this ctor just to ensure when we refactor it next time this aspect is not lost.

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.elasticsearch.ElasticsearchSecurityException;
import org.elasticsearch.action.ResolvedIndexExpression;
import org.elasticsearch.action.ResolvedIndexExpressions;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.test.ESTestCase;
Expand Down Expand Up @@ -1408,6 +1409,35 @@ public void testShouldReportFirstRemote404WhenNo403AndLocalProjectIsExcluded() {
assertThat(e.getSuppressed(), emptyArray());
}

public void testResolvedIndexExpressionsAreCopiedOntoNewSearchRequest() {
ResolvedIndexExpressions expr = new ResolvedIndexExpressions(
List.of(
new ResolvedIndexExpression(
"logs",
new ResolvedIndexExpression.LocalExpressions(
Set.of("logs"),
ResolvedIndexExpression.LocalIndexResolutionResult.SUCCESS,
null
),
Set.of("P1:logs")
)
)
);

String projectRouting = "_alias:_origin";
SearchRequest original = new SearchRequest("logs");
original.setResolvedIndexExpressions(expr);
original.setProjectRouting(projectRouting);

/*
* When a new SearchRequest object is created from an existing one, we should copy over the previously
* resolved expressions since the new object will not go through the Security Action Filter.
*/
SearchRequest rewritten = new SearchRequest(original);
assertThat(rewritten.getResolvedIndexExpressions(), equalTo(expr));
assertThat(rewritten.getProjectRouting(), equalTo(projectRouting));
}

private IndicesOptions getStrictAllowNoIndices() {
return getIndicesOptions(true, false);
}
Expand Down