Skip to content

Commit

Permalink
Fix JSM policy for arrow-flight-rpc module
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhmaurya committed Nov 24, 2024
1 parent 12ad318 commit 90c8d61
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
import org.opensearch.threadpool.ThreadPool;

import java.io.IOException;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Objects;

/**
Expand All @@ -55,7 +58,14 @@ public class FlightService extends AbstractLifecycleComponent {
* @param settings The settings for the FlightService.
*/
public FlightService(Settings settings) {
ServerConfig.init(settings);
try {
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
ServerConfig.init(settings);
return null;
});
} catch (Exception e) {
throw new RuntimeException("Failed to initialize Arrow Flight server", e);
}
}

/**
Expand Down Expand Up @@ -89,7 +99,10 @@ public void setSecureTransportSettingsProvider(SecureTransportSettingsProvider s
@Override
protected void doStart() {
try {
allocator = new RootAllocator(Integer.MAX_VALUE);
allocator = AccessController.doPrivileged(
(PrivilegedExceptionAction<BufferAllocator>) () -> new RootAllocator(Integer.MAX_VALUE)
);

BaseFlightProducer producer = new BaseFlightProducer(clientManager, streamManager, allocator);
FlightServerBuilder builder = new FlightServerBuilder(threadPool.get(), () -> allocator, producer, sslContextProvider);
server = builder.build();
Expand All @@ -98,6 +111,8 @@ protected void doStart() {
} catch (IOException e) {
logger.error("Failed to start Arrow Flight server", e);
throw new RuntimeException("Failed to start Arrow Flight server", e);
} catch (PrivilegedActionException e) {
throw new RuntimeException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

grant codeBase "${codebase.arrow-flight-rpc}" {
// arrow flight service permissions
permission java.util.PropertyPermission "arrow.allocation.manager.type", "write";
permission java.util.PropertyPermission "arrow.enable_null_check_for_get", "write";
permission java.util.PropertyPermission "arrow.enable_unsafe_memory_access", "write";
permission java.util.PropertyPermission "arrow.memory.debug.allocator", "write";

permission java.util.PropertyPermission "io.netty.tryReflectionSetAccessible", "write";
permission java.util.PropertyPermission "io.netty.allocator.numDirectArenas", "write";
permission java.util.PropertyPermission "io.netty.noUnsafe", "write";
permission java.util.PropertyPermission "io.netty.tryUnsafe", "write";
};
12 changes: 2 additions & 10 deletions server/src/main/resources/org/opensearch/bootstrap/security.policy
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,6 @@ grant {
permission java.io.FilePermission "/sys/fs/cgroup/memory", "read";
permission java.io.FilePermission "/sys/fs/cgroup/memory/-", "read";

// arrow flight server permissions
permission java.security.AllPermission;
permission java.util.PropertyPermission "arrow.allocation.manager.type", "write";
permission java.util.PropertyPermission "arrow.enable_null_check_for_get", "write";
permission java.util.PropertyPermission "io.netty.tryReflectionSetAccessible", "write";
permission java.util.PropertyPermission "arrow.enable_unsafe_memory_access", "write";
permission java.util.PropertyPermission "io.netty.allocator.numDirectArenas", "write";
permission java.util.PropertyPermission "io.netty.noUnsafe", "write";
permission java.util.PropertyPermission "io.netty.tryUnsafe", "write";
permission java.util.PropertyPermission "arrow.memory.debug.allocator", "write";
// Needed for netty based arrow flight server for netty configs related to buffer allocator
permission java.security.AllPermission "modifyThreadGroup";
};

0 comments on commit 90c8d61

Please sign in to comment.