-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[SFTP] [v6 Regression] ResourceKnownHostsServerKeyVerifier does not match by IP #8693
Comments
It is hard to test this with mocks, so I'd be glad to see more stack trace for that error to determine where exactly we should catch it and fallback to the IP address. Correct me if I'm wrong.
As a workaround you can specify that host name in the
Does it all make sense? |
Another workaround is to provide an externally configured
This way you can inject any custom |
Well, I have looked into the previous
Where
So, no way it is going to work in that version if there is no IP variant in the entry. But that is only if I look into a proper direction for what I'd like to hear from you back. Thank |
We have the exact same issue. If i only downgrade from version 6.1.5 spring-integration-sftp to version 5.5.20 it works! i have normal known_hosts file with a host name without ip-adress. Of course if have to change a bit the code because of the missing IntegrationFlows in version 6.1.5. for example if have to change:
back to
or change the
back to
but thats only very smal changes like i mentioned |
Sorry, @sebastianfilke , but that's not helpful. Perhaps you can share what your Thanks for understanding! |
Hi @artembilan, is there any update on this topic? I have the same issue as mentioned above, after migrating SB from 2.x to 3.2. My
and set on |
Hi @laguiar ! Thank you for reaching out! Would you mind to share more info? As you see in all the comments, no one has provided a proper environment to determine where we exactly are failing to find a path for fix. |
Sure... it's probably very standard, I don't have much customisation on this component. public DefaultSftpSessionFactory defineSftpSessionFactory() {
var sessionFactory = new DefaultSftpSessionFactory();
sessionFactory.setHost(host);
sessionFactory.setPort(port);
sessionFactory.setUser(user);
sessionFactory.setPrivateKey(privateKey);
sessionFactory.setPrivateKeyPassphrase(privateKeyPassphrase);
sessionFactory.setTimeout(Math.toIntExact(timeout.toMillis()));
sessionFactory.setAllowUnknownKeys(true);
sessionFactory.setKnownHostsResource(knownHostsFile);
var hostConfig = defineHostConfig();
sessionFactory.setHostConfig(hostConfig);
return sessionFactory;
}
private HostConfigEntry defineHostConfig() {
var hostConfig = new HostConfigEntry(host, host, port, user);
hostConfig.setProperty("MaxAuthTries", "3");
hostConfig.setProperty("PreferredAuthentications", "publickey");
return hostConfig;
} |
And what is that This is still so generic that it does not give any clues what might be wrong in the framework. Thanks for understanding! |
@artembilan I believe my issue is related to this Lines 363 to 367 in 4d33ea0
Previously, if you specified both // this session factory configuration works with 5.x.x but breaks with 6.x.x
sessionFactory.setAllowUnknownKeys(true);
sessionFactory.setKnownHostsResource(knownHostsFile); // knownHostsFile pointing to /dev/null But now if the For my case, the integration tests specified the knownHostsFile as It's possible that users have a bad |
thank you for sharing your experience, but I don't see how your problem is related to the original report.
So, the logic you show is correct and it really reflects those Javadocs. I see an inconvenient with your configuration expectations, but that is what we might revise in the next Feel free to raise a new GH issue! |
It's a Resource object pointing to a
|
@laguiar , may we have the whole stack trace to determine the relevance to our project? |
@artembilan sorry... I was replying from my phone. This is the stacktrace: org.springframework.messaging.MessageHandlingException: error occurred in message handler [bean 'businessObject.message-handler#0' for component 'businessObject.org.springframework.integration.config.ConsumerEndpointFactoryBean#0'; defined in: 'class path resource [com/org/Configuration.class]'; from source: 'bean method businessObject'], failedMessage=GenericMessage [payload={value}, headers={id=60a20-5e19-0f0a-141a, timestamp=1715848695857}]
at org.springframework.integration.support.utils.IntegrationUtils.wrapInHandlingExceptionIfNecessary(IntegrationUtils.java:191)
at org.springframework.integration.handler.AbstractMessageHandler.doHandleMessage(AbstractMessageHandler.java:108)
at org.springframework.integration.handler.AbstractMessageHandler.handleWithMetrics(AbstractMessageHandler.java:90)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:70)
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:132)
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:133)
at org.springframework.integration.dispatcher.UnicastingDispatcher$1.run(UnicastingDispatcher.java:114)
at org.springframework.integration.util.ErrorHandlingTaskExecutor.lambda$execute$0(ErrorHandlingTaskExecutor.java:57)
at datadog.trace.bootstrap.instrumentation.java.concurrent.Wrapper.run(Wrapper.java:46)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: org.springframework.messaging.MessagingException: Failed to execute on session
at org.springframework.integration.file.remote.RemoteFileTemplate.execute(RemoteFileTemplate.java:461)
at org.springframework.integration.file.remote.RemoteFileTemplate.send(RemoteFileTemplate.java:314)
at org.springframework.integration.file.remote.RemoteFileTemplate.send(RemoteFileTemplate.java:302)
at org.springframework.integration.file.remote.RemoteFileTemplate.send(RemoteFileTemplate.java:294)
at org.springframework.integration.file.remote.handler.FileTransferringMessageHandler.handleMessageInternal(FileTransferringMessageHandler.java:207)
at org.springframework.integration.handler.AbstractMessageHandler.doHandleMessage(AbstractMessageHandler.java:105)
... 10 more
Caused by: java.lang.IllegalStateException: failed to create SFTP Session
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.getSession(DefaultSftpSessionFactory.java:304)
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.getSession(DefaultSftpSessionFactory.java:80)
at org.springframework.integration.file.remote.RemoteFileTemplate.execute(RemoteFileTemplate.java:447)
... 15 more
Caused by: org.apache.sshd.common.SshException: Server key did not validate
at org.apache.sshd.common.future.AbstractSshFuture.verifyResult(AbstractSshFuture.java:141)
at org.apache.sshd.client.future.DefaultAuthFuture.verify(DefaultAuthFuture.java:56)
at org.apache.sshd.client.future.DefaultAuthFuture.verify(DefaultAuthFuture.java:35)
at org.apache.sshd.common.future.VerifiableFuture.verify(VerifiableFuture.java:110)
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.initClientSession(DefaultSftpSessionFactory.java:331)
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.getSession(DefaultSftpSessionFactory.java:294)
... 17 more
Caused by: org.apache.sshd.common.SshException: Server key did not validate |
Thanks, @laguiar ! Would you mind enable
But would be great to have more info about those hosts and their keys to determine why they don't match. |
Unfortunately, I won't be able to do that. |
@jgormley6 thank you for your suggestion, I had a malformed known_hosts |
In what version(s) of Spring Integration are you seeing this issue?
main
branchDescribe the bug
When using a
DefaultSftpSessionFactory
withknownHostsResource
set, theknown_hosts
are matched only by hostname, and not by IP.Even if
host
is set to an IP address in the configuration, only its reverse DNS is matched.Exception from the log (redacted)
To Reproduce
Configure a
DefaultSftpSessionFactory
, withhost
set to an IP address, andknownHostsResource
set to a classpathknown_host
file with a public key configured for the IP.Expected behavior
The known_hosts should be matched with the IP from the
host
config param, like it did in Spring Integration SFTP < 6.Analyzing a bit more
ResourceKnownHostsServerKeyVerifier.resolveHostNetworkIdentities()
callsSshdSocketAddress.toSshdSocketAddress
, which always fetches the hostname from the connect address's IP.This behavior appears to be copied from Apache Mina's
KnownHostsServerKeyVerifier
. It might well be on purpose on their side to only use hostnames, but this is a regression from the behavior in previous versions of Spring Integration SFTP.Maybe
ResourceKnownHostsServerKeyVerifier.resolveHostNetworkIdentities()
should (in addition?) return the raw address fromclientSession.getConnectAddress()
?The text was updated successfully, but these errors were encountered: