-
Notifications
You must be signed in to change notification settings - Fork 148
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
Run IT tests with security plugin (#335) #1986
Merged
Yury-Fridlyand
merged 5 commits into
opensearch-project:main
from
Bit-Quill:integ-IT-with-security
Aug 21, 2023
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f99d895
Run IT tests with security plugin (#335)
Yury-Fridlyand dd52ff1
Merge remote-tracking branch 'upstream/main' into integ-IT-with-security
Yury-Fridlyand 4a6b8c0
Minor fix.
Yury-Fridlyand 23c83ec
Address PR feedback.
Yury-Fridlyand 600cbde
Typo fix.
Yury-Fridlyand 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
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,43 @@ | ||
name: Security Plugin IT | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches-ignore: | ||
- 'dependabot/**' | ||
paths: | ||
- 'integ-test/**' | ||
- '.github/workflows/integ-tests-with-security.yml' | ||
|
||
jobs: | ||
security-it: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ ubuntu-latest, windows-latest, macos-latest ] | ||
java: [ 11, 17 ] | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK ${{ matrix.java }} | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'temurin' | ||
java-version: ${{ matrix.java }} | ||
|
||
- name: Build with Gradle | ||
run: ./gradlew integTestWithSecurity | ||
|
||
- name: Upload test reports | ||
if: ${{ always() }} | ||
uses: actions/upload-artifact@v2 | ||
continue-on-error: true | ||
with: | ||
name: test-reports-${{ matrix.os }}-${{ matrix.java }} | ||
path: | | ||
integ-test/build/reports/** | ||
integ-test/build/testclusters/*/logs/* | ||
integ-test/build/testclusters/*/config/* |
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 |
---|---|---|
|
@@ -24,7 +24,10 @@ | |
|
||
import org.opensearch.gradle.test.RestIntegTestTask | ||
import org.opensearch.gradle.testclusters.StandaloneRestIntegTestTask | ||
import org.opensearch.gradle.testclusters.OpenSearchCluster | ||
|
||
import groovy.xml.XmlParser | ||
import java.nio.file.Paths | ||
import java.util.concurrent.Callable | ||
import java.util.stream.Collectors | ||
|
||
|
@@ -62,6 +65,82 @@ ext { | |
projectSubstitutions = [:] | ||
licenseFile = rootProject.file('LICENSE.TXT') | ||
noticeFile = rootProject.file('NOTICE') | ||
|
||
getSecurityPluginDownloadLink = { -> | ||
var repo = "https://aws.oss.sonatype.org/content/repositories/snapshots/org/opensearch/plugin/" + | ||
"opensearch-security/$opensearch_build/" | ||
var metadataFile = Paths.get(projectDir.toString(), "build", "maven-metadata.xml").toAbsolutePath().toFile() | ||
download.run { | ||
src repo + "maven-metadata.xml" | ||
dest metadataFile | ||
} | ||
def metadata = new XmlParser().parse(metadataFile) | ||
def securitySnapshotVersion = metadata.versioning.snapshotVersions[0].snapshotVersion[0].value[0].text() | ||
|
||
return repo + "opensearch-security-${securitySnapshotVersion}.zip" | ||
} | ||
|
||
File downloadedSecurityPlugin = null | ||
|
||
configureSecurityPlugin = { OpenSearchCluster cluster -> | ||
|
||
cluster.getNodes().forEach { node -> | ||
var creds = node.getCredentials() | ||
if (creds.isEmpty()) { | ||
creds.add(Map.of('useradd', 'admin', '-p', 'admin')) | ||
} else { | ||
creds.get(0).putAll(Map.of('useradd', 'admin', '-p', 'admin')) | ||
} | ||
} | ||
|
||
var projectAbsPath = projectDir.getAbsolutePath() | ||
|
||
// add a check to avoid re-downloading multiple times during single test run | ||
if (downloadedSecurityPlugin == null) { | ||
downloadedSecurityPlugin = Paths.get(projectAbsPath, 'bin', 'opensearch-security-snapshot.zip').toFile() | ||
download.run { | ||
src getSecurityPluginDownloadLink() | ||
dest downloadedSecurityPlugin | ||
} | ||
} | ||
|
||
// Config below including files are copied from security demo configuration | ||
['esnode.pem', 'esnode-key.pem', 'root-ca.pem'].forEach { file -> | ||
File local = Paths.get(projectAbsPath, 'bin', file).toFile() | ||
download.run { | ||
src "https://raw.githubusercontent.com/opensearch-project/security/main/bwc-test/src/test/resources/security/" + file | ||
dest local | ||
overwrite false | ||
} | ||
cluster.extraConfigFile file, local | ||
} | ||
[ | ||
'plugins.security.ssl.transport.pemcert_filepath' : 'esnode.pem', | ||
'plugins.security.ssl.transport.pemkey_filepath' : 'esnode-key.pem', | ||
'plugins.security.ssl.transport.pemtrustedcas_filepath' : 'root-ca.pem', | ||
'plugins.security.ssl.transport.enforce_hostname_verification' : 'false', | ||
// https is disabled : because `OpenSearchCluster` is hardcoded to validate cluster health by http | ||
// refer how IT framework implemented in security plugin and reuse/copy to activate https | ||
'plugins.security.ssl.http.enabled' : 'false', | ||
'plugins.security.ssl.http.pemcert_filepath' : 'esnode.pem', | ||
'plugins.security.ssl.http.pemkey_filepath' : 'esnode-key.pem', | ||
'plugins.security.ssl.http.pemtrustedcas_filepath' : 'root-ca.pem', | ||
'plugins.security.allow_unsafe_democertificates' : 'true', | ||
|
||
'plugins.security.allow_default_init_securityindex' : 'true', | ||
//'plugins.security.authcz.admin_dn' : 'CN=kirk,OU=client,O=client,L=test,C=de', | ||
'plugins.security.authcz.admin_dn' : 'CN=admin,OU=SSL,O=Test,L=Test,C=DE', | ||
'plugins.security.audit.type' : 'internal_opensearch', | ||
'plugins.security.enable_snapshot_restore_privilege' : 'true', | ||
'plugins.security.check_snapshot_restore_write_privileges' : 'true', | ||
'plugins.security.restapi.roles_enabled' : '["all_access", "security_rest_api_access"]', | ||
'plugins.security.system_indices.enabled' : 'true' | ||
].forEach { name, value -> | ||
cluster.setting name, value | ||
} | ||
|
||
cluster.plugin provider((Callable<RegularFile>) (() -> (RegularFile) (() -> downloadedSecurityPlugin))) | ||
} | ||
} | ||
|
||
tasks.withType(licenseHeaders.class) { | ||
|
@@ -108,6 +187,7 @@ dependencies { | |
testImplementation group: 'com.h2database', name: 'h2', version: '2.2.220' | ||
testImplementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.41.2.2' | ||
testImplementation group: 'com.google.code.gson', name: 'gson', version: '2.8.9' | ||
testCompileOnly 'org.apiguardian:apiguardian-api:1.1.2' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you explain why this is here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To remove hundreds of
from log. Nice to have in general. |
||
|
||
// Needed for BWC tests | ||
zipArchive group: 'org.opensearch.plugin', name:'opensearch-sql-plugin', version: "${bwcVersion}-SNAPSHOT" | ||
|
@@ -128,21 +208,28 @@ compileTestJava { | |
} | ||
|
||
testClusters.all { | ||
testDistribution = 'archive' | ||
|
||
// debug with command, ./gradlew opensearch-sql:run -DdebugJVM. --debug-jvm does not work with keystore. | ||
if (System.getProperty("debugJVM") != null) { | ||
jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005' | ||
} | ||
} | ||
|
||
testClusters.integTest { | ||
plugin ":opensearch-sql-plugin" | ||
setting "plugins.query.datasources.encryption.masterkey", "1234567812345678" | ||
} | ||
|
||
testClusters { | ||
integTest { | ||
testDistribution = 'archive' | ||
plugin ":opensearch-sql-plugin" | ||
setting "plugins.query.datasources.encryption.masterkey", "1234567812345678" | ||
} | ||
remoteCluster { | ||
testDistribution = 'archive' | ||
plugin ":opensearch-sql-plugin" | ||
} | ||
integTestWithSecurity { | ||
testDistribution = 'archive' | ||
plugin ":opensearch-sql-plugin" | ||
} | ||
remoteIntegTestWithSecurity { | ||
testDistribution = 'archive' | ||
plugin ":opensearch-sql-plugin" | ||
} | ||
} | ||
|
@@ -223,6 +310,65 @@ task integJdbcTest(type: RestIntegTestTask) { | |
} | ||
} | ||
|
||
task integTestWithSecurity(type: RestIntegTestTask) { | ||
useCluster testClusters.integTestWithSecurity | ||
useCluster testClusters.remoteIntegTestWithSecurity | ||
|
||
systemProperty "cluster.names", | ||
getClusters().stream().map(cluster -> cluster.getName()).collect(Collectors.joining(",")) | ||
|
||
getClusters().forEach { cluster -> | ||
configureSecurityPlugin(cluster) | ||
} | ||
|
||
useJUnitPlatform() | ||
dependsOn ':opensearch-sql-plugin:bundlePlugin' | ||
testLogging { | ||
events "passed", "skipped", "failed" | ||
} | ||
afterTest { desc, result -> | ||
logger.quiet "${desc.className}.${desc.name}: ${result.resultType} ${(result.getEndTime() - result.getStartTime())/1000}s" | ||
} | ||
|
||
systemProperty 'tests.security.manager', 'false' | ||
systemProperty 'project.root', project.projectDir.absolutePath | ||
|
||
// Set default query size limit | ||
systemProperty 'defaultQuerySizeLimit', '10000' | ||
|
||
// Tell the test JVM if the cluster JVM is running under a debugger so that tests can use longer timeouts for | ||
// requests. The 'doFirst' delays reading the debug setting on the cluster till execution time. | ||
doFirst { | ||
systemProperty 'cluster.debug', getDebug() | ||
getClusters().forEach { cluster -> | ||
|
||
String allTransportSocketURI = cluster.nodes.stream().flatMap { node -> | ||
node.getAllTransportPortURI().stream() | ||
}.collect(Collectors.joining(",")) | ||
String allHttpSocketURI = cluster.nodes.stream().flatMap { node -> | ||
node.getAllHttpSocketURI().stream() | ||
}.collect(Collectors.joining(",")) | ||
|
||
systemProperty "tests.rest.${cluster.name}.http_hosts", "${-> allHttpSocketURI}" | ||
systemProperty "tests.rest.${cluster.name}.transport_hosts", "${-> allTransportSocketURI}" | ||
} | ||
|
||
systemProperty "https", "false" | ||
systemProperty "user", "admin" | ||
systemProperty "password", "admin" | ||
} | ||
|
||
if (System.getProperty("test.debug") != null) { | ||
jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005' | ||
} | ||
|
||
// NOTE: this IT config discovers only junit5 (jupiter) tests. | ||
// https://github.com/opensearch-project/sql/issues/1974 | ||
filter { | ||
includeTestsMatching 'org.opensearch.sql.ppl.CrossClusterSearchIT' | ||
} | ||
} | ||
|
||
// Run PPL ITs and new, legacy and comparison SQL ITs with new SQL engine enabled | ||
integTest { | ||
useCluster testClusters.remoteCluster | ||
|
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
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.
do we need this?
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.
This is a part of demo configuration, I replated it with example from docs. Not sure how/whether it works.
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.
This is the subject of the admin certificate. You most likely will not need it for doing testing using testClusters.
You would need it if you plan to use securityadmin. Copying the demo config should be fine.
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.
Thank you @cwperks!
I updated config and added a comment in 23c83ec.