Skip to content

Commit 745aa1e

Browse files
ldematteelasticsearchmachine
andauthored
[Entitlements] Instrumentation of NIO Files and Channels (#122816 and #122591) (#122986)
* [Entitlements] Add check functions for NIO Files (#122591) * [Entitlements] Instrumentation of NIO file channels (#122816) * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <[email protected]>
1 parent 1420de7 commit 745aa1e

File tree

31 files changed

+1606
-58
lines changed

31 files changed

+1606
-58
lines changed

distribution/tools/server-cli/src/main/java/org/elasticsearch/server/cli/SystemJvmOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ private static Stream<String> maybeAttachEntitlementAgent(boolean useEntitlement
189189
}
190190
// We instrument classes in these modules to call the bridge. Because the bridge gets patched
191191
// into java.base, we must export the bridge from java.base to these modules, as a comma-separated list
192-
String modulesContainingEntitlementInstrumentation = "java.logging,java.net.http,java.naming";
192+
String modulesContainingEntitlementInstrumentation = "java.logging,java.net.http,java.naming,jdk.net";
193193
return Stream.of(
194194
"-Des.entitlements.enabled=true",
195195
"-XX:+EnableDynamicAgentLoading",

libs/entitlement/bridge/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// At build and run time, the bridge is patched into the java.base module.
1212
module org.elasticsearch.entitlement.bridge {
1313
requires java.net.http;
14+
requires jdk.net;
1415

1516
exports org.elasticsearch.entitlement.bridge;
1617
}

libs/entitlement/bridge/src/main/java/org/elasticsearch/entitlement/bridge/EntitlementChecker.java

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99

1010
package org.elasticsearch.entitlement.bridge;
1111

12+
import jdk.nio.Channels;
13+
1214
import java.io.File;
1315
import java.io.FileDescriptor;
1416
import java.io.FileFilter;
1517
import java.io.FilenameFilter;
1618
import java.io.InputStream;
19+
import java.io.OutputStream;
1720
import java.io.PrintStream;
1821
import java.io.PrintWriter;
1922
import java.net.ContentHandlerFactory;
@@ -51,12 +54,18 @@
5154
import java.nio.file.CopyOption;
5255
import java.nio.file.DirectoryStream;
5356
import java.nio.file.FileStore;
57+
import java.nio.file.FileVisitOption;
58+
import java.nio.file.FileVisitor;
5459
import java.nio.file.LinkOption;
5560
import java.nio.file.OpenOption;
5661
import java.nio.file.Path;
5762
import java.nio.file.WatchEvent;
5863
import java.nio.file.WatchService;
64+
import java.nio.file.attribute.BasicFileAttributes;
5965
import java.nio.file.attribute.FileAttribute;
66+
import java.nio.file.attribute.FileAttributeView;
67+
import java.nio.file.attribute.FileTime;
68+
import java.nio.file.attribute.PosixFilePermission;
6069
import java.nio.file.attribute.UserPrincipal;
6170
import java.nio.file.spi.FileSystemProvider;
6271
import java.security.KeyStore;
@@ -70,6 +79,7 @@
7079
import java.util.TimeZone;
7180
import java.util.concurrent.ExecutorService;
7281
import java.util.concurrent.ForkJoinPool;
82+
import java.util.function.BiPredicate;
7383

7484
import javax.net.ssl.HostnameVerifier;
7585
import javax.net.ssl.HttpsURLConnection;
@@ -606,12 +616,210 @@ public interface EntitlementChecker {
606616
void check$java_util_zip_ZipFile$(Class<?> callerClass, File file, int mode, Charset charset);
607617

608618
// nio
619+
// channels
620+
void check$java_nio_channels_FileChannel$(Class<?> callerClass);
621+
622+
void check$java_nio_channels_FileChannel$$open(
623+
Class<?> callerClass,
624+
Path path,
625+
Set<? extends OpenOption> options,
626+
FileAttribute<?>... attrs
627+
);
628+
629+
void check$java_nio_channels_FileChannel$$open(Class<?> callerClass, Path path, OpenOption... options);
630+
631+
void check$java_nio_channels_AsynchronousFileChannel$(Class<?> callerClass);
632+
633+
void check$java_nio_channels_AsynchronousFileChannel$$open(
634+
Class<?> callerClass,
635+
Path path,
636+
Set<? extends OpenOption> options,
637+
ExecutorService executor,
638+
FileAttribute<?>... attrs
639+
);
640+
641+
void check$java_nio_channels_AsynchronousFileChannel$$open(Class<?> callerClass, Path path, OpenOption... options);
642+
643+
void check$jdk_nio_Channels$$readWriteSelectableChannel(
644+
Class<?> callerClass,
645+
FileDescriptor fd,
646+
Channels.SelectableChannelCloser closer
647+
);
648+
649+
// files
609650
void check$java_nio_file_Files$$getOwner(Class<?> callerClass, Path path, LinkOption... options);
610651

611652
void check$java_nio_file_Files$$probeContentType(Class<?> callerClass, Path path);
612653

613654
void check$java_nio_file_Files$$setOwner(Class<?> callerClass, Path path, UserPrincipal principal);
614655

656+
void check$java_nio_file_Files$$newInputStream(Class<?> callerClass, Path path, OpenOption... options);
657+
658+
void check$java_nio_file_Files$$newOutputStream(Class<?> callerClass, Path path, OpenOption... options);
659+
660+
void check$java_nio_file_Files$$newByteChannel(
661+
Class<?> callerClass,
662+
Path path,
663+
Set<? extends OpenOption> options,
664+
FileAttribute<?>... attrs
665+
);
666+
667+
void check$java_nio_file_Files$$newByteChannel(Class<?> callerClass, Path path, OpenOption... options);
668+
669+
void check$java_nio_file_Files$$newDirectoryStream(Class<?> callerClass, Path dir);
670+
671+
void check$java_nio_file_Files$$newDirectoryStream(Class<?> callerClass, Path dir, String glob);
672+
673+
void check$java_nio_file_Files$$newDirectoryStream(Class<?> callerClass, Path dir, DirectoryStream.Filter<? super Path> filter);
674+
675+
void check$java_nio_file_Files$$createFile(Class<?> callerClass, Path path, FileAttribute<?>... attrs);
676+
677+
void check$java_nio_file_Files$$createDirectory(Class<?> callerClass, Path dir, FileAttribute<?>... attrs);
678+
679+
void check$java_nio_file_Files$$createDirectories(Class<?> callerClass, Path dir, FileAttribute<?>... attrs);
680+
681+
void check$java_nio_file_Files$$createTempFile(Class<?> callerClass, Path dir, String prefix, String suffix, FileAttribute<?>... attrs);
682+
683+
void check$java_nio_file_Files$$createTempFile(Class<?> callerClass, String prefix, String suffix, FileAttribute<?>... attrs);
684+
685+
void check$java_nio_file_Files$$createTempDirectory(Class<?> callerClass, Path dir, String prefix, FileAttribute<?>... attrs);
686+
687+
void check$java_nio_file_Files$$createTempDirectory(Class<?> callerClass, String prefix, FileAttribute<?>... attrs);
688+
689+
void check$java_nio_file_Files$$createSymbolicLink(Class<?> callerClass, Path link, Path target, FileAttribute<?>... attrs);
690+
691+
void check$java_nio_file_Files$$createLink(Class<?> callerClass, Path link, Path existing);
692+
693+
void check$java_nio_file_Files$$delete(Class<?> callerClass, Path path);
694+
695+
void check$java_nio_file_Files$$deleteIfExists(Class<?> callerClass, Path path);
696+
697+
void check$java_nio_file_Files$$copy(Class<?> callerClass, Path source, Path target, CopyOption... options);
698+
699+
void check$java_nio_file_Files$$move(Class<?> callerClass, Path source, Path target, CopyOption... options);
700+
701+
void check$java_nio_file_Files$$readSymbolicLink(Class<?> callerClass, Path link);
702+
703+
void check$java_nio_file_Files$$getFileStore(Class<?> callerClass, Path path);
704+
705+
void check$java_nio_file_Files$$isSameFile(Class<?> callerClass, Path path, Path path2);
706+
707+
void check$java_nio_file_Files$$mismatch(Class<?> callerClass, Path path, Path path2);
708+
709+
void check$java_nio_file_Files$$isHidden(Class<?> callerClass, Path path);
710+
711+
void check$java_nio_file_Files$$getFileAttributeView(
712+
Class<?> callerClass,
713+
Path path,
714+
Class<? extends FileAttributeView> type,
715+
LinkOption... options
716+
);
717+
718+
void check$java_nio_file_Files$$readAttributes(
719+
Class<?> callerClass,
720+
Path path,
721+
Class<? extends BasicFileAttributes> type,
722+
LinkOption... options
723+
);
724+
725+
void check$java_nio_file_Files$$setAttribute(Class<?> callerClass, Path path, String attribute, Object value, LinkOption... options);
726+
727+
void check$java_nio_file_Files$$getAttribute(Class<?> callerClass, Path path, String attribute, LinkOption... options);
728+
729+
void check$java_nio_file_Files$$readAttributes(Class<?> callerClass, Path path, String attributes, LinkOption... options);
730+
731+
void check$java_nio_file_Files$$getPosixFilePermissions(Class<?> callerClass, Path path, LinkOption... options);
732+
733+
void check$java_nio_file_Files$$setPosixFilePermissions(Class<?> callerClass, Path path, Set<PosixFilePermission> perms);
734+
735+
void check$java_nio_file_Files$$isSymbolicLink(Class<?> callerClass, Path path);
736+
737+
void check$java_nio_file_Files$$isDirectory(Class<?> callerClass, Path path, LinkOption... options);
738+
739+
void check$java_nio_file_Files$$isRegularFile(Class<?> callerClass, Path path, LinkOption... options);
740+
741+
void check$java_nio_file_Files$$getLastModifiedTime(Class<?> callerClass, Path path, LinkOption... options);
742+
743+
void check$java_nio_file_Files$$setLastModifiedTime(Class<?> callerClass, Path path, FileTime time);
744+
745+
void check$java_nio_file_Files$$size(Class<?> callerClass, Path path);
746+
747+
void check$java_nio_file_Files$$exists(Class<?> callerClass, Path path, LinkOption... options);
748+
749+
void check$java_nio_file_Files$$notExists(Class<?> callerClass, Path path, LinkOption... options);
750+
751+
void check$java_nio_file_Files$$isReadable(Class<?> callerClass, Path path);
752+
753+
void check$java_nio_file_Files$$isWritable(Class<?> callerClass, Path path);
754+
755+
void check$java_nio_file_Files$$isExecutable(Class<?> callerClass, Path path);
756+
757+
void check$java_nio_file_Files$$walkFileTree(
758+
Class<?> callerClass,
759+
Path start,
760+
Set<FileVisitOption> options,
761+
int maxDepth,
762+
FileVisitor<? super Path> visitor
763+
);
764+
765+
void check$java_nio_file_Files$$walkFileTree(Class<?> callerClass, Path start, FileVisitor<? super Path> visitor);
766+
767+
void check$java_nio_file_Files$$newBufferedReader(Class<?> callerClass, Path path, Charset cs);
768+
769+
void check$java_nio_file_Files$$newBufferedReader(Class<?> callerClass, Path path);
770+
771+
void check$java_nio_file_Files$$newBufferedWriter(Class<?> callerClass, Path path, Charset cs, OpenOption... options);
772+
773+
void check$java_nio_file_Files$$newBufferedWriter(Class<?> callerClass, Path path, OpenOption... options);
774+
775+
void check$java_nio_file_Files$$copy(Class<?> callerClass, InputStream in, Path target, CopyOption... options);
776+
777+
void check$java_nio_file_Files$$copy(Class<?> callerClass, Path source, OutputStream out);
778+
779+
void check$java_nio_file_Files$$readAllBytes(Class<?> callerClass, Path path);
780+
781+
void check$java_nio_file_Files$$readString(Class<?> callerClass, Path path);
782+
783+
void check$java_nio_file_Files$$readString(Class<?> callerClass, Path path, Charset cs);
784+
785+
void check$java_nio_file_Files$$readAllLines(Class<?> callerClass, Path path, Charset cs);
786+
787+
void check$java_nio_file_Files$$readAllLines(Class<?> callerClass, Path path);
788+
789+
void check$java_nio_file_Files$$write(Class<?> callerClass, Path path, byte[] bytes, OpenOption... options);
790+
791+
void check$java_nio_file_Files$$write(
792+
Class<?> callerClass,
793+
Path path,
794+
Iterable<? extends CharSequence> lines,
795+
Charset cs,
796+
OpenOption... options
797+
);
798+
799+
void check$java_nio_file_Files$$write(Class<?> callerClass, Path path, Iterable<? extends CharSequence> lines, OpenOption... options);
800+
801+
void check$java_nio_file_Files$$writeString(Class<?> callerClass, Path path, CharSequence csq, OpenOption... options);
802+
803+
void check$java_nio_file_Files$$writeString(Class<?> callerClass, Path path, CharSequence csq, Charset cs, OpenOption... options);
804+
805+
void check$java_nio_file_Files$$list(Class<?> callerClass, Path dir);
806+
807+
void check$java_nio_file_Files$$walk(Class<?> callerClass, Path start, int maxDepth, FileVisitOption... options);
808+
809+
void check$java_nio_file_Files$$walk(Class<?> callerClass, Path start, FileVisitOption... options);
810+
811+
void check$java_nio_file_Files$$find(
812+
Class<?> callerClass,
813+
Path start,
814+
int maxDepth,
815+
BiPredicate<Path, BasicFileAttributes> matcher,
816+
FileVisitOption... options
817+
);
818+
819+
void check$java_nio_file_Files$$lines(Class<?> callerClass, Path path, Charset cs);
820+
821+
void check$java_nio_file_Files$$lines(Class<?> callerClass, Path path);
822+
615823
// file system providers
616824
void check$java_nio_file_spi_FileSystemProvider$(Class<?> callerClass);
617825

libs/entitlement/qa/entitlement-test-plugin/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
// Modules we'll attempt to use in order to exercise entitlements
1717
requires java.logging;
1818
requires java.net.http;
19+
requires jdk.net;
1920
}

0 commit comments

Comments
 (0)