Skip to content
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

Fix data-stream name resolution for wild-cards #1716

Merged
merged 1 commit into from
Mar 30, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ private void resolveIndexPatterns(final String name, final IndicesOptions indice

final Collection<String> matchingAliases;
Collection<String> matchingAllIndices;
Collection<String> matchingDataStreams = null;

if (isLocalAll(original)) {
if (isTraceEnabled) {
Expand Down Expand Up @@ -259,8 +260,11 @@ private void resolveIndexPatterns(final String name, final IndicesOptions indice
final boolean isDebugEnabled = log.isDebugEnabled();
try {
matchingAllIndices = Arrays.asList(resolver.concreteIndexNames(state, indicesOptions, localRequestedPatterns.toArray(new String[0])));
matchingDataStreams = resolver.dataStreamNames(state, indicesOptions, localRequestedPatterns.toArray(new String[0]));

if (isDebugEnabled) {
log.debug("Resolved pattern {} to {}", localRequestedPatterns, matchingAllIndices);
log.debug("Resolved pattern {} to indices: {} and data-streams: {}",
localRequestedPatterns, matchingAllIndices, matchingDataStreams);
}
} catch (IndexNotFoundException e1) {
if (isDebugEnabled) {
Expand All @@ -271,13 +275,16 @@ private void resolveIndexPatterns(final String name, final IndicesOptions indice
}
}

if (isTraceEnabled) {
log.trace("Resolved patterns {} for {} ({}) to [aliases {}, allIndices {}, originalRequested{}, remote indices {}]",
original, name, this.name, matchingAliases, matchingAllIndices, Arrays.toString(original), remoteIndices);
if (matchingDataStreams == null || matchingDataStreams.size() == 0) {
matchingDataStreams = Arrays.asList(NOOP);
}

resolveTo(matchingAliases, matchingAllIndices, original, remoteIndices);
if (isTraceEnabled) {
log.trace("Resolved patterns {} for {} ({}) to [aliases {}, allIndices {}, dataStreams {}, originalRequested{}, remote indices {}]",
original, name, this.name, matchingAliases, matchingAllIndices, matchingDataStreams, Arrays.toString(original), remoteIndices);
cliu123 marked this conversation as resolved.
Show resolved Hide resolved
}

resolveTo(matchingAliases, matchingAllIndices, matchingDataStreams, original, remoteIndices);
}

private void resolveToLocalAll() {
Expand All @@ -286,9 +293,11 @@ private void resolveToLocalAll() {
originalRequested.add(Resolved.ANY);
}

private void resolveTo(Iterable<String> matchingAliases, Iterable<String> matchingAllIndices, String[] original, Iterable<String> remoteIndices) {
private void resolveTo(Iterable<String> matchingAliases, Iterable<String> matchingAllIndices,
Iterable<String> matchingDataStreams, String[] original, Iterable<String> remoteIndices) {
aliases.addAll(matchingAliases);
allIndices.addAll(matchingAllIndices);
allIndices.addAll(matchingDataStreams);
originalRequested.add(original);
this.remoteIndices.addAll(remoteIndices);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public void createSampleDataStreams(RestHelper rh) throws Exception{
rh.executePutRequest("/_index_template/my-data-stream-template", getIndexTemplateBody(), encodeBasicHeader("ds1", "nagilum"));

rh.executePutRequest("/_data_stream/my-data-stream11", getIndexTemplateBody(), encodeBasicHeader("ds3", "nagilum"));
rh.executePutRequest("/_data_stream/my-data-stream21", getIndexTemplateBody(), encodeBasicHeader("ds3", "nagilum"));
rh.executePutRequest("/_data_stream/my-data-stream22", getIndexTemplateBody(), encodeBasicHeader("ds3", "nagilum"));
rh.executePutRequest("/_data_stream/my-data-stream23", getIndexTemplateBody(), encodeBasicHeader("ds3", "nagilum"));
rh.executePutRequest("/_data_stream/my-data-stream33", getIndexTemplateBody(), encodeBasicHeader("ds3", "nagilum"));
}

Expand Down Expand Up @@ -89,6 +91,27 @@ public void testGetDataStream() throws Exception {

response = rh.executeGetRequest("/_data_stream/my-data-stream33", encodeBasicHeader("ds3", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream*", encodeBasicHeader("ds0", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream21,my-data-stream22", encodeBasicHeader("ds0", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream*", encodeBasicHeader("ds1", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream2*", encodeBasicHeader("ds2", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream21,my-data-stream22", encodeBasicHeader("ds2", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream*", encodeBasicHeader("ds2", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream*", encodeBasicHeader("ds3", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());
}

@Test
Expand All @@ -103,18 +126,39 @@ public void testDeleteDataStream() throws Exception {
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream11", encodeBasicHeader("ds1", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream11", encodeBasicHeader("ds2", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream22", encodeBasicHeader("ds2", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream33", encodeBasicHeader("ds3", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream*", encodeBasicHeader("ds0", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream21,my-data-stream22", encodeBasicHeader("ds0", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream22", encodeBasicHeader("ds1", "nagilum"));
response = rh.executeDeleteRequest("/_data_stream/my-data-stream*", encodeBasicHeader("ds1", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream21,my-data-stream22", encodeBasicHeader("ds1", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream2*", encodeBasicHeader("ds2", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream33", encodeBasicHeader("ds3", "nagilum"));
response = rh.executeDeleteRequest("/_data_stream/my-data-stream21,my-data-stream22", encodeBasicHeader("ds2", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream*", encodeBasicHeader("ds2", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeDeleteRequest("/_data_stream/my-data-stream*", encodeBasicHeader("ds3", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());
}

Expand Down Expand Up @@ -143,5 +187,26 @@ public void testDataStreamStats() throws Exception {

response = rh.executeGetRequest("/_data_stream/my-data-stream33/_stats", encodeBasicHeader("ds3", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream*/_stats", encodeBasicHeader("ds0", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream21,my-data-stream22/_stats", encodeBasicHeader("ds0", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream*/_stats", encodeBasicHeader("ds1", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream2*/_stats", encodeBasicHeader("ds2", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream21,my-data-stream22/_stats", encodeBasicHeader("ds2", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream*/_stats", encodeBasicHeader("ds2", "nagilum"));
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode());

response = rh.executeGetRequest("/_data_stream/my-data-stream*/_stats", encodeBasicHeader("ds3", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());
}
}
2 changes: 1 addition & 1 deletion src/test/resources/roles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,6 @@ data_stream_1:
allowed_actions:
- "indices:admin/data_stream/get"
- "indices:admin/data_stream/create"
- "indices:admin/data_stream/delete"

data_stream_2:
reserved: true
Expand All @@ -1105,6 +1104,7 @@ data_stream_2:
- "indices:admin/data_stream/get"
- "indices:admin/data_stream/create"
- "indices:monitor/data_stream/stats"
- "indices:admin/data_stream/delete"

data_stream_3:
reserved: true
Expand Down