-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add signing configuration for cross cluster api keys #134137
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
20ca640
Add signing configuration for cross cluster api keys
jfreden 4fea9e2
Update docs/changelog/134137.yaml
jfreden 93f2304
fixup! CI
jfreden 4035b14
fixup! fips
jfreden ab97104
fixup! Update forbidden patterns
jfreden 181b715
fixup! Test issue
jfreden 75e6ac2
fixup! Update tests for fips compliance
jfreden 648892e
Merge remote-tracking branch 'upstream/main' into rcs2.1/conf_signing…
jfreden 1fe6444
fixup! Make buildEffectiveSettings clearer
jfreden b87acda
fixup! Code review comments
jfreden 8e24ec6
[CI] Auto commit changes from spotless
3ce1bf6
fixup! address race condition when creating signer
jfreden e500b0f
fixup! Do not include private key in exception
jfreden c9c0b73
[CI] Auto commit changes from spotless
effcde7
fixup! Strict validation on node startup
jfreden 2b48116
Merge remote-tracking branch 'upstream/main' into rcs2.1/conf_signing…
jfreden 8f3f4c6
[CI] Auto commit changes from spotless
57641b5
Merge branch 'main' into rcs2.1/conf_signing_cert
jfreden 558ad02
fixup! handle race condition and concurrency bug
jfreden 04257b7
fixup! Simplify after refactor
jfreden fad4c41
Simplify further
jfreden 67a6287
Merge remote-tracking branch 'upstream/main' into rcs2.1/conf_signing…
jfreden 8077f01
fixup! Use new secure settings util
jfreden 1347761
fixup! Config corner case
jfreden 727bc38
Add support for validator in addAffixGroupUpdateConsumer
jfreden 2e178ba
Use validator
jfreden 00eb36f
fixup! Wrong api...
jfreden 5a9af92
Merge remote-tracking branch 'upstream/main' into rcs2.1/conf_signing…
jfreden d6a582b
[CI] Auto commit changes from spotless
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 hidden or 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
127 changes: 127 additions & 0 deletions
127
...t/java/org/elasticsearch/xpack/security/transport/CrossClusterApiKeySignerIntegTests.java
This file contains hidden or 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,127 @@ | ||
| /* | ||
| * 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; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.security.transport; | ||
|
|
||
| import org.elasticsearch.common.settings.MockSecureSettings; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.common.ssl.PemKeyConfig; | ||
| import org.elasticsearch.test.SecurityIntegTestCase; | ||
|
|
||
| import static org.elasticsearch.xpack.security.transport.CrossClusterApiKeySignerSettings.SIGNING_CERT_PATH; | ||
| import static org.elasticsearch.xpack.security.transport.CrossClusterApiKeySignerSettings.SIGNING_KEYSTORE_ALIAS; | ||
| import static org.elasticsearch.xpack.security.transport.CrossClusterApiKeySignerSettings.SIGNING_KEYSTORE_PATH; | ||
| import static org.elasticsearch.xpack.security.transport.CrossClusterApiKeySignerSettings.SIGNING_KEYSTORE_SECURE_PASSWORD; | ||
| import static org.elasticsearch.xpack.security.transport.CrossClusterApiKeySignerSettings.SIGNING_KEY_PATH; | ||
|
|
||
| public class CrossClusterApiKeySignerIntegTests extends SecurityIntegTestCase { | ||
|
|
||
| private static final String DYNAMIC_TEST_CLUSTER_ALIAS = "dynamic_test_cluster"; | ||
| private static final String STATIC_TEST_CLUSTER_ALIAS = "static_test_cluster"; | ||
|
|
||
| public void testSignWithPemKeyConfig() { | ||
| final CrossClusterApiKeySigner signer = internalCluster().getInstance( | ||
| CrossClusterApiKeySigner.class, | ||
| internalCluster().getRandomNodeName() | ||
| ); | ||
| final String[] testHeaders = randomArray(5, String[]::new, () -> randomAlphanumericOfLength(randomInt(20))); | ||
|
|
||
| X509CertificateSignature signature = signer.sign(STATIC_TEST_CLUSTER_ALIAS, testHeaders); | ||
| signature.certificate().getPublicKey(); | ||
|
|
||
| var keyConfig = new PemKeyConfig( | ||
| "signing_rsa.crt", | ||
| "signing_rsa.key", | ||
| new char[0], | ||
| getDataPath("/org/elasticsearch/xpack/security/signature/signing_rsa.crt").getParent() | ||
| ); | ||
|
|
||
| assertEquals(signature.algorithm(), keyConfig.getKeys().getFirst().v2().getSigAlgName()); | ||
| assertEquals(signature.certificate(), keyConfig.getKeys().getFirst().v2()); | ||
| } | ||
|
|
||
| public void testSignUnknownClusterAlias() { | ||
| final CrossClusterApiKeySigner signer = internalCluster().getInstance( | ||
| CrossClusterApiKeySigner.class, | ||
| internalCluster().getRandomNodeName() | ||
| ); | ||
| final String[] testHeaders = randomArray(5, String[]::new, () -> randomAlphanumericOfLength(randomInt(20))); | ||
|
|
||
| X509CertificateSignature signature = signer.sign("unknowncluster", testHeaders); | ||
| assertNull(signature); | ||
| } | ||
|
|
||
| public void testSeveralKeyStoreAliases() { | ||
| final CrossClusterApiKeySigner signer = internalCluster().getInstance( | ||
| CrossClusterApiKeySigner.class, | ||
| internalCluster().getRandomNodeName() | ||
| ); | ||
|
|
||
| try { | ||
| // Create a new config without an alias. Since there are several aliases in the keystore, no signature should be generated | ||
| updateClusterSettings( | ||
| Settings.builder() | ||
| .put( | ||
| SIGNING_KEYSTORE_PATH.getConcreteSettingForNamespace(DYNAMIC_TEST_CLUSTER_ALIAS).getKey(), | ||
| getDataPath("/org/elasticsearch/xpack/security/signature/signing.jks") | ||
| ) | ||
| ); | ||
|
|
||
| { | ||
| X509CertificateSignature signature = signer.sign(DYNAMIC_TEST_CLUSTER_ALIAS, "test", "test"); | ||
| assertNull(signature); | ||
| } | ||
|
|
||
| // Add an alias from the keystore | ||
| updateClusterSettings( | ||
| Settings.builder() | ||
| .put(SIGNING_KEYSTORE_ALIAS.getConcreteSettingForNamespace(DYNAMIC_TEST_CLUSTER_ALIAS).getKey(), "wholelottakey") | ||
| ); | ||
| { | ||
| X509CertificateSignature signature = signer.sign(DYNAMIC_TEST_CLUSTER_ALIAS, "test", "test"); | ||
| assertNotNull(signature); | ||
| } | ||
|
|
||
| // Add an alias not in the keystore | ||
| updateClusterSettings( | ||
| Settings.builder() | ||
| .put(SIGNING_KEYSTORE_ALIAS.getConcreteSettingForNamespace(DYNAMIC_TEST_CLUSTER_ALIAS).getKey(), "idonotexist") | ||
| ); | ||
| { | ||
| X509CertificateSignature signature = signer.sign(DYNAMIC_TEST_CLUSTER_ALIAS, "test", "test"); | ||
| assertNull(signature); | ||
| } | ||
| } finally { | ||
| updateClusterSettings( | ||
| Settings.builder() | ||
| .putNull(SIGNING_KEYSTORE_PATH.getConcreteSettingForNamespace(DYNAMIC_TEST_CLUSTER_ALIAS).getKey()) | ||
| .putNull(SIGNING_KEYSTORE_ALIAS.getConcreteSettingForNamespace(DYNAMIC_TEST_CLUSTER_ALIAS).getKey()) | ||
| .setSecureSettings(new MockSecureSettings()) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) { | ||
| var builder = Settings.builder(); | ||
| MockSecureSettings secureSettings = (MockSecureSettings) builder.put(super.nodeSettings(nodeOrdinal, otherSettings)) | ||
| .put( | ||
| SIGNING_CERT_PATH.getConcreteSettingForNamespace(STATIC_TEST_CLUSTER_ALIAS).getKey(), | ||
| getDataPath("/org/elasticsearch/xpack/security/signature/signing_rsa.crt") | ||
| ) | ||
| .put( | ||
| SIGNING_KEY_PATH.getConcreteSettingForNamespace(STATIC_TEST_CLUSTER_ALIAS).getKey(), | ||
| getDataPath("/org/elasticsearch/xpack/security/signature/signing_rsa.key") | ||
| ) | ||
| .getSecureSettings(); | ||
| secureSettings.setString( | ||
| SIGNING_KEYSTORE_SECURE_PASSWORD.getConcreteSettingForNamespace(DYNAMIC_TEST_CLUSTER_ALIAS).getKey(), | ||
| "secretpassword" | ||
| ); | ||
| return builder.build(); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.