-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[Entitlements] Allow policy overrides via system properties #124489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4636e67
read base64 policy overrides from syspros
ldematte 7a8d4e1
versioned policies
ldematte c92ef83
IT tests for policy override
ldematte aa3f266
Merge remote-tracking branch 'upstream/main' into entitlements/policy…
ldematte 0b635b0
Add IT test for policy override on files
ldematte c1738b7
Fixed forbidden API
ldematte 1c2e374
Use constants
ldematte c46d606
Merge remote-tracking branch 'upstream/main' into entitlements/policy…
ldematte 5b75e1a
Simplify callbacks
ldematte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
.../javaRestTest/java/org/elasticsearch/entitlement/qa/EntitlementsAllowedViaOverrideIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.entitlement.qa; | ||
|
|
||
| import com.carrotsearch.randomizedtesting.annotations.Name; | ||
| import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; | ||
|
|
||
| import org.elasticsearch.core.Strings; | ||
| import org.junit.ClassRule; | ||
|
|
||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Path; | ||
| import java.util.Base64; | ||
| import java.util.Map; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import static org.elasticsearch.entitlement.qa.EntitlementsTestRule.ENTITLEMENT_QA_TEST_MODULE_NAME; | ||
| import static org.elasticsearch.entitlement.qa.EntitlementsTestRule.ENTITLEMENT_TEST_PLUGIN_NAME; | ||
|
|
||
| public class EntitlementsAllowedViaOverrideIT extends AbstractEntitlementsIT { | ||
|
|
||
| private static Map<String, String> createPolicyOverrideSystemProperty(Path tempDir) { | ||
| String policyOverride = Strings.format(""" | ||
| policy: | ||
| %s: | ||
| - load_native_libraries | ||
| - files: | ||
| - path: %s | ||
| mode: read | ||
| """, ENTITLEMENT_QA_TEST_MODULE_NAME, tempDir.resolve("read_dir")); | ||
| var encodedPolicyOverride = new String(Base64.getEncoder().encode(policyOverride.getBytes(StandardCharsets.UTF_8))); | ||
| return Map.of("es.entitlements.policy." + ENTITLEMENT_TEST_PLUGIN_NAME, encodedPolicyOverride); | ||
| } | ||
|
|
||
| @ClassRule | ||
| public static EntitlementsTestRule testRule = new EntitlementsTestRule( | ||
| true, | ||
| null, | ||
| EntitlementsAllowedViaOverrideIT::createPolicyOverrideSystemProperty | ||
| ); | ||
|
|
||
| public EntitlementsAllowedViaOverrideIT(@Name("actionName") String actionName) { | ||
| super(actionName, true); | ||
| } | ||
|
|
||
| @ParametersFactory | ||
| public static Iterable<Object[]> data() { | ||
| return Stream.of("runtime_load_library", "fileList").map(action -> new Object[] { action }).toList(); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getTestRestCluster() { | ||
| return testRule.cluster.getHttpAddresses(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...titlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/VersionedPolicy.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.entitlement.runtime.policy; | ||
|
|
||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * A Policy and associated versions to which the policy applies | ||
| */ | ||
| public record VersionedPolicy(Policy policy, Set<String> versions) {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My suggestion would be to not have the version parsing as part of the
PolicyParserat all since it's only used to determine if a policy override is valid.I see two different possibilities to accomplish this:
PolicyParserto take in an XContentBuilder instead of an InputStream. Pull out the xcontent necessary for version checking in elasticsearch bootstrapping code.InputStreaminto thePolicyParser.I think this may also remove the need for a VersionedPolicy record as well.