Skip to content

Commit e9b772b

Browse files
authored
[8.18][Entitlements] Add URLConnection instrumentation (#123966)
* [Entitlements] Add URLConnection instrumentation (#123503) * [Entitlements] Add URLConnection instrumentation for ftp, http and https protocols (#123802)
1 parent ac3742f commit e9b772b

File tree

11 files changed

+1133
-11
lines changed

11 files changed

+1133
-11
lines changed

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

Lines changed: 201 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,209 @@ public interface EntitlementChecker {
314314

315315
void check$java_net_Socket$connect(Class<?> callerClass, Socket that, SocketAddress endpoint, int backlog);
316316

317-
// Network miscellanea
317+
// URLConnection (java.net + sun.net.www)
318+
319+
void check$java_net_URL$openConnection(Class<?> callerClass, java.net.URL that);
320+
318321
void check$java_net_URL$openConnection(Class<?> callerClass, java.net.URL that, Proxy proxy);
319322

323+
void check$java_net_URL$openStream(Class<?> callerClass, java.net.URL that);
324+
325+
void check$java_net_URL$getContent(Class<?> callerClass, java.net.URL that);
326+
327+
void check$java_net_URL$getContent(Class<?> callerClass, java.net.URL that, Class<?>[] classes);
328+
329+
void check$java_net_URLConnection$getContentLength(Class<?> callerClass, java.net.URLConnection that);
330+
331+
void check$java_net_URLConnection$getContentLengthLong(Class<?> callerClass, java.net.URLConnection that);
332+
333+
void check$java_net_URLConnection$getContentType(Class<?> callerClass, java.net.URLConnection that);
334+
335+
void check$java_net_URLConnection$getContentEncoding(Class<?> callerClass, java.net.URLConnection that);
336+
337+
void check$java_net_URLConnection$getExpiration(Class<?> callerClass, java.net.URLConnection that);
338+
339+
void check$java_net_URLConnection$getDate(Class<?> callerClass, java.net.URLConnection that);
340+
341+
void check$java_net_URLConnection$getLastModified(Class<?> callerClass, java.net.URLConnection that);
342+
343+
void check$java_net_URLConnection$getHeaderFieldInt(Class<?> callerClass, java.net.URLConnection that, String name, int defaultValue);
344+
345+
void check$java_net_URLConnection$getHeaderFieldLong(Class<?> callerClass, java.net.URLConnection that, String name, long defaultValue);
346+
347+
void check$java_net_URLConnection$getHeaderFieldDate(Class<?> callerClass, java.net.URLConnection that, String name, long defaultValue);
348+
349+
void check$java_net_URLConnection$getContent(Class<?> callerClass, java.net.URLConnection that);
350+
351+
void check$java_net_URLConnection$getContent(Class<?> callerClass, java.net.URLConnection that, Class<?>[] classes);
352+
353+
void check$java_net_HttpURLConnection$getResponseCode(Class<?> callerClass, java.net.HttpURLConnection that);
354+
355+
void check$java_net_HttpURLConnection$getResponseMessage(Class<?> callerClass, java.net.HttpURLConnection that);
356+
357+
void check$java_net_HttpURLConnection$getHeaderFieldDate(
358+
Class<?> callerClass,
359+
java.net.HttpURLConnection that,
360+
String name,
361+
long defaultValue
362+
);
363+
364+
// Using java.net.URLConnection for "that" as sun.net.www.* is not exported
365+
void check$sun_net_www_URLConnection$getHeaderField(Class<?> callerClass, java.net.URLConnection that, String name);
366+
367+
void check$sun_net_www_URLConnection$getHeaderFields(Class<?> callerClass, java.net.URLConnection that);
368+
369+
void check$sun_net_www_URLConnection$getHeaderFieldKey(Class<?> callerClass, java.net.URLConnection that, int n);
370+
371+
void check$sun_net_www_URLConnection$getHeaderField(Class<?> callerClass, java.net.URLConnection that, int n);
372+
373+
void check$sun_net_www_URLConnection$getContentType(Class<?> callerClass, java.net.URLConnection that);
374+
375+
void check$sun_net_www_URLConnection$getContentLength(Class<?> callerClass, java.net.URLConnection that);
376+
377+
void check$sun_net_www_protocol_ftp_FtpURLConnection$connect(Class<?> callerClass, java.net.URLConnection that);
378+
379+
void check$sun_net_www_protocol_ftp_FtpURLConnection$getInputStream(Class<?> callerClass, java.net.URLConnection that);
380+
381+
void check$sun_net_www_protocol_ftp_FtpURLConnection$getOutputStream(Class<?> callerClass, java.net.URLConnection that);
382+
383+
void check$sun_net_www_protocol_http_HttpURLConnection$$openConnectionCheckRedirects(Class<?> callerClass, java.net.URLConnection c);
384+
385+
void check$sun_net_www_protocol_http_HttpURLConnection$connect(Class<?> callerClass, java.net.HttpURLConnection that);
386+
387+
void check$sun_net_www_protocol_http_HttpURLConnection$getOutputStream(Class<?> callerClass, java.net.HttpURLConnection that);
388+
389+
void check$sun_net_www_protocol_http_HttpURLConnection$getInputStream(Class<?> callerClass, java.net.HttpURLConnection that);
390+
391+
void check$sun_net_www_protocol_http_HttpURLConnection$getErrorStream(Class<?> callerClass, java.net.HttpURLConnection that);
392+
393+
void check$sun_net_www_protocol_http_HttpURLConnection$getHeaderField(
394+
Class<?> callerClass,
395+
java.net.HttpURLConnection that,
396+
String name
397+
);
398+
399+
void check$sun_net_www_protocol_http_HttpURLConnection$getHeaderFields(Class<?> callerClass, java.net.HttpURLConnection that);
400+
401+
void check$sun_net_www_protocol_http_HttpURLConnection$getHeaderField(Class<?> callerClass, java.net.HttpURLConnection that, int n);
402+
403+
void check$sun_net_www_protocol_http_HttpURLConnection$getHeaderFieldKey(Class<?> callerClass, java.net.HttpURLConnection that, int n);
404+
405+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$connect(Class<?> callerClass, javax.net.ssl.HttpsURLConnection that);
406+
407+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getOutputStream(
408+
Class<?> callerClass,
409+
javax.net.ssl.HttpsURLConnection that
410+
);
411+
412+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getInputStream(
413+
Class<?> callerClass,
414+
javax.net.ssl.HttpsURLConnection that
415+
);
416+
417+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getErrorStream(
418+
Class<?> callerClass,
419+
javax.net.ssl.HttpsURLConnection that
420+
);
421+
422+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getHeaderField(
423+
Class<?> callerClass,
424+
javax.net.ssl.HttpsURLConnection that,
425+
String name
426+
);
427+
428+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getHeaderFields(
429+
Class<?> callerClass,
430+
javax.net.ssl.HttpsURLConnection that
431+
);
432+
433+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getHeaderField(
434+
Class<?> callerClass,
435+
javax.net.ssl.HttpsURLConnection that,
436+
int n
437+
);
438+
439+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getHeaderFieldKey(
440+
Class<?> callerClass,
441+
javax.net.ssl.HttpsURLConnection that,
442+
int n
443+
);
444+
445+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getResponseCode(
446+
Class<?> callerClass,
447+
javax.net.ssl.HttpsURLConnection that
448+
);
449+
450+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getResponseMessage(
451+
Class<?> callerClass,
452+
javax.net.ssl.HttpsURLConnection that
453+
);
454+
455+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getContentLength(
456+
Class<?> callerClass,
457+
javax.net.ssl.HttpsURLConnection that
458+
);
459+
460+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getContentLengthLong(
461+
Class<?> callerClass,
462+
javax.net.ssl.HttpsURLConnection that
463+
);
464+
465+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getContentType(
466+
Class<?> callerClass,
467+
javax.net.ssl.HttpsURLConnection that
468+
);
469+
470+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getContentEncoding(
471+
Class<?> callerClass,
472+
javax.net.ssl.HttpsURLConnection that
473+
);
474+
475+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getExpiration(Class<?> callerClass, javax.net.ssl.HttpsURLConnection that);
476+
477+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getDate(Class<?> callerClass, javax.net.ssl.HttpsURLConnection that);
478+
479+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getLastModified(
480+
Class<?> callerClass,
481+
javax.net.ssl.HttpsURLConnection that
482+
);
483+
484+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getHeaderFieldInt(
485+
Class<?> callerClass,
486+
javax.net.ssl.HttpsURLConnection that,
487+
String name,
488+
int defaultValue
489+
);
490+
491+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getHeaderFieldLong(
492+
Class<?> callerClass,
493+
javax.net.ssl.HttpsURLConnection that,
494+
String name,
495+
long defaultValue
496+
);
497+
498+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getHeaderFieldDate(
499+
Class<?> callerClass,
500+
javax.net.ssl.HttpsURLConnection that,
501+
String name,
502+
long defaultValue
503+
);
504+
505+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getContent(Class<?> callerClass, javax.net.ssl.HttpsURLConnection that);
506+
507+
void check$sun_net_www_protocol_https_HttpsURLConnectionImpl$getContent(
508+
Class<?> callerClass,
509+
javax.net.ssl.HttpsURLConnection that,
510+
Class<?>[] classes
511+
);
512+
513+
void check$sun_net_www_protocol_https_AbstractDelegateHttpsURLConnection$connect(
514+
Class<?> callerClass,
515+
javax.net.ssl.HttpsURLConnection that
516+
);
517+
518+
// Network miscellanea
519+
320520
// HttpClient#send and sendAsync are abstract, so we instrument their internal implementations
321521
void check$jdk_internal_net_http_HttpClientImpl$send(
322522
Class<?> callerClass,

libs/entitlement/qa/entitled-plugin/src/main/java/org/elasticsearch/entitlement/qa/entitled/EntitledActions.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import org.elasticsearch.core.SuppressForbidden;
1313

1414
import java.io.IOException;
15+
import java.net.URI;
16+
import java.net.URLConnection;
1517
import java.nio.file.Files;
1618
import java.nio.file.Path;
1719
import java.nio.file.Paths;
@@ -57,4 +59,16 @@ public static Path createTempDirectoryForWrite() throws IOException {
5759
public static Path createTempSymbolicLink() throws IOException {
5860
return Files.createSymbolicLink(readDir().resolve("entitlements-link-" + random.nextLong()), readWriteDir());
5961
}
62+
63+
public static URLConnection createHttpURLConnection() throws IOException {
64+
return URI.create("http://127.0.0.1:12345/").toURL().openConnection();
65+
}
66+
67+
public static URLConnection createHttpsURLConnection() throws IOException {
68+
return URI.create("https://127.0.0.1:12345/").toURL().openConnection();
69+
}
70+
71+
public static URLConnection createFtpURLConnection() throws IOException {
72+
return URI.create("ftp://127.0.0.1:12345/").toURL().openConnection();
73+
}
6074
}

libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/NetworkAccessCheckActions.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import java.net.ServerSocket;
1919
import java.net.Socket;
2020
import java.net.SocketException;
21-
import java.net.URI;
22-
import java.net.URISyntaxException;
2321
import java.nio.ByteBuffer;
2422
import java.nio.channels.AsynchronousServerSocketChannel;
2523
import java.nio.channels.AsynchronousSocketChannel;
@@ -75,12 +73,6 @@ static void socketConnect() throws IOException {
7573
}
7674
}
7775

78-
static void urlOpenConnectionWithProxy() throws URISyntaxException, IOException {
79-
var url = new URI("http://localhost").toURL();
80-
var urlConnection = url.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(0)));
81-
assert urlConnection != null;
82-
}
83-
8476
static void createLDAPCertStore() {
8577
try {
8678
// We pass down null params to provoke a InvalidAlgorithmParameterException

libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/RestEntitlementsCheckAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ static CheckAction alwaysDenied(CheckedRunnable<Exception> action) {
143143
entry("server_socket_bind", forPlugins(NetworkAccessCheckActions::serverSocketBind)),
144144
entry("server_socket_accept", forPlugins(NetworkAccessCheckActions::serverSocketAccept)),
145145

146-
entry("url_open_connection_proxy", forPlugins(NetworkAccessCheckActions::urlOpenConnectionWithProxy)),
147146
entry("http_client_send", forPlugins(VersionSpecificNetworkChecks::httpClientSend)),
148147
entry("http_client_send_async", forPlugins(VersionSpecificNetworkChecks::httpClientSendAsync)),
149148
entry("create_ldap_cert_store", forPlugins(NetworkAccessCheckActions::createLDAPCertStore)),
@@ -195,6 +194,7 @@ static CheckAction alwaysDenied(CheckedRunnable<Exception> action) {
195194
getTestEntries(PathActions.class),
196195
getTestEntries(SpiActions.class),
197196
getTestEntries(SystemActions.class),
197+
getTestEntries(URLConnectionNetworkActions.class),
198198
getTestEntries(VersionSpecificManageThreadsActions.class),
199199
getTestEntries(VersionSpecificNioFileSystemActions.class)
200200
)

0 commit comments

Comments
 (0)