Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

package org.elasticsearch.entitlement.runtime.policy;

import org.elasticsearch.core.Strings;
import org.elasticsearch.entitlement.runtime.policy.entitlements.FilesEntitlement;
import org.elasticsearch.entitlement.runtime.policy.entitlements.FilesEntitlement.Mode;
import org.elasticsearch.logging.LogManager;
Expand Down Expand Up @@ -202,6 +203,7 @@ static String normalizePath(Path path) {
}

private boolean checkPath(String path, String[] paths) {
logger.trace(() -> Strings.format("checking [%s] against [%s]", path, String.join(",", paths)));
if (paths.length == 0) {
return false;
}
Expand All @@ -219,6 +221,7 @@ private boolean checkPath(String path, String[] paths) {
}

private static boolean isParent(String maybeParent, String path) {
logger.trace(() -> Strings.format("checking isParent [%s] for [%s]", maybeParent, path));
return path.startsWith(maybeParent) && path.startsWith(FILE_SEPARATOR, maybeParent.length());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

package org.elasticsearch.entitlement.runtime.policy;

import org.elasticsearch.core.PathUtils;
import org.elasticsearch.core.Strings;
import org.elasticsearch.core.SuppressForbidden;
import org.elasticsearch.entitlement.instrumentation.InstrumentationService;
Expand Down Expand Up @@ -61,6 +62,8 @@ public class PolicyManager {
static final String SERVER_COMPONENT_NAME = "(server)";
static final String APM_AGENT_COMPONENT_NAME = "(APM agent)";

static final Class<?> DEFAULT_FILESYSTEM_CLASS = PathUtils.getDefaultFileSystem().getClass();

/**
* @param componentName the plugin name; or else one of the special component names
* like {@link #SERVER_COMPONENT_NAME} or {@link #APM_AGENT_COMPONENT_NAME}.
Expand Down Expand Up @@ -305,7 +308,26 @@ public void checkFileRead(Class<?> callerClass, File file) {
checkFileRead(callerClass, file.toPath());
}

private static boolean isPathOnDefaultFilesystem(Path path) {
var pathFileSystemClass = path.getFileSystem().getClass();
if (path.getFileSystem().getClass() != DEFAULT_FILESYSTEM_CLASS) {
logger.trace(
() -> Strings.format(
"File entitlement trivially allowed: path [%s] is for a different FileSystem class [%s], default is [%s]",
path.toString(),
pathFileSystemClass.getName(),
DEFAULT_FILESYSTEM_CLASS.getName()
)
);
return false;
}
return true;
}

public void checkFileRead(Class<?> callerClass, Path path) {
if (isPathOnDefaultFilesystem(path) == false) {
return;
}
var requestingClass = requestingClass(callerClass);
if (isTriviallyAllowed(requestingClass)) {
return;
Expand All @@ -332,6 +354,9 @@ public void checkFileWrite(Class<?> callerClass, File file) {
}

public void checkFileWrite(Class<?> callerClass, Path path) {
if (isPathOnDefaultFilesystem(path) == false) {
return;
}
var requestingClass = requestingClass(callerClass);
if (isTriviallyAllowed(requestingClass)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ static boolean isAbsolutePath(String path) {
// Unix/BSD absolute
return true;
}

return isWindowsAbsolutePath(path);
}

Expand Down