Commit graph

50 commits

Author SHA1 Message Date
Lorenzo Dematté
02493f35f3
Add package-info.java and javadocs to document Entitlements design and implementation (#127023)
Design and implementation of Entitlement with this level of detail needs to stay close to the code, and take advantage of javadoc features like linking and class-references to help us with refactorings and future code changes.

The bulk of the information went into the package-info file for the main library, but I split up some parts and referenced them from the main doc, where I thought it made sense (mainly: the bridge sub-project for some implementation details, PolicyManager, EntitlementInitialization and FileAccessTree); this way they still can be reached from the "overview" while being closer to where the information really belongs.

Relates to ES-11284
2025-04-22 10:46:20 +02:00
Patrick Doyle
b8c70ae36d
Custom getCallerClass in entitlement bridge (#125139) 2025-04-01 14:45:12 -04:00
Moritz Mack
c26d195120
Rethrow NoSuchFileException if encountering an invalid symlink when checking file entitlements (#124483)
This will rethrow the `NoSuchFileException` when encountering an invalid
symbolic link when following links during file (read) entitlement
checks.

Relates to https://github.com/elastic/elasticsearch/pull/124133
(ES-11019)
2025-03-11 20:38:03 +11:00
Lorenzo Dematté
a15aee6274
[Entitlements] Add URLConnection instrumentation for jar protocol (#123861)
Follows #123824

Relates to ES-10994
2025-03-09 09:30:42 +01:00
Lorenzo Dematté
b663616aa2
[Entitlements] Fix AbstractDelegateHttpsURLConnection "this" parameter type (#124304)
Our check methods injected by the instrumenter receive "this" as the second parameter.
For internal classes like AbstractDelegateHttpsURLConnection we generally use a base type; in this case we were using javax.net.ssl.HttpsURLConnection, which is incorrect as AbstractDelegateHttpsURLConnection derives from java.net.HttpURLConnection.
This was not failing in our tests because we don't actually use that parameter in that check function.

Also, it was not failing on transform, just on retransformClasses, and only in JDK 24. Apparently, JDK 24 introduced new validation there (to be confirmed).

And it was failing just on cloud as the APM agent there (which is loaded before our agent) connects to a https endpoint - our IT tests, and ./gradlew run --with-apm-server, use a http endpoint. Using https makes the JVM load AbstractDelegateHttpsURLConnection, making it one of the classes we need to retransform, triggering the VerifyError.
2025-03-07 13:41:47 +01:00
Lorenzo Dematté
cce1333744
[Entitlements] MailToURLConnection instrumentation (#123829) 2025-03-06 09:52:15 -05:00
Lorenzo Dematté
67d0dd4df2
[Entitlements] Add URLConnection instrumentation for file protocol (#123824) 2025-03-05 07:36:55 +01:00
Lorenzo Dematté
4f2f1bc2a7
[Entitlements] Add URLConnection instrumentation for ftp, http and https protocols (#123802) 2025-03-04 08:35:14 +01:00
Lorenzo Dematté
678738acc0
[Entitlements] Add URLConnection instrumentation (#123503) 2025-03-03 08:40:53 +01:00
Patrick Doyle
afd7e4e911
Misc non-java.base file entitlements (#123078)
* Misc non-java.base file entitlements

* Remove unnecessary dependency
2025-02-21 14:54:34 +00:00
Lorenzo Dematté
a4c7d29675
[Entitlements] Instrumentation of NIO file channels (#122816) 2025-02-19 23:18:07 +01:00
Lorenzo Dematté
20b829fc14
[Entitlements] Add check functions for NIO Files (#122591) 2025-02-19 21:55:06 +01:00
Patrick Doyle
877963c652
Miscellaneous java.base file entitlements (#122906)
* java.base entitlements

* SuppressForbidden, and add a missing test

* Revert logging back to commented-out printlns

* Merge FileCheckActions and rename for overloads

* Remove stray logger

* Remove more traces of logging change

* Remove more traces of logging
2025-02-19 13:17:15 -05:00
Moritz Mack
8eb89cf7c1
Add entitlement checks for java.io stream classes (#122406) 2025-02-18 14:12:01 +01:00
Ryan Ernst
bf1cbb0e47
Instrument methods on File that require read permissions (#122544)
This commit adds instrumentation for File methods that require read permissions.

see #122109 for the write side
2025-02-17 16:27:42 +01:00
Moritz Mack
7fd1addccf
[Entitlements] Instrument nio path (#122507) 2025-02-17 14:01:57 +01:00
Patrick Doyle
f8aa047994
Entitlements: manage_threads (#122261)
* Refactor: protected -> private

* Initial thread-related entitlements

* Entitlements from manual test runs

* Refactor: notEntitled method

* Entitlements reporting mode

* Entitlements from CI

* Revert "Entitlements reporting mode"

This reverts commit 443ca767333269a73accd0cedf9ca6c6ac51698a.

* Remove unnecessary EntitledActions.newThread

* Don't log in entitlements ITs by default

* Import SuppressForbidden

* Respond to PR comments

* Move manage_threads tests to their own file
2025-02-13 13:45:51 -05:00
Lorenzo Dematté
bd242cccbc
[Entitlements] Instrumentation for FileSystemProvider (#122232) 2025-02-12 18:56:13 +01:00
Ryan Ernst
5f00b64ec7
Instrument methods on File that require write permission (#122109)
This commit adds instrumentation for File methods that require write
permission. No server or plugins use these methods, so no policy changes
were necessary. Note that since we are not planning to restrict temp
file creation, the bootstrap self test on file writing was removed,
which failed with these changes.
2025-02-12 06:20:34 -08:00
Lorenzo Dematté
ec7f4ccb04
[Entitlements] Add FileStore instrumentation + tests (#122348) 2025-02-12 14:04:18 +01:00
Ryan Ernst
e32b9f48b0
Use dynamic policy for entitled test plugin (#121852)
Like the plugin being testing, the entitled test plugin needs access to
dynamic elements (namely, file paths). This commit dynamically generates
the entitlement policy for the entitlted test plugin when it is
installed. It also adds using the file entitltlement as an example.
2025-02-07 21:47:48 +01:00
Lorenzo Dematté
05340746bb
Missing providers from nio (#122004) 2025-02-07 17:09:36 +01:00
Ryan Ernst
6389dfc2e7
Sort groups of instrumented methods (#121616)
Instrumented methods in EntitlementChecker are loosely grouped by the
associated entitlement. This commit sorts the methods within groups to
allow more clear placement of additional instrumented methods.
2025-02-04 15:27:29 -08:00
Lorenzo Dematté
e260f29464
[Entitlements] "dynamic" instrumentation method keys (#120811) 2025-01-30 12:29:24 +01:00
Ryan Ernst
e0b168d3f6
Add initial file entitlement check (#120243)
This commit adds FileEntitlement to entitlements. It does not add checks
for all file access methods yet, instead opting for example read and
write methods.

Each module contains a sorted array of paths with read and write
permissions. Binary search is used to quickly identify the closest path
to determine whether a target path can be read or written.

Some important things about FileEntitlement are the path can either be a
file or a directory. All directories grant recursive permission. The
mode is either read or read_write. All operations like create or delete
are considered write.

relates ES-10354

Co-authored-by: Jack Conradson <osjdconrad@gmail.com>
2025-01-28 21:13:31 +01:00
Lorenzo Dematté
436e604b90
[Entitlements] Add checks for native libraries restricted methods (#120775) 2025-01-28 13:08:05 +01:00
Moritz Mack
58b893e78b
[Entitlements] Deny setting global defaults for Locale / TimeZone (#120804)
Part of #ES-10359
2025-01-27 09:44:57 +01:00
Lorenzo Dematté
bdd2fc00d3
[Entitlements] Policy and checks for loading native libraries (#120044) 2025-01-22 14:00:40 +01:00
Moritz Mack
f1447fe821
[Entitlements] Instrument write access to System properties (#120357)
Instrument write access to System properties by means of the `WriteSystemPropertiesEntitlement`.
`System.setProperties(Properties)` is always denied.

Part of #ES-10359
2025-01-21 18:07:40 +01:00
Lorenzo Dematté
cd86b3b497
[Entitlements] Refactor Network Entitlement (#120391) 2025-01-20 18:29:32 +01:00
Lorenzo Dematté
a397fe9291
[Entitlements] Network access checks for NIO classes (#120138) 2025-01-17 11:54:27 +01:00
Lorenzo Dematté
cbb7c24ada
[Entitlements] Network access checks for miscellanea (#120262) 2025-01-17 09:48:22 +01:00
Lorenzo Dematté
1848d6bb93
[Entitlements] Network access checks on Sockets (#120093) 2025-01-15 22:01:56 +01:00
Lorenzo Dematté
19965d5794
Removing unneeded check on SSLSession#getSessionContext (#120191) 2025-01-15 15:32:59 +01:00
Lorenzo Dematté
1be9253779
[Entitlements] Network entitlement classes + Datagram socket check functions (#119735) 2025-01-14 09:08:15 +01:00
Lorenzo Dematté
d3a1d9b509
Add "always denied" network access checks (#119867) 2025-01-13 09:26:55 +01:00
Lorenzo Dematté
78890e9312
Reintroduce entitlement check on System.exit (#119757) 2025-01-08 18:30:07 +01:00
Patrick Doyle
6484f94614
Entitlements for JDK-wide global state changes (#119592)
* Refactor: separate check method name vs signature parsing

* Cosmetic: change checker comment format

* Entitlements for JDK-wide global state

* [CI] Auto commit changes from spotless

* Comment explaining entitlement add-exports

* @SuppressForbidden

* Refactor: rename dummy subclases

---------

Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
2025-01-08 01:12:27 +00:00
Jack Conradson
7297390378
Add entitlement checks for java.lang.ClassLoader (#119027)
This commit adds an entitlement for creating a classloader.
2025-01-02 21:55:00 +00:00
Lorenzo Dematté
5df57fda72
[Entitlements] Add set_https_connection_properties entitlement and checks (#118577) 2025-01-02 16:06:37 +01:00
Patrick Doyle
401220868a
Mandatory class name (#118626)
* Use $$ for static check methods

* Always use class name from checker method name

* Spotless

* Varargs assertParseCheckerMethodSignatureThrows

* Remove hasReceiver again

* Spotless

* Cosmetic changes

* Change to new check method naming convention
2024-12-30 21:57:38 +00:00
Patrick Doyle
7c46556e21
Grant all entitlements to system modules (#119168)
* Grant all entitlements to system modules

* [CI] Auto commit changes from spotless

* Make NO_ENTITLEMENTS_MODULE non-null

* Initialize NO_ENTITLEMENTS_MODULE with @BeforeClass.

Looks like @WithoutSecurityManager doesn't work with static initializers.

* Move check to public method

* Logging adjustments

---------

Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
2024-12-30 17:35:26 +00:00
Patrick Doyle
c3a59bb965
Process execution checks and IT tests (#119010)
* Process creation checks and IT tests

* Remove process queries; only forbid execution
2024-12-18 23:06:52 +00:00
Lorenzo Dematté
1bad1cf6b2
Implementing the correct exit functions (Runtime) (#118657) 2024-12-13 16:21:42 +01:00
Lorenzo Dematté
9799d0082b
[Entitlements] Add support for instrumenting constructors (#117332) 2024-11-27 11:31:02 +01:00
Ryan Ernst
b45564364b
Add java version variants of entitlements checker (#116878)
As each version of Java is released, there may be additional methods we
want to instrument for entitlements. Since new methods won't exist in
the base version of Java that Elasticsearch is compiled with, we need to
hava different classes and compilation for each version.

This commit adds a scaffolding for adding the classes for new versions
of Java. Unfortunately it requires several classes in different
locations. But hopefully these are infrequent enough that the
boilerplate is ok. We could consider adding a helper Gradle task to
templatize the new classes in the future if it is too cumbersome. Note
that the example for Java23 does not have anything meaningful in it yet,
it's only meant as an example until we find go through classes and
methods that were added after Java 21.
2024-11-22 07:40:06 -08:00
Lorenzo Dematté
adcc5bed1e
[Entitlements] Implement entry point definitions via checker function signature (#116754) 2024-11-21 07:40:55 +01:00
Lorenzo Dematté
d702919fdb
[Entitlements] External IT test for checkSystemExit (#116435) 2024-11-13 09:36:40 +01:00
Patrick Doyle
338c0538b7
Dynamic entitlement agent (#116125)
* Refactor: treat "maybe" JVM options uniformly

* WIP

* Get entitlement running with bridge all the way through, with qualified
exports

* Cosmetic changes to SystemJvmOptions

* Disable entitlements by default

* Bridge module comments

* Fixup forbidden APIs

* spotless

* Rename EntitlementChecker

* Fixup InstrumenterTests

* exclude recursive dep

* Fix some compliance stuff

* Rename asm-provider

* Stop using bridge in InstrumenterTests

* Generalize readme for asm-provider

* InstrumenterTests doesn't need EntitlementCheckerHandle

* Better javadoc

* Call parseBoolean

* Add entitlement to internal module list

* Docs as requested by Lorenzo

* Changes from Jack

* Rename ElasticsearchEntitlementChecker

* Remove logging javadoc

* exportInitializationToAgent should reference EntitlementInitialization, not EntitlementBootstrap.

They're currently in the same module, but if that ever changes, this code would have become wrong.

* Some suggestions from Mark

---------

Co-authored-by: Ryan Ernst <ryan@iernst.net>
2024-11-06 00:07:52 +01:00
Ryan Ernst
30090b6b60
Move entitlement jars to libs (#115883)
The distribution tools are meant to be CLIs. This commit moves the
entitlements jar projects to the libs dir, under a single
libs/entitlement root directory to keep the related jars together.
2024-10-30 21:26:13 +01:00