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

jmx-scraper add ssl support #1710

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

SylvainJuge
Copy link
Contributor

@SylvainJuge SylvainJuge commented Feb 7, 2025

This is based on #1684 which is not merged yet, I'll rebase to minimize the diff once it's merged.

Part of #1681

This adds the following features with proper integration tests for JMX with SSL:

  • SSL enabled on server, server certificate must be trusted on the client
  • SSL enabled on server with SSL RMI registry
  • SSL enabled on server with client SSL certificate

Using other advanced JAAS configuration options for authentication is not part of this PR and will be implemented in a separate PR.

@SylvainJuge SylvainJuge force-pushed the jmx-scraper-server-ssl branch from 129ed8b to 057ba99 Compare February 17, 2025 13:27
Comment on lines +163 to +183
logger.info("Connecting with SSL protected RMI registry to " + url);
String hostName;
int port;

if (url.getURLPath().startsWith("/jndi/")) {
String[] components = url.getURLPath().split("/", 3);
URI uri = URI.create(components[2]);
hostName = uri.getHost();
port = uri.getPort();
} else {
hostName = url.getHost();
port = url.getPort();
}

try {
JMXConnector jmxConn = new RMIConnector(getStub(hostName, port), null);
jmxConn.connect(env);
return jmxConn;
} catch (IOException e) {
throw new IllegalStateException("Unable to connect to " + url, e);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[for reviewer] copied almost as-is from jmx gatherer

@SylvainJuge SylvainJuge marked this pull request as ready for review February 17, 2025 15:18
@SylvainJuge SylvainJuge requested a review from a team as a code owner February 17, 2025 15:18
jmx-scraper/README.md Show resolved Hide resolved
@@ -99,6 +198,19 @@ public void start() {
super.start();
}

private void addKeyStore(
Path path, String password, boolean keyStore, Map<String, String> properties) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boolean keyStore could be StoreTypeEnum storeType, where StoreTypeEnum would be KEY_STORE, TRUST_STORE

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having any kind of strong typing is not really necessary here IMHO as there are only a few use-cases so I think a boolean is fine. We could also have introduced dedicated interfaces for trust and key stores but in practice it's the same file and only the usage we make of it makes it either a trust or a key store, we could even use a single key store for both trusted certificates and storing key pairs.

@@ -94,24 +92,24 @@ private static void testServerSsl(Path tempDir, boolean sslRmiRegistry) {
// server keystore with public/private key pair
// client trust store with certificate from server

Path serverKeystore = tempDir.resolve("server.jks");
Path clientTrustStore = tempDir.resolve("client.jks");
TestKeyStore serverKeystore =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something for next PR maybe - to keep consistent name pattern it should be named serverKeyStore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants