Skip to content
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

Pass-through/transparent management interfaces #268

Merged

Conversation

vista-
Copy link

@vista- vista- commented Oct 14, 2024

This PR adds pass-through as a mode for management interfaces. The default mode for management interfaces remains host-forwarded (which is the previous and only mode supported for management interfaces).

The pass-through mode functions by simply creating yet another tc mirred interface for the NOS VM management NIC instead of binding it to a user-mode, host-forwarded one.

The main advantages of transparently passing management traffic is:

  • All protocols/traffic pass through and are visible from both the containerlab host and between vrnetlab containers, allowing for labbing to include management connectivity, e.g. via a firewall
  • The NOS configuration accurately reflects the management IPs of the vrnetlab nodes. This is very useful when generating configurations from a source of truth.

The downside of this approach is that it is no longer possible to pass traffic directly from the vrnetlab container, which has two main implications, which means you cannot install/update packages, download files via curl, etc in the container.
Pre-defined exception traffic originating from outside the container (e.g. to the QEMU serial port listening on port 5000) can be selectively directed to the container.

With this change, three NOSes default to pass-through/transparent management:

  • vJunos-router
  • vJunos-switch
  • vJunosEvolved

All other NOS types should not be impacted by this change.

The management interface mode can be overridden by passing the envvar CLAB_MGMT_PASSTHROUGH (true/false).

Tip

For developers:

The __init__ constructor of vrnetlab.VM now has an additional parameter mgmt_passthrough, which defaults to False. Setting this to True creates a tc mirred interface for the management/first NIC instead of the host-forwarded type. This can be overridden by the envvar described above, and the resolved value can be accessed through the self.mgmt_nic_passthrough attribute of vrnetlab.VM.

Two additional convenience attributes are also available for automatically generating startup configs:

  • self.mgmt_address_ipv4 contains the management IP of the node in CIDR format.
    This is either 10.0.0.15/24 for host-forwarded mode, or the actual management IP for pass-through mode.
  • self.mgmt_gw_ipv4 contains the management default gateway for the node.
    10.0.0.2 for host-forwarded mode, or the actual management gateway IP for pass-through mode.

To add new exception traffic that should be directed towards the VM, you need to add a new tc filter rule.
An example rule is the following, for the QEMU serial port listening on TCP port 5000-5007.

tc filter add dev eth0 ingress prio 1 protocol ip flower ip_proto tcp dst_port 5000-5007 action pass

The exception traffic filters should be added first (lower priority numbers), before the eth0 mirred redirect rule, which should be the last.

NOS Implementations

SR OS

The work is done in #272

common/vrnetlab.py Outdated Show resolved Hide resolved
common/vrnetlab.py Outdated Show resolved Hide resolved
common/vrnetlab.py Outdated Show resolved Hide resolved
@plajjan
Copy link

plajjan commented Oct 18, 2024

Very cool!

As an anecdote, in the early days, probably in the first year after I wrote vrnetlab, I presented to a few NTT guys and they were curious if they could bridge into the mgmt interfaces instead of doing NAT. At the time, the whole networking story in docker looked quite different and doing what we do now in containerlab wasn't easy, which is why vr-xcon was built in the first place. We also did a lot of work around SnabbSwitch (now Snabb - https://github.com/snabbco/snabb) and I had these ideas on using it to apply flexible forwarding rules, like take port 5000 (serial console) and send to the container while the rest could be forwarded transparently to the VM. We never had time / it was never important enough to warrant the work. But here we are, a lot later, and this PR is looking really good, very cool :)

I can't help but wonder if we can make the tc rules more specific and only redirect specific traffic, and that way, we could still have some ports be forwarded to the container so we can reach the serial port!? WDYT?

@vista-
Copy link
Author

vista- commented Oct 18, 2024

Thanks for the review @plajjan!

I pushed two commits to address your comments, which should work in theory, but they're still untested at the moment. I'm not sure if I can run tests today, but I'll try testing the changes over the weekend.

@vista-

This comment was marked as outdated.

@vista-
Copy link
Author

vista- commented Oct 21, 2024

Correction to the post above: if you clone the management MAC of the VM, and mirror both ARP requests and responses incoming to the management interface of the VM, the serial port workaround now works! I'm marking the PR as ready for review.

@vista- vista- marked this pull request as ready for review October 21, 2024 14:07
@michelredondo
Copy link

Looks great!
Could you also please add get_mgmt_address_ipv6/get_mgmt_gw_ipv6 so it's v4/v6 ready? Thanks

Based on your ideas I have added support for SROS in #272
In this case I'm using tc to rewrite traffic from VM so it can also access the container (in clab SROS we use a tftp server to download the license and save config).

@vista-
Copy link
Author

vista- commented Oct 24, 2024

@michelredondo I added IPv6 support to the management address/gw helper functions. Do note that v4/v6 has been combined into the same function returning a tuple.

@hellt hellt changed the base branch from master to transparent-mgmt-intfs-dev November 9, 2024 11:55
@hellt
Copy link
Owner

hellt commented Nov 9, 2024

@vista- I am changing the base for this PR to be the transparent-mgmt-intfs-dev branch that I just created. I want to merge your PR into this base branch and then target #272 to this dev branch as well.

In other words, your branch becomes the base for other systems to test/align/implement this method.

@hellt hellt merged commit baeab04 into hellt:transparent-mgmt-intfs-dev Nov 9, 2024
1 check failed
@michelredondo
Copy link

