Azure/azure-relay-bridge

Could not get azbridge working on Linux

dboretti opened this issue · 2 comments

Hi,
let me premise that I've been succesfully able to run azbridge for connecting to a remote SQL instance using SSMS with a Windows local forwarder and a Windows remote receiver

The problems I've found comes where there's a Linux (Centos 7) local forwarder and a Windows remote receiver, the program that runs on the Linux machine uses a JDBC driver that performs a TCP connection on a remote SQL Server instance, using a public IP address assigned to the remote host it works but the goal is to avoid the use of public IP addresses at all

Here's the output I get from the Centos 7 forwarder (address 127.0.5.1 was added to hosts file)

[azureuser@matillionvm azbridge]$ ./azbridge -L 127.0.5.1:1433:mtconnection -x "<relayconnectionstring>" -v
info: azbridge[0]
      [05/13/2021 10:15:26], RemoteForwardHostStart, 4ce62b53-90e2-41ef-8e5a-82778748b789,
info: azbridge[0]
      [05/13/2021 10:15:26], LocalForwardListenerStart, 9bd76a74-bdef-4dbd-a737-bf94f8bba4fa, { localEndpoint = 127.0.5.1:1433 }
info: azbridge[0]
      [05/13/2021 10:15:26], LocalForwardBridgeStart, c258dd40-75d0-4617-91ed-7a5c0218e75a, { bindToAddress = 127.0.5.1, localForward = Microsoft.Azure.Relay.Bridge.Configuration.LocalForward }
info: azbridge[0]
      [05/13/2021 10:15:26], LocalForwardHostStart, 489a3b2b-04c7-40fa-905d-de0ca6c5f7b8,
info: azbridge[0]
      [05/13/2021 10:16:52], LocalForwardBridgeConnectionStart, 00000000-0000-0000-0000-000000000000, { bridgeActivity = Microsoft.Azure.Relay.Bridge.EventTraceActivity, localEndpoint = 127.0.5.1:1433, hybridConnectionClient = Microsoft.Azure.Relay.HybridConnectionClient }
info: azbridge[0]
      [05/13/2021 10:17:11], LocalForwardBridgeConnectionFailed, 00000000-0000-0000-0000-000000000000, { bridgeActivity = Microsoft.Azure.Relay.Bridge.EventTraceActivity, exception = System.Threading.Tasks.TaskCanceledException: A task was canceled.
         at Microsoft.Azure.Relay.Bridge.TcpLocalForwardBridge.BridgeSocketConnectionAsync(TcpClient tcpClient) in C:\azure-relay-bridge-master\azure-relay-bridge-master\src\Microsoft.Azure.Relay.Bridge\TcpLocalForwardBridge.cs:line 232 }
info: azbridge[0]
      [05/13/2021 10:17:11], LocalForwardSocketComplete, a532c997-f21e-46d3-88cf-7609fa85d661, { endpoint = 127.0.5.1:1433 }
info: azbridge[0]
      [05/13/2021 10:17:11], LocalForwardSocketClosed, a532c997-f21e-46d3-88cf-7609fa85d661, { socket = 127.0.5.1:1433 }
info: azbridge[0]
      [05/13/2021 10:17:11], LocalForwardBridgeConnectionStart, 00000000-0000-0000-0000-000000000000, { bridgeActivity = Microsoft.Azure.Relay.Bridge.EventTraceActivity, localEndpoint = 127.0.5.1:1433, hybridConnectionClient = Microsoft.Azure.Relay.HybridConnectionClient }
info: azbridge[0]
      [05/13/2021 10:17:31], LocalForwardBridgeConnectionFailed, 00000000-0000-0000-0000-000000000000, { bridgeActivity = Microsoft.Azure.Relay.Bridge.EventTraceActivity, exception = System.Threading.Tasks.TaskCanceledException: A task was canceled.
         at Microsoft.Azure.Relay.Bridge.TcpLocalForwardBridge.BridgeSocketConnectionAsync(TcpClient tcpClient) in C:\azure-relay-bridge-master\azure-relay-bridge-master\src\Microsoft.Azure.Relay.Bridge\TcpLocalForwardBridge.cs:line 232 }

Here's the output of the remote Windows receiver:

PS C:\azbridge> .\azbridge -R mtconnection:127.0.5.1:1433 -x "<relayconnectionstring>" -v
dbug: azbridge[0]
      [5/13/2021 10:15:39 AM], RemoteForwardHostStarting, 549cd4d3-f839-4339-af95-2474d97c389f,
dbug: azbridge[0]
      [5/13/2021 10:15:39 AM], RemoteForwardBridgeStarting, 8ff5a52b-be72-497a-a563-62b48012f457, { remoteForward = Microsoft.Azure.Relay.Bridge.Configuration.RemoteForward }
info: azbridge[0]
      [5/13/2021 10:15:40 AM], RemoteForwardBridgeOnline, 8ff5a52b-be72-497a-a563-62b48012f457, { hybridConnectionUri = sb://paintpoc-relay.servicebus.windows.net/mtconnection, tcpRemoteForwardBridge = Microsoft.Azure.Relay.Bridge.TcpRemoteForwardBridge }
info: azbridge[0]
      [5/13/2021 10:15:40 AM], RemoteForwardBridgeStart, 8ff5a52b-be72-497a-a563-62b48012f457, { uri = sb://paintpoc-relay.servicebus.windows.net/mtconnection }
info: azbridge[0]
      [5/13/2021 10:15:40 AM], RemoteForwardHostStart, 549cd4d3-f839-4339-af95-2474d97c389f,
dbug: azbridge[0]
      [5/13/2021 10:15:40 AM], LocalForwardHostStarting, 2536a854-4cf5-4c41-a69a-c093ad8e605e,
info: azbridge[0]
      [5/13/2021 10:15:40 AM], LocalForwardHostStart, 2536a854-4cf5-4c41-a69a-c093ad8e605e,
warn: azbridge[0]
      [5/13/2021 10:16:52 AM], HandledExceptionAsWarning, 00000000-0000-0000-0000-000000000000, { source = System.Net.Sockets.NetworkStream, exception = System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
         at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
         at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
         --- End of inner exception stack trace ---
         at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
         at System.Threading.Tasks.TaskFactory`1.FromAsyncTrimPromise`1.Complete(TInstance thisRef, Func`3 endMethod, IAsyncResult asyncResult, Boolean requiresSynchronization)
      --- End of stack trace from previous location where exception was thrown ---
         at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
         at Microsoft.Azure.Relay.Bridge.StreamPump.<RunAsync>d__0.MoveNext() }

As additional information let's say that I've not been able to build the .rpm package for CentOS 7 using the package.sh and package-all.cmd scripts on a Windows Server 2019 host with VS 2019 and Docker for Windows, so I've built it manually with the .net 5.0 SDK using this command and copying the files on the Linux machine

dotnet publish --configuration Release --framework netcoreapp5.0 --runtime centos.7-x64

Another detail, if it can help I've seen that the internal firewall of the Linux machine is configured to route all incoming traffic on port 443 to port 8443 but this should not be a problem for the Azure relay connection, am I correct?

thanks in advance for any input that can help to figure out

Update,
In the end I was able to run it succesfully on Centos 7 with the previous version 0.13 and not the latest one of the master

Regarding the latest master at some point I was able to generate the rpm package for centos modifying the file build/repo.props and running the package.sh script on a Linux environment with the .net 5 SDK installed (and not in Windows with Docker for Windows, where it failed with an error about mounting the build volume which I wasn't able to troubleshoot) but after installing and running it I got the same error described in the previous post

So in the end I picked the sources of the latest released build 0.13 which was 3 years old, and built it with the netcore SDK 2.1 on a Linux machine (I've tried before with Docker on Windows but hit the same error on mounting volume I've told earlier) generated the package for centos and after installing it I got it finally work as expected

Hope that this could help someone

At the moment I've been able to upgrade successfully that 0.13 version of AzBridge to .net core 3.1, in the meantime before this will get out of support next year I hope that the external software actually hosted on Centos 7 we're using will be upgraded to be hosted on CentOS 8 and work on the latest sources of AzBridge