Skip to content
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

[2.x] Enable security for bwc tests #3257

Merged
merged 29 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ed796a9
[2.x] Run BWC Tests with security plugin enabled
cwperks Aug 25, 2023
a65a901
Add certs with IPv6 loopback address ::1
cwperks Aug 25, 2023
96f590b
Move to bwc-test
cwperks Aug 25, 2023
422a26c
Rest client settings
cwperks Aug 25, 2023
9c2bdf1
Override getProtocol
cwperks Aug 25, 2023
1011f94
Bump to 2.11 for testing
cwperks Aug 25, 2023
a35e0ad
Fake 3.0.0
cwperks Aug 25, 2023
f4be930
2.10 to 2.10
cwperks Aug 25, 2023
4ad5900
Add dependency on common-utils
cwperks Aug 25, 2023
6cafd2a
Import HttpHost
cwperks Aug 25, 2023
1411492
Import IOException
cwperks Aug 25, 2023
ec58df3
Add kirk keystore
cwperks Aug 25, 2023
fbdacc3
Add debug statement
cwperks Aug 25, 2023
f956a9c
Add network.publish_host
cwperks Aug 28, 2023
b44f462
Add securityconfig
cwperks Aug 28, 2023
62fc4a1
Update path
cwperks Aug 28, 2023
c04201c
Show bwc tests working with security plugin enabled
cwperks Aug 28, 2023
c9ed63e
Remove added period by mistake
cwperks Aug 28, 2023
d5255cd
Run spotlessApply
cwperks Aug 28, 2023
dc4ed62
Try w/o config files
cwperks Aug 29, 2023
5362e89
Merge branch 'enable-security-for-bwc-tests-without-config' into enab…
cwperks Aug 29, 2023
6c022df
Use demo certificates
cwperks Aug 29, 2023
b7bf55f
Remove commented out settings
cwperks Aug 29, 2023
c84d017
Use demo certs
cwperks Aug 29, 2023
7458267
Add more inputs to run-bwc-suite
cwperks Aug 29, 2023
675ca43
Remove use-https param
cwperks Aug 29, 2023
0b82a16
Remove commented out code
cwperks Aug 29, 2023
2545807
Fix description
cwperks Aug 29, 2023
7fb2ef2
Add WhoAmI test
cwperks Aug 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/actions/create-bwc-build/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ runs:
uses: gradle/gradle-build-action@v2
with:
cache-disabled: true
arguments: assemble -Dbuild.snapshot=false
arguments: assemble
build-root-directory: ${{ inputs.plugin-branch }}

- id: get-opensearch-version
Expand All @@ -47,5 +47,5 @@ runs:
- name: Copy current distro into the expected folder
run: |
mkdir -p ./bwc-test/src/test/resources/${{ steps.get-opensearch-version.outputs.version }}
cp ${{ inputs.plugin-branch }}/build/distributions/opensearch-security-${{ steps.get-opensearch-version.outputs.version }}.zip ./bwc-test/src/test/resources/${{ steps.get-opensearch-version.outputs.version }}
cp ${{ inputs.plugin-branch }}/build/distributions/opensearch-security-${{ steps.get-opensearch-version.outputs.version }}-SNAPSHOT.zip ./bwc-test/src/test/resources/${{ steps.get-opensearch-version.outputs.version }}
shell: bash
11 changes: 11 additions & 0 deletions .github/actions/run-bwc-suite/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ inputs:
description: 'The name of the artifacts for this run, e.g. "BWC-2.1-to-2.4-results"'
required: true

username:
description: 'Username to use for cluster health check in testClusters'
required: true

password:
description: 'Password to use for cluster health check in testClusters'
required: true

runs:
using: "composite"
steps:
Expand All @@ -35,6 +43,9 @@ runs:
arguments: |
bwcTestSuite
-Dtests.security.manager=false
-Dtests.opensearch.secure=true
-Dtests.opensearch.username=${{ inputs.username }}
-Dtests.opensearch.password=${{ inputs.password }}
-Dbwc.version.previous=${{ steps.build-previous.outputs.built-version }}
-Dbwc.version.next=${{ steps.build-next.outputs.built-version }} -i
build-root-directory: bwc-test
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ jobs:
plugin-previous-branch: "2.9"
plugin-next-branch: "current_branch"
report-artifact-name: bwc-${{ matrix.platform }}-jdk${{ matrix.jdk }}
username: admin
password: admin

code-ql:
runs-on: ubuntu-latest
Expand Down
13 changes: 8 additions & 5 deletions bwc-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ ext {

buildscript {
ext {
opensearch_version = System.getProperty("opensearch.version", "2.9.0-SNAPSHOT")
opensearch_version = System.getProperty("opensearch.version", "2.10.0-SNAPSHOT")
opensearch_group = "org.opensearch"
common_utils_version = System.getProperty("common_utils.version", '2.9.0.0-SNAPSHOT')
}
repositories {
mavenLocal()
Expand All @@ -70,6 +71,7 @@ dependencies {
testImplementation "com.google.guava:guava:${versions.guava}"
testImplementation "org.opensearch.test:framework:${opensearch_version}"
testImplementation "org.apache.logging.log4j:log4j-core:${versions.log4j}"
testImplementation "org.opensearch:common-utils:${common_utils_version}"
}

loggerUsageCheck.enabled = false
Expand All @@ -84,8 +86,8 @@ String baseName = "securityBwcCluster"
String bwcFilePath = "src/test/resources/"
String projectVersion = nextVersion

String previousOpenSearch = extractVersion(previousVersion);
String nextOpenSearch = extractVersion(nextVersion);
String previousOpenSearch = extractVersion(previousVersion) + "-SNAPSHOT";
String nextOpenSearch = extractVersion(nextVersion) + "-SNAPSHOT";

// Extracts the OpenSearch version from a plugin version string, 2.4.0.0 -> 2.4.0.
def String extractVersion(versionStr) {
Expand Down Expand Up @@ -122,7 +124,8 @@ def String extractVersion(versionStr) {
node.extraConfigFile("esnode.pem", file("src/test/resources/security/esnode.pem"))
node.extraConfigFile("esnode-key.pem", file("src/test/resources/security/esnode-key.pem"))
node.extraConfigFile("root-ca.pem", file("src/test/resources/security/root-ca.pem"))
node.setting("plugins.security.disabled", "true")
node.setting("network.bind_host", "127.0.0.1")
node.setting("network.publish_host", "127.0.0.1")
node.setting("plugins.security.ssl.transport.pemcert_filepath", "esnode.pem")
node.setting("plugins.security.ssl.transport.pemkey_filepath", "esnode-key.pem")
node.setting("plugins.security.ssl.transport.pemtrustedcas_filepath", "root-ca.pem")
Expand All @@ -134,7 +137,7 @@ def String extractVersion(versionStr) {
node.setting("plugins.security.allow_unsafe_democertificates", "true")
node.setting("plugins.security.allow_default_init_securityindex", "true")
node.setting("plugins.security.authcz.admin_dn", "CN=kirk,OU=client,O=client,L=test,C=de")
node.setting("plugins.security.audit.type", "internal_elasticsearch")
node.setting("plugins.security.audit.type", "internal_opensearch")
node.setting("plugins.security.enable_snapshot_restore_privilege", "true")
node.setting("plugins.security.check_snapshot_restore_write_privileges", "true")
node.setting("plugins.security.restapi.roles_enabled", "[\"all_access\", \"security_rest_api_access\"]")
Expand Down
68 changes: 68 additions & 0 deletions bwc-test/src/test/java/SecurityBackwardsCompatibilityIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,38 @@
*/
package org.opensearch.security.bwc;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.message.BasicHeader;
import org.apache.http.ssl.SSLContextBuilder;
import org.junit.Assume;
import org.junit.Before;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.test.rest.OpenSearchRestTestCase;

import org.opensearch.Version;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItem;

import org.opensearch.client.RestClient;
import org.opensearch.client.RestClientBuilder;

import org.junit.Assert;

public class SecurityBackwardsCompatibilityIT extends OpenSearchRestTestCase {

private ClusterType CLUSTER_TYPE;
Expand All @@ -35,6 +52,11 @@ private void testSetup() {
CLUSTER_NAME = System.getProperty("tests.clustername");
}

@Override
protected final boolean preserveClusterUponCompletion() {
return true;
}

@Override
protected final boolean preserveIndicesUponCompletion() {
return true;
Expand All @@ -50,6 +72,11 @@ protected boolean preserveTemplatesUponCompletion() {
return true;
}

@Override
protected String getProtocol() {
return "https";
}

@Override
protected final Settings restClientSettings() {
return Settings.builder()
Expand All @@ -61,6 +88,41 @@ protected final Settings restClientSettings() {
.build();
}

@Override
protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOException {
RestClientBuilder builder = RestClient.builder(hosts);
configureHttpsClient(builder, settings);
boolean strictDeprecationMode = settings.getAsBoolean("strictDeprecationMode", true);
builder.setStrictDeprecationMode(strictDeprecationMode);
return builder.build();
}

protected static void configureHttpsClient(RestClientBuilder builder, Settings settings) throws IOException {
peternied marked this conversation as resolved.
Show resolved Hide resolved
Map<String, String> headers = ThreadContext.buildDefaultHeaders(settings);
Header[] defaultHeaders = new Header[headers.size()];
int i = 0;
for (Map.Entry<String, String> entry : headers.entrySet()) {
defaultHeaders[i++] = new BasicHeader(entry.getKey(), entry.getValue());
}
builder.setDefaultHeaders(defaultHeaders);
builder.setHttpClientConfigCallback(httpClientBuilder -> {
String userName = Optional.ofNullable(System.getProperty("tests.opensearch.username"))
.orElseThrow(() -> new RuntimeException("user name is missing"));
String password = Optional.ofNullable(System.getProperty("tests.opensearch.password"))
.orElseThrow(() -> new RuntimeException("password is missing"));
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));
try {
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)
// disable the certificate since our testing cluster just uses the default security configuration
.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
.setSSLContext(SSLContextBuilder.create().loadTrustMaterial(null, (chains, authType) -> true).build());
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}

public void testBasicBackwardsCompatibility() throws Exception {
peternied marked this conversation as resolved.
Show resolved Hide resolved
String round = System.getProperty("tests.rest.bwcsuite_round");

Expand All @@ -73,6 +135,12 @@ public void testBasicBackwardsCompatibility() throws Exception {
}
}

@SuppressWarnings("unchecked")
public void testWhoAmI() throws Exception {
peternied marked this conversation as resolved.
Show resolved Hide resolved
Map<String, Object> responseMap = (Map<String, Object>) getAsMap("_plugins/_security/whoami");
Assert.assertTrue(responseMap.containsKey("dn"));
}

private enum ClusterType {
OLD,
MIXED,
Expand Down