Skip to content

Commit cd86b3b

Browse files
authored
[Entitlements] Refactor Network Entitlement (#120391)
1 parent 9c0709f commit cd86b3b

File tree

24 files changed

+237
-358
lines changed

24 files changed

+237
-358
lines changed

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,7 @@ public interface EntitlementChecker {
269269
// Network miscellanea
270270
void check$java_net_URL$openConnection(Class<?> callerClass, java.net.URL that, Proxy proxy);
271271

272-
// HttpClient.Builder is an interface, so we instrument its only (internal) implementation
273-
void check$jdk_internal_net_http_HttpClientBuilderImpl$build(Class<?> callerClass, HttpClient.Builder that);
274-
275-
// HttpClient#send and sendAsync are abstract, so we instrument their internal implementation
272+
// HttpClient#send and sendAsync are abstract, so we instrument their internal implementations
276273
void check$jdk_internal_net_http_HttpClientImpl$send(
277274
Class<?> callerClass,
278275
HttpClient that,
@@ -295,6 +292,28 @@ public interface EntitlementChecker {
295292
HttpResponse.PushPromiseHandler<?> pushPromiseHandler
296293
);
297294

295+
void check$jdk_internal_net_http_HttpClientFacade$send(
296+
Class<?> callerClass,
297+
HttpClient that,
298+
HttpRequest request,
299+
HttpResponse.BodyHandler<?> responseBodyHandler
300+
);
301+
302+
void check$jdk_internal_net_http_HttpClientFacade$sendAsync(
303+
Class<?> callerClass,
304+
HttpClient that,
305+
HttpRequest userRequest,
306+
HttpResponse.BodyHandler<?> responseHandler
307+
);
308+
309+
void check$jdk_internal_net_http_HttpClientFacade$sendAsync(
310+
Class<?> callerClass,
311+
HttpClient that,
312+
HttpRequest userRequest,
313+
HttpResponse.BodyHandler<?> responseHandler,
314+
HttpResponse.PushPromiseHandler<?> pushPromiseHandler
315+
);
316+
298317
// We need to check the LDAPCertStore, as this will connect, but this is internal/created via SPI,
299318
// so we instrument the general factory instead and then filter in the check method implementation
300319
void check$java_security_cert_CertStore$$getInstance(Class<?> callerClass, String type, CertStoreParameters params);

libs/entitlement/qa/common/src/main/java/org/elasticsearch/entitlement/qa/common/NetworkAccessCheckActions.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,6 @@ static void urlOpenConnectionWithProxy() throws URISyntaxException, IOException
8484
assert urlConnection != null;
8585
}
8686

87-
static void httpClientBuilderBuild() {
88-
try (HttpClient httpClient = HttpClient.newBuilder().build()) {
89-
assert httpClient != null;
90-
}
91-
}
92-
9387
static void httpClientSend() throws InterruptedException {
9488
try (HttpClient httpClient = HttpClient.newBuilder().build()) {
9589
// Shutdown the client, so the send action will shortcut before actually executing any network operation

libs/entitlement/qa/common/src/main/java/org/elasticsearch/entitlement/qa/common/RestEntitlementsCheckAction.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ static CheckAction alwaysDenied(CheckedRunnable<Exception> action) {
160160
entry("server_socket_accept", forPlugins(NetworkAccessCheckActions::serverSocketAccept)),
161161

162162
entry("url_open_connection_proxy", forPlugins(NetworkAccessCheckActions::urlOpenConnectionWithProxy)),
163-
entry("http_client_builder_build", forPlugins(NetworkAccessCheckActions::httpClientBuilderBuild)),
164163
entry("http_client_send", forPlugins(NetworkAccessCheckActions::httpClientSend)),
165164
entry("http_client_send_async", forPlugins(NetworkAccessCheckActions::httpClientSendAsync)),
166165
entry("create_ldap_cert_store", forPlugins(NetworkAccessCheckActions::createLDAPCertStore)),
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
ALL-UNNAMED:
22
- create_class_loader
33
- set_https_connection_properties
4-
- network:
5-
actions:
6-
- listen
7-
- accept
8-
- connect
4+
- inbound_network
5+
- outbound_network
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
org.elasticsearch.entitlement.qa.common:
22
- create_class_loader
33
- set_https_connection_properties
4-
- network:
5-
actions:
6-
- listen
7-
- accept
8-
- connect
4+
- inbound_network
5+
- outbound_network

libs/entitlement/src/main/java/org/elasticsearch/entitlement/initialization/EntitlementInitialization.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
import org.elasticsearch.entitlement.runtime.policy.CreateClassLoaderEntitlement;
2323
import org.elasticsearch.entitlement.runtime.policy.Entitlement;
2424
import org.elasticsearch.entitlement.runtime.policy.ExitVMEntitlement;
25-
import org.elasticsearch.entitlement.runtime.policy.NetworkEntitlement;
25+
import org.elasticsearch.entitlement.runtime.policy.InboundNetworkEntitlement;
26+
import org.elasticsearch.entitlement.runtime.policy.OutboundNetworkEntitlement;
2627
import org.elasticsearch.entitlement.runtime.policy.Policy;
2728
import org.elasticsearch.entitlement.runtime.policy.PolicyManager;
2829
import org.elasticsearch.entitlement.runtime.policy.PolicyParser;
@@ -45,9 +46,6 @@
4546
import java.util.Set;
4647
import java.util.stream.Collectors;
4748

48-
import static org.elasticsearch.entitlement.runtime.policy.NetworkEntitlement.ACCEPT_ACTION;
49-
import static org.elasticsearch.entitlement.runtime.policy.NetworkEntitlement.CONNECT_ACTION;
50-
import static org.elasticsearch.entitlement.runtime.policy.NetworkEntitlement.LISTEN_ACTION;
5149
import static org.elasticsearch.entitlement.runtime.policy.PolicyManager.ALL_UNNAMED;
5250

5351
/**
@@ -106,11 +104,12 @@ private static PolicyManager createPolicyManager() throws IOException {
106104
List.of(
107105
new ExitVMEntitlement(),
108106
new CreateClassLoaderEntitlement(),
109-
new NetworkEntitlement(LISTEN_ACTION | CONNECT_ACTION | ACCEPT_ACTION)
107+
new InboundNetworkEntitlement(),
108+
new OutboundNetworkEntitlement()
110109
)
111110
),
112-
new Scope("org.apache.httpcomponents.httpclient", List.of(new NetworkEntitlement(CONNECT_ACTION))),
113-
new Scope("io.netty.transport", List.of(new NetworkEntitlement(LISTEN_ACTION)))
111+
new Scope("org.apache.httpcomponents.httpclient", List.of(new OutboundNetworkEntitlement())),
112+
new Scope("io.netty.transport", List.of(new InboundNetworkEntitlement(), new OutboundNetworkEntitlement()))
114113
)
115114
);
116115
// agents run without a module, so this is a special hack for the apm agent

0 commit comments

Comments
 (0)