Commit graph

394 commits

Author SHA1 Message Date
Ryan Ernst
b5e92db171
Remove security manager from tests (#127087)
Now that entitlements are always used, there is no need to run tests
with security manager (a future enhancement will run tests with
entitlements). This commit removes setting up security manager from
tests.
2025-04-22 18:08:09 +02:00
Ryan Ernst
3495b4e4fe
Use explicit newline with keystore stdin test (#127094)
The add string keystore command accepts input on stdin. In this case,
the terminal is responsible for separating input by newlines that are
system dependent. The mock terminal normally adds the system dependent
newline. However, we also have tests that ensure both unix and windows
style newlines are tested explicitly. This commit fixes the windows
style carriage returns to explicitly contain a newline.

closes #127089
2025-04-21 13:19:32 -07:00
Ryan Ernst
584b2379f0
Use Terminal.readSecret in add string keystore command (#126966)
As a followon to #126729, the add string keystore command doesn't need
to use a reader at all (and it was incorrect for it to close the reader
from the terminal). Instead, the Terminal abstraction already handles
how to get at line by line secrets. This commit removes that usage of
reader and uses readSecret calls instead.

closes #126882
2025-04-18 19:50:15 +02:00
Ryan Ernst
42dc870ece
Ensure logs dir exists before using as working dir (#126566)
With the change to using the logs dir as the working dir of the
Elasticsearch process we need to ensure the logs dir exists within the
CLI instead of later during startup.

relates #124966
2025-04-17 12:59:47 -07:00
Ryan Ernst
b47bd3adc7
Use terminal reader in keystore add command (#126729)
When reading a string value from stdin the keystore add command
currently looks directly at stdin. However, stdin may also be consumed
while reading the keystore password. This commit changes the add command
to use the reader from the termainl instead of looking at stdin
directly.

closes #98115
2025-04-14 12:55:56 -07:00
Ryan Ernst
3bac50e818
Use logs dir as working directory (#124966)
In the unexpected case that Elasticsearch dies due to a segfault or
other similar native issue, a core dump is useful in diagnosing the
problem. Yet core dumps are written to the working directory, which is
read-only for most installations of Elasticsearch. This commit changes
the working directory to the logs dir which should always be writeable.
2025-04-09 07:07:11 -07:00
Lorenzo Dematté
40dd91b800
[Entitlements] Replace Permissions with Entitlements in InstallPluginAction (#125207)
This PR replaces the parsing and formatting of SecurityManager policies with the parsing and formatting of Entitlements policy during plugin installation.

Relates to ES-10923
2025-04-02 11:03:27 +01:00
Lorenzo Dematté
e0b7c8bdfc
[Entitlements] Print a warning during plugin installation if a legacy policy file is found (#125294)
This PR adds a check and a warning message if the user is trying to install a plugin containing the legacy plugin-security.policy used by SecurityManager.

Relates to ES-10846
2025-03-24 08:29:52 +01:00
Armin Braun
50437e79d3
Cleanup missing use of StandardCharsets (#125424)
Random annoyance that I figured, I'd just fix globally:
We can do a bit of a cleaner job when doing byte <-> string conversion here and there.
2025-03-21 20:10:15 +01:00
Lorenzo Dematté
a4d7297944
Permanently switch from SecurityManager to Entitlements (#124865) (#125117)
The JDK team has completely disabled the Java SecurityManager from Java 24. Elasticsearch has always used the Java SecurityManager as an additional protection mechanism; in order to retain this second line of defense, the Elasticsearch Core/Infra team has been working on the Entitlements project.

Similar to SecurityManager, Entitlements only allow calling specific methods in the JDK when the caller has a matching policy attached. In other words, if some code (in the main Elasticsearch codebase, in a plugin/module, or in a script) attempts to perform a "privileged" operation and it is not entitled to do so, a NotEntitledException will be thrown.

This PR includes the minimal set of changes to always use Entitlements, regardless of system properties or Java version.

Relates to ES-10921
2025-03-18 18:38:45 +02:00
Ryan Ernst
11961730da
Cleanup command line setting errors (#124963)
This commit improves the error cases when command line settings are
found that are duplicates or conflict with special system properties.
2025-03-18 09:38:14 -07:00
Ryan Ernst
789eb2fadb
Log system information early during startup (#124926)
Information about the system, and in particular the running JVM, is
logged relatively late in startup. When problems occur in low level
initialization, it is often useful to have this information. This commit
moves logging of system information to right after logging has been
initialized. Note that it no longer utilizes the JvmInfo class as most
was already easily available and the static init of JvmInfo does a lot.
2025-03-15 14:55:02 +00:00
Ryan Ernst
47454df24e
Ensure we always use vectorization in Lucene (#124914)
By default Lucene only uses vectorization up to the JDK version
available at the time of its release. When testing against EA versions,
we want to still use vectorization. This commit adds a sysprop to force
lucene to use the current version for vectorization.
2025-03-14 20:08:15 +00:00
Mark Vieira
d61b86477d
Add jdk.management.agent module to server boot layer on start (#123938) 2025-03-04 11:32:42 -08:00
Arpad Kiraly
196e083502
Remove @UpdateForV9 usages that are related to security manager removal (#123690)
* Remove @UpdateForV9 annotation in RuntimeVersionFeature

Re ES-10338 the Core/Infra team agreed that this is not blocked on security manager removal. We should go ahead and remove these 2 instances of the @UpdateForV9 annotation, the code will be cleaned up soon with the removal of Security Manager.

* Remove @UpdateForV9 annotation from SystemJvmOptions

re ES-10338 the Core/Infra team agreed this is not blocked on security manager removal. We should go ahead and remove this instance of the @UpdateForV9 annotation.
2025-03-03 11:34:46 +01:00
Rene Groeschke
cd8fbab5b5
Fix some early tasks creations (#123637)
We want to use the task avoidance api whereever possible and delay task
creation
2025-02-28 07:54:01 +11:00
Ryan Ernst
b5e482bc91
Enable entitlements by default (#122907)
Entitlements are almost complete. This commit enables them by default,
in preparation for 8.18/9.0.
2025-02-25 09:58:39 -08:00
Lorenzo Dematté
6d042511a1
Create test entitlement libs dir and jar to pass validation (#123013) 2025-02-20 13:34:19 -05:00
Lorenzo Dematté
4c6fd56864
Skip tests that require old security manager policy parsing/validation when running on Java 24 (#123009) 2025-02-20 14:54:28 +01:00
Lorenzo Dematté
a4c7d29675
[Entitlements] Instrumentation of NIO file channels (#122816) 2025-02-19 23:18:07 +01:00
Lorenzo Dematté
2b54de1e4b
Skip SM policy parsing and validation for Java24+ (#122233) 2025-02-12 08:14:36 +01:00
Ryan Ernst
0cf42f2388
Rename environment dir accessors (#121803)
The node environment has many paths. The accessors for these currently
use a "file" suffix, but they are always directories. This commit
renames the accessors to make it clear these paths are directories.
2025-02-05 14:03:28 -08:00
Moritz Mack
6648a03bab
Revert "Revert "Remove deprecated tracing.apm.* settings for v9 (#119926)"" (#120895)
This reverts commit 5f44911ef8.
Reverts revert in #120268 after blockers have been resolved.
Relates to ES-10293
2025-01-27 16:04:36 +01:00
Lorenzo Dematté
81a9348431
[Entitlements] Enable native access based on policies (#120638) 2025-01-24 08:29:38 +01:00
Lorenzo Dematté
cbb7c24ada
[Entitlements] Network access checks for miscellanea (#120262) 2025-01-17 09:48:22 +01:00
Moritz Mack
5f44911ef8
Revert "Remove deprecated tracing.apm.* settings for v9 (#119926)" (#120268)
Temporarily reverts elastic/elasticsearch#119926 due to unforeseen
usage.

Relates to ES-10293
2025-01-16 22:47:49 +11:00
Moritz Mack
5123b948a9
Remove deprecated tracing.apm.* settings for v9 (#119926) 2025-01-14 08:41:11 +01:00
Ryan Ernst
38b2fc53a7
Default to entitlements only for JDK 24+ (#119885)
Since entitlements are still being developed, we are not yet ready to
enable them for all JDK versions. But we must use them for JDK 24+ since
the security manager is not useable there. This commit tweaks the logic
for determining whether to use entitlements to take into account  the
runtime version.
2025-01-10 09:19:39 -08:00
Moritz Mack
16d8aaf386
Strengthen encryption for elasticsearch-keystore tool to AES 256 (#119749)
The latest format version (7) of KeyStoreWrapper will be using a 256
bits key for the AES cipher.

Closes #ES-10419
2025-01-09 08:57:47 +01:00
Lorenzo Dematté
28ce53f0aa
[Entitlements] Fix "No SecurityManager when entitlements are enabled" (#119742) 2025-01-08 15:17:41 +01:00
Lorenzo Dematté
3464adb3ae
Adjust Bootstrap and JVM options to ensure the SM is never used when entitlements are enabled (#119689) 2025-01-08 10:24:03 +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
Lorenzo Dematté
ba9e0cef4d
Do not try to enable SecurityManager on JDK 24 (#117999) 2024-12-10 18:00:58 +01:00
Lorenzo Dematté
7bd5c69c8c
Update ASM 9.7 -> 9.7.1 to support JDK 24 (#118094) 2024-12-06 08:16:46 +01:00
Slobodan Adamović
6ea3e01958
Upgrade Bouncy Castle FIPS dependencies (#112989)
This PR updates `bc-fips` and `bctls-fips` dependencies to the latest
minor versions.
2024-11-22 21:39:25 +11: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
Ryan Ernst
e5d5c17c99
Use directory name as project name for libs (#115720)
The libs projects are configured to all begin with `elasticsearch-`.
While this is desireable for the artifacts to contain this consistent
prefix, it means the project names don't match up with their
directories. Additionally, it creates complexities for subproject naming
that must be manually adjusted.

This commit adjusts the project names for those under libs to be their
directory names. The resulting artifacts for these libs are kept the
same, all beginning with `elasticsearch-`.
2024-10-29 13:02:28 -07:00
Lorenzo Dematté
c4c33ff359
Fix NPE on plugin sync (#115640) 2024-10-28 09:33:14 +01:00
Lorenzo Dematté
ef85d0a53f
Avoid double instrumentation via class annotation (#115398) 2024-10-28 09:31:19 +01:00
Jack Conradson
68f0f00dd1
Add initial entitlement policy parsing (#114448)
This change adds entitlement policy parsing with the following design:
* YAML file for readability and re-use of our x-content parsers
* hierarchical structure to group entitlements under a single scope
* no general entitlements without a scope or for the entire project
2024-10-18 16:02:28 -07:00
Patrick Doyle
049c482570
Initial InstrumenterTests (#114422)
* Initial InstrumenterTests

* Assert on instrumentation method arguments
2024-10-11 16:01:48 -04:00
Patrick Doyle
3953331ac5
Entitlements for System.exit (#114015)
* Entitlements for System.exit

* Respond to Simon's comments

* Rename trampoline -> bridge

* Require exactly one bridge jar

* Use Type helpers to generate descriptor strings

* Various cleanup from PR comments

* Remove null "receiver" for static methods

* Use List<Type> instead of voidDescriptor

* Clarifying comment

* Whoops, getMethod

* SuppressForbidden System.exit

* Spotless

* Use embedded provider plugin to keep ASM off classpath

* Oops... forgot the punchline

* Move ASM license to impl

* Use ProviderLocator and simplify bridgeJar logic

* Avoid eager resolution of configurations during task configuration

* Remove compile-time dependency agent->bridge

---------

Co-authored-by: Mark Vieira <portugee@gmail.com>
2024-10-09 09:01:27 -04:00
Simon Cooper
f9aa6f40cd
Always use CLDR locale on ES v9 (#113184)
Regardless of JDK version, ES should always use CLDR locale database from 9.0.0.
This also removes IsoCalendarDataProvider used to override week-date calculations for the root locale only.
2024-09-23 11:05:08 +01:00
Patrick Doyle
67e32e5c82
Initial trivial hello-world entitlements agent (#113112)
* Initial hello-world entitlements agent

* Respond to Ryan's comments

* License header

* Fix forbidden APIs setup

* Rename EntitlementAgent

* Automated refactor missed one

* Automated rename really let me down here

* Very serious test name

* README files for the new modules

* Use "tasks.named('jar')"

Co-authored-by: Rene Groeschke <rene@breskeby.com>

* Use 'tasks.named('test')'

Co-authored-by: Rene Groeschke <rene@breskeby.com>

* More deferral of gradle tasks

Co-authored-by: Rene Groeschke <rene@breskeby.com>

* Even more deferral

Co-authored-by: Rene Groeschke <rene@breskeby.com>

* FIx gradle syntax for javaagent arg

---------

Co-authored-by: Rene Groeschke <rene@breskeby.com>
2024-09-20 13:12:27 -04:00
Joe Gallo
e952b76fd6
There's no need to BufferedInputStream within a GZIPInputStream (#113052) 2024-09-17 19:06:50 -04:00
Ryan Ernst
3a5f8a7ecb
Simplify java version checker (#112955)
The version checker ensures custom JDKs used to run Elasticsearch meet
the minimum Java version. It uses a multi-release jar to pass through
the "ok" versions, falling back to a java 8 version to print an error.
However, a multi-release jar is not necessary, we can instead do simple
string version parsing for the check, special casing Java 1.8.
2024-09-17 05:38:52 +10:00
Mark Vieira
a59c182f9f
Add AGPLv3 as a supported license 2024-09-13 15:29:46 -07:00
Simon Cooper
a36d90cf34
Use CLDR locale provider on JDK 23+ (#110222)
JDK 23 removes the COMPAT locale provider, leaving CLDR as the only option. This commit configures Elasticsearch
to use the CLDR provider when on JDK 23, but still use the existing COMPAT provider when on JDK 22 and below.

This causes some differences in locale behaviour; this also adapts various tests to still work whether run on COMPAT or CLDR.
2024-09-04 13:42:40 +01:00
Ryan Ernst
84bd31eb8e
Fix shutdown race condition in server start (#112300)
When the server CLI is preparing to start Elasticsearch, it may receive
a SIGTERM. That signal causes the close method of the CLI to be invoked,
which checks for a non-null server process, and stops it if it exists.
Since shutdown occurs in a different thread, it is possible close is
invoked, sees the server process is null, so skips calling close, but
then before close finishes the server process is started.

Normally the above case is ok; the close method will cause Java to exit,
and the child process will be sent a SIGTERM. However, in the case of
serverless, close is wrapped so that the CLI can wait on uploading
possible heapdumps. This presents the possibility that close thinks the
child process has been stopped, but it hasn't, so the wrapped close
waits indefinitely on the child process that was started up during the
race.

This commit guards against the startup race by locking the critical
sections that create the child process and stop it. Either the child
process is created first, and will then be stopped immediately, or close
is invoked first, marking that the CLI is shutting down, and creating
the child process will be skipped.
2024-08-29 10:20:43 -07:00