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

feat(ssh): allow to use pubkey auth #111

Merged
merged 3 commits into from
Mar 23, 2024

Conversation

alexandrebrg
Copy link
Contributor

@alexandrebrg alexandrebrg commented Mar 21, 2024

What changes are being made and why?

👋

SSH plugin command was missing authentication with asymmetric keys. I added an option to determine which option will be used in the SSH command (PASSWORD vs PUBLIC_KEY), with the ability to give a private key and a passphrase for it.

Moreover, JSch has been replaced by this fork. It's a drop-in replacement, with enhanced capabilities, especially in cryptography. Original version was only able to run ssh-rsa keys, which is a method deprecated nowadays in OpenSSL, and even more, it's disabled by default. (see here).

Based on my light research, this lib wasn't used by any other component, meaning it shouldn't impact other plugins. A little note here to talk about available algorithms, this lib will load various (most commons) algo depending on the java version is it built with (doc). If I remember well, Kestra must be built & run with at least java 17, so it should be good :D

How the changes have been QAed?

I'm running a simple docker-compose as described here, with the below flow and this additional docker compose service:

services:
  openssh-server:
    image: lscr.io/linuxserver/openssh-server:latest
    container_name: openssh-server
    hostname: openssh-server #optional
    environment:
      PUBLIC_KEY: ${ED255_19_PUB_KEY_HERE}
      PUID: 1000
      PGID: 1000
      TZ: Etc/UTC
      LOG_STDOUT: true
      PASSWORD_ACCESS: true
      USER_PASSWORD: password
    ports:
      - 2222:2222
    restart: unless-stopped
# Run the plugin with the two methods: password, public_key
id: hello-world
namespace: company.team
tasks:
  - id: "command"
    type: "io.kestra.plugin.fs.ssh.Command"
    host: openssh-server
    port: "2222"
    authMethod: PUBLIC_KEY
    username: linuxserver.io
    privateKey: ${ED_KEY}
    commands:
      - "touch i_was_here"
  - id: "command-password"
    type: "io.kestra.plugin.fs.ssh.Command"
    host: openssh-server
    port: "2222"
    authMethod: PASSWORD
    username: linuxserver.io
    password: password
    commands:
      - "touch i_was_here"

Setup Instructions

  1. Generate key ssh-keygen -t ed255_19 -f keypair -P "" -N ""
  2. Create a simple SSH server (see above)
  3. Create flow like above
  4. Run it, enjoy

@loicmathieu loicmathieu self-requested a review March 22, 2024 08:10
Copy link
Member

@loicmathieu loicmathieu left a comment

Choose a reason for hiding this comment

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

Hi, thanks a lot.
Overall it looks good, I suggest some small code changes to make it coherent with the way we declare plugin properties.

src/main/java/io/kestra/plugin/fs/ssh/Command.java Outdated Show resolved Hide resolved
src/main/java/io/kestra/plugin/fs/ssh/Command.java Outdated Show resolved Hide resolved
src/main/java/io/kestra/plugin/fs/ssh/Command.java Outdated Show resolved Hide resolved
src/main/java/io/kestra/plugin/fs/ssh/Command.java Outdated Show resolved Hide resolved
@alexandrebrg
Copy link
Contributor Author

Hi, thanks a lot. Overall it looks good, I suggest some small code changes to make it coherent with the way we declare plugin properties.

Thanks for the review, I applied the changes

Copy link
Member

@loicmathieu loicmathieu left a comment

Choose a reason for hiding this comment

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

LGTM, thanks a lot.

Signed-off-by: AlexandreBrg <[email protected]>
@alexandrebrg
Copy link
Contributor Author

@loicmathieu Tests should now be passing properly :)

Copy link
Member

@loicmathieu loicmathieu left a comment

Choose a reason for hiding this comment

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

LGTM thanks a lot

@loicmathieu loicmathieu merged commit 26bdde3 into kestra-io:master Mar 23, 2024
1 check passed
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.

2 participants