-
Notifications
You must be signed in to change notification settings - Fork 332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
T5873: ipsec remote access VPN: support VTI interfaces. #3221
Conversation
Changing this to a draft as it appears the up/down script may need some work for this to work properly. Seems to have been lost in the rebase. |
It’s not related to this PR. I also don’t think that fix is related to the instability I’ve been seeing in https://vyos.dev/T6177. I am planning to resume work on this shortly while I continue to debug that issue. |
Sounds great, thank you 🙂 |
Very interesting approach. But why I need also pools if now ecerything cones from the VTI? Is it b/c of IP address assignment reasons (fake dhcp?) |
Yeah, the IP addresses are still assigned to clients via the IKE protocol, so the pool configuration is needed to tell strongswan what range to create client IPs from. Getting the up/down logic for the interface right is a little interesting. I would assume if a remote access is bound to the VTI, the VTI interface should be up all the time. Cleanest implementation is probably to have vyos-1x/python/vyos/ifconfig/vti.py Line 59 in 9eb018c
Btw the logic for T6085 for site-to-site configs (9eb018c) has some potentially unintended behavior that disabling/re-enabling a VTI interface in the config does not immediately take effect—the interface state will only update after the ipsec connection gets torn down or ipsec is restarted. |
Any updates? |
I think I set this aside awaiting further feedback on the approach for the up/down script I shared in this comment: #3221 (comment). Let me re-visit later this week and try to put together an implementation—that may be a faster way to move this forward. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This might be off topic, but how come there all of a sudden is a conflict, with no new commits? |
The action was not run automatically for quiet some time |
Okay, that explains it 🙂 |
Hi all, I haven't forgotten about this PR, but my work schedule has been rather unforgiving lately. Thanks for your patience and I'll hopefully have some improvements soon to get this closer to merging. |
I am about half way through an implementation for the There are three issues with the current vti-up-down hook:
My plan to introduce a new database file For remote-access connections, the config logic will also bring the interface up at apply time if it is not already. The VTI class's Obviously this has turned into a bigger change than I was expecting, but hopefully once I work the last few kinks out it will buy us a more robust foundation for future ipsec/VTI work. |
@lucasec is there a way the database can end up inconsistent? (Like a connection not getting removed if something crashes) |
Just got an idea - not sure if it would work - but what if the "down" parsed the output from |
Added additional comments and improved method naming. New smoketests pass and this is largely ready for others to try out, but I am still refining/working on a few race conditions found via manual testing on my live system. Some discussion in Slack here: https://vyos-community.slack.com/archives/C01A6CJFW1F/p1720164511770299?thread_ts=1719111681.530719&cid=C01A6CJFW1F |
5eb85b1
to
934605b
Compare
From testing so far, the ipsec daemon seems to invoke the up-down hook synchronously, so there is not much need to worry about races on the VTI up-down DB ( Both the DB race and config read race are largely solvable by calling I am also removing some old logic around clearing route table 220 and warnings about the combination of VTI and the lack of |
FYI, the only smoke test failure in that latest execution is I still am not seeing the smoketest action including new tests I added in this PR, e.g. I am reasonably confident in the implementation now and would say everything here is ready for review. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Conflicts have been resolved. A maintainer will review the pull request shortly. |
Rebased on top of changes merged in #3841. |
CI integration 👍 passed! Details
|
This should not be backported to 1.4 as it's a massive extension! Lets rather keep some nice features in 1.5 |
Great, thanks for reviewing! re: backporting to 1.4. I am in favor of holding off, at least for now, as there is a definitely a lot of new functionality here that could benefit from some extended QA. The re-write of the updown hook specifically might be worthy at some point as I believe the current hook in 1.4 has a few bugs in its current form (e.g. see https://vyos-community.slack.com/archives/C01A6CJFW1F/p1720165471164579). I am not convinced this PR solves 100% of those bugs... yet, so I'd be fine putting a pin in this and re-visiting after a while. |
Change Summary
Route-based VPNs can be more convenient to configure and tie in nicely with existing routing protocols, zone-based firewalls, and other common network configurations. OpenVPN users are already quite familiar with this pattern. This PR extends the IPsec (IKEv2) Remote Access VPN to support "virtual tunnel interfaces" enabling similar usage patterns.
Types of changes
Related Task(s)
https://vyos.dev/T5873
also lays some groundwork needed to complete https://vyos.dev/T5874
Related PR(s)
Component(s) name
ipsec
Proposed changes
This PR includes several changes to enable VTI-based remote access VPNs.
remote-access pool range block
The
remote-access pool
configuration block has been extended to accept arange
block, as an alternative to the current CIDRprefix
attribute. This allows defining a more granular range for assigning VPN client IPs, which is helpful if you want to reserve one or more IPs at the start of a CIDR block for the router itself on the VTI interface.remote-access
bind
attributeThe
remote-access connection
accepts a newbind
attribute. This works identically to thepeer <peer> vti bind
attribute (for site-to-site peers you either define one or moretunnel
s, or avti
block—there is no equivalent oftunnel
for remote-access connections hence the decision not to nest it undervti
here). Once defined, all traffic to/from connected peers uses the specified VTI interface, as opposed to being routed by kernel policies. This change is enabled by the internal change in VyOS 1.4 that switched from the legacyvti
interface type to the newerxfrm
interface type, which happily multiple tunnels with different local/remote traffic selectors, e.g. for each connected VPN client.vti-up-down hook revamp
To facilitate the use of the
bind
attribute with remote-access connections, a revamp of thevti-up-down
hook was also required. The hook is called by the ipsec daemon to dynamically bring VTI interfaces up and down.The existing logic was build for site-to-site connections with the assumption every VTI interface maps 1:1 to a single ipsec connection. These assumptions were already outdated for dual-stack site-to-site connections (the existing hook ignored events for the IPv6 side of the connection). Remote access configurations further expose this limitation, as each VPN client establishes its own connection.
This PR introduces a new hook mechanism that relies on a plaintext DB file (
/tmp/ipsec_vti_interfaces
). When ipsec connections come up and down, the DB file is updated with the list of connections that "want" a particular VTI interface to come up. Interfaces are brought up when referenced by at least one entry in the DB and taken down if there are no references. If a remote access connection is configured, a persistent reference is placed for the connection, since clients can connect at any time (I see little value in having the interface go down when no client are connected). Modifications to the interfacedisable
config now take effect immediately—removingdisable
brings the interface up if and only if it is referenced by an entry in the DB.Miscellaneous cleanup
The old
vti-up-down
hook had some code around deleting route table 220. This was also tied to warnings issued at config time if VTI is used without thedisable-route-autoinstall
option. These are leftover from the previousvti
interface type implementation and not relevant to thexfrm
implementation.Naming of remote-access child ESP sessions is improved (making the output of
show vpn ipsec sa
more useful).Certain vestiges of ipsec config (such as DHCP interface references) are still written even if the peer or connection is disabled.
How to test
Example configuration:
Smoketest result
Checklist: