diff --git a/conf/main_ipv4.conf.sample b/conf/main_ipv4.conf.sample index 255a218..e08a0ad 100644 --- a/conf/main_ipv4.conf.sample +++ b/conf/main_ipv4.conf.sample @@ -104,6 +104,11 @@ any_access_from_inet_networks="" # - # - allow_all_ext_traffic_to_local_service="local-address:port:protocol [local-address:port:protocol] .." # - +# - Instead of 'local-address' an extern interface (e.g. $ext_if_static_1) can +# - be given. Then traffic coming in on that interface to the given port of the +# - gateway itself is allowed (INPUT chain, no address needed). Useful e.g. if +# - the gateway acts as reverse proxy (see also 'allow_gw_to_local_service'). +# - # - Note: # - ===== # - - Only 'tcp' and 'udp' are allowed valuse for protocol. @@ -111,10 +116,12 @@ any_access_from_inet_networks="" # - Example: # - allow extern traffic to service at 83.223.73.210 on port 1036 # - allow extern traffic to https service at 83.223.73.204 +# - allow extern traffic on interface $ext_if_static_1 to port 9443 of the gateway # - -# - allow_ext_net_to_local_service=" +# - allow_all_ext_traffic_to_local_service=" # - 83.223.73.210:1036:tcp # - 83.223.73.204:$standard_https_port:tcp +# - $ext_if_static_1:9443:tcp # - " # - # - Blank separated list @@ -470,13 +477,33 @@ allow_to_ext_net="" # - connection from the gateway to the local service is dropped by the OUTPUT # - chain and the reverse proxy answers with '502 Bad Gateway'. # - -# - Note: Incoming traffic to the reverse proxy on the gateway itself (e.g. port -# - 443) must be allowed separately. +# - Note: This parameter only covers the connection gateway -> local server. +# - Incoming traffic to the reverse proxy on the gateway itself must be +# - allowed separately: +# - +# - - Standard ports (80/443): set 'local_http_service=true'. +# - +# - - Any other port (e.g. 9443): use parameter +# - 'allow_all_ext_traffic_to_local_service' with the extern interface, +# - so that the port is only opened on that interface: +# - +# - allow_all_ext_traffic_to_local_service="$ext_if_static_1:9443:tcp" +# - +# - Do NOT add such a port to 'http_ports': that parameter is used in +# - many rules (FORWARD to local web servers, ..) and would open the +# - port far beyond what is needed. # - # - Only 'tcp' and 'udp' are allowed values for protocol. A port range # - can be given as 'from-to'. # - # - Example: +# - nginx on the gateway listens on port 9443 and forwards requests to +# - http://192.168.10.13:9663: +# - +# - allow_all_ext_traffic_to_local_service="$ext_if_static_1:9443:tcp" +# - allow_gw_to_local_service="192.168.10.13:9663:tcp" +# - +# - Further example with a port range: # - allow_gw_to_local_service="192.168.10.13:9663:tcp # - 192.168.10.20:8000-8010:tcp" # - diff --git a/conf/main_ipv6.conf.sample b/conf/main_ipv6.conf.sample index 1f27205..86c93ac 100644 --- a/conf/main_ipv6.conf.sample +++ b/conf/main_ipv6.conf.sample @@ -101,6 +101,11 @@ any_access_from_inet_networks="" # - # - allow_all_ext_traffic_to_local_service="local-address,port,protocol [local-address,port,protocol] .." # - +# - Instead of 'local-address' an extern interface (e.g. $ext_if_static_1) can +# - be given. Then traffic coming in on that interface to the given port of the +# - gateway itself is allowed (INPUT chain, no address needed). Useful e.g. if +# - the gateway acts as reverse proxy (see also 'allow_gw_to_local_service'). +# - # - Note: # - ===== # - - Only 'tcp' and 'udp' are allowed valuse for protocol. @@ -108,10 +113,12 @@ any_access_from_inet_networks="" # - Example: # - allow extern traffic to service at 2a01:30:1fff:fd00::210 on port 1036 # - allow extern traffic to https service at 2a01:30:1fff:fd00::204 +# - allow extern traffic on interface $ext_if_static_1 to port 9443 of the gateway # - -# - allow_ext_net_to_local_service=" +# - allow_all_ext_traffic_to_local_service=" # - 2a01:30:1fff:fd00::210,1036,tcp # - 2a01:30:1fff:fd00::204,$standard_https_port,tcp +# - $ext_if_static_1,9443,tcp # - " # - # - Blank separated list @@ -457,8 +464,21 @@ allow_to_ext_net="" # - connection from the gateway to the local service is dropped by the OUTPUT # - chain and the reverse proxy answers with '502 Bad Gateway'. # - -# - Note: Incoming traffic to the reverse proxy on the gateway itself (e.g. port -# - 443) must be allowed separately. +# - Note: This parameter only covers the connection gateway -> local server. +# - Incoming traffic to the reverse proxy on the gateway itself must be +# - allowed separately: +# - +# - - Standard ports (80/443): set 'local_http_service=true'. +# - +# - - Any other port (e.g. 9443): use parameter +# - 'allow_all_ext_traffic_to_local_service' with the extern interface, +# - so that the port is only opened on that interface: +# - +# - allow_all_ext_traffic_to_local_service="$ext_if_static_1,9443,tcp" +# - +# - Do NOT add such a port to 'http_ports': that parameter is used in +# - many rules (FORWARD to local web servers, ..) and would open the +# - port far beyond what is needed. # - # - Only 'tcp' and 'udp' are allowed values for protocol. A port range # - can be given as 'from-to'. @@ -466,6 +486,13 @@ allow_to_ext_net="" # - Note: Fields are separated by comma (not colon) because of IPv6 addresses. # - # - Example: +# - nginx on the gateway listens on port 9443 and forwards requests to +# - http://[fd2c:d4d1:4f03:10::13]:9663: +# - +# - allow_all_ext_traffic_to_local_service="$ext_if_static_1,9443,tcp" +# - allow_gw_to_local_service="fd2c:d4d1:4f03:10::13,9663,tcp" +# - +# - Further example with a port range: # - allow_gw_to_local_service="fd2c:d4d1:4f03:10::13,9663,tcp # - fd2c:d4d1:4f03:10::20,8000-8010,tcp" # - diff --git a/ip6t-firewall-gateway b/ip6t-firewall-gateway index 44dbe9f..0285eb7 100755 --- a/ip6t-firewall-gateway +++ b/ip6t-firewall-gateway @@ -1469,9 +1469,17 @@ if [[ ${#allow_all_ext_traffic_to_local_service_arr[@]} -gt 0 ]] \ IFS=',' read -a _val_arr <<< "${_val}" + # - An extern interface is given instead of an address (e.g. $ext_if_static_1): + # - allow traffic to the gateway itself coming in on that interface. + # - + if containsElement "${_val_arr[0]}" "${ext_if_arr[@]}" ; then + $ip6t -A INPUT -i ${_val_arr[0]} -p ${_val_arr[2]} --dport ${_val_arr[1]} -m conntrack --ctstate NEW -j ACCEPT + continue + fi + for _dev in ${ext_if_arr[@]} ; do - if containsElement "${_val_arr[0]}" "${gateway_ipv4_address_arr[@]}" ; then + if containsElement "${_val_arr[0]}" "${gateway_ipv6_address_arr[@]}" ; then $ip6t -A INPUT -i $_dev -p ${_val_arr[2]} -d ${_val_arr[0]} --dport ${_val_arr[1]} -m conntrack --ctstate NEW -j ACCEPT continue fi diff --git a/ipt-firewall-gateway b/ipt-firewall-gateway index 0bd2cb2..840eae5 100755 --- a/ipt-firewall-gateway +++ b/ipt-firewall-gateway @@ -2150,6 +2150,14 @@ if [[ ${#allow_all_ext_traffic_to_local_service_arr[@]} -gt 0 ]] \ IFS=':' read -a _val_arr <<< "${_val}" + # - An extern interface is given instead of an address (e.g. $ext_if_static_1): + # - allow traffic to the gateway itself coming in on that interface. + # - + if containsElement "${_val_arr[0]}" "${ext_if_arr[@]}" ; then + $ipt -A INPUT -i ${_val_arr[0]} -p ${_val_arr[2]} --dport ${_val_arr[1]} -m conntrack --ctstate NEW -j ACCEPT + continue + fi + for _dev in ${ext_if_arr[@]} ; do if containsElement "${_val_arr[0]}" "${gateway_ipv4_address_arr[@]}" ; then