-
Notifications
You must be signed in to change notification settings - Fork 188
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
Connect through ssh gateway #346
Comments
Never seen this attempted before. Have you tried using FreeTDS' |
Agreed with the above. I'd do the following things:
Both of these tests should be presumed on your local machine, not while SSH'd into the remote machine. Presuming it only uses that one port to communicate I can't think of a reason why this shouldn't work. Good luck and let us know how it turns out! |
Thank you for the heads up! I've tried the following:
I'm a bit confused what may prevent TinyTds from working via Net::SSH::Gateway then |
One more thing: in my app I also use the same gateway to connect to the remote Mysql server, which works fine |
What is the output of |
Also tried on Ubuntu with:
|
The second one looks like a problem. That version is too and I do not see OpenSSL in there. |
First one is fine, though? It won't work as well |
Right... but we have distilled that the issue is specifically TinyTds with a Net::SSH::Gateway and that |
Yep, that is correct |
So Odd! I wonder if using a |
I agree, very odd! My understanding was that ssh gateways act as a transparent VPN of sorts through a machine running sshd and that the client using the gateway can be completely ignorant of the fact that it's using ssh or any form of encryption as a gateway. If the gateway is set up using ssh port forwarding I would expect it to work in both cases since the port forward worked with both tsql and TinyTds. 😕 |
Ran into the same problem today, virtually the same setup on macOS. freetds 1.00.27, TinyTds 1.0.5, TDS 7.3. Not much else to add. Certainly seems like something going on in TinyTds/freetds. |
Did a bit more digging -- turns out FreeTDS will log if you set an environment variable (per http://www.freetds.org/userguide/logging.htm). Here is a sample session:
This occurs when attempting to connect via a jump box:
|
I'm having the same issue with tiny tds 0.6, 1.3 and 2.0 running Ubuntu 14.04 with FreeTDS 1.00.21. I'm able to connect with tiny tds if I forward the ports through ssh in the terminal but not programmatically with Net::SSH::Gateway. My code is essentially identical to zetetics. Has anyone found a solution to this? |
@itsfocus I was never able to figure this out. I suspect the issue may be in FreeTDS instead of tiny_tds, but I don't know enough about SQL Server to go down that road with any confidence. Maybe it assumes that any reference to a port on localhost means that it is trying to reach a local server somehow? and ignores the forwarding? Might help to reach out to FreeTDS as well. |
Same her, never figured it out |
I decided to do my own test following these steps:
I tested using the following 2 scripts to generate SSH Gateways: require 'net/ssh/gateway'
gateway = Net::SSH::Gateway.new(
'45.55.184.27',
'coderjoe',
password: 'coderjoetest'
)
gateway.open('10.132.11.218', 1433, 1433) do |port|
puts "Gateway open, try connecting via localhost:#{port}"
while true do; end
end require 'net/ssh/gateway'
require 'tiny_tds'
gateway = Net::SSH::Gateway.new(
'45.55.184.27',
'coderjoe',
password: 'coderjoetest'
)
gateway.open('10.132.11.218', 1433, 1433) do |port|
puts "Gateway open, try connecting via localhost:#{port}"
puts "Connecting with TinyTDS"
client = TinyTds::Client.new(
username: 'sa',
password: '0c1af7866b544a6385e9bfa6$',
login_timeout: 60,
host: '127.0.0.1',
port: port
)
puts "Running SQL..."
result = client.execute("SELECT 'test completed through gateway!'")
puts "Checking results.."
result.each do |row|
puts "got row: #{row.to_s}"
end
end When using the gateway (without tiny_tds) I can connect just fine as reported above. More tests will come later but it seems to point to some problem with tiny_tds right now. |
Can we test this more with 2.1.0.pre2? |
freetds: stable 1.00.91 (bottled) tiny_tds: 2.1.2 Issue same as before ... connection is opened through the gateway but the initial request times out:
|
Hey guys I've got the same error... EnvironmentWindows with WSL (ubuntu xenial) MS SQL Server 2016 tsql -C output
FreeTDS Log:
When opening a SSH Gateway via 'net-ssh-gateway' gem. Now hopefully a hint to solve this issue... Ruby Coderequire 'net/ssh/gateway'
require 'tiny_tds'
ssh_configs = ['HOST', 'USER']
ssh_configs << { passphrase: ENV['MY_SSH_PASSPHRASE'] }
gateway = Net::SSH::Gateway.new(*ssh_configs)
p = gateway.open('sql_host', 1433, 1433)
sql_client = TinyTds::Client.new(username: 'SQL_USER', password: 'SQL_PW', host: '127.0.0.1', port: p) |
TL;DR open a Tunnel via CLI out of ruby: system("`which ssh` -i #{ident_file} -f -N -L 1433:#{SQL_HOST}:1433 #{user}@#{tunnelhost}") and opening the client as intendet: client = TinyTds::Client.new(username: 'SQL_USER', password: 'SQL_PW', host: '127.0.0.1', port: '1433') to discard the tunnel you need to get the process ID from that command: %x(kill -kill `pidof $(which ssh)`) done ;) Hope this helps everyone who is encountering this Problem until it gets fixed. |
Excited to find this thread, but then I saw that a solution hasn't been found yet. violen's solution seems to sometimes work, but not reliably for what I'm after. Still trying to investigate some options to query a remote SQL Server, through ssh tunnel. |
is there still interest in a solution by anyone in this thread (or somebody from the future that finds this comment)?
edit: looking into |
I'm trying to connect to SQL Server using tiny_tds using ssh gateway like this:
As you can see, the connection times out. But, if I try to SSH to the Windows machine from the console and then connect to the SQL Server using
sqlcmd
- everything works just fine.The text was updated successfully, but these errors were encountered: