- 
                Notifications
    
You must be signed in to change notification settings  - Fork 25.6k
 
[Failure Store] Manage-style privileges grant both data and failures access #125900
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
          
     Merged
      
      
            elasticsearchmachine
  merged 8 commits into
  elastic:main
from
n1v0lg:failure-store-data-and-failures-privileges
  
      
      
   
  Apr 1, 2025 
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            8 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      20061fc
              
                [Failure Store] manage privileges grant data and failures access
              
              
                n1v0lg 35b214b
              
                More tests
              
              
                n1v0lg 65dd807
              
                ff
              
              
                n1v0lg 7f195f1
              
                Tests
              
              
                n1v0lg f881a48
              
                Test
              
              
                n1v0lg c1b4903
              
                Address review comments
              
              
                n1v0lg 2b608c2
              
                Merge branch 'main' into failure-store-data-and-failures-privileges
              
              
                n1v0lg 6514b39
              
                Merge branch 'main' into failure-store-data-and-failures-privileges
              
              
                n1v0lg 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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -50,7 +50,6 @@ | |
| import java.util.Collections; | ||
| import java.util.HashSet; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.LinkedHashSet; | ||
| import java.util.Locale; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| 
          
            
          
           | 
    @@ -195,7 +194,11 @@ public final class IndexPrivilege extends Privilege { | |
| public static final IndexPrivilege WRITE = new IndexPrivilege("write", WRITE_AUTOMATON); | ||
| public static final IndexPrivilege CREATE_DOC = new IndexPrivilege("create_doc", CREATE_DOC_AUTOMATON); | ||
| public static final IndexPrivilege MONITOR = new IndexPrivilege("monitor", MONITOR_AUTOMATON); | ||
| public static final IndexPrivilege MANAGE = new IndexPrivilege("manage", MANAGE_AUTOMATON); | ||
| public static final IndexPrivilege MANAGE = new IndexPrivilege( | ||
| "manage", | ||
| MANAGE_AUTOMATON, | ||
| IndexComponentSelectorPredicate.DATA_AND_FAILURES | ||
| ); | ||
| public static final IndexPrivilege DELETE_INDEX = new IndexPrivilege("delete_index", DELETE_INDEX_AUTOMATON); | ||
| public static final IndexPrivilege CREATE_INDEX = new IndexPrivilege("create_index", CREATE_INDEX_AUTOMATON); | ||
| public static final IndexPrivilege VIEW_METADATA = new IndexPrivilege("view_index_metadata", VIEW_METADATA_AUTOMATON); | ||
| 
        
          
        
         | 
    @@ -204,7 +207,8 @@ public final class IndexPrivilege extends Privilege { | |
| public static final IndexPrivilege MANAGE_ILM = new IndexPrivilege("manage_ilm", MANAGE_ILM_AUTOMATON); | ||
| public static final IndexPrivilege MANAGE_DATA_STREAM_LIFECYCLE = new IndexPrivilege( | ||
| "manage_data_stream_lifecycle", | ||
| MANAGE_DATA_STREAM_LIFECYCLE_AUTOMATON | ||
| MANAGE_DATA_STREAM_LIFECYCLE_AUTOMATON, | ||
| IndexComponentSelectorPredicate.DATA_AND_FAILURES | ||
| ); | ||
| public static final IndexPrivilege MAINTENANCE = new IndexPrivilege("maintenance", MAINTENANCE_AUTOMATON); | ||
| public static final IndexPrivilege AUTO_CONFIGURE = new IndexPrivilege("auto_configure", AUTO_CONFIGURE_AUTOMATON); | ||
| 
          
            
          
           | 
    @@ -364,6 +368,7 @@ private static Set<IndexPrivilege> resolve(Set<String> name) { | |
| final Set<IndexPrivilege> allSelectorAccessPrivileges = new HashSet<>(); | ||
| final Set<IndexPrivilege> dataSelectorAccessPrivileges = new HashSet<>(); | ||
| final Set<IndexPrivilege> failuresSelectorAccessPrivileges = new HashSet<>(); | ||
| final Set<IndexPrivilege> dataAndFailuresSelectorAccessPrivileges = new HashSet<>(); | ||
| 
     | 
||
| boolean containsAllAccessPrivilege = name.stream().anyMatch(n -> getNamedOrNull(n) == ALL); | ||
| for (String part : name) { | ||
| 
        
          
        
         | 
    @@ -383,6 +388,8 @@ 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.DATA_AND_FAILURES) { | ||
| dataAndFailuresSelectorAccessPrivileges.add(indexPrivilege); | ||
| } else { | ||
| String errorMessage = "unexpected selector [" + indexPrivilege.selectorPredicate + "]"; | ||
| assert false : errorMessage; | ||
| 
        
          
        
         | 
    @@ -406,6 +413,7 @@ private static Set<IndexPrivilege> resolve(Set<String> name) { | |
| allSelectorAccessPrivileges, | ||
| dataSelectorAccessPrivileges, | ||
| failuresSelectorAccessPrivileges, | ||
| dataAndFailuresSelectorAccessPrivileges, | ||
| actions | ||
| ); | ||
| assertNamesMatch(name, combined); | ||
| 
        
          
        
         | 
    @@ -416,24 +424,33 @@ private static Set<IndexPrivilege> combineIndexPrivileges( | |
| Set<IndexPrivilege> allSelectorAccessPrivileges, | ||
| Set<IndexPrivilege> dataSelectorAccessPrivileges, | ||
| Set<IndexPrivilege> failuresSelectorAccessPrivileges, | ||
| Set<IndexPrivilege> dataAndFailuresSelectorAccessPrivileges, | ||
| Set<String> actions | ||
| ) { | ||
| assert false == allSelectorAccessPrivileges.isEmpty() | ||
| || false == dataSelectorAccessPrivileges.isEmpty() | ||
| || false == failuresSelectorAccessPrivileges.isEmpty() | ||
| || false == dataAndFailuresSelectorAccessPrivileges.isEmpty() | ||
| || false == actions.isEmpty() : "at least one of the privilege sets or actions must be non-empty"; | ||
| 
     | 
||
| if (false == allSelectorAccessPrivileges.isEmpty()) { | ||
| assert failuresSelectorAccessPrivileges.isEmpty() && dataSelectorAccessPrivileges.isEmpty() | ||
| : "data and failure access must be empty when all access is present"; | ||
| assert failuresSelectorAccessPrivileges.isEmpty() | ||
| && dataSelectorAccessPrivileges.isEmpty() | ||
| && dataAndFailuresSelectorAccessPrivileges.isEmpty() : "data and failure access must be empty when all access is present"; | ||
| return Set.of(union(allSelectorAccessPrivileges, actions, IndexComponentSelectorPredicate.ALL)); | ||
| } | ||
| 
     | 
||
| // linked hash set to preserve order across selectors | ||
| final Set<IndexPrivilege> combined = new LinkedHashSet<>(); | ||
| final Set<IndexPrivilege> combined = Sets.newLinkedHashSetWithExpectedSize( | ||
| dataAndFailuresSelectorAccessPrivileges.size() + failuresSelectorAccessPrivileges.size() + dataSelectorAccessPrivileges.size() | ||
| + actions.size() | ||
| ); | ||
| if (false == dataSelectorAccessPrivileges.isEmpty() || false == actions.isEmpty()) { | ||
| combined.add(union(dataSelectorAccessPrivileges, actions, IndexComponentSelectorPredicate.DATA)); | ||
| } | ||
| if (false == dataAndFailuresSelectorAccessPrivileges.isEmpty()) { | ||
| combined.add(union(dataAndFailuresSelectorAccessPrivileges, Set.of(), IndexComponentSelectorPredicate.DATA_AND_FAILURES)); | ||
| 
         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. nit: consider pre-sizing the   | 
||
| } | ||
| if (false == failuresSelectorAccessPrivileges.isEmpty()) { | ||
| combined.add(union(failuresSelectorAccessPrivileges, Set.of(), IndexComponentSelectorPredicate.FAILURES)); | ||
| } | ||
| 
          
            
          
           | 
    ||
  
    
      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
    
  
  
    
              
      
      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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.