One important thing to consider is that docker implements POSTROUTING MASQUERADE rules for mgmt. prefixes:

Chain POSTROUTING (policy ACCEPT 1025 packets, 256K bytes)
 pkts bytes target     prot opt in     out     source               destination
  172 12925 MASQUERADE  all  --  *      !br-inline-mgmt  100.103.2.0/24       0.0.0.0/0
    6   392 MASQUERADE  all  --  *      !br-91cef2fdceb8  172.16.172.0/24      0.0.0.0/0
    0     0 MASQUERADE  all  --  *      !br-8671008f2987  192.168.121.0/24     0.0.0.0/0
  16M 1216M MASQUERADE  all  --  *      !br-104b3e59e170  172.80.80.0/24       0.0.0.0/0

So all traffic leaving the node will be source-nated to the same IP address , which contradicts the whole purpose of transparency. A workaround is to insert a rule that just accepts the traffic before the masquerade kicks in.

@hellt hellt mentioned this pull request Dec 2, 2024
16 tasks
hellt pushed a commit that referenced this pull request Dec 3, 2024
* vrnetlab: Add pass-through management interfaces

* vjunos: Add pass-through management interface support

* vrnetlab: Use JSON output of iproute2

* vrnetlab: Add exception for serial console ports 5000-5007 for transparent mode mgmt interface

* vrnetlab: Remove non-working port 5000 tc mirred exception, redirect to correct interface

* vrnetlab: Use tc clsact qdisc and flower matching as best practice

* vrnetlab: Re-add workaround for serial ports in transparent mgmt mode

* vrnetlab: Add IPv6 support to management address/gw functions

* vjunos: Add IPv6 management addresses, fix v4 address templating

* vrnetlab: Set dummy IPv6 address/gw for hostfwd management
hellt added a commit that referenced this pull request Dec 14, 2024
* Pass-through/transparent management interfaces (#268)

* vrnetlab: Add pass-through management interfaces

* vjunos: Add pass-through management interface support

* vrnetlab: Use JSON output of iproute2

* vrnetlab: Add exception for serial console ports 5000-5007 for transparent mode mgmt interface

* vrnetlab: Remove non-working port 5000 tc mirred exception, redirect to correct interface

* vrnetlab: Use tc clsact qdisc and flower matching as best practice

* vrnetlab: Re-add workaround for serial ports in transparent mgmt mode

* vrnetlab: Add IPv6 support to management address/gw functions

* vjunos: Add IPv6 management addresses, fix v4 address templating

* vrnetlab: Set dummy IPv6 address/gw for hostfwd management

* nokia_sros: Add pass-through management interface support (#272)

* vrnetlab: Add pass-through management interfaces

* vjunos: Add pass-through management interface support

* vrnetlab: Use JSON output of iproute2

* vrnetlab: Add exception for serial console ports 5000-5007 for transparent mode mgmt interface

* vrnetlab: Remove non-working port 5000 tc mirred exception, redirect to correct interface

* vrnetlab: Use tc clsact qdisc and flower matching as best practice

* vrnetlab: Re-add workaround for serial ports in transparent mgmt mode

* vrnetlab: Add IPv6 support to management address/gw functions

* vjunos: Add IPv6 management addresses, fix v4 address templating

* vrnetlab: Set dummy IPv6 address/gw for hostfwd management

* Fix CSR1000v and c8000v (#269)

* Remove whitespaces from IMG_NAME and IMG_VENDOR

* Fix Cisco CSR1000v

* Fix Cisco c8000v

* Use env var passed from containerlab for IOL launch PID (#270)

* nokia_sros: Add pass-through management interface support

* fix comment

* change mgmt address parsing

* added self.mgmt_nic_passthrough to VR and VM classes

* remove copy of a healthcheck

* formatting

* added mgmt passthrough to the VR class and aligned SR OS

* added v6 address to bof

---------

Co-authored-by: vista <[email protected]>
Co-authored-by: Athanasios Kompouras <[email protected]>
Co-authored-by: Kaelem <[email protected]>
Co-authored-by: Roman Dodin <[email protected]>

* default vjunos to to host-forwarded mgmt mode

* note on default systems

* vsrx: Add transparent management interface mode compatibility (#288)

* fix host vs passthrough notes

* Transparent management interfaces for Cisco nodes. (#290)

* Add function to convert CIDR to DDN notation

* Add IOS-XE device support for transparent mgmt intf

* Implement transparent mgmt intf on XRv

* Add transparent mgmt if functionality to xrv9k

* Add transparent mgmt intf to vIOS

* Add transparent mgmt intf to n9kv and use 2048 bit keys

* Remove incorrectly pasted command from n9kv

* Add explicit IPv6 enablement to vIOS

* Update vIOS default creds to `admin:admin`

* NXOS: Add transparent mgmt intf support + mgmt vrf + 2048-bit SSH keys

* change n9kv version parser and FROM image

* fix comment

* Update images to `debian:bookworm-slim`

* Update `cidr_to_ddn()` func to use stdlib for address splitting

* use `super().gen_mgmt()` to extend `gen_mgmt()` fn on XRv9k

---------

Co-authored-by: Roman Dodin <[email protected]>

* added dell sonic transparent mgmt (#292)

---------

Co-authored-by: vista- <[email protected]>
Co-authored-by: Michel Redondo <[email protected]>
Co-authored-by: Athanasios Kompouras <[email protected]>
Co-authored-by: Kaelem <[email protected]>
Co-authored-by: Kaelem Chandra <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants