|
| 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