Repository navigation
overlay: don't override a configured index mount option - #13805
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes the overlay snapshotter’s handling of the index overlayfs mount option so that an explicit user configuration (index=on/index=off) is not silently overridden by the snapshotter’s default behavior. This prevents invalid option combinations (notably nfs_export=on with an appended index=off) that can cause overlay mounts to fail with EINVAL.
Changes:
- Fixes the
indexoption guard to treatindexas a valued option by matchingindex=(instead of the bareindex). - Adds a regression test asserting that configured
index=onprevents auto-appendingindex=off.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| plugins/snapshots/overlay/overlay.go | Corrects option-detection logic so configured index=... isn’t overridden by an appended index=off. |
| plugins/snapshots/overlay/overlay_test.go | Adds a regression test ensuring index=off is not auto-appended when index=on is configured. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
I suggest we drop the hasValue argument entirely, because we're always looking for key in a key[=value] string. That way the caller doesn't have to be aware of the option requires (or does not require) a value.
While updating, I would also replace the manual splitting for a basic strings.Cut (we can keep a fast-path for a straight match);
func hasOption(options []string, key string) bool {
for _, option := range options {
if option == key {
return true
}
optionKey, _, _ := strings.Cut(option, "=")
if optionKey == key {
return true
}
}
return false
}AFAICS, we're only interested "was option index (or userxattr ) used as part of the options (regardless of what value they have)"? So removing the boolean makes that much more fool-proof.
containerd/plugins/snapshots/overlay/overlay.go
Lines 150 to 163 in cb23630
There was a problem hiding this comment.
Good call — done. Dropped the boolean entirely: hasOption now matches the key of a key[=value] option via strings.Cut (with the exact-match fast path kept), and both call sites just pass the key.
NewSnapshotter auto-appends "index=off" unless the configured mount_options already carry an index option — but the check used hasOption(..., "index", false), which compares against the literal string "index". No valid mount option ever equals "index" (it is always valued, "index=on"/"index=off"), so the append happened unconditionally whenever the kernel exposes the overlay index parameter. Mount options are last-wins in the kernel, so a user-configured "index=on" was silently overridden. Worse, configuring mount_options = ["index=on", "nfs_export=on"] (the documented way to make overlay mounts NFS-exportable) produced "index=on,nfs_export=on,index=off", which the kernel rejects with EINVAL (nfs_export=on conflicts with an explicit index=off) — breaking every snapshot mount including image unpack. Make hasOption match the key of a "key[=value]" option so callers need not care whether the option takes a value, and add a regression test. Signed-off-by: AprilNEA <[email protected]>
1f86bb1 to
5e25f36
Compare
|
/cherry-pick release/2.2 |
|
@AprilNEA: only containerd org members may request cherry picks. If you are already part of the org, make sure to change your membership to public. Otherwise you can still do the cherry-pick manually. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
Hi @AprilNEA, thank you for the fix and opening these backports. Since these cherry-pick cleanly, I'm going to use Prow to land them instead, which is our preferred process. Manual backports are still appreciated, but we use them primarily when there's a conflict or needs changes to land in an older branch /cherry-pick release/2.0 |
|
@chrishenzie: new pull request created: #14490 DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
@chrishenzie: new pull request created: #14491 DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
@chrishenzie: new pull request created: #14492 DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
The overlay snapshotter auto-appends
index=offto its mount options unless the user configuration already carries an index option — but the guard can never fire:hasOption(..., hasValue=false)compares each option against the literal string"index". The index option is always valued (index=on/index=off), so no valid configuration ever matches, andindex=offis appended unconditionally whenever/sys/module/overlay/parameters/indexexists.Mount options are last-wins in the kernel, so a configured
index=onis silently overridden. The practical casualty is NFS export of overlay mounts: configuringproduces
index=on,nfs_export=on,index=offon every snapshot mount, which the kernel rejects with EINVAL —nfs_export=onconflicts with an explicitindex=off(fs/overlayfs/params.c, "conflicting options: nfs_export=on,index=off"). The first casualty is image unpack:(Reproduced on containerd 2.2.5 / kernel 6.12 with dockerd 29.6.1 using the containerd image store; the code is unchanged on main.)
This changes the check to
hasValue=true(prefixindex=match, the same helper the valued form exists for), so a configured index option suppresses the auto-append. The neighboringuserxattrcheck keepshasValue=false, which is correct for a bare flag option.Also adds a regression test asserting that a snapshotter configured with
WithMountOptions([]string{"index=on", "nfs_export=on"})does not end up withindex=offin its options.