Skip to content

Safe subdirectory based CNI chain configuration loading #1419

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

Merged

Conversation

dougbtv
Copy link
Member

@dougbtv dougbtv commented Apr 9, 2025

Implements a method for loading CNI plugins in a chain using a cnilib v1.3.0 feature for safe subdirectory based configuration loading, as introduced in containernetworking/cni#1052

See also, this asciinema demo of the functionality: https://asciinema.org/a/LKwyxyxdafgps5BXneME7ZMJE

@coveralls
Copy link

coveralls commented Apr 9, 2025

Coverage Status

coverage: 52.959% (-2.5%) from 55.425%
when pulling 4104fea on dougbtv:rebase5-cni-subdirectory-chain
into 55ef3b1 on k8snetworkplumbingwg:master.

@dougbtv dougbtv force-pushed the rebase5-cni-subdirectory-chain branch from fa49747 to d7a450c Compare April 9, 2025 19:02
@@ -258,16 +258,25 @@ func confDel(rt *libcni.RuntimeConf, rawNetconf []byte, multusNetconf *types.Net
return err
}

func conflistAdd(rt *libcni.RuntimeConf, rawnetconflist []byte, multusNetconf *types.NetConf, exec invoke.Exec) (cnitypes.Result, error) {
func conflistAdd(rt *libcni.RuntimeConf, rawnetconflist []byte, cniConfList *libcni.NetworkConfigList, multusNetconf *types.NetConf, exec invoke.Exec) (cnitypes.Result, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: Check that this works without conflists

Copy link
Member Author

Choose a reason for hiding this comment

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

So, I think it works as intended without conflists... If you don't have a conflist to begin with -- you can't chain on it.

But in that case, you can use AuxiliaryCNIChainName and have that as a place to chain instead.

return delegateConf, nil
}

// !bang
Copy link
Member Author

Choose a reason for hiding this comment

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

remove that !bang

@dougbtv dougbtv force-pushed the rebase5-cni-subdirectory-chain branch 2 times, most recently from 31b08b3 to 591f6d1 Compare April 9, 2025 20:32
@dougbtv dougbtv force-pushed the rebase5-cni-subdirectory-chain branch 9 times, most recently from 085c8a7 to f41b35a Compare April 10, 2025 20:59
@@ -72,6 +72,7 @@ is provided.
- `"logLevel"`: the logging level for the multus daemon logs.
- `"logToStderr"`: enable this to have the daemon multus logs echoed to stderr
as well. By default, it is disabled.
- `"auxiliaryCNIChainName"`: set a value to executed chained cni configurations from disk in an auxiliary CNI chain (see details in [configuration.md](configuration.md))
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: replace executed with execute

Copy link
Member Author

Choose a reason for hiding this comment

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

got it! thx

@@ -111,3 +112,4 @@ It allows the following keys:
In thick plugin case, delegate CNI plugin is executed by multus-daemon from Pod, hence if the delegate CNI requires resources in container host, for example unix socket or even file, then CNI plugin is failed to execute because multus-daemon runs in Pod. Multus-daemon supports "chrootDir" option which executes delegate CNI under chroot (to container host).

This configuration is enabled in deployments/multus-daemonset-thick.yml as default.

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: whitespace

Copy link
Member Author

Choose a reason for hiding this comment

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

got it, should just be newline now

@@ -538,31 +540,117 @@ func getNetDelegate(client *ClientInfo, pod *v1.Pod, netname, confdir, namespace
} else {
// option4) if file path (absolute), then load it directly
if strings.HasSuffix(netname, ".conflist") {
confList, err := libcni.ConfListFromFile(netname)
confList, err := LoadChainedPluginsFromFile(netname)
if err != nil {
return nil, resourceMap, logging.Errorf("error loading CNI conflist file %s: %v", netname, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think we should change the log to reflect the change from loading in conf files to loading in plugins

Copy link
Member Author

Choose a reason for hiding this comment

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

good call, I put a few debug output lines in LoadChainedPluginsFromFile so that one can see that it's happening if it matters at that time.

}
delegate, err := types.LoadDelegateNetConf(configBytes, nil, "", "")

Copy link
Collaborator

Choose a reason for hiding this comment

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

how would we get to this point? i remember you had a brief explanation when we talkied, might be good to add a comment here

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah! good question, so, you can definitely get there, say, if you provide a file path that is a .conf -- which is the case for say, ovn-kubernetes. In that case, you can't chain onto a .conf, only a .conflist, in which case -- you must use the auxiliaryCNIChain to add chaining. So if you use ovn-k as your primary CNI, you'll have to configure multus to use the aux CNI chain, which will then load the subdirectory chain.

dougbtv added 2 commits April 15, 2025 15:53
…ation loading.

Removes the it `fails to execute confListDel given no 'plugins' key"` test.

This test no longer fails after libcni version 1.2.3.
It probably shouldn't failduring a DEL action as it is, we want the least error prone path.

The GC test now uses both cni.dev attachment formats.

Uses both attachment formats as per containernetworking/cni#1101 for GC's cni.dev/valid-attachments & cni.dev/attachments
Adds a test for plain subdirectory chaining and also using passthru CNI with auxiliaryCNIChainName
@dougbtv dougbtv force-pushed the rebase5-cni-subdirectory-chain branch from f41b35a to 4104fea Compare April 15, 2025 19:53
@bpickard22 bpickard22 merged commit 4517063 into k8snetworkplumbingwg:master Apr 16, 2025
25 checks passed
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.

3 participants