-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filter out CA PrivateKeyEntry when creating a KeyManager (#73807)
In 8.0, with security on by default, we store the HTTP layer CA PrivateKeyEntry in the http.ssl keystore (along with the node certificate) so that it is available in our Enrollment API transport actions. When loading a keystore, the current behavior is that the X509ExtendedKeyManager will iterate through the PrivateKeyEntry objects and will return the first key/certificate that satisfies the requirements of the client and the server configuration, and lacks any additional logic/filters. We need the KeyManager to deterministically pick the node certificate/key in all cases as this is the intended entry to be used for TLS on the HTTP layer. This change introduces filtering when creating the in-memory keystore the KeyManager is loaded with, so that it will not include PrivateKeyEntry objects when: - there are more than 1 PrivateKeyEntry objects in the keystore - The leaf certificate associated with the PrivateKeyEntry is a CA certificate Related: #75097 Co-authored-by: Ioannis Kakavas <[email protected]>
- Loading branch information
1 parent
cdf67e0
commit 063a1f2
Showing
17 changed files
with
231 additions
and
61 deletions.
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
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,45 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import org.elasticsearch.gradle.internal.test.RestIntegTestTask | ||
import org.elasticsearch.gradle.internal.info.BuildParams | ||
|
||
apply plugin: 'elasticsearch.java-rest-test' | ||
dependencies { | ||
javaRestTestImplementation(testArtifact(project(':client:rest-high-level'))) | ||
} | ||
|
||
tasks.matching{ it.name == "javaRestTest" }.configureEach { | ||
onlyIf { BuildParams.inFipsJvm == false} | ||
systemProperty 'tests.rest.cluster.username', System.getProperty('tests.rest.cluster.username', 'test_user') | ||
systemProperty 'tests.rest.cluster.password', System.getProperty('tests.rest.cluster.password', 'test-user-password') | ||
} | ||
|
||
testClusters.matching { it.name == 'javaRestTest' }.configureEach { | ||
testDistribution = 'DEFAULT' | ||
numberOfNodes = 2 | ||
setting 'xpack.license.self_generated.type', 'trial' | ||
setting 'xpack.security.enabled', 'true' | ||
setting 'xpack.security.authc.token.enabled', 'true' | ||
setting 'xpack.security.authc.api_key.enabled', 'true' | ||
|
||
extraConfigFile 'httpCa.p12', file('./src/javaRestTest/resources/httpCa.p12') | ||
extraConfigFile 'transport.p12', file('./src/javaRestTest/resources/transport.p12') | ||
|
||
// TBD: sync these settings (which options are set) with the ones we will be generating in #74868 | ||
setting 'xpack.security.http.ssl.enabled', 'true' | ||
setting 'xpack.security.transport.ssl.enabled', 'true' | ||
setting 'xpack.security.http.ssl.keystore.path', 'httpCa.p12' | ||
setting 'xpack.security.transport.ssl.keystore.path', 'transport.p12' | ||
setting 'xpack.security.transport.ssl.verification_mode', 'certificate' | ||
|
||
|
||
keystore 'xpack.security.http.ssl.keystore.secure_password', 'password' | ||
keystore 'xpack.security.transport.ssl.keystore.secure_password', 'password' | ||
user username: 'admin_user', password: 'admin-password', role: 'superuser' | ||
} |
82 changes: 82 additions & 0 deletions
82
...igh-level/qa/ssl-enabled/src/javaRestTest/java/org/elasticsearch/client/EnrollmentIT.java
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,82 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.client; | ||
|
||
import org.elasticsearch.client.security.KibanaEnrollmentResponse; | ||
import org.elasticsearch.client.security.NodeEnrollmentResponse; | ||
import org.elasticsearch.common.settings.SecureString; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.util.concurrent.ThreadContext; | ||
import org.elasticsearch.core.PathUtils; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.net.URL; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.Matchers.endsWith; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
|
||
public class EnrollmentIT extends ESRestHighLevelClientTestCase { | ||
private static Path httpTrustStore; | ||
|
||
@BeforeClass | ||
public static void findTrustStore() throws Exception { | ||
final URL resource = EnrollmentIT.class.getResource("/httpCa.p12"); | ||
if (resource == null) { | ||
throw new FileNotFoundException("Cannot find classpath resource /httpCa.p12"); | ||
} | ||
httpTrustStore = PathUtils.get(resource.toURI()); | ||
} | ||
|
||
@AfterClass | ||
public static void cleanupStatics() { | ||
httpTrustStore = null; | ||
} | ||
|
||
@Override | ||
protected String getProtocol() { | ||
return "https"; | ||
} | ||
|
||
@Override | ||
protected Settings restClientSettings() { | ||
String token = basicAuthHeaderValue("admin_user", new SecureString("admin-password".toCharArray())); | ||
return Settings.builder() | ||
.put(ThreadContext.PREFIX + ".Authorization", token) | ||
.put(TRUSTSTORE_PATH, httpTrustStore) | ||
.put(TRUSTSTORE_PASSWORD, "password") | ||
.build(); | ||
} | ||
|
||
public void testEnrollNode() throws Exception { | ||
final NodeEnrollmentResponse nodeEnrollmentResponse = | ||
execute(highLevelClient().security()::enrollNode, highLevelClient().security()::enrollNodeAsync, RequestOptions.DEFAULT); | ||
assertThat(nodeEnrollmentResponse, notNullValue()); | ||
assertThat(nodeEnrollmentResponse.getHttpCaKey(), endsWith("K2S3vidA=")); | ||
assertThat(nodeEnrollmentResponse.getHttpCaCert(), endsWith("LfkRjirc=")); | ||
assertThat(nodeEnrollmentResponse.getTransportKey(), endsWith("1I-r8vOQ==")); | ||
assertThat(nodeEnrollmentResponse.getTransportCert(), endsWith("OpTdtgJo=")); | ||
List<String> nodesAddresses = nodeEnrollmentResponse.getNodesAddresses(); | ||
assertThat(nodesAddresses.size(), equalTo(2)); | ||
} | ||
|
||
public void testEnrollKibana() throws Exception { | ||
KibanaEnrollmentResponse kibanaResponse = | ||
execute(highLevelClient().security()::enrollKibana, highLevelClient().security()::enrollKibanaAsync, RequestOptions.DEFAULT); | ||
assertThat(kibanaResponse, notNullValue()); | ||
assertThat(kibanaResponse.getHttpCa() | ||
, endsWith("brcNC5xq6YE7C4_06nH7F6le4kE4Uo6c9fpkl4ehOxQxndNLn462tFF-8VBA8IftJ1PPWzqGxLsCTzM6p6w8sa-XhgNYglLfkRjirc=")); | ||
assertNotNull(kibanaResponse.getPassword()); | ||
assertThat(kibanaResponse.getPassword().toString().length(), equalTo(14)); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
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
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
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
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
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
Binary file added
BIN
+2.48 KB
...ore/src/test/resources/org/elasticsearch/xpack/security/transport/ssl/certs/simple/ca.p12
Binary file not shown.
Binary file added
BIN
+6.64 KB
...src/test/resources/org/elasticsearch/xpack/security/transport/ssl/certs/simple/httpCa.p12
Binary file not shown.
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
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.