Skip to content

Conversation

aojea
Copy link
Contributor

@aojea aojea commented Nov 7, 2024

The proposed "netdevices" field provides a declarative way to specify which host network devices should be moved into a container's network namespace.

This approach is similar than the existing "devices" field used for block devices but uses a dictionary keyed by the interface name instead.

The proposed scheme is based on the existing representation of network device by the struct net_device
https://docs.kernel.org/networking/netdevices.html.

This proposal focuses solely on moving existing network devices into the container namespace. It does not cover the complexities of network configuration or network interface creation, emphasizing the separation of device management and network configuration.

A list of real use cases that justify this proposal is:

  1. Pre-Configuring Physical Devices:

    • Scenario: A container requires a specific physical network interface with a complex IP configuration, RDMA or SR-IOV
    • Implementation:
      • Configure the physical interface on the host with the desired IP addresses, routing, and other settings. In kubernetes this can be done with DRA or Device Plugins.
      • Use netDevices to move the pre-configured interface into the container.
  2. Creating and Moving Virtual Interfaces:

    • Scenario: A container needs to have its own unique MAC address on an existing physical network, without bridging.
    • Implementation:
      • Create the macvlan interface on the host, based on an existing physical interface.
      • Use netDevices to move the MACVLAN interface into the container.
  3. Network Function Containers:

    • Scenario: A container acts as a network router or firewall.
    • Implementation:
      • Use netDevices to move multiple physical or virtual interfaces into the container.
      • The container's processes manage the network configuration, routing, and firewall rules.

References

Implementations

Fixes: #1239

@aojea
Copy link
Contributor Author

aojea commented Nov 7, 2024

/assign @samuelkarp

@AkihiroSuda
Copy link
Member

@aojea aojea force-pushed the network-devices branch 2 times, most recently from 51e5104 to 3a666eb Compare November 12, 2024 12:26
@aojea
Copy link
Contributor Author

aojea commented Nov 12, 2024

https://github.com/opencontainers/runtime-spec/blob/main/features.md should be updated too

updated and addressed the comments

@aojea
Copy link
Contributor Author

aojea commented Nov 12, 2024

AI @aojea (document the cleanup and destroy of the network interfaces)

@samuelkarp
Copy link
Member

From the in-person discussion today:

  • Net device lifecycle should follow the network namespace lifecycle
  • @aojea will follow up to determine whether any cleanup actions need to be taken by the OCI runtime on a container being deleted
  • @kad was concerned about restarts and error handling
  • Should we prohibit the new netdev addition to an existing netns? IOW only allow this for containers where a new netns is created? What about containers where the root netns is used?

config-linux.md Outdated

This schema focuses solely on moving existing network devices identified by name into the container namespace. It does not cover the complexities of network device creation or network configuration, such as IP address assignment, routing, and DNS setup.

**`netDevices`** (object, OPTIONAL) set of network devices that MUST be available in the container. The runtime is responsible for providing these devices; the underlying mechanism is implementation-defined.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This spec said "MUST" but, I think it can't do it in the rootless container because the rootless container doesn't have CAP_NET_ADMIN, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we should take care of the rootless container.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be an error in the case of a rootless container, if the runtime is not able to satisfy the MUST condition.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be an error in the case of a rootless container, if the runtime is not able to satisfy the MUST condition.

+1 but It'd be better to clarify it in the spec.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added mor explanations about runtime and network devices lifecycle and runtime checks, PTAL

@aojea
Copy link
Contributor Author

aojea commented Nov 19, 2024

om the in-person discussion today:

  • Net device lifecycle should follow the network namespace lifecycle
  • @aojea will follow up to determine whether any cleanup actions need to be taken by the OCI runtime on a container being deleted
  • @kad was concerned about restarts and error handling
  • Should we prohibit the new netdev addition to an existing netns? IOW only allow this for containers where a new netns is created? What about containers where the root netns is used?

