Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into incremental_rest_earl…
Browse files Browse the repository at this point in the history
…ier_path
  • Loading branch information
Tim-Brooks committed Sep 20, 2024
2 parents dddafbd + 079b4c3 commit 700ef7a
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 0 deletions.
10 changes: 10 additions & 0 deletions distribution/tools/entitlement-agent/README.md
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`.
39 changes: 39 additions & 0 deletions distribution/tools/entitlement-agent/build.gradle
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'
}

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;
}
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();
}
}
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());
}

}
14 changes: 14 additions & 0 deletions libs/entitlement-runtime/README.md
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`.
24 changes: 24 additions & 0 deletions libs/entitlement-runtime/build.gradle
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'
}
14 changes: 14 additions & 0 deletions libs/entitlement-runtime/src/main/java/module-info.java
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;
}
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;
}
}
14 changes: 14 additions & 0 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,20 @@ tests:
- class: org.elasticsearch.xpack.security.authz.SecurityScrollTests
method: testSearchAndClearScroll
issue: https://github.com/elastic/elasticsearch/issues/113285
- class: org.elasticsearch.xpack.esql.qa.mixed.MixedClusterEsqlSpecIT
method: test {date.EvalDateFormatString SYNC}
issue: https://github.com/elastic/elasticsearch/issues/113293
- class: org.elasticsearch.xpack.esql.ccq.MultiClusterSpecIT
method: test {date.EvalDateFormat}
issue: https://github.com/elastic/elasticsearch/issues/113294
- class: org.elasticsearch.xpack.esql.ccq.MultiClusterSpecIT
method: test {date.DocsDateFormat}
issue: https://github.com/elastic/elasticsearch/issues/113295
- class: org.elasticsearch.xpack.esql.ccq.MultiClusterSpecIT
method: test {stats.DocsStatsGroupByMultipleValues}
issue: https://github.com/elastic/elasticsearch/issues/113296
- class: org.elasticsearch.xpack.esql.qa.mixed.MixedClusterEsqlSpecIT
issue: https://github.com/elastic/elasticsearch/issues/113298

# Examples:
#
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ List projects = [
'distribution:tools:keystore-cli',
'distribution:tools:geoip-cli',
'distribution:tools:ansi-console',
'distribution:tools:entitlement-agent',
'server',
'test:framework',
'test:fixtures:azure-fixture',
Expand Down

0 comments on commit 700ef7a

Please sign in to comment.