Skip to content

Conversation

@DarshitChanpura
Copy link
Member

@DarshitChanpura DarshitChanpura commented Oct 13, 2025

Description

Implements resource-access-control for workflow and workflow_state.

Related Issues

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

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.

… framework

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
@DarshitChanpura
Copy link
Member Author

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>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
@DarshitChanpura
Copy link
Member Author

CI blocked by #1252

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Copy link
Member

@owaiskazi19 owaiskazi19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1st iteration

Copy link
Member

@owaiskazi19 owaiskazi19 left a 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" ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be replaced with

Suggested change
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)) {
Copy link
Member

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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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));
Copy link
Member

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);
Copy link
Member

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

Suggested change
resourceSharingClientAccessor.client.set(client);
this.client.set(client);

* Get the resource sharing client
*/
public ResourceSharingClient getResourceSharingClient() {
return resourceSharingClientAccessor.client.get();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For thread safety

Suggested change
private static ResourceSharingClientAccessor resourceSharingClientAccessor;
private static final ResourceSharingClientAccessor INSTANCE = new ResourceSharingClientAccessor();

Comment on lines +26 to +30
if (resourceSharingClientAccessor == null) {
resourceSharingClientAccessor = new ResourceSharingClientAccessor();
}

return resourceSharingClientAccessor;
Copy link
Member

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

Suggested change
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}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
testImplementation "org.awaitility:awaitility:${awaitlityVersion}"
testImplementation "org.awaitility:awaitility:${awaitilityVersion}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Onboard flow-framework plugin to Centralized Resource AuthZ framework

2 participants