Skip to content
Permalink
Browse files

fix alias resolution (ITT-1380) when permitted alias is a pattern

  • Loading branch information...
floragunncom committed May 7, 2018
1 parent 5258132 commit 5a99fec08ba34368786753e998b19e052f5def79
@@ -43,7 +43,6 @@
import org.elasticsearch.action.OriginalIndices;
import org.elasticsearch.action.RealtimeRequest;
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesAction;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
@@ -1157,8 +1156,24 @@ private PrivEvalResponse evaluateSnapshotRestore(final User user, String action,
private void handleIndicesWithWildcard(final String[] action0, final String permittedAliasesIndex,
final Map<String, Settings> permittedAliasesIndices, final Set<IndexType> requestedResolvedIndexTypes, final Set<IndexType> _requestedResolvedIndexTypes, final Set<String> requestedResolvedIndices0) {

final List<String> permittedAliasesIndicesResolved = new ArrayList<String>();
permittedAliasesIndicesResolved.add(permittedAliasesIndex);

if(WildcardMatcher.containsWildcard(permittedAliasesIndex)) {
final String[] aliasesForPermittedPattern = clusterService.state().getMetaData().getAliasAndIndexLookup()
.entrySet().stream()
.filter(e->e.getValue().isAlias())
.filter(e->WildcardMatcher.match(permittedAliasesIndex, e.getKey()))
.map(e->e.getKey()).toArray(String[]::new);


if(aliasesForPermittedPattern != null && aliasesForPermittedPattern.length > 0) {
permittedAliasesIndicesResolved.addAll(Arrays.asList(resolver.concreteIndexNames(clusterService.state(), DEFAULT_INDICES_OPTIONS, aliasesForPermittedPattern)));
}
}

List<String> wi = null;
if (!(wi = WildcardMatcher.getMatchAny(permittedAliasesIndex, requestedResolvedIndices0.toArray(new String[0]))).isEmpty()) {
if (!(wi = WildcardMatcher.getMatchAny(permittedAliasesIndicesResolved.toArray(new String[0]), requestedResolvedIndices0)).isEmpty()) {

if (log.isDebugEnabled()) {
log.debug(" Wildcard match for {}: {}", permittedAliasesIndex, wi);
@@ -1982,17 +1982,25 @@ public void testRegexExcludes() throws Exception {

@Test
public void testAliasResolution() throws Exception {

final Settings settings = Settings.builder()
.build();
setup(settings);
final RestHelper rh = nonSslRestHelper();

try (TransportClient tc = getInternalTransportClient()) {
tc.index(new IndexRequest("concreteindex-1").type("doc").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)).actionGet();
tc.admin().indices().aliases(new IndicesAliasesRequest().addAliasAction(AliasActions.add().indices("concreteindex-1").alias("calias-1"))).actionGet();
}

Assert.assertEquals(HttpStatus.SC_OK, rh.executeGetRequest("calias-1/_search?pretty", encodeBasicHeader("aliastest", "nagilum")).getStatusCode());
try (TransportClient tc = getInternalTransportClient()) {
tc.index(new IndexRequest("concreteindex-1").type("doc").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)).actionGet();
tc.admin().indices().aliases(new IndicesAliasesRequest().addAliasAction(AliasActions.add().indices("concreteindex-1").alias("calias-1"))).actionGet();
tc.index(new IndexRequest(".kibana-6").type("doc").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)).actionGet();
tc.admin().indices().aliases(new IndicesAliasesRequest().addAliasAction(AliasActions.add().indices(".kibana-6").alias(".kibana"))).actionGet();

}

Assert.assertEquals(HttpStatus.SC_OK, rh.executeGetRequest("calias-1/_search?pretty", encodeBasicHeader("aliastest", "nagilum")).getStatusCode());
Assert.assertEquals(HttpStatus.SC_OK, rh.executeGetRequest("calias-*/_search?pretty", encodeBasicHeader("aliastest", "nagilum")).getStatusCode());
Assert.assertEquals(HttpStatus.SC_OK, rh.executeGetRequest("*kibana/_search?pretty", encodeBasicHeader("aliastest", "nagilum")).getStatusCode());
Assert.assertEquals(HttpStatus.SC_OK, rh.executeGetRequest(".ki*ana/_search?pretty", encodeBasicHeader("aliastest", "nagilum")).getStatusCode());
Assert.assertEquals(HttpStatus.SC_OK, rh.executeGetRequest(".kibana/_search?pretty", encodeBasicHeader("aliastest", "nagilum")).getStatusCode());
}

}
@@ -380,16 +380,12 @@ sg_rexclude:

sg_aliastest:
indices:
'concreteindex-2':
'?kibana':
'*':
- indices:data/write/*
- indices:data/read/*
'calias-1':
'*':
- indices:data/write/*
- indices:data/read/*
'calias-2':
'*':
- indices:data/write/*
- indices:data/read/*

0 comments on commit 5a99fec

Please sign in to comment.
You can’t perform that action at this time.