- 
                Notifications
    You must be signed in to change notification settings 
- Fork 25.6k
[PoC] Support ::failures selector and access to failure store with CCS #125448
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
          
     Closed
      
      
            slobodanadamovic
  wants to merge
  16
  commits into
  elastic:main
from
slobodanadamovic:sa-poc-ccs-failure-store
  
      
      
   
      
    
  
     Closed
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            16 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      2bc0e99
              
                Prevent usage of :: selectors for remote cluster requests
              
              
                slobodanadamovic fc2271c
              
                fail only if ::failures selector is used
              
              
                slobodanadamovic ba976a9
              
                cleanup and extend existing rest IT
              
              
                slobodanadamovic f6c96e2
              
                Merge branch 'main' into sa-prevent-using-selectors-for-ccs-ccr
              
              
                slobodanadamovic 5bc46b5
              
                test ccs with rcs1
              
              
                slobodanadamovic e92ffde
              
                nit
              
              
                slobodanadamovic 29de669
              
                remove remote_indices - not relevant for RCS1 test case
              
              
                slobodanadamovic eaf9a01
              
                test CCS with RCS2
              
              
                slobodanadamovic 41da2e6
              
                Merge branch 'main' of github.com:elastic/elasticsearch into sa-preve…
              
              
                slobodanadamovic 4e366ed
              
                cleanup tests, handle edge cases with ccs_minimize_roundtrips
              
              
                slobodanadamovic 542aa54
              
                Merge branch 'main' of github.com:elastic/elasticsearch into sa-preve…
              
              
                slobodanadamovic 816d919
              
                more test users
              
              
                slobodanadamovic 7dc89d4
              
                fix assertion
              
              
                slobodanadamovic 26e8ae3
              
                test direct access to backing failure index for other users
              
              
                slobodanadamovic 9c3d0d7
              
                fix assertion
              
              
                slobodanadamovic e325104
              
                support ::failures with ccs
              
              
                slobodanadamovic File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -188,7 +188,11 @@ public final class IndexPrivilege extends Privilege { | |
| public static final IndexPrivilege NONE = new IndexPrivilege("none", Automatons.EMPTY); | ||
| public static final IndexPrivilege ALL = new IndexPrivilege("all", ALL_AUTOMATON, IndexComponentSelectorPredicate.ALL); | ||
| public static final IndexPrivilege READ = new IndexPrivilege("read", READ_AUTOMATON); | ||
| public static final IndexPrivilege READ_CROSS_CLUSTER = new IndexPrivilege("read_cross_cluster", READ_CROSS_CLUSTER_AUTOMATON); | ||
| public static final IndexPrivilege READ_CROSS_CLUSTER = new IndexPrivilege( | ||
| "read_cross_cluster", | ||
| READ_CROSS_CLUSTER_AUTOMATON, | ||
| IndexComponentSelectorPredicate.ALL | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the key part: making the  | ||
| ); | ||
| public static final IndexPrivilege CREATE = new IndexPrivilege("create", CREATE_AUTOMATON); | ||
| public static final IndexPrivilege INDEX = new IndexPrivilege("index", INDEX_AUTOMATON); | ||
| public static final IndexPrivilege DELETE = new IndexPrivilege("delete", DELETE_AUTOMATON); | ||
|  | @@ -383,6 +387,9 @@ private static Set<IndexPrivilege> resolve(Set<String> name) { | |
| dataSelectorAccessPrivileges.add(indexPrivilege); | ||
| } else if (indexPrivilege.selectorPredicate == IndexComponentSelectorPredicate.FAILURES) { | ||
| failuresSelectorAccessPrivileges.add(indexPrivilege); | ||
| } else if (indexPrivilege.selectorPredicate == IndexComponentSelectorPredicate.ALL) { | ||
| failuresSelectorAccessPrivileges.add(indexPrivilege); | ||
| dataSelectorAccessPrivileges.add(indexPrivilege); | ||
| } else { | ||
| String errorMessage = "unexpected selector [" + indexPrivilege.selectorPredicate + "]"; | ||
| assert false : errorMessage; | ||
|  | ||
        
          
          
            139 changes: 139 additions & 0 deletions
          
          139 
        
  ...rg/elasticsearch/xpack/remotecluster/AbstractRemoteClusterSecurityFailureStoreRestIT.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|  | ||
| package org.elasticsearch.xpack.remotecluster; | ||
|  | ||
| import org.elasticsearch.action.search.SearchResponse; | ||
| import org.elasticsearch.client.Request; | ||
| import org.elasticsearch.client.RequestOptions; | ||
| import org.elasticsearch.client.Response; | ||
| import org.elasticsearch.common.xcontent.support.XContentMapValues; | ||
| import org.elasticsearch.core.Tuple; | ||
| import org.elasticsearch.search.SearchHit; | ||
| import org.elasticsearch.search.SearchResponseUtils; | ||
|  | ||
| import java.io.IOException; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
|  | ||
| import static org.hamcrest.Matchers.containsInAnyOrder; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
|  | ||
| abstract class AbstractRemoteClusterSecurityFailureStoreRestIT extends AbstractRemoteClusterSecurityTestCase { | ||
|  | ||
| protected void assertSearchResponseContainsIndices(Response response, String... expectedIndices) throws IOException { | ||
| assertOK(response); | ||
| final SearchResponse searchResponse = SearchResponseUtils.parseSearchResponse(responseAsParser(response)); | ||
| try { | ||
| final List<String> actualIndices = Arrays.stream(searchResponse.getHits().getHits()) | ||
| .map(SearchHit::getIndex) | ||
| .collect(Collectors.toList()); | ||
| assertThat(actualIndices, containsInAnyOrder(expectedIndices)); | ||
| } finally { | ||
| searchResponse.decRef(); | ||
| } | ||
| } | ||
|  | ||
| protected void setupTestDataStreamOnFulfillingCluster() throws IOException { | ||
| // Create data stream and index some documents | ||
| final Request createComponentTemplate = new Request("PUT", "/_component_template/component1"); | ||
| createComponentTemplate.setJsonEntity(""" | ||
| { | ||
| "template": { | ||
| "mappings": { | ||
| "properties": { | ||
| "@timestamp": { | ||
| "type": "date" | ||
| }, | ||
| "age": { | ||
| "type": "integer" | ||
| }, | ||
| "email": { | ||
| "type": "keyword" | ||
| }, | ||
| "name": { | ||
| "type": "text" | ||
| } | ||
| } | ||
| }, | ||
| "data_stream_options": { | ||
| "failure_store": { | ||
| "enabled": true | ||
| } | ||
| } | ||
| } | ||
| }"""); | ||
| assertOK(performRequestAgainstFulfillingCluster(createComponentTemplate)); | ||
|  | ||
| final Request createTemplate = new Request("PUT", "/_index_template/template1"); | ||
| createTemplate.setJsonEntity(""" | ||
| { | ||
| "index_patterns": ["test*"], | ||
| "data_stream": {}, | ||
| "priority": 500, | ||
| "composed_of": ["component1"] | ||
| }"""); | ||
| assertOK(performRequestAgainstFulfillingCluster(createTemplate)); | ||
|  | ||
| final Request createDoc1 = new Request("PUT", "/test1/_doc/1?refresh=true&op_type=create"); | ||
| createDoc1.setJsonEntity(""" | ||
| { | ||
| "@timestamp": 1, | ||
| "age" : 1, | ||
| "name" : "jack", | ||
| "email" : "[email protected]" | ||
| }"""); | ||
| assertOK(performRequestAgainstFulfillingCluster(createDoc1)); | ||
|  | ||
| final Request createDoc2 = new Request("PUT", "/test1/_doc/2?refresh=true&op_type=create"); | ||
| createDoc2.setJsonEntity(""" | ||
| { | ||
| "@timestamp": 2, | ||
| "age" : "this should be an int", | ||
| "name" : "jack", | ||
| "email" : "[email protected]" | ||
| }"""); | ||
| assertOK(performRequestAgainstFulfillingCluster(createDoc2)); | ||
| } | ||
|  | ||
| protected Response performRequestWithRemoteSearchUser(final Request request) throws IOException { | ||
| request.setOptions( | ||
| RequestOptions.DEFAULT.toBuilder().addHeader("Authorization", headerFromRandomAuthMethod(REMOTE_SEARCH_USER, PASS)) | ||
| ); | ||
| return client().performRequest(request); | ||
| } | ||
|  | ||
| protected Response performRequestWithUser(final String user, final Request request) throws IOException { | ||
| request.setOptions(RequestOptions.DEFAULT.toBuilder().addHeader("Authorization", headerFromRandomAuthMethod(user, PASS))); | ||
| return client().performRequest(request); | ||
| } | ||
|  | ||
| @SuppressWarnings("unchecked") | ||
| protected Tuple<List<String>, List<String>> getDataAndFailureIndices(String dataStreamName) throws IOException { | ||
| Request dataStream = new Request("GET", "/_data_stream/" + dataStreamName); | ||
| Response response = performRequestAgainstFulfillingCluster(dataStream); | ||
| Map<String, Object> dataStreams = entityAsMap(response); | ||
| assertEquals(Collections.singletonList("test1"), XContentMapValues.extractValue("data_streams.name", dataStreams)); | ||
| List<String> dataIndexNames = (List<String>) XContentMapValues.extractValue("data_streams.indices.index_name", dataStreams); | ||
| List<String> failureIndexNames = (List<String>) XContentMapValues.extractValue( | ||
| "data_streams.failure_store.indices.index_name", | ||
| dataStreams | ||
| ); | ||
| return new Tuple<>(dataIndexNames, failureIndexNames); | ||
| } | ||
|  | ||
| protected Tuple<String, String> getSingleDataAndFailureIndices(String dataStreamName) throws IOException { | ||
| Tuple<List<String>, List<String>> indices = getDataAndFailureIndices(dataStreamName); | ||
| assertThat(indices.v1().size(), equalTo(1)); | ||
| assertThat(indices.v2().size(), equalTo(1)); | ||
| return new Tuple<>(indices.v1().get(0), indices.v2().get(0)); | ||
| } | ||
|  | ||
| } | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
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.
read_failure_storemust be granted to cross-cluster API keys