jugi
jugi

Reputation: 702

Apache Nifi SOCKS Proxy Setup

I try to access a SFTP Source with Apache Nifi. The processor does not contain proxy settings. Therefor I wanted to provide Proxy Details on Startup as JVM Parameters.

java.arg.16=-DsocksProxyHost="123.123.123.123"
java.arg.17=-DsocksProxyVersion=5
java.arg.18=-Djava.net.socks.username="MYUSERNAME"
java.arg.19=-Djava.net.socks.password="MYPASSWORD"
java.arg.20=-DsocksProxyPort=1080

This does not work. I could not find any implementation of jsch explicitly using a proxy in the nifi code on github https://github.com/apache/nifi/search?utf8=%E2%9C%93&q=jsch&type=

The question is: Is Jsch using the provide parameters internally?

Upvotes: 1

Views: 841

Answers (1)

Koji
Koji

Reputation: 66

The underlying SFTP library Jsch that NiFi uses has its own proxy implementations such as com.jcraft.jsch.ProxySOCKS5. It seems those classes do not use system properties such as -Duser.name.

Instead, proxy instances should be passed manually from client application code, that requires NiFi SFTP related processors change. If following example looks promising to work with your environment, too, then I recommend to create a JIRA ticket to request adding proxy support for SFTP processors from Apache NiFi JIRA.

I wrote an example code to confirm that Jsch SFTP client can use SOCKS5 proxy. Following code worked:

import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Proxy;
import com.jcraft.jsch.ProxySOCKS5;
import com.jcraft.jsch.Session;
import org.junit.Test;

import java.util.Properties;
import java.util.Vector;

public class TestSFTPProxy {

    @Test
    public void test() throws Exception {
        final JSch jsch = new JSch();
        Session session = jsch.getSession("ftp-user", "ftp-server-host");
        final Properties properties = new Properties();
        properties.setProperty("StrictHostKeyChecking", "no");
        properties.setProperty("PreferredAuthentications", "publickey,password,keyboard-interactive");
        session.setConfig(properties);

        Proxy proxy = new ProxySOCKS5("proxy-host", proxy-port);
        proxy.setUserPasswd("proxy-user", "proxy-password");
        session.setProxy(proxy);

        session.setPassword("ftp-user-password");
        session.connect();

        ChannelSftp sftp = (ChannelSftp) session.openChannel("sftp");

        sftp.connect();
        System.out.println(sftp);

        Vector ls = sftp.ls("path");
        System.out.println(ls.get(0));

        sftp.disconnect();
        session.disconnect();
    }

}

Upvotes: 1

Related Questions