davsclaus opened a new pull request, #3197:
URL: https://github.com/apache/camel-kamelets/pull/3197
Part of #3170: `ssh-source` and `ssh-sink` can log in with a private key,
for the many servers that turn off password login. They also take
`failOnUnknownHost` and `connectTimeout`.
### The options
Both Kamelets get the same four options. All are optional and have no
`default`.
| Option | Endpoint parameter | What it does |
|---|---|---|
| `privateKeyResource` | `certResource={{?privateKeyResource}}` | The
private key to log in with: `file:` and a path, `classpath:`, `http:` or
`https:`. It has the same `pattern:` as `knownHostsResource`. |
| `privateKeyPassphrase` |
`certResourcePassword=RAW({{?privateKeyPassphrase}})` | The passphrase of the
key. It is a secret: `format: password` and `urn:camel:group:credentials`. |
| `failOnUnknownHost` | `failOnUnknownHost={{?failOnUnknownHost}}` | With
`knownHostsResource`, a server that is not listed in the file is refused.
Without it, such a server is accepted, as today. |
| `connectTimeout` | `timeout={{?connectTimeout}}` | How long to wait for
the connection, the login and the start of the command, in milliseconds. It
does not limit how long the command runs. |
`password` is no longer required, and is now `password=RAW({{?password}})`.
When a key is set, camel-ssh logs in with the key only, and the password is not
used. When neither is set, every command fails before anything is sent, with
`No password provided`. An empty password is never sent.
**Why `connectTimeout` and not `timeout`:** the `kamelet:` component has its
own `timeout` option, and it takes a `timeout` parameter for itself before the
template sees it. A Kamelet option named `timeout` on `ssh-sink` was therefore
ignored: the connection still waited 30000 ms. `exec-sink` (#3196) uses
`commandTimeout` for the same reason.
None of the options has a `default`. When they are not set, the optional
placeholders drop their parameters, so the endpoint URI is exactly today's. A
`default` would put `timeout=30000` and `failOnUnknownHost=false` on every
endpoint.
The option descriptions and the "Good to know" paragraphs say how to choose
between the password and the key, and how `knownHostsResource` and
`failOnUnknownHost` combine. The partial pages have a private key example and
explain the host key options and `timeout`.
### Verification
Tested with Camel JBang 4.24.0-SNAPSHOT against two
`linuxserver/openssh-server` containers: one with password login off (it offers
only `publickey,keyboard-interactive`), and one that takes passwords. Each case
ran `ssh-sink` with a command from a timer, and the key, password and host key
cases ran `ssh-source` with a `pollCommand` too.
| Case | Result |
|---|---|
| ed25519 key without a passphrase, server without password login | Logged
in; the command ran (sink and source) |
| RSA key in OpenSSH format, with a passphrase containing a space | Logged
in |
| ed25519 key with a passphrase (sink and source) | Logged in |
| ed25519 key with the passphrase `p&s+w=d%20x` | Logged in: `RAW()` keeps
it as it is |
| RSA keys in PEM format, without and with a passphrase | Logged in |
| A key whose public key is not on the server (sink and source) | Fails:
`Failed to authenticate username camel` |
| Wrong passphrase, missing passphrase, missing key file | Fails: `No
key-pair to add` |
| Password, server that takes passwords, Kamelet from `main` and from this
PR (sink and source) | Both log in; the password `s3cr&t=pw` works |
| Password, server without password login | Fails: `Failed to authenticate
username camel` |
| Key and a wrong password, server that takes passwords | Logged in with the
key; the password is not used |
| Neither a key nor a password | Fails before login: `No password provided` |
| Only the password set, `camel get endpoint` on `main` and on this PR | The
same URIs: `ssh://localhost:2232?password=RAW(...)&username=RAW(camel)`, and
for the source
`?delay=3000&password=RAW(...)&pollCommand=...&username=RAW(camel)` |
| All new options set, no password |
`certResource=...&certResourcePassword=RAW(...)&failOnUnknownHost=true&knownHostsResource=...&timeout=10000&username=RAW(camel)`,
no `password` |
| known_hosts with the server, `failOnUnknownHost: true` (sink and source) |
Logged in |
| known_hosts with only another host, `failOnUnknownHost` unset | Accepted,
with a warning, as today |
| known_hosts with only another host, `failOnUnknownHost: true` (sink and
source) | Refused: `Server key did not validate` |
| known_hosts with the server under another key, `failOnUnknownHost` unset |
Refused |
| `failOnUnknownHost: true` without `knownHostsResource` | Accepted: the
option needs the file |
| `connectTimeout: 2000`, a host that does not answer (`ssh-sink`) | Fails
after 2 seconds: `Failed to connect to 10.255.255.1:22 within timeout 2000ms` |
| `connectTimeout: 1000`, command `sleep 4; echo slept` | Runs to the end:
the timeout does not limit the command |
`./mvnw clean verify -DskipTests` and `./mvnw clean verify` from the root
both pass.
_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]