netavark

repository·main·Indexed 20 days ago

https://github.com/containers/netavark

A Rust-based network stack for Linux containers designed for OCI-compliant container managers like Podman. It handles network interface management (including MACVLAN), firewall configuration for NAT and port forwarding via firewalld and nftables, and DNS resolution via aardvark-dns. It supports rootless containers, IPv4, and IPv6.

Tokens
21.2K
Snippets
71
Records
101
Agent score
68%

What's inside netavark

  1. Overview of Netavark container network stack

    main

    Netavark is a Rust-based network stack designed for configuring networking for Linux containers. While primarily designed to work with Podman, it is applicable to other OCI container management applications.

    Key capabilities include:

    • Configuring container networks via JSON configuration files.
    • Managing network interfaces (including MACVLAN).
    • Automating firewall configuration for NAT and port forwarding (supporting firewalld and nftables).
    • Supporting rootless containers.
    • Supporting both IPv4 and IPv6.
    • Providing container DNS resolution via the aardvark-dns project.
  2. Use netavark-dhcp-proxy for MacVLAN DHCP networking

    main
    When configuring containers with MacVLAN networking that require DHCP, containers often lack an internal DHCP client or init system. netavark-dhcp-proxy acts as a proxy server that handles DHCP interactions on behalf of the container. This tool is designed to be used in combination with Podman and Netavark to enable DHCP support for MacVLAN-based container networks.
  3. Implement a netavark plugin via subcommands

    main

    A netavark plugin is an external binary that must implement a specific set of subcommands used by Podman and netavark to manage container networking. The required subcommands are:

    • create: Creates a new network configuration.
    • setup: Sets up the network configuration for a container (called when a container starts or connects to a network).
    • teardown: Reverts the actions performed by the setup command.
    • info: Provides metadata about the plugin, including its version and the supported API version.
  4. Structure of the Netavark `create` command JSON input

    main

    The netavark create command requires a JSON configuration object divided into three primary sections:

    1. network: Defines the specific configuration for the new network being created.
    2. used: Provides context about existing resources (interfaces, names, subnets) to prevent conflicts.
    3. options: Contains global creation settings, such as subnet allocation pools and conflict checking behavior.
  5. Handle StrictForwardPorts in firewalld

    main

    In firewalld version 2.3.0 and later, the StrictForwardPorts setting in /etc/firewalld/firewalld.conf controls how port forwarding behaves with root Podman.

    • When StrictForwardPorts=no (default): Port forwarding with Podman works normally.
    • When StrictForwardPorts=yes: Port forwarding with root Podman will fail when using -p or -P options. Rootless Podman is unaffected and continues to function normally.

    If StrictForwardPorts is enabled, you must manually manage port forwarding using firewall-cmd instead of relying on Podman's automatic forwarding.

  6. Access and clean up coverage reports

    main

    Once the report is generated, you can view it by opening the index.html file in a web browser. After the report is successfully created, you can safely delete the default_*.profraw files to clean up the raw profiling data.

    # View the report
    firefox target/coverage/index.html
    
    # Cleanup raw profiling data
    rm default_*.profraw
  7. Build and publish the Rust image

    main

    To build and publish the Rust image used for verifying the Minimum Supported Rust Version (MSRV) in CI, ensure you have valid quay.io/libpod credentials configured. Use the provided shell script to automate the build and push process.

    If you need to update the MSRV, update the version in the Dockerfile.Rust FROM line before running the build script.

    ./build_and_publish_rust_image.sh
  8. Configure vendored sources for Netavark packaging

    main

    When packaging Netavark, you can use the upstream vendored source tarball (available at https://github.com/containers/netavark/releases/download/v{version}/netavark-v{version}-vendor.tar.gz).

    After extracting the tarball, create a .cargo/config file to point Cargo to the vendor directory:

    tar xvf %{SOURCE}
    mkdir -p .cargo
    cat >.cargo/config << EOF
    [source.crates-io]
    replace-with = "vendored-sources"
    
    [source.vendored-sources]
    directory = "vendor"
    EOF