Commit graph

63 commits

Author SHA1 Message Date
Ryan Ernst
04e979aa50
Simplify entitlement rest test discovery (#125449) (#126539)
This commit cleans up how entitlement test methods are discovered. It
also adds another robustness check to ensure an annotation doesn't exist
on a private method.
2025-04-10 01:55:06 +10:00
Ryan Ernst
33dc75fede
Move remaining check methods in RestEntitlementsCheckAction (#125351) (#125443)
* Move remaining check methods in RestEntitlementsCheckAction (#125351)

All future check methods should be found reflectively with the
EntitlementTest annotation.

* Fix compilation after #125442
2025-03-22 09:03:37 +11:00
Lorenzo Dematté
e2ae238bce
[Entitlements] Add an option to perform bytecode verification during instrumentation (#124404) (#125224)
Using ASM CheckClassAdapter was key to diagnose the issue we had with incorrect signatures for some check methods.
In this PR I polished up the code I used to pinpoint the issue, and made it available via a system property so it can be turned on if we need it (and it's always on for Entitlements IT tests too).

It is also turned on in case we get VerifyErrors during retransformClasses early in the Entitlement agent bootstrap: retransformClasses runs in the native part of the JVM, so the VerifyError it produces is not so readable (e.g. it lacks a full stack trace and a description); in case this happens, we re-apply the transformation with verification turned on to get a meaningful error before dying.
2025-03-21 09:16:19 +01:00
Ryan Ernst
5c5a743dd8
Split out jvm and operating system actions in entitlement tests (#125122) (#125343)
This is part of continued cleanup to remove actions from
RestEntitlementCheckAction.
2025-03-21 07:42:27 +11:00
Lorenzo Dematté
0be9e357e3
[Entitlements] Allow policy overrides via system properties (#124489) (#124860)
This PR adds the ability to override entitlement policies for Elasticsearch plugins and modules via a system property.

The system property is in the form es.entitlements.policy.<plugin name>, and accepts a versioned policy:

versions:
  - version1
  - versionN
policy:
  <a standard entitlement policy>

For example:

versions:
  - 9.1.0
policy:
  ALL-UNNAMED:
    - set_https_connection_properties
    - outbound_network
    - files:
      - relative_path: ".config/gcloud"
        relative_to: home
        mode: read

The versioned policy needs to be base64 encoded. For example, to pass the above policy to a test cluster via gradle run:

./gradlew run --debug-jvm -Dtests.jvm.argline="-Des.entitlements.policy.repository-gcs=dmVyc2lvbnM6CiAgLSA5LjEuMApwb2xpY3k6CiAgQUxMLVVOTkFNRUQ6CiAgICAtIHNldF9odHRwc19jb25uZWN0aW9uX3Byb3BlcnRpZXMKICAgIC0gb3V0Ym91bmRfbmV0d29yawogICAgLSBmaWxlczoKICAgICAgLSByZWxhdGl2ZV9wYXRoOiAiLmNvbmZpZy9nY2xvdWQiCiAgICAgICAgcmVsYXRpdmVfdG86IGhvbWUKICAgICAgICBtb2RlOiByZWFkCg=="

The versions listed in the policy are string-matched against Build.version().current(); it is possible to specify any number of versions. If the list is empty/there is no versions field, the policy is assumed to match any Elasticsearch versions.

The override policy specified for any given plugin replaces the embedded policy for that plugin. See how EntitlementsAllowedViaOverrideIT replaces an empty policy for the entitlement-test-plugin with a policy that allows load_native_libraries and access to files in the test read_dir.

Also tested manually with an override with a different version, with an override with an invalid policy and with a valid override (see command above).

Relates to ES-11009
2025-03-14 20:41:37 +11:00
Lorenzo Dematté
c0afff1b38
[Entitlements] Add support for IT tests of always allowed actions (take 2) (#124429) (#124704)
Writing tests for #123861, turns out that #124195 is not enough.
We really need new IT test cases for "always allowed" actions: in order to be sure they are allowed, we need to setup the plugin with no policy.
This PR adds test cases for that, plus the support for writing test functions that accept one Environment parameter: many test paths we test and allow/deny are relative to paths in Environment, so it's useful to have access to it (see readAccessConfigDirectory as an example)
2025-03-13 21:07:47 +11:00
Lorenzo Dematté
b81b89660c
[Entitlements] Exclude java.desktop from system modules (#124563) (#124618)
* exclude java.desktop from system modules

* add IT test
2025-03-12 19:51:59 +11:00
Moritz Mack
f790cb894b
Rethrow NoSuchFileException if encountering an invalid symlink when checking file entitlements (#124483) (#124541)
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 21:51:31 +11:00
Lorenzo Dematté
b23b5b0a21
fix file tests to work across multiple invocations (#124412) (#124503) 2025-03-11 03:56:44 +11:00
Moritz Mack
155ba4980b
Fix entitlement checks for relative links (#124133) (#124478) 2025-03-11 00:55:10 +11:00
Lorenzo Dematté
2a82161670
[Entitlements] Add URLConnection instrumentation for jar protocol (#123861) (#124441)
Follows #123824

Relates to ES-10994
2025-03-09 21:56:47 +11:00
Lorenzo Dematté
02c8dcf298
[Entitlements] Add support for IT testing always allowed actions (#124195) (#124414) 2025-03-09 02:59:58 +11:00
Lorenzo Dematté
236b458de3
[Entitlements] MailToURLConnection instrumentation (#123829) (#124232) 2025-03-07 20:18:27 +11:00
Lorenzo Dematté
c709524233
[Entitlements] Add URLConnection instrumentation for file protocol (#123824) (#124065) 2025-03-05 19:18:59 +11:00
Lorenzo Dematté
e9b772bc60
[8.18][Entitlements] Add URLConnection instrumentation (#123966)
* [Entitlements] Add URLConnection instrumentation (#123503)

* [Entitlements] Add URLConnection instrumentation for ftp, http and https protocols (#123802)
2025-03-04 20:30:02 +11:00
Patrick Doyle
f45e283441
Reduce warnings in entitlement REST tests (#123028) (#123063) (#123075)
Backport of a bunch of minor cosmetic changes to reduce warnings.
2025-02-21 14:59:10 -05:00
Patrick Doyle
fcfde3b489
Misc non-java.base file entitlements (#123078) (#123154) (#123164)
* Misc non-java.base file entitlements

* Remove unnecessary dependency
2025-02-22 04:27:16 +11:00
Lorenzo Dematté
6e8074ed6f
[Entitlements] Instrumentation of NIO Files and Channels (#122816 and #122591) (#122986) (#122993)
* [Entitlements] Add check functions for NIO Files (#122591)

* [Entitlements] Instrumentation of NIO file channels (#122816)

* [CI] Auto commit changes from spotless

---------

Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
2025-02-20 20:45:01 +11:00
Patrick Doyle
2cf8e6a25b
Miscellaneous java.base file entitlements (#122906) (#122957)
* 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-20 06:29:06 +11:00
Moritz Mack
b00a24fb3d
Add entitlement checks for java.io stream classes (#122406) (#122851)
(cherry picked from commit 8eb89cf7c1)

# Conflicts:
#	libs/entitlement/bridge/src/main/java/org/elasticsearch/entitlement/bridge/EntitlementChecker.java
#	libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/api/ElasticsearchEntitlementChecker.java
2025-02-19 04:08:13 +11:00
Moritz Mack
e2bde8ac76
Instrument methods on File that require read permissions (#122544) (#122862)
This commit adds instrumentation for File methods that require read permissions.

see #122109 for the write side

(cherry picked from commit bf1cbb0e47)

# Conflicts:
#	x-pack/plugin/security/src/main/plugin-metadata/entitlement-policy.yaml

Co-authored-by: Ryan Ernst <ryan@iernst.net>
2025-02-19 02:56:58 +11:00
Moritz Mack
46387fbb32
[Entitlements] Instrument nio path (#122507) (#122763)
(cherry picked from commit 7fd1addccf)

# Conflicts:
#	libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/api/ElasticsearchEntitlementChecker.java
2025-02-18 19:54:45 +11:00
Lorenzo Dematté
f65580822f
[8.x][Entitlements] Add file read entitlement check to library load functions #122494 (#122624) (#122635)
* [Entitlements] Add file read entitlement check to library load functions #122494

* Missing variant
2025-02-15 06:26:20 +11:00
Patrick Doyle
0205d3fc86
Entitlements: manage_threads (#122261) (#122533)
* 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

* Move ForkJoinPool.setParallelism to VersionSpecificManageThreadsActions

* [CI] Auto commit changes from spotless

---------

Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
2025-02-14 09:18:28 +11:00
Lorenzo Dematté
4816497ec1
[8.x][Entitlements] Instrumentation for FileSystemProvider (#122232) (#122471) (#122492)
* [Entitlements] Instrumentation for FileSystemProvider (#122232)

* Move some check function and tests to version specific checker classes

* Refactor/fix: lookupImplementationMethod looks up the class hierarchy too

* Spotless
2025-02-13 23:09:21 +11:00
Lorenzo Dematté
2bf93c0432
[Entitlements] Add FileStore instrumentation + tests (#122348) (#122366) 2025-02-13 06:07:55 +11:00
Ryan Ernst
d907cbc9e5
Instrument methods on File that require write permission (#122109) (#122387)
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-13 02:34:54 +11:00
Ryan Ernst
ff43a24dd8
Use dynamic policy for entitled test plugin (#121852) (#122094)
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-08 08:55:18 +11:00
Lorenzo Dematté
ba9b6d7faa
Missing providers from nio (#122004) (#122051) 2025-02-08 04:19:18 +11:00
Jack Conradson
28edad3908
Merge all file entitlements into a single files entitlement (#121864) (#121937)
This change replaces FileEntitlement with FilesEntitlement so that we can have exactly one entitlement 
class per module (or possibly future scope). This cleans up our policy files so that all files are located 
together to allow access, and this opens up the design for future optimizations.
2025-02-07 07:28:25 +11:00
Lorenzo Dematté
5bc7657bcb
[Entitlements] Add native checks support for preview (pre-22 Java versions) (#121798) (#121902) 2025-02-07 01:20:36 +11:00
Ryan Ernst
28f3102a53
Move spi and system actions into separate classes (#121555) (#121779)
This commit moves methods used to test spi and system actions out of
RestEntitlementsCheckAction into separate classes, to ease future
merges.
2025-02-06 03:51:03 +11:00
Patrick Doyle
5ed039726b
Remove entitlement reflection ITs. (#121550) (#121561)
This is best tested in unit tests, not REST actions.
2025-02-04 07:41:37 +11:00
Patrick Doyle
33c916443d
Entitlement tests using reflection (#121436) (#121452)
* 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-02-01 06:32:17 +11:00
Ryan Ernst
8233a99ca3
Make entitlement IT tests reflective (#121355) (#121417)
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-02-01 03:16:52 +11:00
Ryan Ernst
2a30ebeb1a
Add initial file entitlement check (#120243) (#121252)
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-30 12:32:36 +11:00
Lorenzo Dematté
2171064f5c
[8.x] [Entitlements] Add checks for native libraries restricted methods (#120775) (#121017)
* [Entitlements] Add checks for native libraries restricted methods (#120775)

* Introducing main21 (does not compile with main23 on the main lib)

* Move foreign API to Java22; fix EntitlementInitialization to work across multiple versions

* [CI] Auto commit changes from spotless

---------

Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
2025-01-29 20:58:57 +11:00
Patrick Doyle
43d4b60b7f
Entitled plugin for testing (#120840) (#120961)
* 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-28 09:08:17 +11:00
Moritz Mack
2c8ccf7989
[Entitlements] Deny setting global defaults for Locale / TimeZone (#120804) (#120878)
Part of #ES-10359
2025-01-27 20:57:44 +11:00
Ryan Ernst
30c219bf96
Share more entitlement IT setup (#120846) (#120851)
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-25 11:27:09 +11:00
Lorenzo Dematté
9489c3710a
Rename test-plugin to entitlement-test-plugin (#120696) (#120723) 2025-01-24 02:43:33 +11:00
Lorenzo Dematté
ea4713736f
[Entitlements] Relax check in IT tests for FIPS environments (#120463) (#120693) 2025-01-23 15:29:23 +01:00
Ryan Ernst
857fbcd2a3
Refactor entitlement IT test to allow dynamic policy (#120443) (#120666)
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-23 07:42:09 +11:00
Lorenzo Dematté
72ab00dad2
[Entitlements] Policy and checks for loading native libraries (#120044) (#120623) 2025-01-23 03:57:35 +11:00
Moritz Mack
2b2ae57d04
[Entitlements] Instrument write access to System properties (#120357) (#120544)
Instrument write access to System properties by means of the `WriteSystemPropertiesEntitlement`.
`System.setProperties(Properties)` is always denied.

Part of #ES-10359
2025-01-22 05:13:42 +11:00
Lorenzo Dematté
d223dd0118
[Entitlements] Refactor Network Entitlement (#120391) (#120478) 2025-01-21 06:13:02 +11:00
Lorenzo Dematté
b6994cc423
[Entitlements] Network access checks for NIO classes (#120138) (#120394) 2025-01-20 23:22:54 +11:00
Lorenzo Dematté
fdffdd1225
[8.x] [Entitlements] Network access checks for miscellanea (#120262) (#120353)
* [Entitlements] Network access checks for miscellanea (#120262)

* Move checks that use version-specific API
2025-01-17 23:58:25 +11:00
Lorenzo Dematté
1d0295e400
[Entitlements] Network access checks on Sockets (#120093) (#120264) 2025-01-16 22:12:03 +11:00
Lorenzo Dematté
36e8af7e9b
Removing unneeded check on SSLSession#getSessionContext (#120191) (#120220) 2025-01-16 05:31:01 +11:00