forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into incremental_rest_earl…
…ier_path
- Loading branch information
Showing
11 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,10 @@ | ||
### Entitlement Agent | ||
|
||
This is a java agent that instruments sensitive class library methods with calls into the `entitlement-runtime` module to check for permissions granted under the _entitlements_ system. | ||
|
||
The entitlements system provides an alternative to the legacy `SecurityManager` system, which is deprecated for removal. | ||
With this agent, the Elasticsearch server can retain some control over which class library methods can be invoked by which callers. | ||
|
||
This module is responsible for inserting the appropriate bytecode to achieve enforcement of the rules governed by the `entitlement-runtime` module. | ||
|
||
It is not responsible for permission granting or checking logic. That responsibility lies with `entitlement-runtime`. |
This file contains 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,39 @@ | ||
/* | ||
* 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". | ||
*/ | ||
|
||
apply plugin: 'elasticsearch.build' | ||
|
||
configurations { | ||
entitlementRuntime | ||
} | ||
|
||
dependencies { | ||
entitlementRuntime project(":libs:elasticsearch-entitlement-runtime") | ||
implementation project(":libs:elasticsearch-entitlement-runtime") | ||
testImplementation project(":test:framework") | ||
} | ||
|
||
tasks.named('test').configure { | ||
dependsOn('jar') | ||
jvmArgs "-javaagent:${ tasks.named('jar').flatMap{ it.archiveFile }.get()}" | ||
} | ||
|
||
tasks.named('jar').configure { | ||
manifest { | ||
attributes( | ||
'Premain-Class': 'org.elasticsearch.entitlement.agent.EntitlementAgent' | ||
, 'Can-Retransform-Classes': 'true' | ||
) | ||
} | ||
} | ||
|
||
tasks.named('forbiddenApisMain').configure { | ||
replaceSignatureFiles 'jdk-signatures' | ||
} | ||
|
13 changes: 13 additions & 0 deletions
13
distribution/tools/entitlement-agent/src/main/java/module-info.java
This file contains 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,13 @@ | ||
/* | ||
* 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". | ||
*/ | ||
|
||
module org.elasticsearch.entitlement.agent { | ||
requires java.instrument; | ||
requires org.elasticsearch.entitlement.runtime; | ||
} |
21 changes: 21 additions & 0 deletions
21
...entitlement-agent/src/main/java/org/elasticsearch/entitlement/agent/EntitlementAgent.java
This file contains 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,21 @@ | ||
/* | ||
* 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.agent; | ||
|
||
import org.elasticsearch.entitlement.runtime.api.EntitlementChecks; | ||
|
||
import java.lang.instrument.Instrumentation; | ||
|
||
public class EntitlementAgent { | ||
|
||
public static void premain(String agentArgs, Instrumentation inst) throws Exception { | ||
EntitlementChecks.setAgentBooted(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...lement-agent/src/test/java/org/elasticsearch/entitlement/agent/EntitlementAgentTests.java
This file contains 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,29 @@ | ||
/* | ||
* 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.agent; | ||
|
||
import org.elasticsearch.entitlement.runtime.api.EntitlementChecks; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.test.ESTestCase.WithoutSecurityManager; | ||
|
||
/** | ||
* This is an end-to-end test that runs with the javaagent installed. | ||
* It should exhaustively test every instrumented method to make sure it passes with the entitlement | ||
* and fails without it. | ||
* See {@code build.gradle} for how we set the command line arguments for this test. | ||
*/ | ||
@WithoutSecurityManager | ||
public class EntitlementAgentTests extends ESTestCase { | ||
|
||
public void testAgentBooted() { | ||
assertTrue(EntitlementChecks.isAgentBooted()); | ||
} | ||
|
||
} |
This file contains 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,14 @@ | ||
### Entitlement runtime | ||
|
||
This module implements mechanisms to grant and check permissions under the _entitlements_ system. | ||
|
||
The entitlements system provides an alternative to the legacy `SecurityManager` system, which is deprecated for removal. | ||
The `entitlement-agent` tool instruments sensitive class library methods with calls to this module, in order to enforce the controls. | ||
|
||
This module is responsible for: | ||
- Defining which class library methods are sensitive | ||
- Defining what permissions should be checked for each sensitive method | ||
- Implementing the permission checks | ||
- Offering a "grant" API to grant permissions | ||
|
||
It is not responsible for anything to do with bytecode instrumentation; that responsibility lies with `entitlement-agent`. |
This file contains 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,24 @@ | ||
/* | ||
* 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". | ||
*/ | ||
apply plugin: 'elasticsearch.build' | ||
apply plugin: 'elasticsearch.publish' | ||
|
||
dependencies { | ||
compileOnly project(':libs:elasticsearch-core') | ||
|
||
testImplementation project(":test:framework") | ||
} | ||
|
||
tasks.named('forbiddenApisMain').configure { | ||
replaceSignatureFiles 'jdk-signatures' | ||
} | ||
|
||
tasks.named('forbiddenApisMain').configure { | ||
replaceSignatureFiles 'jdk-signatures' | ||
} |
This file contains 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,14 @@ | ||
/* | ||
* 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". | ||
*/ | ||
|
||
module org.elasticsearch.entitlement.runtime { | ||
requires org.elasticsearch.base; | ||
|
||
exports org.elasticsearch.entitlement.runtime.api to org.elasticsearch.entitlement.agent; | ||
} |
22 changes: 22 additions & 0 deletions
22
...nt-runtime/src/main/java/org/elasticsearch/entitlement/runtime/api/EntitlementChecks.java
This file contains 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,22 @@ | ||
/* | ||
* 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.api; | ||
|
||
public class EntitlementChecks { | ||
static boolean isAgentBooted = false; | ||
|
||
public static void setAgentBooted() { | ||
isAgentBooted = true; | ||
} | ||
|
||
public static boolean isAgentBooted() { | ||
return isAgentBooted; | ||
} | ||
} |
This file contains 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 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