Commit graph

322 commits

Author SHA1 Message Date
Mark Vieira
0279c0a909
Add AGPLv3 as a supported license 2024-09-13 14:30:33 -07:00
Ryan Ernst
c6f82604d7
Move exec syscall filtering to NativeAccess (#108970)
This commit moves the system call filtering initialization into
NativeAccess. The code is essentially unmodified from its existing
state, now existing within the *NativeAccess implementations.

relates #104876
2024-07-09 12:25:27 -07:00
Simon Cooper
8329a094ab
Add permission to secure access to certain config files (#107827)
This adds a SecuredFileAccessPermission that Elasticsearch and plugins can use to limit access to certain files, so that only code that also has that same permission can access the specified files
2024-05-28 12:46:15 +01:00
Ryan Ernst
bc499e7c83
Move rlimit calls into NativeAccess (#108805)
This commit moves getting max threads, max virtual memory size, and max
file size into NativeAccess.

relates https://github.com/elastic/elasticsearch/pull/104876
2024-05-20 11:09:50 -04:00
Simon Cooper
177dc263b3
Block specific config files from being accessed after startup (#107481)
Some files should never be accessed by ES or plugin code once startup has completed. Use the security manager to block these files from being accessed by anything at all. The current blocked files are elasticsearch.yml, jvm.options, and the jvm.options.d directory.
2024-04-29 09:58:12 +01:00
Simon Cooper
b752169ee9
Use hamcrest regex matcher rather than our own (#104457)
The difference is that our matcher uses .find() to search for a regex match anywhere in the string, whereas the hamcrest one uses .matches() to check the whole string against the regex. This leads to more specific regex checks.

I've left our own one for YAML tests, as that way we don't need to mangle the regex to add .* either side, which might be confusing in test failures.
2024-02-22 16:15:36 +00:00
Moritz Mack
6b50b6ddf9
Block updates to log level for restricted loggers if less specific than INFO (#105020)
To prevent leaking sensitive information such as credentials and keys in logs, this 
commit prevents configuring some restricted loggers (currently `org.apache.http` 
and `com.amazonaws.request`) at high verbosity unless the NetworkTraceFlag 
(`es.insecure_network_trace_enabled`) is enabled.
2024-02-21 17:45:51 +01:00
Joe Gallo
f2e7b64c18
Remove gradle references to the rest-high-level client (#104871) 2024-01-29 14:13:06 -05:00
ning pan
c3dece132d
Add a docs link to the log message about each failing bootstrap check (#99644)
Add a docs link to the log message about each failing bootstrap check to
help new users to understand failing bootstrap checks.

Closes #99614
2023-09-21 02:45:28 -04:00
Jake Landis
6c26ca0751
Minor clean up of guava dependencies (#99593)
This commit bumps up the version of jimfs and jimfs_gauva and guava
that is used for security and idp plugins.
2023-09-18 10:03:03 -05:00
David Turner
a20ee3f8f2
Migrate simple usages of ThreadPool#schedule (#99051)
In #99027 we deprecated the string-based version of
`ThreadPool#schedule`. This commit migrates all the simple usages of
this API to the new version.
2023-08-31 07:37:31 +01:00
Pooya Salehi
c9c2f76d79
Make EWMA alpha configurable in FixedExecutor (#97424)
For Stateless autoscaling, we'd need a different Alpha to track the task
execution time EWMA. This change makes the EWMA Alpha configurable  and
uses a different value for the Write executors.

Closes ES-6325
2023-07-10 06:05:04 -04:00
Ryan Ernst
7d8aac3a3e
Implement custom JUL bridge (#96872)
The log4j JUL bridge turned out to have issues because it relied on java
beans. This commit implements a custom bridge between JUL and Log4j.

closes #94613
2023-06-20 09:48:25 -07:00
Przemyslaw Gomulka
31e20d9239
Revert "Add JUL bridge (#96683)" (#96832)
This reverts commit 2bdf1bc0d6.
2023-06-14 14:37:53 +02:00
Ryan Ernst
2bdf1bc0d6
Add JUL bridge (#96683)
This commit adds the Log4j JUL bridge so that messages using JUL are
more nicely converted to log4j messages. Currently these messages are
captured via the stdout logging stream. This commit also adds a log4j
filter to replace the logging stream filtering mechanism used to quiet
some Lucene log messages that may be confusing to users.

closes #94613
2023-06-13 19:31:05 -04:00
Rory Hunter
fe1083f6c5
Upgrade spotless plugin to 6.17.0 (#94994)
Fixes #82794. Upgrade the spotless plugin, which addresses the issue
around formatting `instanceof` expressions. Formatting of statements
including lambdas seems to have improved too.
2023-04-04 10:03:32 +01:00
David Turner
6da721edda
Assert TaskTransportChannel completed once (#94598) 2023-03-21 13:56:45 -04:00
David Turner
c0587289af
Improve master service batching queues (#92021)
Today the master's pending task queue is just the
`PriorityBlockingQueue<Runnable>` belonging to the underlying
`ThreadPoolExecutor`. The reasons for this date back a long way but it
doesn't really reflect the structure of the queue as it exists today. In
particular, we must keep track of batches independently of the queue
itself, and must do various bits of unchecked casting to process
multiple items of the same type at once.

This commit introduces an new queueing mechanism, independent of the
executor's queue, which better represents the conceptual structure of
the master's pending tasks:

* Today we use a priority queue to allow important tasks to preempt less-important ones. However there are only a small number of priority levels, so it is simpler to maintain a queue for each priority, effectively replacing the sorting within the priority queue with a radix sort.

* Today when a task is submitted we perform a map lookup to see if it can be added to an existing batch or not. With this change we allow client code to create its own dedicated queue of tasks. The entries in the per-priority-level queues are themselves queues, one for each executor, representing the batches to be run.

* Today each task in the queue holds a reference to its executor, but the executor used to run a task may belong to a different task in the same batch. In practice we know they're the same executor (that's how batches are defined) but we cannot express this knowledge in the type system so we have to do a bunch of unchecked casting to work around it. With this change we associate each per-executor queue directly with its executor, avoiding the need to do all this unchecked casting.

* Today the master service must block its thread while waiting for each task to complete, because otherwise the executor would start to process the next task in the queue. This makes testing using a `DeterministicTaskQueue` harder (see `FakeThreadPoolMasterService`). This change avoids enqueueing tasks on the `ThreadPoolExecutor` unless there is genuinely work to do, although it leaves the removal of the actual blocking to a followup.

Closes #81626
2023-02-23 08:01:03 -05:00
Andrei Dan
fb033b9e82
Move SchedulerEngine and TimeValueSchedule to server/common/scheduler (#93862)
We built quite a bit of infrastructure to have one polling job
running via the `SchedulerEngine` and `ActiveSchedule`. This moves this
infrastructure outside x-pack to server so elasticsearch/modules can use
it and avoid re-implementing it using `threadPool.schedule`.
2023-02-17 08:55:40 +00:00
Rick Boyd
f7bb5e02c5
Support profiling queries in Tracer (#90574)
This pull request adds the necessary support, and implementation, for profiling queries in the Tracer.

In order to use the APM Agent's inferred spans functionality, the active span's context has to be open in the current thread. This PR adds context-sensitive methods to the Tracer interface, implements them in APMTracer, and makes use of them in the private SearchService.executeQueryPhase(), which is on the stack for a lot of our most critical operations.
2022-10-04 08:45:16 -04:00
Francisco Fernández Castaño
284dce6a2a
Centralize the concept of processors configuration (#89662)
This commit centralize the processor count concept into the Processors class.
With this change now all the places using a processor count rely on this new class,
such as desired nodes, `node.processors` setting and autoscaling deciders.

- Processor counts are rounded to up to 5 decimal places
- Processors can be represented as doubles

Desired nodes processors were stored as floats, this poses some challenges during
upgrades as once the value is casted to a double, the precision increases and therefore
the number is not the same. In order to allow idempotent desired nodes updates after
upgrades, this commit introduces `DesiredNode#equalsWithProcessorsCloseTo(DesiredNode that)`
which allows comparing two desired nodes that differ up to a max delta in their processor
specification as floats.
2022-09-06 18:17:36 +02:00
Chris Hegarty
1ce64290a1
Add package cache to EmbeddedImplClassLoader (#88537)
The initial implementation of the embedded class loader took a brute
force approach to supporting multi-release JARs - iterating over all
possible release versions when searching for classes and resources. This
change improves upon that approach by deriving and caching package and
version specific maps, so class and resource loading can go directly to
the class and resource bytes, respectively, rather than searching.

It's hard to get empirical numbers to quanify just how much this change
improves the performance of classes loaded by this loader, and there is
typically only a couple of hundred classes loaded, but the initial cli
seems observably much quicker, while the server startup has improved
just a bit (at least on my machine).
2022-07-25 15:31:58 +01:00
Ryan Ernst
4a2eb01f13
Move logging config assertion to server cli (#87774)
The log4j configuration file is shipped with all ES distributions. We
also check recursively for files possibly added by plugins. If no files
are found, we give a helpful startup error message. However, since the
log4j2 configuration file shipped with ES should always exist, we can
check upfront in the cli before even initializing logging.

This commit moves the validation of an existing log4j2 properties file
to the server cli.
2022-06-17 06:16:33 -07:00
Ryan Ernst
cf92a16a10
Make pidfile deletion more resilient (#87134)
Deleting the pidfile when Elasticsearch is shutting down was moved in #86934.
However, the delete SM permission is still needed, since SM is installed
by the time we shutdown. This commit adds back to the pidfile delete
permission, and also rethrows any io exception so it can be logged by
our uncaught exception handler.
2022-05-26 06:48:52 -07:00
Przemyslaw Gomulka
43b69b6f70
Replace new ParametrizedMessage() with java.util.Supplier<String> (#87077)
This is a result of structural search/replace in intellij. This only affects log methods with a signature
logger.info(ParametrizedMessage)
logger.info(ParametrizedMessage, Throwable)

relates https://github.com/elastic/elasticsearch/issues/86549
2022-05-26 11:21:35 +02:00
Ryan Ernst
300a578ad3
Rename PluginInfo to PluginDescriptor (#86950)
The class PluginInfo represents the plugin-descriptor.properties file
that each plugin must have. This commit renames the class to more
closely match what it represents: the plugin descriptor.
2022-05-20 07:23:44 -07:00
Ryan Ernst
55d8e60298
Move pidfile handling to server cli (#86934)
Now that the server cli is in java, we can do more system level things
inside it. This commit moves validating and writing the pidfile into the
server cli. One benefit is we get validation of directory/file problems
up front before even trying to start the ES process.
2022-05-19 14:59:56 -07:00
Ryan Ernst
507202ae4a
Add annotation for disabling security manager in tests (#86706)
The Elasticsearch test framework initializes a test security manager, so
that tests run in a similar environment to that which we run in
production. However, some tests need to run without security manager
because they do "evil" things, like setting adding and removing jvm wide
shutdown hooks. Currently these tests must exist in separate projects,
mostly under qa/evil-tests, so that the security manager can be disabled
for the entire jvm with the tests.security.manager system property. The
separation between these tests and the other tests for the server makes
development of these tests more difficult, especially the inability to run
these within IntelliJ without manually adding additional sysprops.

This commit adds a new mechanism to disable security manager for these
tests. A new `@NoSecurityManager` annotation can be added to a test
suite. ESTestCase detects this annotation and removes the security
manager for the duration of that test suite. We could potentially allow
this per test as well, but I started with the simple suite wide
strategy. One example test is converted. The rest will be converted in
followups.
2022-05-12 08:27:33 -07:00
Rene Groeschke
a50ab961da
Do not apply StandaloneRestTestPlugin in StandaloneTestPlugin (#86400)
As we are moving away from StandaloneRestTestPlugin (see https://github.com/elastic/elasticsearch/pull/85491) we want to reduce the surface of that plugin.
If rest tests are used a rest test related plugin should be applied
2022-05-09 12:55:02 +02:00
Ryan Ernst
733f9fa5b8
Move cli shutdown hook to CliToolLauncher (#86412)
Each Command subclass can implement close() so that resources will be
cleaned up on exceptional exit like SIGINT. This is implemented through
a shutdown hook added in the superclass constructor. However, this hook
makes testing difficult because the hook cannot be added in normal
tests, so a flag must be overriden when testing Command classes.

This commit moves the shutdown hook handling into the CliToolLauncher
that creates the command. It also adds non-evil tests that check how the
hook runs, in place of the old evil tests that actually registered a
real shutdown hook.

relates #85758
2022-05-05 06:50:45 -07:00
Ryan Ernst
a5f1782ba3
Make env aware CLI command publicly runnable (#86313)
The EnvironmentAwareCommand is the most common base class for CLI tools.
Sometimes it is desirable for one tool to call into another. With the
new CliToolLauncher, this becomes easier to do. However, that only gives
access to the base Command class, which means the Environment would be
reparsed if the implementation is an EnvironmentAwareCommand. This
commit makes the execute method of EnvironmentAwareCommand public so
that other tools can pass the already parsed env.

relates #85758
2022-04-29 17:13:49 -07:00
Ryan Ernst
ed749fcc5c
Move cli sysprops and envVars to execute parameter (#86279)
The sysprops and envVars members of Command provide cli implementations
with information about the jvm process that is running. This is
convenient for runtime, but difficult for tests to mock because they
must subclass the cli class.

This commit adds a ProcessInfo record, and plumbs it through the
main and execute methods. The new record includes system properties,
environment variables and the working directory. By having this be a
single new parameter, additional information can be added in the future
without again needing to modify the method signatures.

relates #85758
2022-04-29 13:47:30 -07:00
Ryan Ernst
d742be81a4
Isolate console appender startup logic (#86243)
When bootstrapping Elasticsearch, the console appender is automatically
added by our log4j config. However, there are some cases where we want
to remove that appender. First, if --quiet is passed, we do not want to
log anything to it. Second, if we are daemonizing, then we want to close
the streams, so we need to remove it if it exists. Third, when huge
guice/startup exceptions occur, we log these only to the ES log file, so
we need to remove the appender temporarily.

This commit moves the logic for mucking with the console appender into
LogConfigurator. In the future this can be better isolated within
logging, perhaps even avoiding creating the console appender to begin
with when using --quiet, but for now this at least gets some log specific
logic out of bootstrap.

relates #85758
2022-04-28 06:01:38 -07:00
Ryan Ernst
3e581c66f1
Cleanup Terminal to make it easier to subclass (#86198)
Terminal is the abstraction Elasticsearch uses for all input and output,
both character based and binary. In an interactive shell, this is backed
by Java's Console, and in non-interactive it is backed by
stdin/stdout/stderr. Over time, the Terminal class has been amended to
support several different use cases, which has made constructing
subclasses for testing or filter based implementations complex. This
commit reworks Terminal so that the readers/writers/streams are
constructor arguments, instead of overrides. This allows subclasses to
simply call super with what is neeeded, rather than overloading several
methods and adding the same boilerplate implementation as others.

Note that the majority of the modifications here are to tests because
MockTerminal now has a factory method instead of direct constructor.

relates #85758
2022-04-27 19:06:05 -07:00
Ryan Ernst
9f46aae615
Consolidating logging initialization in cli launcher (#85920)
Serveral mechanisms exist for intializing logging in cli tools. Some
base Command classes exist which initialize logging. But they do this
late, when they are constructed, which may be after static init has
occured for classes grabbing a Logger. Other CLIs like node tool
explicitly initialize logging to avoid that problem.

This commit removes all the of the LoggingAware classes, and
unifies logging configuration to occur at the very beginning of the cli
launcher.

relates #85758
2022-04-18 08:22:50 -07:00
Ryan Ernst
1088ef6ded
Capture system properties and env variables for cli tools to use (#85885)
Currently any code needing to access system properties or environment
variables does it with the static methods provided by Java. While this
is ok in production since these are instantiated for the entire jvm
once, it makes any code reading these properties difficult to test
without mucking with the test jvm.

This commit adds system properties and environment variables to the base
Command class that our CLI tools use. While it does not propagate the
properties and env down for all possible uses in the system, it is the
first step, and it makes CLI testing a bit easier.
2022-04-14 09:22:57 -07:00
Armin Braun
1da8f15c2a
Make EsPolicy.implies a little Faster (#84295)
Extract cold paths + build a more efficient permissions collection for the hot
data path permissions that don't need the generic collection because it's all
file permissions only.
2022-02-28 13:03:53 +01:00
Mayya Sharipova
26c3dd6857
Upgrade to lucene-9.1.0-snapshot-1336263051c (#83667)
Lucene issues that resulted in elasticsearch changes:

LUCENE-9820 Separate logic for reading the BKD index from logic to intersecting it.
LUCENE-10377: Replace 'sortPos' with 'enableSkipping' in SortField.getComparator()
LUCENE-10301: make the test-framework a proper module by moving all test
classes to org.apache.lucene.tests
LUCENE-10300: rewrite how resources are read in ukrainian morfologik analyzer:
LUCENE-10054 Make HnswGraph hierarchical
2022-02-22 09:53:20 +01:00
James Rodewig
fe2990829a
Update setting deprecation messages to remove major release references (#83528)
Updates our setting deprecation messages to avoid references to future major releases.
2022-02-04 13:53:20 -05:00
Artem Prigoda
cce5ad2e4f
Migrate to Java16 records (part 2) (#82914)
Try to represent immutable data with Java records introduced in JEP 395

Convert only existing immutable classes, no "POJO with setters to a record" refactorings.
2022-01-25 00:31:15 +01:00
Tanguy Leroux
24e1888ae3
Allow scaling executors to reject tasks after shutdown (#81856)
Today scaling thread pools never reject tasks but always add them to the
queue of task the execute, even in the case the thread pool executor is
shutting down or terminated. This behaviour does not work great when a
task is blocked waiting for another task from another scaling thread
pool to complete an I/O operation which will never be executed if the
task was enqueued just before the scaling thread pool was shutting down.


This situation is more likely to happen with searchable snapshots in
which multiple threads can be blocked waiting for parts of Lucene files
to be fetched and made available in cache. We saw tests failures in CI
where Lucene 9 uses concurrent threads (to asynchronously checks
indices) that were blocked waiting for cache files to be available and
failing because of leaking files handles (see #77017, #77178).

This pull request changes the `ForceQueuePolicy` used by scaling thread
pools so that it now accepts a `rejectAfterShutdown` flag which can be
set on a per thread pool basis to indicate when tasks should just be
rejected once the thread pool is shut down. Because we rely on many
scaling thread pools to be black holes and never reject tasks, this flag
is set to `false` on most of them to keep the current behavior. In some
cases where the rejection logic was already implemented correctly this
flag has been set to `true`.

This pull request also reimplements the interface
`XRejectedExecutionHandler` into an abstract class
`EsRejectedExecutionHandler` that allows to share some logic for
rejections.
2022-01-24 05:35:38 -05:00
Mary Gouseti
4499050341
Use pattern matching for instanceof in plugins through qa, server/internalClusterTest (#82161) 2022-01-12 11:34:15 +01:00
Przemyslaw Gomulka
f954919d65
Add doPrivileged section in deprecation logger (#81819)
Scripts using deprecation logger can trigger log files rolling over.
Scripts also run with a very limited permissions and without
doPrivileged section would cause SM exception

closes #81708
2021-12-17 09:18:42 +01:00
Chris Hegarty
f205b7655f
Allow plugins MBeanTrustPermission (#81508)
MBeans are sometimes used by third party libraries, e.g. to report
metrics through JMX. This commit builds upon the initial set of MBean
permissions added in #76329, to further alllow a plugin register an
MBean, i.e to allow plugins to grant MBeanTrustPermission("register").
2021-12-08 11:21:02 +00:00
Chris Hegarty
c16dd35b81
Fix split package between libs/cli and server, move org.elasticsearch.cli to org.elasticsearch.common.cli (#81038)
Fix the split package org.elasticsearch.cli, between server and the cli library. Move the server org.elasticsearch.cli package to org.elasticsearch.common.cli. Removing split packages is a prerequisite to modularization.
2021-11-25 14:42:22 +00:00
Mark Vieira
12ad399c48 Reformat Elasticsearch source 2021-10-27 08:19:51 -07:00
Ryan Ernst
d97d282933
Revert "Convert path.data to String setting instead of List (#72282)" (#79091)
This reverts commit d933ecd26c.

The revert had two conflicts. The first was very minor in JoinHelper.
The second was several tests in PersistedClusterStateServiceTests.

relates #78525
relates #71205
2021-10-13 17:56:40 -07:00
Ryan Ernst
aa11f0f281
Revert "Make Environment.dataFiles singular (#72327)" (#79028)
This reverts commit b1eab79f4c.

This revert was conflict free.

relates #78525
relates #71205
2021-10-13 08:53:02 -07:00
Ryan Ernst
6fbc1b88d8
Fix split packages in plugin cli (#78027)
* Fix split packages in plugin cli

The plugin CLI was born out of the server jar, to allow the code to be
independent, as well as have more isolated tests that use jimfs to test
any many filesystem implementations. Yet the cli classes continue to
reside in the same package as the plugin service. This commit renames
the package in the cli to be cli specific.

Most of the change is simple renames and adding imports. A few cases
required making plugin service specific classes public. In the future
these could be made scoped exports specific to a plugin-cli module, but
for now this fix the split packages. Also note the PluginSecurity class
was only used by the cli, but is also only tested in the evil-tests,
which are run without security manager. Since those will all eventually
go away, the test package is also renamed there.

* fix shell scripts
2021-09-20 15:25:46 -04:00
Przemyslaw Gomulka
0d3cebe812
Change default deprecation logger level to CRITICAL (#77030)
This commit changes default deprecation logger level to CRITICAL, where default means deprecations emitted by DeprecationLogger#critical method.
It also introduces WARN deprecations which are emitted by DeprecationLogger#warn Those log lines emitted at WARN are meant to indicate that a functionality is deprecated but will not break at next major version.
relates #76754
2021-09-09 12:23:52 +02:00