Skip to content

Commit a5081f3

Browse files
authored
Install demo security information when running ./gradlew run -PinstalledPlugins="['opensearch-security']" (opensearch-project#20372)
* Install demon security information when running ./gradlew run -PinstalledPlugins="['opensearch-security']" Signed-off-by: Craig Perkins <cwperx@amazon.com> * Add to CHANGELOG Signed-off-by: Craig Perkins <cwperx@amazon.com> * Address review comments Signed-off-by: Craig Perkins <cwperx@amazon.com> --------- Signed-off-by: Craig Perkins <cwperx@amazon.com>
1 parent 0b1cacc commit a5081f3

3 files changed

Lines changed: 71 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1919
- Cleanup HttpServerTransport.Dispatcher in Netty tests ([#20160](https://github.com/opensearch-project/OpenSearch/pull/20160))
2020
- Add `cluster.initial_cluster_manager_nodes` to testClusters OVERRIDABLE_SETTINGS ([#20348](https://github.com/opensearch-project/OpenSearch/pull/20348))
2121
- Add BigInteger support for unsigned_long fields in gRPC transport ([#20346](https://github.com/opensearch-project/OpenSearch/pull/20346))
22+
- Install demo security information when running ./gradlew run -PinstalledPlugins="['opensearch-security']" ([#20372](https://github.com/opensearch-project/OpenSearch/pull/20372))
2223

2324
### Fixed
2425
- Fix bug of warm index: FullFileCachedIndexInput was closed error ([#20055](https://github.com/opensearch-project/OpenSearch/pull/20055))

build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ apply from: 'gradle/run.gradle'
7171
apply from: 'gradle/missing-javadoc.gradle'
7272
apply from: 'gradle/code-coverage.gradle'
7373

74+
// Apply security setup if opensearch-security is in installedPlugins
75+
if (project.hasProperty('installedPlugins') &&
76+
project.property('installedPlugins').toString().contains('opensearch-security')) {
77+
apply from: 'gradle/security-setup.gradle'
78+
}
79+
7480
// Apply FIPS configuration to all projects
7581
allprojects {
7682
apply from: "$rootDir/gradle/fips.gradle"

gradle/security-setup.gradle

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
ext.securityEnabled = project.hasProperty('installedPlugins') &&
10+
project.property('installedPlugins').toString().contains('opensearch-security')
11+
12+
if (securityEnabled) {
13+
// Download security certificates
14+
['esnode.pem', 'esnode-key.pem', 'kirk.pem', 'kirk-key.pem', 'root-ca.pem'].forEach { file ->
15+
File local = project.layout.buildDirectory.file(file).get().asFile
16+
tasks.register("download${file.replace('-', '').replace('.', '').capitalize()}") {
17+
doLast {
18+
if (!local.exists()) {
19+
local.parentFile.mkdirs()
20+
new URL("https://raw.githubusercontent.com/opensearch-project/security/refs/heads/main/bwc-test/src/test/resources/security/" + file).withInputStream { i ->
21+
local.withOutputStream { it << i }
22+
}
23+
}
24+
}
25+
}
26+
}
27+
28+
// Configure security for run task
29+
afterEvaluate {
30+
if (testClusters.findByName('runTask')) {
31+
testClusters.runTask.nodes.each { node ->
32+
// Add certificate files
33+
node.extraConfigFile("kirk.pem", project.layout.buildDirectory.file("kirk.pem").get().asFile)
34+
node.extraConfigFile("kirk-key.pem", project.layout.buildDirectory.file("kirk-key.pem").get().asFile)
35+
node.extraConfigFile("esnode.pem", project.layout.buildDirectory.file("esnode.pem").get().asFile)
36+
node.extraConfigFile("esnode-key.pem", project.layout.buildDirectory.file("esnode-key.pem").get().asFile)
37+
node.extraConfigFile("root-ca.pem", project.layout.buildDirectory.file("root-ca.pem").get().asFile)
38+
39+
// Security settings
40+
node.setting("plugins.security.ssl.transport.pemcert_filepath", "esnode.pem")
41+
node.setting("plugins.security.ssl.transport.pemkey_filepath", "esnode-key.pem")
42+
node.setting("plugins.security.ssl.transport.pemtrustedcas_filepath", "root-ca.pem")
43+
node.setting("plugins.security.ssl.transport.enforce_hostname_verification", "false")
44+
node.setting("plugins.security.ssl.http.enabled", "true")
45+
node.setting("plugins.security.ssl.http.pemcert_filepath", "esnode.pem")
46+
node.setting("plugins.security.ssl.http.pemkey_filepath", "esnode-key.pem")
47+
node.setting("plugins.security.ssl.http.pemtrustedcas_filepath", "root-ca.pem")
48+
node.setting("plugins.security.allow_unsafe_democertificates", "true")
49+
node.setting("plugins.security.allow_default_init_securityindex", "true")
50+
node.setting("plugins.security.authcz.admin_dn", "\n - CN=kirk,OU=client,O=client,L=test,C=de")
51+
node.setting("plugins.security.audit.type", "internal_opensearch")
52+
node.setting("plugins.security.enable_snapshot_restore_privilege", "true")
53+
node.setting("plugins.security.check_snapshot_restore_write_privileges", "true")
54+
node.setting("plugins.security.restapi.roles_enabled", "[\"all_access\", \"security_rest_api_access\"]")
55+
node.setting("plugins.security.system_indices.enabled", "true")
56+
}
57+
58+
// Make run task depend on certificate downloads
59+
tasks.named('run') {
60+
dependsOn tasks.matching { it.name.startsWith('download') && it.name.contains('pem') }
61+
}
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)