- 
                Notifications
    
You must be signed in to change notification settings  - Fork 25.6k
 
Fix compilation and tests for customAuthzEngine #125469
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
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            3 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -11,10 +11,8 @@ | |
| 
     | 
||
| import org.elasticsearch.action.search.SearchRequest; | ||
| import org.elasticsearch.action.support.PlainActionFuture; | ||
| import org.elasticsearch.cluster.metadata.IndexAbstraction; | ||
| import org.elasticsearch.cluster.metadata.IndexAbstraction.ConcreteIndex; | ||
| import org.elasticsearch.action.support.SubscribableListener; | ||
| import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
| import org.elasticsearch.cluster.metadata.Metadata; | ||
| import org.elasticsearch.cluster.metadata.ProjectMetadata; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.index.IndexVersion; | ||
| 
        
          
        
         | 
    @@ -31,9 +29,6 @@ | |
| import org.elasticsearch.xpack.core.security.user.User; | ||
| 
     | 
||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.stream.Stream; | ||
| 
     | 
||
| import static org.hamcrest.Matchers.is; | ||
| 
     | 
||
| 
        
          
        
         | 
    @@ -52,13 +47,15 @@ public void testGetAuthorizationInfo() { | |
| 
     | 
||
| public void testAuthorizeRunAs() { | ||
| final String action = "cluster:monitor/foo"; | ||
| final TransportRequest request = new TransportRequest() {}; | ||
| final TransportRequest request = new TransportRequest() { | ||
| }; | ||
| CustomAuthorizationEngine engine = new CustomAuthorizationEngine(); | ||
| // unauthorized | ||
| { | ||
| Authentication authentication = Authentication | ||
| .newRealmAuthentication(new User("bar", "not_superuser"), new RealmRef("test", "test", "node")) | ||
| .runAs(new User("joe", "custom_superuser"), new RealmRef("test", "test", "node")); | ||
| Authentication authentication = Authentication.newRealmAuthentication( | ||
| new User("bar", "not_superuser"), | ||
| new RealmRef("test", "test", "node") | ||
| ).runAs(new User("joe", "custom_superuser"), new RealmRef("test", "test", "node")); | ||
| 
         
      Comment on lines
    
      -59
     to 
      +58
    
   
  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. No real change here other than format. This module has not been properly formatted for a while. There are a few more places in the PR like this.  | 
||
| RequestInfo info = new RequestInfo(authentication, request, action, null); | ||
| PlainActionFuture<AuthorizationInfo> future = new PlainActionFuture<>(); | ||
| engine.resolveAuthorizationInfo(info, future); | ||
| 
        
          
        
         | 
    @@ -72,9 +69,10 @@ public void testAuthorizeRunAs() { | |
| 
     | 
||
| // authorized | ||
| { | ||
| Authentication authentication = Authentication | ||
| .newRealmAuthentication(new User("bar", "custom_superuser"), new RealmRef("test", "test", "node")) | ||
| .runAs(new User("joe", "not_superuser"), new RealmRef("test", "test", "node")); | ||
| Authentication authentication = Authentication.newRealmAuthentication( | ||
| new User("bar", "custom_superuser"), | ||
| new RealmRef("test", "test", "node") | ||
| ).runAs(new User("joe", "not_superuser"), new RealmRef("test", "test", "node")); | ||
| RequestInfo info = new RequestInfo(authentication, request, action, null); | ||
| PlainActionFuture<AuthorizationInfo> future = new PlainActionFuture<>(); | ||
| engine.resolveAuthorizationInfo(info, future); | ||
| 
          
            
          
           | 
    @@ -103,10 +101,12 @@ public void testAuthorizeClusterAction() { | |
| 
     | 
||
| // unauthorized | ||
| { | ||
| RequestInfo unauthReqInfo = | ||
| new RequestInfo( | ||
| Authentication.newRealmAuthentication(new User("joe", "not_superuser"), new RealmRef("test", "test", "node")), | ||
| requestInfo.getRequest(), requestInfo.getAction(), null); | ||
| RequestInfo unauthReqInfo = new RequestInfo( | ||
| Authentication.newRealmAuthentication(new User("joe", "not_superuser"), new RealmRef("test", "test", "node")), | ||
| requestInfo.getRequest(), | ||
| requestInfo.getAction(), | ||
| null | ||
| ); | ||
| PlainActionFuture<AuthorizationInfo> future = new PlainActionFuture<>(); | ||
| engine.resolveAuthorizationInfo(unauthReqInfo, future); | ||
| AuthorizationInfo authzInfo = future.actionGet(); | ||
| 
        
          
        
         | 
    @@ -120,48 +120,59 @@ public void testAuthorizeClusterAction() { | |
| 
     | 
||
| public void testAuthorizeIndexAction() { | ||
| CustomAuthorizationEngine engine = new CustomAuthorizationEngine(); | ||
| ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault()).put(IndexMetadata.builder("index") | ||
| .settings(Settings.builder().put("index.version.created", IndexVersion.current())) | ||
| .numberOfShards(1) | ||
| .numberOfReplicas(0) | ||
| .build(), | ||
| false | ||
| ).build(); | ||
| ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault()) | ||
| .put( | ||
| IndexMetadata.builder("index") | ||
| .settings(Settings.builder().put("index.version.created", IndexVersion.current())) | ||
| .numberOfShards(1) | ||
| .numberOfReplicas(0) | ||
| .build(), | ||
| false | ||
| ) | ||
| .build(); | ||
| // authorized | ||
| { | ||
| RequestInfo requestInfo = | ||
| new RequestInfo( | ||
| Authentication.newRealmAuthentication(new User("joe", "custom_superuser"), new RealmRef("test", "test", "node")), | ||
| new SearchRequest(), "indices:data/read/search", null); | ||
| RequestInfo requestInfo = new RequestInfo( | ||
| Authentication.newRealmAuthentication(new User("joe", "custom_superuser"), new RealmRef("test", "test", "node")), | ||
| new SearchRequest(), | ||
| "indices:data/read/search", | ||
| null | ||
| ); | ||
| PlainActionFuture<AuthorizationInfo> future = new PlainActionFuture<>(); | ||
| engine.resolveAuthorizationInfo(requestInfo, future); | ||
| AuthorizationInfo authzInfo = future.actionGet(); | ||
| 
     | 
||
| PlainActionFuture<IndexAuthorizationResult> resultFuture = new PlainActionFuture<>(); | ||
| engine.authorizeIndexAction(requestInfo, authzInfo, | ||
| listener -> listener.onResponse(new ResolvedIndices(Collections.singletonList("index"), Collections.emptyList())), | ||
| project, resultFuture); | ||
| IndexAuthorizationResult result = resultFuture.actionGet(); | ||
| final SubscribableListener<IndexAuthorizationResult> resultListener = engine.authorizeIndexAction( | ||
| requestInfo, | ||
| authzInfo, | ||
| () -> SubscribableListener.newSucceeded(new ResolvedIndices(Collections.singletonList("index"), Collections.emptyList())), | ||
| project | ||
| ); | ||
| IndexAuthorizationResult result = safeAwait(resultListener); | ||
| assertThat(result.isGranted(), is(true)); | ||
| IndicesAccessControl indicesAccessControl = result.getIndicesAccessControl(); | ||
| assertNotNull(indicesAccessControl.getIndexPermissions("index")); | ||
| } | ||
| 
     | 
||
| // unauthorized | ||
| { | ||
| RequestInfo requestInfo = | ||
| new RequestInfo( | ||
| Authentication.newRealmAuthentication(new User("joe", "not_superuser"), new RealmRef("test", "test", "node")), | ||
| new SearchRequest(), "indices:data/read/search", null); | ||
| RequestInfo requestInfo = new RequestInfo( | ||
| Authentication.newRealmAuthentication(new User("joe", "not_superuser"), new RealmRef("test", "test", "node")), | ||
| new SearchRequest(), | ||
| "indices:data/read/search", | ||
| null | ||
| ); | ||
| PlainActionFuture<AuthorizationInfo> future = new PlainActionFuture<>(); | ||
| engine.resolveAuthorizationInfo(requestInfo, future); | ||
| AuthorizationInfo authzInfo = future.actionGet(); | ||
| 
     | 
||
| PlainActionFuture<IndexAuthorizationResult> resultFuture = new PlainActionFuture<>(); | ||
| engine.authorizeIndexAction(requestInfo, authzInfo, | ||
| listener -> listener.onResponse(new ResolvedIndices(Collections.singletonList("index"), Collections.emptyList())), | ||
| project, resultFuture); | ||
| IndexAuthorizationResult result = resultFuture.actionGet(); | ||
| final SubscribableListener<IndexAuthorizationResult> resultListener = engine.authorizeIndexAction( | ||
| requestInfo, | ||
| authzInfo, | ||
| () -> SubscribableListener.newSucceeded(new ResolvedIndices(Collections.singletonList("index"), Collections.emptyList())), | ||
| project | ||
| ); | ||
| IndexAuthorizationResult result = safeAwait(resultListener); | ||
| assertThat(result.isGranted(), is(false)); | ||
| IndicesAccessControl indicesAccessControl = result.getIndicesAccessControl(); | ||
| assertNull(indicesAccessControl.getIndexPermissions("index")); | ||
| 
        
          
        
         | 
    @@ -170,9 +181,12 @@ public void testAuthorizeIndexAction() { | |
| 
     | 
||
| private RequestInfo getRequestInfo() { | ||
| final String action = "cluster:monitor/foo"; | ||
| final TransportRequest request = new TransportRequest() {}; | ||
| final Authentication authentication = | ||
| Authentication.newRealmAuthentication(new User("joe", "custom_superuser"), new RealmRef("test", "test", "node")); | ||
| final TransportRequest request = new TransportRequest() { | ||
| }; | ||
| final Authentication authentication = Authentication.newRealmAuthentication( | ||
| new User("joe", "custom_superuser"), | ||
| new RealmRef("test", "test", "node") | ||
| ); | ||
| return new RequestInfo(authentication, request, action, null); | ||
| } | ||
| } | ||
  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.
Not related to custom authz engine. But needs to be fixed as well so that CI can pass.