Forum Discussion

Hans_Schneider2's avatar
Hans_Schneider2
Icon for Nimbostratus rankNimbostratus
Nov 10, 2014
Solved

Manage SFTP with iRule

Hi all,

I have a Virtual Server that listens on every port (0) which it has to do. I want to point my SFTP traffic to different servers based on which customer it is. For HTTP traffic I am looking at the HTTP::header but this is not an option with SFTP traffic. Is it possible to do the same with SFTP somehow?

Right now I'm trying to get one SFTP connection working but it's not successful. I have the following in my iRule:

when CLIENT_ACCEPTED {

    if { [TCP::local_port] equals 22 } {

        pool OP_22

        log local0. "FTP TRAFFIC!!"
    }
}

No traffic is reaching the SFTP server.

  • Yes, an http profile on a non http protocol will break the connection. The http profile is going to validate the data meets http specifications, and it will not.

     

    I don't think you can enable/disable/change the HTTP profile in an irule(I assumed you could when I said it above, but after further research it appears you can't), so a separate port 22 vip is probably required. I think you can keep your port 0 vip and just add a port 22 vip for sftp. If I remember correctly it will use the port 22 vip when it matches that port, and the port 0 vip for everything else. The the entire need for the irule goes away.

     

9 Replies

  • Yes, an http profile on a non http protocol will break the connection. The http profile is going to validate the data meets http specifications, and it will not.

     

    I don't think you can enable/disable/change the HTTP profile in an irule(I assumed you could when I said it above, but after further research it appears you can't), so a separate port 22 vip is probably required. I think you can keep your port 0 vip and just add a port 22 vip for sftp. If I remember correctly it will use the port 22 vip when it matches that port, and the port 0 vip for everything else. The the entire need for the irule goes away.

     

    • mimlo_61970's avatar
      mimlo_61970
      Icon for Cumulonimbus rankCumulonimbus
      Did some testing with a port 0 virtual and a port 22 virtual on the same IP address. It does appear to work as expected.
  • Assuming this isn't internet based traffic you could just give each client a dedicated IP address, or, to minimise the config, a distinct TCP port. Then your iRule can direct traffic to the desired pool based on the IP or port.

     

    Your rule looks mostly OK. I think you either need to enclose 22 in double quotes "" to allow a string comparison or replace equals with == to allow a numerical comparison.

     

  • Hi,

     

    I can see that the log prints out "FTP TRAFFIC!!" so the iRule works. I have been monitoring the SFTP server with wireshark but I don't see any requests on port 22 reaching the server. Something with the F5 configuration seems to be wrong. Any other ideas?

     

  • Any other rules in play here?

     

    I assume the Pool Members in Pool OP_22 are configured with Service Port 22?

     

    I'd suggest you do a tcpdump client and server side on the F5 if neither of the above are true.

     

  • No other rules are affecting the SFTP connection. I can see the TCP handshake reaching the VIP but nothing on the server side. Shouldn't the handshake be between the server and the client?

     

    As it is now the handshake happens between client and VIP. Is their some kind of other setting in F5 causing this? F5 is currently configured as SSL offload for HTTP traffic but since this is not the same protocol used in SFTP could it really mather?

     

  • What profiles are on the virtual server? For instance, if there is an http profile attached, that would break SFTP. You'd need to disable the profile in the iRule as well.

     

  • Yes, I have a http profile configured which is necessary for the SSL offloading. So if other protocols are used they will also be breaked?

     

    How can I make a workaround or is the only solution to create a new VIP for port 22 only?

     

  • It works now!

     

    I created a new VIP with only port 22 associated without any profiles.

     

    Thank you so much!