99
1010package org .elasticsearch .entitlement .runtime .policy ;
1111
12+ import org .elasticsearch .core .PathUtils ;
1213import org .elasticsearch .core .Strings ;
1314import org .elasticsearch .core .SuppressForbidden ;
1415import org .elasticsearch .entitlement .instrumentation .InstrumentationService ;
@@ -61,6 +62,8 @@ public class PolicyManager {
6162 static final String SERVER_COMPONENT_NAME = "(server)" ;
6263 static final String APM_AGENT_COMPONENT_NAME = "(APM agent)" ;
6364
65+ static final Class <?> DEFAULT_FILESYSTEM_CLASS = PathUtils .getDefaultFileSystem ().getClass ();
66+
6467 /**
6568 * @param componentName the plugin name; or else one of the special component names
6669 * like {@link #SERVER_COMPONENT_NAME} or {@link #APM_AGENT_COMPONENT_NAME}.
@@ -305,7 +308,26 @@ public void checkFileRead(Class<?> callerClass, File file) {
305308 checkFileRead (callerClass , file .toPath ());
306309 }
307310
311+ private static boolean isPathOnDefaultFilesystem (Path path ) {
312+ var pathFileSystemClass = path .getFileSystem ().getClass ();
313+ if (path .getFileSystem ().getClass () != DEFAULT_FILESYSTEM_CLASS ) {
314+ logger .trace (
315+ () -> Strings .format (
316+ "File entitlement trivially allowed: path [%s] is for a different FileSystem class [%s], default is [%s]" ,
317+ path .toString (),
318+ pathFileSystemClass .getName (),
319+ DEFAULT_FILESYSTEM_CLASS .getName ()
320+ )
321+ );
322+ return false ;
323+ }
324+ return true ;
325+ }
326+
308327 public void checkFileRead (Class <?> callerClass , Path path ) {
328+ if (isPathOnDefaultFilesystem (path ) == false ) {
329+ return ;
330+ }
309331 var requestingClass = requestingClass (callerClass );
310332 if (isTriviallyAllowed (requestingClass )) {
311333 return ;
@@ -332,6 +354,9 @@ public void checkFileWrite(Class<?> callerClass, File file) {
332354 }
333355
334356 public void checkFileWrite (Class <?> callerClass , Path path ) {
357+ if (isPathOnDefaultFilesystem (path ) == false ) {
358+ return ;
359+ }
335360 var requestingClass = requestingClass (callerClass );
336361 if (isTriviallyAllowed (requestingClass )) {
337362 return ;
0 commit comments