Discussion:
[Openswan Users] IPSec/Netkey interaction with IPTables/Netfilter
Nigel Metheringham
2005-08-16 14:45:34 UTC
Permalink
I'm using openswan 2.3.1 on a 2.6.9-11.EL (thats a Centos 4.1/RHEL 4.1)
kernel.

I would prefer to use netkey (kernel native ipsec) rather than klips if
possible to keep the maintenance load down (having to generate kernel
modules every time there is a kernel update could be problematic).
However if anyone can make a good case for using klips over netkey I'd
be interested in hearing the details.

With netkey it appears pretty hard to work out how to handle firewalling
on the ipsec gateway, and it seems rather poorly documented.

This is what I have found/googled/deduced so far - I'd appreciate it if
anyone could comment on this - any inaccuracies or items I have missed
etc. I'll mash it into the wiki in a few days if people are happy with
it.

Incoming IPSec packets
----------------------
[ie coming in as encrypted ipsec packets, with a final destination of
the local box or a network behind the local box]
* Appear on normal INPUT firewall in their encapsulated form (ie
proto ESP, src/dest are the gateway ip addresses.
* Have magic de-encryption applied
* Appear on normal INPUT/FORWARD firewall (as appropriate) in
de-encapsulated form with original src/dest/proto/port. The
input interface is set to the physical interface the encrypted
packet came in on.

This double appearance and difficulty in telling traffic that has some
in through the tunnel and traffic that has sneaked round is a problem.
The suggested solution is to use the iptables mark facility, for
example:-
iptables -t mangle -A INPUT --proto esp -j mark --set-mark 1

This mark stays with the packet after decryption, so any non-esp packets
hitting the INPUT firewall with the mark set have been through the
tunnel.

Outgoing IPSec Packets
----------------------
[ie being sent from the local box, or from another box in clear,
encrypted on this box, and sent on]

* Unencrypted packet appears on OUTPUT/FORWARD iptable (as
appropriate)
* Magic encryption happens
* The packet goes through the mangle/POSTROUTING table as an
encrypted lump.

It therefore looks like it would be possible to do some protective work
in the POSTROUTING table (maybe with some mark magic elsewhere) to make
sure you do not leak unencrypted traffic.

[The packet is not seen on the standard OUTPUT chain - which is a
strange asymmetry]

Any references to articles and people that have worked through this pain
would be helpful :-)

Nigel.
--
[ Nigel Metheringham ***@InTechnology.co.uk ]
[ - Comments in this message are my own and not ITO opinion/policy - ]
Tuomo Soini
2005-08-16 16:51:17 UTC
Permalink
Post by Nigel Metheringham
I'm using openswan 2.3.1 on a 2.6.9-11.EL (thats a Centos 4.1/RHEL 4.1)
kernel.
I'm running openswan-2.4.0dr8 with 2.6.9-11.EL and 2.4.21-32.0.1.EL kernels.
Post by Nigel Metheringham
Any references to articles and people that have worked through this pain
would be helpful :-)
Nigel.
My solution is to use patched _updown script which has hook to
dynamically change firewalling.

You can check current versions of my rpm from:

ftp://ftp.foobar.fi/pub/foobar/linux/3.2/updates/SRPMS/shorewall-2.4.2-11.foo.src.rpm
ftp://ftp.foobar.fi/pub/foobar/linux/3.2/updates/SRPMS/openswan-2.4.0-0.dr8.2.foo.src.rpm

My openswan rpm has patch which allows attaching remote network to
pre-defined firewall zone (shorewall terminology) so that I can just add
to conn definitions:

leftupdown="ipsec _updown shorewall vpn"

So that when ipsec is up, pre-defined vpn zone is used forfor
firewalling IPsec vpn traffic.

so taht I can allow traffic from vpn to loc zone and loc to vpn zone but
drop traffic from net to loc and only allow certain traffic from loc to
net zone.

- --
Tuomo Soini <***@foobar.fi>
Linux and network services
+358 40 5240030
Foobar Oy <http://foobar.fi/>
Paul TBBle Hampson
2005-08-17 09:43:52 UTC
Permalink
Post by Nigel Metheringham
I would prefer to use netkey (kernel native ipsec) rather than klips if
possible to keep the maintenance load down (having to generate kernel
modules every time there is a kernel update could be problematic).
However if anyone can make a good case for using klips over netkey I'd
be interested in hearing the details.
With netkey it appears pretty hard to work out how to handle firewalling
on the ipsec gateway, and it seems rather poorly documented.
An alternative is to use the system policy database to filter non-IPsec packets
you don't want...

This is the script I used to block anything from the wireless link
(10.20.30.0/24) except UDP 67 dhcpd3, UDP 500 (pluto) and local ICMP. As
connections are established with ipsec, they are added to the SPD at a priority
somewhere below 50000 and so override the block.

This means that I only see packets in iptables if they've come from an IPSec
session, or were udp ports 67, 500 or local icmp traffic. I still see the
packets twice, mind you, before and after ipsec. ^_^

ip xfrm policy add src 10.20.30.0/24 dst 0.0.0.0/0 proto udp sport 67 dport 67 dir in priority 10000
ip xfrm policy add src 10.20.30.0/24 dst 0.0.0.0/0 proto udp sport 500 dport 500 dir in priority 10000
ip xfrm policy add src 10.20.30.0/24 dst 0.0.0.0/0 proto icmp dir in priority 10000
ip xfrm policy add src 10.20.30.0/24 dst 0.0.0.0/0 dir in action block priority 50000

ip xfrm policy add src 0.0.0.0/0 dst 10.20.30.0/24 proto udp sport 67 dport 67 dir out priority 10000
ip xfrm policy add src 0.0.0.0/0 dst 10.20.30.0/24 proto udp sport 500 dport 500 dir out priority 10000
ip xfrm policy add src 0.0.0.0/0 dst 10.20.30.0/24 proto icmp dir out priority 10000
ip xfrm policy add src 0.0.0.0/0 dst 10.20.30.0/24 dir out action block priority 50000

ip xfrm policy add src 10.20.30.0/24 dst 0.0.0.0/0 dir fwd action block priority 50000
--
-----------------------------------------------------------
Paul "TBBle" Hampson, MCSE
8th year CompSci/Asian Studies student, ANU
The Boss, Bubblesworth Pty Ltd (ABN: 51 095 284 361)
***@Pobox.com

"No survivors? Then where do the stories come from I wonder?"
-- Capt. Jack Sparrow, "Pirates of the Caribbean"

License: http://creativecommons.org/licenses/by/2.1/au/
-----------------------------------------------------------
Loading...