Commit graph

1062 commits

Author SHA1 Message Date
Jack Conradson
534e171275
Update policy parser to allow static methods for entitlement creation (#121706)
This updates the PolicyParser to allow static methods to have an ExternalEntitlement annotation. This 
removes a limitation where constructors cannot properly support type-erasure with different types of 
data structures for internal entitlement generation and external entitlement generation (for example 
List<Object> from the parser and List<SomeData> from an internal builder). We continue to enforce 
that only one constructor/method may be annotated with ExternalEntitlement per Entitlement class.
2025-02-05 08:57:12 -08:00
Ryan Ernst
5ab175ebc1
Move spi and system actions into separate classes (#121555)
This commit moves methods used to test spi and system actions out of
RestEntitlementsCheckAction into separate classes, to ease future
merges.
2025-02-05 16:37:02 +01:00
Yang Wang
fee57daf53 Merge main into multi-project 2025-02-05 11:03:29 +11: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é
fdbd079bb0
[Entitlements] Fix Entitlement initialization to work across multiple versions (#121192) 2025-02-04 14:32:04 +01:00
Niels Bauman
a15932159a Merge remote-tracking branch 'public/main' into merge-main 2025-02-04 11:19:42 +10:00
Patrick Doyle
cc6e84ecd0
Remove entitlement reflection ITs. (#121550)
This is best tested in unit tests, not REST actions.
2025-02-03 20:25:11 +01:00
Patrick Doyle
aa28d84792
Fix PolicyManager: plugin resolver overrides agent (#121456) 2025-02-03 16:10:01 +01:00
Niels Bauman
1b342b26ef Merge main into multi-project 2025-02-03 21:03:58 +10:00
Patrick Doyle
38a3844441
Entitlement tests using reflection (#121436)
* Entitlement IT cases for reflection

* EntitlementBootstrap selfTest using reflection

* Remove errant logging setting

* Lambdas instead of booleans

* [CI] Auto commit changes from spotless

* Refactor: Extract lambdas to method refs

---------

Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
2025-01-31 19:18:17 +01:00
Patrick Doyle
f205061e91
Reduce duplicate and dead entitlements code (#121409)
* Refactor: remove duplicate canWrite methods.

This serves as a good example of how Path and File handling could be
specialized in the future, but as long as they are identical, the duplication
causes more harm than good.

* Refactor: just one neverEntitled.

The original motivation was to avoid allocating a lambda object on each call,
but since that's a highly optimized operation in the JVM, it's unlikely to make
a difference in practice, and this smacks of premature optimization.

We're pretty liberal about lambdas elsewhere, so let's not sweat it here until
we have some evidence that it matters.

* Remove dead code
2025-01-31 16:29:53 +01:00
Ryan Ernst
37c929b9dc
Make entitlement IT tests reflective (#121355)
This commit adds an EntitlementTest annotation that can be used on
classes containing test actions for entitlements. The annotation mirrors
the parameters of CheckAction. Only file check actions are currently
converted, the rest can be moved and annotated as followups. Note that
the check action name is simply the method name, no fancy name
manipulation is done.
2025-01-31 16:09:51 +01:00
Ryan Ernst
c3f752054e
Pass environment paths into entitlement bootstrap (#121347)
This commit adds the data dirs, config dir and temp dir into
entitlement bootstrapping. It doesn't yet use them in entitlement
policies, but makes them available to use within initialization.
2025-01-31 05:51:44 -08:00
Niels Bauman
da7d58c06c Merge main into multi-project 2025-01-31 11:21:48 +10:00
Patrick Doyle
2bbf7c72db
Fix PolicyManagerTests after package move (#121304)
* Fix PolicyManagerTests after package move

* Unmute
2025-01-30 17:47:37 +01:00
Patrick Doyle
45c191ec55
Refactor: separate package for entitlement records (#121204) 2025-01-30 16:00:12 +01:00
Lorenzo Dematté
e260f29464
[Entitlements] "dynamic" instrumentation method keys (#120811) 2025-01-30 12:29:24 +01:00
Niels Bauman
621a18d947 Merge main into multi-project 2025-01-30 17:26:28 +10:00
Jack Conradson
74e8ae5448
Add single flag entitlement validation (#121234)
This adds basic flag entitlement validation when creating PolicyManager. If a module has the same flag 
entitlement as part of it's policy multiple times we will throw an IllegalArgumentException. With this 
validation we can safely assume FileEntitlement is the only one we currently have that allows multiple entitlements in a policy.
2025-01-29 16:15:46 -08: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
Jack Conradson
343ec0bcc3
Restrict apm agent entitlements to the apm package in an unnamed module (#120546)
This change closes a hole where we assumed any check against an unnamed-module from any 
classloader was for one of our apm agent. This was not the case and made it so scripts could in theory 
have the same entitlements as apm agent. Instead we now check to see if a class is part of the apm 
package in an unnamed module to ensure it's actually for the apm agent.

Relates to ES-10192
2025-01-28 07:18:22 -08:00
Lorenzo Dematté
436e604b90
[Entitlements] Add checks for native libraries restricted methods (#120775) 2025-01-28 13:08:05 +01:00
Moritz Mack
a608f0626e
Added query param ?include_source_on_error for ingest requests (#120725)
A new query parameter `?include_source_on_error` was added for create / index, update and bulk REST APIs to control
if to include the document source in the error response in case of parsing errors. The default value is `true`.
2025-01-28 09:33:22 +01:00
Patrick Doyle
e3c5e975f9
Entitled plugin for testing (#120840)
* Entitled plugin

* [CI] Auto commit changes from spotless

* SuppressForbidden in entitled plugin

* Respond to PR comments

* Reinstate entitled plugin

* Make System_clearProperty package-private

---------

Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
2025-01-27 12:57:15 -08: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
Ryan Ernst
75b772d66c
Share more entitlement IT setup (#120846)
This commit adds an AbstractEntitlementsIT and moves the entitlement
cluster setup into a bespoke EntitlementTestRule. That allows most of
the common code to be deduplicated. This change also automatically
creates a temp dir which the test passes along into the test cluster.
2025-01-24 15:22:32 -08:00
Ryan Ernst
095621f801
Validate mrjar plugin versions (#120823)
The mrjar plugin adds support for sourcesets named in the form mainNN,
which adds the appropriate compiler and other settings for that version
of Java, and produces a multi-release jar. Having multi-release jars
only makes sense for versions of java newer than the minimum compile
version. This commit adds validation that the version is not too old.

Note that the check is slightly relaxed; it allows mainNN where NN is
equal to the min java version. This is due to the desire to keep
code using incubating modules separate because warnings must be
disabled.
2025-01-24 18:59:34 +00:00
Lorenzo Dematté
81a9348431
[Entitlements] Enable native access based on policies (#120638) 2025-01-24 08:29:38 +01:00
Niels Bauman
6495dcbb40 Merge main into multi-project 2025-01-24 15:48:39 +10:00
Lorenzo Dematté
0e5fe75250
Rename test-plugin to entitlement-test-plugin (#120696) 2025-01-23 14:37:00 +01:00
Niels Bauman
682cf0a18f Merge remote-tracking branch 'public/main' into merge-main 2025-01-23 13:27:52 +10:00
Ryan Ernst
14b1611cbb
Ensure entitlements have exactly one external constructor (#120665)
When an entitlement is available to policy files, it should have one
constructor that the parser uses. This commit adjusts the policy parser
to scan the constructor to find that one annotated constructor, and
errors if more than one is found.
2025-01-23 00:54:40 +00:00
Ryan Ernst
0b65bc1525
Refactor entitlement IT test to allow dynamic policy (#120443)
This commit combines the different entitlement test plugins used for
integration tests into a single plugin. When installing the plugin in
the integ test cluster, the entitlement policy and plugin properties are
adjusted to test the desired combination of settings. This allows the
plugin policy to be dynamically generated by each test, rather than rely
on a static policy.
2025-01-22 08:47:09 -08:00
Lorenzo Dematté
d18b6790f4
[Entitlements] Refactor: create/parse entitlement policies earlier during bootstrap (#120611) 2025-01-22 14:29:57 +01:00
Lorenzo Dematté
bdd2fc00d3
[Entitlements] Policy and checks for loading native libraries (#120044) 2025-01-22 14:00:40 +01:00
Simon Cooper
e6a3aff093 Merge commit '13c75c02f0' into merge-main-22-01-25T12 2025-01-22 12:09:34 +00:00
Lorenzo Dematté
61e9a226b9
[Entitlements] Relax check in IT tests for FIPS environments (#120463) 2025-01-22 10:14:13 +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é
3fa2415db8
[Entitlements] Move some checks that use version-specific API (#120397) 2025-01-21 08:38:20 +01:00
Niels Bauman
6c7d2d285b Merge main into multi-project 2025-01-21 11:04:37 +10:00
Lorenzo Dematté
cd86b3b497
[Entitlements] Refactor Network Entitlement (#120391) 2025-01-20 18:29:32 +01:00
Yang Wang
7a1f5c5d4f Merge main into multi-project 2025-01-20 11:17:40 +11:00
Jack Conradson
45e80f55be
Add PolicyValdidationException for entitlements (#120225)
This adds a new exception called PolicyValdidationException. This exception is intended to be used during construction of entitlements that require parsing additional arguments. This allows PolicyParser to give improved error messaging about a specific entitlement that may have failed during the parsing process.
2025-01-17 10:34:53 -08: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
Tim Vernum
552cec7ff0 Merge revision 34059c9dbd into multi-project 2025-01-17 16:32:15 +11:00
Craig Taverner
40c34cd896
Optimize ST_EXTENT_AGG for geo_shape and cartesian_shape (#119889)
Support for `ST_EXTENT_AGG` was added in https://github.com/elastic/elasticsearch/pull/118829, and then partially optimized in https://github.com/elastic/elasticsearch/pull/118829. This optimization worked only for cartesian_shape fields, and worked by extracting the Extent from the doc-values and re-encoding it as a WKB `BBOX` geometry. This does not work for geo_shape, where we need to retain all 6 integers stored in the doc-values, in order to perform the datelline choice only at reduce time during the final phase of the aggregation.

Since both geo_shape and cartesian_shape perform the aggregations using integers, and the original Extent values in the doc-values are integers, this PR expands the previous optimization by:
* Saving all Extent values into a multi-valued field in an IntBlock for both cartesian_shape and geo_shape
* Simplifying the logic around merging intermediate states for all cases (geo/cartesian and grouped and non-grouped aggs)
* Widening test cases for testing more combinations of aggregations and types, and fixing a few bugs found
* Enhancing cartesian extent to convert from 6 ints to 4 ints at block loading time (for efficiency)
* Fixing bugs in both cartesian and geo extents for generating intermediate state with missing groups (flaky tests in serverless)
* Moved the int order to always match Rectangle for 4-int and Extent for 6-int cases (improved internal consistency)

Since the PR already changed the meaning of the invalid/infinite values of the intermediate state integers, it was already not compatible with the previous cluster versions. We disabled mixed-cluster testing to prevent errors as a result of that. This leaves us the opportunity to make further changes that are mixed-cluster incompatible, hence the decision to perform this consistency update now.
2025-01-16 19:43:51 +01:00
Lorenzo Dematté
46a8e69dd6
[Entitlements] Introducing runtime version-specific checks in IT tests (#120265) 2025-01-16 15:50:41 +01:00
Simon Cooper
5a70623d8d Merge remote-tracking branch 'upstream-main/main' into merge-main-16-01-25 2025-01-16 09:23:46 +00:00
Lorenzo Dematté
1848d6bb93
[Entitlements] Network access checks on Sockets (#120093) 2025-01-15 22:01:56 +01:00