Pushed a new commit addressing those comments, the changelog is

  • the network namespace lifecycle will move migratebale network devices and destroy virtual devides, the runtime MAY decide to do cleanup actions
  • runtime MUST check the container has enough privileges and an associated network namespace and fail if the check fail
  • removed the Mask field and use the Address field with CIDR notation (IP/Prefix) to deal with IPv4 and IPv6 addresses. Only one IP is allowed to be specified on purpose to simplify the operations and reduce risks
  • Add a HardwareAddress field for use cases that require to set a
    specific mac or infiniband address

@utam0k
Copy link
Member

utam0k commented Apr 1, 2025

@AkihiroSuda @rata This PR has already got 6 approvals. I think it's ready for merging. Can we merge it?

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rata
Copy link
Member

rata commented Apr 1, 2025

@utam0k Let's merge :)

@utam0k utam0k merged commit e935f99 into opencontainers:main Apr 1, 2025
4 checks passed
giuseppe added a commit to giuseppe/crun that referenced this pull request May 16, 2025
opencontainers/runtime-spec#1271 added support
for moving existing network devices to the container network
namespace.

Closes: containers#1712

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
giuseppe added a commit to giuseppe/crun that referenced this pull request May 16, 2025
opencontainers/runtime-spec#1271 added support
for moving existing network devices to the container network
namespace.

Closes: containers#1712

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
giuseppe added a commit to giuseppe/crun that referenced this pull request May 16, 2025
opencontainers/runtime-spec#1271 added support
for moving existing network devices to the container network
namespace.

Closes: containers#1712

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
giuseppe added a commit to giuseppe/crun that referenced this pull request May 17, 2025
opencontainers/runtime-spec#1271 added support
for moving existing network devices to the container network
namespace.

Closes: containers#1712

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
giuseppe added a commit to giuseppe/crun that referenced this pull request May 17, 2025
opencontainers/runtime-spec#1271 added support
for moving existing network devices to the container network
namespace.

Closes: containers#1712

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
giuseppe added a commit to giuseppe/crun that referenced this pull request May 18, 2025
opencontainers/runtime-spec#1271 added support
for moving existing network devices to the container network
namespace.

Closes: containers#1712

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
giuseppe added a commit to giuseppe/crun that referenced this pull request May 19, 2025
opencontainers/runtime-spec#1271 added support
for moving existing network devices to the container network
namespace.

Closes: containers#1712

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
giuseppe added a commit to giuseppe/crun that referenced this pull request May 19, 2025
opencontainers/runtime-spec#1271 added support
for moving existing network devices to the container network
namespace.

Closes: containers#1712

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
giuseppe added a commit to giuseppe/crun that referenced this pull request May 19, 2025
opencontainers/runtime-spec#1271 added support
for moving existing network devices to the container network
namespace.

Closes: containers#1712

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
giuseppe added a commit to giuseppe/crun that referenced this pull request May 19, 2025
opencontainers/runtime-spec#1271 added support
for moving existing network devices to the container network
namespace.

Closes: containers#1712

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
giuseppe added a commit to giuseppe/crun that referenced this pull request May 20, 2025
opencontainers/runtime-spec#1271 added support
for moving existing network devices to the container network
namespace.

Closes: containers#1712

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
giuseppe added a commit to giuseppe/crun that referenced this pull request May 20, 2025
opencontainers/runtime-spec#1271 added support
for moving existing network devices to the container network
namespace.

Closes: containers#1712

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
giuseppe added a commit to giuseppe/crun that referenced this pull request May 20, 2025
opencontainers/runtime-spec#1271 added support
for moving existing network devices to the container network
namespace.

Closes: containers#1712

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
giuseppe added a commit to giuseppe/crun that referenced this pull request May 20, 2025
opencontainers/runtime-spec#1271 added support
for moving existing network devices to the container network
namespace.

Closes: containers#1712

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
giuseppe added a commit to giuseppe/crun that referenced this pull request May 21, 2025
opencontainers/runtime-spec#1271 added support
for moving existing network devices to the container network
namespace.

Closes: containers#1712

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
lsm5 pushed a commit to lsm5/crun that referenced this pull request May 21, 2025
opencontainers/runtime-spec#1271 added support
for moving existing network devices to the container network
namespace.

Closes: containers#1712

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
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.

Proposal: Network Devices