davsclaus opened a new pull request, #31036: URL: https://github.com/apache/camel/pull/31036
JIRA: https://issues.apache.org/jira/browse/CAMEL-27707 ## What was wrong `SshHelper.sendExecCommand()` took the user name from the `CamelSshUsername` header, when the message had one, for every kind of authentication. With `certResource` or `keyPairProvider` set, the configured private key was then offered as whatever user the header named. Without a key, the `CamelSshPassword` header also replaced the configured password. The doc page said that the headers take precedence over the configured credentials, but not that the header user is also used with the configured key. The consumer is not affected: the exchange of a poll has no headers. ## What changed I added a new option, `allowUsernameAndPasswordFromHeaders`, to the endpoint and the component (through `SshConfiguration`), with the `producer,security` label. It defaults to `false`. - When it is disabled, the producer logs in with the `username` and `password` options and ignores both headers. - When it is enabled, the headers work as before. The header user is also used with `certResource` or `keyPairProvider`, and the header password is used only for password authentication. This is now documented. The name and the default follow `allowSystemIdAndPasswordFromHeaders` of camel-smpp (CAMEL-27227). That option fixed the same kind of problem the same way: headers off by default, with an upgrade guide entry. I also looked at a middle ground: with key authentication, use the header user only when the header password is also set. It does not help for SSH. Key authentication never uses the password, so requiring the password header would not check anything. Two related items of CAMEL-27702 touch the same lines, so they are fixed here as well: - Item 7: the "Failed to authenticate username ..." message now names the user that was used, not always the configured one. - Item 9, for these two headers only: `CamelSshUsername` and `CamelSshPassword` now have `label = "producer"`, and `CamelSshPassword` is marked `secret = true`. ## Tests - New `SshHeaderCredentialsTest`, with 5 tests against the embedded SSHD server on port 0. The server records the user and the password it receives: - password authentication with the headers: the headers are ignored by default, and used when the option is set on the endpoint, or on the component; - key authentication (`certResource`) with the headers: the header user is ignored by default; with the option, the key logs in as the header user and the header password is not used. - With the old `SshHelper`, `testPasswordHeadersIgnoredByDefault` and `testKeyUsernameHeaderIgnoredByDefault` fail. The other 3 pass with both versions, as they test the enabled path. - `SshComponentProducerTest.testCredentialsAsHeaders` and `SshProducerExitCodeTest` use the headers, so they now set `allowUsernameAndPasswordFromHeaders=true`. - All 83 tests of the module pass. ## Docs and upgrade guide - `ssh-component.adoc`: the Authentication section no longer says the headers always win. A new subsection, "User name and password from headers", explains the option, covers key authentication, and has a Java/XML/YAML example. The catalog copy is updated too. - The option and header descriptions are updated. - Upgrade guide 4.24: new entry `camel-ssh - the user name and password headers need the allowUsernameAndPasswordFromHeaders option`. Routes that rely on the headers must set the option. - Regenerated: the component JSON (and its catalog copy), the configurers, the endpoint DSL (option and header builders) and the component DSL. _Claude Code on behalf of Claus Ibsen_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
