Forum Discussion

SANTHOSHKUMAR_S's avatar
SANTHOSHKUMAR_S
Icon for Nimbostratus rankNimbostratus
Aug 01, 2016

irule for x forwarder

We have virtual server with wildcard certificate installed , like *apps.abc.com . I need have x forwarder enabled when there is request for name1.apps.abc.com , Similarly I need to disable x forwarder when there is request for name2.apps.abc.com . Is this feasible with IRULE . kindly comment on this .

 

  • Hi Santhoshkumar,

    you may try the iRule below...

    when HTTP_REQUEST {
        set low_hostname [string tolower [HTTP::host]]
        if { ( $low_hostname eq "name1.apps.abc.com" ) or 
             ( $low_hostname eq "nameX.apps.abc.com" ) } then {
             Site requires X-Forwarded-For headers. Adding the X-Forwarded-For header to request... 
            HTTP::header insert "X-Forwarded-For" [getfield [IP::client_addr] "%" 1]
        } else { 
             Do nothing. Site doesn't require X-Forwarded-For header to be present...
        }
    }
    

    Cheers, Kai

  • Hi Kai , Thanks for your response on this , I have multiple FQDN { eg 10 No's} which need X forwarder only one FDQN which doesn't need to X forwarder . How we can achieve this . Kindly advise . Thanks

     

  • Hi Santhoshkumar,

     

    you may change the code to not insert the X-Forwarded-For header for a specific HTTP::host value (e.g. name2.apps.abc.com) and then insert the header on every other request...

     

    when HTTP_REQUEST {
        if { [string tolower [HTTP::host]] eq "name2.apps.abc.com" } then {
             Do nothing. Site doesn't require X-Forwarded-For header to be present...
        } else { 
             Site requires X-Forwarded-For header. Adding the X-Forwarded-For header to request... 
            HTTP::header insert "X-Forwarded-For" [getfield [IP::client_addr] "%" 1]
        }
    }

    Cheers, Kai

     

  • Hi,

    You can also use switch or a datagroup :

    using SWITCH :

        when HTTP_REQUEST {
            switch [HTTP::host] {
                "name1.apps.abc.com" - 
                "namex.apps.abc.com" {
                     HTTP::header remove "X-Forwarded-For"
                     or do nothing
                }
                default {
                    HTTP::header insert "X-Forwarded-For" [getfield [IP::client_addr] "%" 1]
                }
            }
        }
    

    Using DATAGROUPS

        when HTTP_REQUEST {
            if { [class match [HTTP::host] contains X_FORWARD_HOST] } {
                HTTP::header insert "X-Forwarded-For" [getfield [IP::client_addr] "%" 1]
            } else {
                 HTTP::header remove "X-Forwarded-For"
                 or do nothing
            }
        }
    

    Once you know the logic of those commands, you can choose the way you want to manage your exceptions.

    • SANTHOSHKUMAR_S's avatar
      SANTHOSHKUMAR_S
      Icon for Nimbostratus rankNimbostratus

      Hi Yann , Please be more specific which rule must be ideal for my request , if my host name contain name1.apps.abc.com i should do nothing on x forwarder . If it contains any other name like name2.apps.abc.com or name3.apps.abc.com i should do x forwarder . Thanks

       

    • Yann_Desmarest's avatar
      Yann_Desmarest
      Icon for Cirrus rankCirrus

      Hi,

       

      If you have only one exception so I suggest to use a single if condition with the host exception in direct within the irule code.

       

      If you have several exceptions, you can thing implementing the switch version of the irule.

       

      And if you have lot of exceptions, I recommend to use datagroups.

       

      For single if condition :

       

      when HTTP_REQUEST {
          if { !([HTTP::host] eq "name1.apps.abc.com") } {
              HTTP::header insert "X-Forwarded-For" [getfield [IP::client_addr] "%" 1]
          }
      }

      Hope it helps you to make your choice.

       

  • Hi,

    You can also use switch or a datagroup :

    using SWITCH :

        when HTTP_REQUEST {
            switch [HTTP::host] {
                "name1.apps.abc.com" - 
                "namex.apps.abc.com" {
                     HTTP::header remove "X-Forwarded-For"
                     or do nothing
                }
                default {
                    HTTP::header insert "X-Forwarded-For" [getfield [IP::client_addr] "%" 1]
                }
            }
        }
    

    Using DATAGROUPS

        when HTTP_REQUEST {
            if { [class match [HTTP::host] contains X_FORWARD_HOST] } {
                HTTP::header insert "X-Forwarded-For" [getfield [IP::client_addr] "%" 1]
            } else {
                 HTTP::header remove "X-Forwarded-For"
                 or do nothing
            }
        }
    

    Once you know the logic of those commands, you can choose the way you want to manage your exceptions.

    • SANTHOSHKUMAR_S's avatar
      SANTHOSHKUMAR_S
      Icon for Nimbostratus rankNimbostratus

      Hi Yann , Please be more specific which rule must be ideal for my request , if my host name contain name1.apps.abc.com i should do nothing on x forwarder . If it contains any other name like name2.apps.abc.com or name3.apps.abc.com i should do x forwarder . Thanks

       

    • Yann_Desmarest_'s avatar
      Yann_Desmarest_
      Icon for Nacreous rankNacreous

      Hi,

       

      If you have only one exception so I suggest to use a single if condition with the host exception in direct within the irule code.

       

      If you have several exceptions, you can thing implementing the switch version of the irule.

       

      And if you have lot of exceptions, I recommend to use datagroups.

       

      For single if condition :

       

      when HTTP_REQUEST {
          if { !([HTTP::host] eq "name1.apps.abc.com") } {
              HTTP::header insert "X-Forwarded-For" [getfield [IP::client_addr] "%" 1]
          }
      }

      Hope it helps you to make your choice.

       

  • Dear Yann/Kasi , I had modified the irule , which means i will disable X forwarder for kib.apps.abc.com . And rest other FQDN will have X forwarder enabled . After implementing this irule . Kib.apps.abc.com is working fine , for rest other FQDN i am getting 503 error . Kindly advise me on this

     

    when HTTP_REQUEST { if { !([HTTP::host] eq "kib.apps.abc.com") } { HTTP::header insert "X-Forwarded-For" [getfield [IP::client_addr] "%" 1] } }