- 
                Notifications
    
You must be signed in to change notification settings  - Fork 56
 
Onboards flow-framework plugin to resource-sharing and access control framework #1251
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
base: main
Are you sure you want to change the base?
Onboards flow-framework plugin to resource-sharing and access control framework #1251
Conversation
… framework Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
| 
           CI will resolve once: opensearch-project/security#5677 is merged.  | 
    
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
…e-sharing tests Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
8f62909    to
    6937e06      
    Compare
  
    Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
dace39b    to
    69009e6      
    Compare
  
    | 
           CI blocked by #1252  | 
    
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
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.
1st iteration
        
          
                src/main/java/org/opensearch/flowframework/util/ParseUtils.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/main/java/org/opensearch/flowframework/transport/PluginClient.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/main/java/org/opensearch/flowframework/transport/PluginClient.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/main/java/org/opensearch/flowframework/transport/PluginClient.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/main/java/org/opensearch/flowframework/util/ResourceSharingClientAccessor.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
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.
2nd iteration
| strategy: | ||
| matrix: | ||
| java: [21] | ||
| resource_sharing_flag: [ "", "-Dresource_sharing.enabled=true" ] | 
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.
Can be replaced with
| resource_sharing_flag: [ "", "-Dresource_sharing.enabled=true" ] | |
| resource_sharing_flag: [ false, true ] | 
and later can be used -Dresource_sharing.enabled=${{ matrix.resource_sharing_flag }}.
| */ | ||
| public static void verifyResourceAccessAndProcessRequest(String resourceType, Runnable onSuccess, Runnable fallBackIfDisabled) { | ||
| // Resource access will be auto-evaluated | ||
| if (shouldUseResourceAuthz(resourceType)) { | 
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.
Should be under a try/catch block here
| if (subject == null) { | ||
| throw new IllegalStateException("PluginClient is not initialized."); | ||
| } | ||
| try (ThreadContext.StoredContext ctx = threadPool().getThreadContext().newStoredContext(false)) { | 
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.
| try (ThreadContext.StoredContext ctx = threadPool().getThreadContext().newStoredContext(false)) { | |
| try (ThreadContext.StoredContext ctx = threadPool().getThreadContext().stashContext) { | 
newStoredContext(false) might unintentionally preserve or lose headers
| try (ThreadContext.StoredContext ctx = threadPool().getThreadContext().newStoredContext(false)) { | ||
| subject.runAs(() -> { | ||
| logger.info("Running transport action with subject: {}", subject.getPrincipal().getName()); | ||
| super.doExecute(action, request, ActionListener.runBefore(listener, ctx::restore)); | 
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.
Here, doExecute would still be running since it runs in async manner. Since the context is created in the try block, it would be restored once the try block finishes. So the doExecute request would still be running and can cause thread context leak or premature restoration.
Better way would be just
ThreadContext.StoredContext ctx =  threadPool().getThreadContext().stashContext();
subject.runAs(() -> {
    super.doExecute(action, request, ActionListener.runBefore(listener, ctx::restore));
});this would ensure context is restored back only when listener returns either a response or a failure
| * Set the resource sharing client | ||
| */ | ||
| public void setResourceSharingClient(ResourceSharingClient client) { | ||
| resourceSharingClientAccessor.client.set(client); | 
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.
no need to reference static field here
| resourceSharingClientAccessor.client.set(client); | |
| this.client.set(client); | 
| * Get the resource sharing client | ||
| */ | ||
| public ResourceSharingClient getResourceSharingClient() { | ||
| return resourceSharingClientAccessor.client.get(); | 
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.
| return resourceSharingClientAccessor.client.get(); | |
| return this.client.get(); | 
Also, can we add a null check here and return IllegalStateException
| public class ResourceSharingClientAccessor { | ||
| private final AtomicReference<ResourceSharingClient> client = new AtomicReference<>(); | ||
| 
               | 
          ||
| private static ResourceSharingClientAccessor resourceSharingClientAccessor; | 
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.
For thread safety
| private static ResourceSharingClientAccessor resourceSharingClientAccessor; | |
| private static final ResourceSharingClientAccessor INSTANCE = new ResourceSharingClientAccessor(); | 
| if (resourceSharingClientAccessor == null) { | ||
| resourceSharingClientAccessor = new ResourceSharingClientAccessor(); | ||
| } | ||
| 
               | 
          ||
| return resourceSharingClientAccessor; | 
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.
Now we can just return
| if (resourceSharingClientAccessor == null) { | |
| resourceSharingClientAccessor = new ResourceSharingClientAccessor(); | |
| } | |
| return resourceSharingClientAccessor; | |
| return INSTANCE; | 
| testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") | ||
| testImplementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${versions.jackson_databind}") | ||
| 
               | 
          ||
| testImplementation "org.awaitility:awaitility:${awaitlityVersion}" | 
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.
| testImplementation "org.awaitility:awaitility:${awaitlityVersion}" | |
| testImplementation "org.awaitility:awaitility:${awaitilityVersion}" | 
Description
Implements resource-access-control for workflow and workflow_state.
Related Issues
Check List
--signoff.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.