Skip to content

Conversation

@ldematte
Copy link
Contributor

@ldematte ldematte commented Feb 26, 2025

We currently do not match these 3 permissions on elastic-apm-agent (module elastic.apm.agent)

permission java.net.SocketPermission "*", "connect,resolve";
permission org.elasticsearch.secure_sm.ThreadPermission "modifyArbitraryThreadGroup";
permission java.io.FilePermission "<<ALL FILES>>", "read,write";

I've added the first 2; I was surprised we did not caught the first one, it's pretty important to communicate to the APM agent, but then I looked at IT tests and we might have a miss there (we test only to localhost).
It's worth more investigation though, I made a note to do that.
The second one might be already covered by agentEntitlements, but I added it to the module as well - I think it's safer to err on the safer side :)

I'm very reluctant to add the third permission however. Read and write to all files? No. Wdyt?

Relates to ES-10031

Complete picture for reference:
(legend: x we have it, - we don't care about it, ? missing

grant {
 -   permission java.lang.RuntimePermission "accessSystemModules";
 x   permission java.lang.RuntimePermission "createClassLoader";
 -   permission java.lang.RuntimePermission "getClassLoader";
 x   permission java.util.PropertyPermission "elastic.apm.*", "write";
 x   permission java.util.PropertyPermission "*", "read,write";
 -   permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
};

grant codeBase "${codebase.elastic-apm-agent}" {
-    permission java.lang.RuntimePermission "accessDeclaredMembers";
-    permission java.lang.RuntimePermission "setContextClassLoader";
x    permission java.lang.RuntimePermission "setFactory";
-    permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
?    permission java.net.SocketPermission "*", "connect,resolve";
    // profiling function in APM agent
x    permission java.util.PropertyPermission "AsyncProfiler.safemode", "write";
-    permission java.lang.RuntimePermission "accessUserInformation";
x    permission java.lang.RuntimePermission "loadLibrary.*";
-    permission java.lang.RuntimePermission "getClassLoader";
?    permission java.io.FilePermission "<<ALL FILES>>", "read,write";
?    permission org.elasticsearch.secure_sm.ThreadPermission "modifyArbitraryThreadGroup";
-    permission java.net.NetPermission "getProxySelector";
};

@ldematte ldematte added >non-issue auto-backport Automatically create backport pull requests when merged v8.18.1 v8.19.0 v9.0.1 v9.1.0 :Core/Infra/Entitlements Entitlements infrastructure labels Feb 26, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label Feb 26, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@ldematte ldematte requested a review from a team February 26, 2025 08:44
@mosche
Copy link
Contributor

mosche commented Feb 26, 2025

I checked in QA, it looks like we're in deed missing permissions for the agent to write it's log file. Though, it could also be due to the fact that we're just logging >= WARN. We should deploy a project with INFO logging for the agent to be sure.

@mosche
Copy link
Contributor

mosche commented Feb 26, 2025

I can see metrics, so it seems to be able to connect to APM server

- AsyncProfiler.safemode
- load_native_libraries
- manage_threads
- outbound_network
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering, why is elastic.apm.agent needed at all? shouldn't this be covered by the default agent policy?
a bit worrying is that we receive metrics from my QA projects despite not allowing outbound_network here or in the default agent policy 😱

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were they apm metrics or just generic container metrics provided by metricbeat on the host?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue about missing outbound_network but still working might be due to missing instrumentation to URLConnection & derived that we discovered.

why is elastic.apm.agent needed at all

Hypothesis (that I will try to confirm): in the plugin that jar/module is used kind of a client/an API to talk to the agent/to the server?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I do wonder if we need these policies in both places, or just here, or just on the agentEntitlements fixed set.
I'll dig a bit more on this point too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved these entitlements to the agentEntitlements policy; considering the dependency is runtimeOnly and the code using these entitlements is in the agent, seems like that is the right place for them.
Tests pass, even though APM tests are really limited - I tried to run ES with-apm-server too and no errors there.
Will also try a Serverless QA deployment before merging.

@ldematte ldematte requested a review from mosche February 27, 2025 11:23
Copy link
Contributor

@mosche mosche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

new LoadNativeLibrariesEntitlement(),
new FilesEntitlement(
List.of(
FileData.ofPath(Path.of("/co/elastic/apm/agent/"), READ),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually these weird paths are ZipPaths! #123744 will fix that and we can remove them.

new SetHttpsConnectionPropertiesEntitlement(),
new OutboundNetworkEntitlement(),
new WriteSystemPropertiesEntitlement(Set.of("AsyncProfiler.safemode")),
new LoadNativeLibrariesEntitlement(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @rjernst pointed out, we don't need this anymore: the APM Agent is loaded before entitlements are turned on, so native loading happens before that and an entitlement is not needed. I'll remove this.

@ldematte ldematte merged commit c663e3d into elastic:main Mar 4, 2025
17 checks passed
@ldematte ldematte deleted the entitlements/missing-policies-3 branch March 4, 2025 07:33
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.18 Commit could not be cherrypicked due to conflicts
8.x Commit could not be cherrypicked due to conflicts
9.0 Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 123462

ldematte added a commit to ldematte/elasticsearch that referenced this pull request Mar 4, 2025
ldematte added a commit to ldematte/elasticsearch that referenced this pull request Mar 4, 2025
ldematte added a commit to ldematte/elasticsearch that referenced this pull request Mar 4, 2025
georgewallace pushed a commit to georgewallace/elasticsearch that referenced this pull request Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged :Core/Infra/Entitlements Entitlements infrastructure >non-issue Team:Core/Infra Meta label for core/infra team v8.18.1 v8.19.0 v9.0.1 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants