Skip to content

Commit 63fa8d2

Browse files
authored
Download certs from security repo (#650)
* Download certs from security repo Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove unused import Signed-off-by: Craig Perkins <cwperx@amazon.com> * Fix ci check Signed-off-by: Craig Perkins <cwperx@amazon.com> * Include setup-java step Signed-off-by: Craig Perkins <cwperx@amazon.com> * getParent Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove markAsSystemContext Signed-off-by: Craig Perkins <cwperx@amazon.com> * Configure basic auth header Signed-off-by: Craig Perkins <cwperx@amazon.com> * Remove unused imports Signed-off-by: Craig Perkins <cwperx@amazon.com> * Update link to security repo Signed-off-by: Craig Perkins <cwperx@amazon.com> --------- Signed-off-by: Craig Perkins <cwperx@amazon.com>
1 parent 546d060 commit 63fa8d2

File tree

6 files changed

+38
-46
lines changed

6 files changed

+38
-46
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ jobs:
8282
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
8383

8484
steps:
85+
# This step uses the setup-java Github action: https://github.com/actions/setup-java
86+
- name: Set Up JDK ${{ matrix.java }}
87+
uses: actions/setup-java@v3
88+
with:
89+
distribution: temurin # Temurin is a distribution of adoptium
90+
java-version: ${{ matrix.java }}
8591
- name: Checkout Branch
8692
uses: actions/checkout@v3
8793
- uses: actions/download-artifact@v3
@@ -90,9 +96,9 @@ jobs:
9096
- name: Pull and Run Docker for security tests
9197
run: |
9298
plugin=${{ needs.linux-build.outputs.build-test-linux }}
93-
version=`echo $plugin|awk -F- '{print $3}'| cut -d. -f 1-3`
94-
plugin_version=`echo $plugin|awk -F- '{print $3}'| cut -d. -f 1-4`
95-
qualifier=`echo $plugin|awk -F- '{print $4}'| cut -d. -f 1-1`
99+
version=`echo $plugin|awk -F- '{print $4}'| cut -d. -f 1-3`
100+
plugin_version=`echo $plugin|awk -F- '{print $4}'| cut -d. -f 1-4`
101+
qualifier=`echo $plugin|awk -F- '{print $5}'| cut -d. -f 1-1`
96102
97103
if [ -n "$qualifier" ] && [ "$qualifier" != "SNAPSHOT" ]; then
98104
qualifier=-${qualifier}

build.gradle

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ buildscript {
4242
//****************************************************************************/
4343

4444
plugins {
45+
id "de.undercouch.download" version "5.3.0"
4546
id 'com.netflix.nebula.ospackage' version "11.10.0"
4647
id 'checkstyle'
4748
}
@@ -79,6 +80,20 @@ ext {
7980
projectSubstitutions = [:]
8081
licenseFile = rootProject.file('LICENSE.txt')
8182
noticeFile = rootProject.file('NOTICE.txt')
83+
84+
['sample.pem', 'test-kirk.jks'].forEach { file ->
85+
File local = getLayout().getBuildDirectory().file(file).get().getAsFile()
86+
download.run {
87+
src "https://raw.githubusercontent.com/opensearch-project/security/refs/heads/main/bwc-test/src/test/resources/security/" + file
88+
dest local
89+
overwrite false
90+
}
91+
}
92+
93+
processResources {
94+
from(getLayout().getBuildDirectory().file('sample.pem').get().getAsFile())
95+
from(getLayout().getBuildDirectory().file('test-kirk.jks').get().getAsFile())
96+
}
8297
}
8398

8499
java {

src/main/java/org/opensearch/search/asynchronous/management/AsynchronousSearchManagementService.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,6 @@ public void run() {
194194
public final void performCleanUp() {
195195
final ThreadContext threadContext = threadPool.getThreadContext();
196196
try (ThreadContext.StoredContext ignore = threadContext.stashContext()) {
197-
// we have to execute under the system context so that if security is enabled the sync is authorized
198-
threadContext.markAsSystemContext();
199197
final Map<String, DiscoveryNode> dataNodes = clusterService.state().nodes().getDataNodes();
200198
List<DiscoveryNode> nodes = Stream.of(dataNodes.values().toArray(new DiscoveryNode[0]))
201199
.collect(Collectors.toList());

src/test/java/org/opensearch/search/asynchronous/SecurityEnabledRestTestCase.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
import org.apache.hc.core5.http.Header;
99
import org.apache.hc.core5.http.HttpHost;
10-
import org.apache.hc.client5.http.auth.AuthScope;
11-
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
12-
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
1310
import org.apache.hc.core5.http.message.BasicHeader;
1411
import org.apache.hc.core5.ssl.SSLContextBuilder;
1512
import org.apache.hc.core5.util.Timeout;
@@ -36,8 +33,11 @@
3633
import java.io.IOException;
3734
import java.net.URI;
3835
import java.net.URISyntaxException;
36+
import java.nio.charset.StandardCharsets;
3937
import java.nio.file.Path;
38+
import java.util.Base64;
4039
import java.util.Collections;
40+
import java.util.HashMap;
4141
import java.util.List;
4242
import java.util.Map;
4343
import java.util.Objects;
@@ -95,7 +95,7 @@ protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOE
9595
if (Objects.nonNull(keystore)) {
9696
URI uri = null;
9797
try {
98-
uri = this.getClass().getClassLoader().getResource("security/sample.pem").toURI();
98+
uri = this.getClass().getClassLoader().getResource("sample.pem").toURI();
9999
} catch (URISyntaxException e) {
100100
throw new RuntimeException(e);
101101
}
@@ -145,23 +145,22 @@ protected void wipeAllOSIndices() throws IOException {
145145
}
146146

147147
protected static void configureHttpsClient(RestClientBuilder builder, Settings settings) throws IOException {
148-
Map<String, String> headers = ThreadContext.buildDefaultHeaders(settings);
148+
Map<String, String> headers = new HashMap<>(ThreadContext.buildDefaultHeaders(settings));
149+
if (System.getProperty("user") != null && System.getProperty("password") != null) {
150+
String userName = System.getProperty("user");
151+
String password = System.getProperty("password");
152+
headers.put(
153+
"Authorization",
154+
"Basic " + Base64.getEncoder().encodeToString((userName + ":" + password).getBytes(StandardCharsets.UTF_8))
155+
);
156+
}
149157
Header[] defaultHeaders = new Header[headers.size()];
150158
int i = 0;
151159
for (Map.Entry<String, String> entry : headers.entrySet()) {
152160
defaultHeaders[i++] = new BasicHeader(entry.getKey(), entry.getValue());
153161
}
154162
builder.setDefaultHeaders(defaultHeaders);
155163
builder.setHttpClientConfigCallback(httpClientBuilder -> {
156-
String userName = Optional
157-
.ofNullable(System.getProperty("user"))
158-
.orElseThrow(() -> new RuntimeException("user name is missing"));
159-
String password = Optional
160-
.ofNullable(System.getProperty("password"))
161-
.orElseThrow(() -> new RuntimeException("password is missing"));
162-
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
163-
credentialsProvider.setCredentials(new AuthScope(new HttpHost("localhost", 9200)),
164-
new UsernamePasswordCredentials(userName, password.toCharArray()));
165164
try {
166165
final TlsStrategy tlsStrategy = ClientTlsStrategyBuilder.create()
167166
.setSslContext(SSLContextBuilder.create().loadTrustMaterial(null, (chains, authType) -> true).build())
@@ -172,8 +171,7 @@ protected static void configureHttpsClient(RestClientBuilder builder, Settings s
172171
.build();
173172

174173
return httpClientBuilder
175-
.setConnectionManager(connectionManager)
176-
.setDefaultCredentialsProvider(credentialsProvider);
174+
.setConnectionManager(connectionManager);
177175
} catch (Exception e) {
178176
throw new RuntimeException(e);
179177
}

src/test/resources/security/sample.pem

Lines changed: 0 additions & 25 deletions
This file was deleted.
-3.68 KB
Binary file not shown.

0 commit comments

Comments
 (0)