Skip to content

Commit de7dbd6

Browse files
authored
[Entitlements] Improve FileAccessTree logging (#127050) (#127152)
We already had logging in FileAccessTree as result of debugging the \\pipe\ failures a while ago; this PR slightly improves the logs to provide more information.
1 parent 2d6f5e1 commit de7dbd6

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/FileAccessTree.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,15 @@ private FileAccessTree(FilesEntitlement filesEntitlement, PathLookup pathLookup,
256256
this.exclusivePaths = sortedExclusivePaths;
257257
this.readPaths = pruneSortedPaths(readPaths).toArray(new String[0]);
258258
this.writePaths = pruneSortedPaths(writePaths).toArray(new String[0]);
259+
260+
logger.debug(
261+
() -> Strings.format(
262+
"Created FileAccessTree with paths: exclusive [%s], read [%s], write [%s]",
263+
String.join(",", this.exclusivePaths),
264+
String.join(",", this.readPaths),
265+
String.join(",", this.writePaths)
266+
)
267+
);
259268
}
260269

261270
// package private for testing
@@ -303,11 +312,17 @@ public static FileAccessTree withoutExclusivePaths(
303312
}
304313

305314
public boolean canRead(Path path) {
306-
return checkPath(normalizePath(path), readPaths);
315+
var normalizedPath = normalizePath(path);
316+
var canRead = checkPath(normalizedPath, readPaths);
317+
logger.trace(() -> Strings.format("checking [%s] (normalized to [%s]) for read: %b", path, normalizedPath, canRead));
318+
return canRead;
307319
}
308320

309321
public boolean canWrite(Path path) {
310-
return checkPath(normalizePath(path), writePaths);
322+
var normalizedPath = normalizePath(path);
323+
var canWrite = checkPath(normalizedPath, writePaths);
324+
logger.trace(() -> Strings.format("checking [%s] (normalized to [%s]) for write: %b", path, normalizedPath, canWrite));
325+
return canWrite;
311326
}
312327

313328
/**
@@ -325,7 +340,6 @@ static String normalizePath(Path path) {
325340
}
326341

327342
private boolean checkPath(String path, String[] paths) {
328-
logger.trace(() -> Strings.format("checking [%s] against [%s]", path, String.join(",", paths)));
329343
if (paths.length == 0) {
330344
return false;
331345
}
@@ -343,8 +357,9 @@ private boolean checkPath(String path, String[] paths) {
343357
}
344358

345359
private static boolean isParent(String maybeParent, String path) {
346-
logger.trace(() -> Strings.format("checking isParent [%s] for [%s]", maybeParent, path));
347-
return path.startsWith(maybeParent) && path.startsWith(FILE_SEPARATOR, maybeParent.length());
360+
var isParent = path.startsWith(maybeParent) && path.startsWith(FILE_SEPARATOR, maybeParent.length());
361+
logger.trace(() -> Strings.format("checking isParent [%s] for [%s]: %b", maybeParent, path, isParent));
362+
return isParent;
348363
}
349364

350365
@Override

0 commit comments

Comments
 (0)