0

for some reason in a company there is a need to automate a couple of commands on a server which is behind socks proxy. So far I managed to this in a Pipeline (which is quite new for me though) in that way:

sh 'ssh -vvv -t -o StrictHostKeyChecking=no -o ProxyCommand="nc -x elki-palki.socks4.chot-b-ego.com:1080 %h %p" petya.properdikin@xxx.xxx.xxx.xxx <<-EOF "pwd\n /tmp/jenkins/01.sh\n pwd\n ....."EOF'

Is there a way to configure an SSH-Site with SOCKS4 proxy for using usual Freestyle Jobs? enter image description here

2 Answers2

0

Just the ssh in pipeline is explained well in this question

For the socks proxy it's more complicated. Basing on this article and Java docs you would have to start your Jenkins with some additional flags, here are the docs:

SOCKS This is another type of proxy. It allows for lower level type of tunneling since it works at the TCP level. In effect, in the Java(tm) platform setting a SOCKS proxy server will result in all TCP connections to go through that proxy, unless other proxies are specified. If SOCKS is supported by a Java SE implementation, the following properties will be used:

socksProxyHost (default: <none>)
The hostname, or address, of the proxy server.

socksProxyPort (default: 1080)
The port number of the proxy server.

socksProxyVersion (default: 5)
The version of the SOCKS protocol supported by the server. The default is 5 indicating SOCKS V5, alternatively 4 can be specified for

SOCKS V4. Setting the property to values other than these leads to unspecified behavior.

java.net.socks.username (default: <none>)
Username to use if the SOCKSv5 server asks for authentication and no java.net.Authenticator instance was found.

java.net.socks.password (default: <none>)
Password to use if the SOCKSv5 server asks for authentication and no java.net.Authenticator instance was found.

It would most likely look like this

java -DsocksProxyHost=some.proxy.host -DsocksProxyPort=1234 -DsocksProxyVersion=4 -jar jenkins.war

Depending on how you actually start your jenkins etc.

hakamairi
  • 4,464
  • 4
  • 30
  • 53
  • Well, the question was on how to use Socks4 Proxy (if there is any way to do this) in usual Freestyle Jobs (e.g. "execute shell script on remote host using ssh" step - see attached screenshot in the 1st post) rather than in Pipeline or How to use Jenkins Server behind Socks4 Proxy server. – Pavel Tsirulnikov Jul 03 '18 at 23:06
0

Solved, just to refuse using execute shell script on remote host using ssh. Instead, use ordinary execute shell. Then you will have to create ssh_config either in ~/.ssh/config or globally in /etc/ssh/ssh_config and paste info with Socks4 (or whatever proxy is used) there:

Host xxx.xxx.xxx.xxx
    ProxyCommand='nc -x elki-palki.socks.chob-ego.com:1080 %h %p'
    User petya.properdikin
    ForwardAgent yes
    Port 22

Then it should work (presumed that ssh keys are set up correctly)