Repository navigation
bump selinux to v1.15.1, use SetProcessKind - #13395
Conversation
There was a problem hiding this comment.
Pull request overview
This PR vendors and integrates upcoming github.com/opencontainers/selinux changes (targeting v1.15.0) into containerd, updating CRI SELinux handling to use newer APIs like ChangeLabelType, ReserveLabelV2, and SetCategoryRange, and removing the internal seutil helper.
Changes:
- Bump
github.com/opencontainers/selinuxto v1.15.0 and (for now)replaceit togithub.com/kolyshkin/selinuxat a specific pseudo-version for testing. - Switch CRI KVM label adjustment to
selinux.ChangeLabelType(...)and dropinternal/cri/seutil. - Update label reservation flow to propagate reservation errors (
ReserveLabelV2) and validate category range viaSetCategoryRange.
Reviewed changes
Copilot reviewed 8 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| vendor/modules.txt | Updates vendored module metadata for the selinux bump and replace. |
| vendor/github.com/opencontainers/selinux/pkg/pwalkdir/pwalkdir.go | Sync with upstream vendored changes (incl. Go 1.22 integer-range loop). |
| vendor/github.com/opencontainers/selinux/go-selinux/selinux.go | Adds new public APIs (ChangeLabelType, SetCategoryRange, ReserveLabelV2, etc.). |
| vendor/github.com/opencontainers/selinux/go-selinux/selinux_stub.go | Updates non-Linux stubs to match new upstream API surface. |
| vendor/github.com/opencontainers/selinux/go-selinux/selinux_linux.go | Syncs Linux implementation changes (label reservation semantics, context fallback plumbing, etc.). |
| vendor/github.com/opencontainers/selinux/go-selinux/label/label_stub.go | Removes legacy build tag line in vendored stub. |
| vendor/github.com/opencontainers/selinux/go-selinux/label/label_linux.go | Adjusts InitLabels option parsing and uses ReserveLabelV2 for custom levels. |
| internal/cri/store/label/label.go | Makes the store’s Reserver return errors and wires it to ReserveLabelV2. |
| internal/cri/store/label/label_test.go | Updates tests for the new Reserver func(string) error signature. |
| internal/cri/store/container/container_test.go | Updates test override for the new Reserver signature. |
| internal/cri/server/service_linux.go | Uses selinux.SetCategoryRange instead of assigning CategoryRange directly. |
| internal/cri/server/podsandbox/helpers_linux.go | Replaces seutil.ChangeToKVM with selinux.ChangeLabelType and gates on selinux.GetEnabled(). |
| internal/cri/server/helpers_linux.go | Same KVM label update as podsandbox helper, using ChangeLabelType. |
| internal/cri/seutil/seutil.go | Removes the now-redundant SELinux KVM label helper. |
| go.sum | Adds sums for the temporary replacement module. |
| go.mod | Bumps selinux requirement to v1.15.0 and adds a temporary replace directive. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| l, err := seutil.ChangeToKVM(spec.Process.SelinuxLabel) | ||
| l, err := selinux.ChangeLabelType(spec.Process.SelinuxLabel, selinux.TypeKVMProcess) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get selinux kvm label: %w", err) |
There was a problem hiding this comment.
Potato, potahto...
| l, err := seutil.ChangeToKVM(spec.Process.SelinuxLabel) | ||
| l, err := selinux.ChangeLabelType(spec.Process.SelinuxLabel, selinux.TypeKVMProcess) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get selinux kvm label: %w", err) |
| if err := s.Reserver(label); err != nil { | ||
| return err | ||
| } |
2a1e112 to
e5c90ed
Compare
|
Not sure how can I summon the maintainers to please review this one; @thaJeztah halp 🙏🏻 |
e5c90ed to
dbded8e
Compare
| if err := s.Reserver(label); err != nil { | ||
| return err | ||
| } |
|
|
||
| if _, ok := s.levels[level]; !ok { | ||
| s.Reserver(label) | ||
| if err := s.Reserver(label); err != nil { |
There was a problem hiding this comment.
do we need to ignore selinux.ErrMCSAlreadyExists here?
There was a problem hiding this comment.
Good question. I looked at it before opening this PR, here's my (non-AI generated:)) recap.
It looks like we only call ReserveLabel for when s.levels[level] is non-existent (IOW its refcount is 0), and after the successful reservation we increase the refcount (to 1). So, if Reserve is called twice with the same label, we won't call ReserveLabel and thus won't get ErrMCSAlreadyExists.
This is actually tested by existing tests, e.g. this part in TestAddThenRemove:
t.Log("should count to two level")
assert.NoError(store.Reserve("junk:junk:junk:c1,c2"))
assert.NoError(store.Reserve("junk2:junk2:junk2:c1,c2"))The same level component ("c1,c2") is reserved twice here. If it were a bare call to selinux.ReserveLabelV2, we would definitely get ErrMCSAlreadyExists error.
There was a problem hiding this comment.
actually
NetNS:0x2efe7fd56230 StopCh:0x2efe7fd40960 Stats:<nil> Endpoint:{Address: Version:0}} into store: MCS label already exists"
|
Alas I am on vacation for the next couple of weeks, the options are:
I'd go with 3 because this is what was happening before. Now, this might be a real bug ("reusing the label when we shouldn't" or "forgetting to release the label" or something else) or a dud (we just re-reserve a label and it is completely normal). Have to look deeper to find out. |
PR #2769 upgraded `github.com/opencontainers/selinux` from `v1.13.1` to `v1.15.0`. However, containerd is still on `v1.13.1`, and the version mismatch is blocking the upgrade of new hcsshim releases (containerd/containerd#13671). Upgrading the `selinux` dependency in containerd is currently blocked (containerd/containerd#13395), so, for now, roll back the version until the latter PR is merged so their hcsshim dependency can be updated. Signed-off-by: Hamza El-Saawy <[email protected]>
Dependabot PR containerd#13671 is using older tag, which is blocked by `selinux` update (containerd#13395). Update hcsshim to version that does not bump the `selinux` package (which was only updated via dependabot PRs). Signed-off-by: Hamza El-Saawy <[email protected]>
f059771 to
479f5e0
Compare
|
So I figured it out. The label is actually reserved multiple times:
Since a container can either have the same label as the pod or a distinct one, it's hard to fix this properly. So I'm just ignoring Rebased; PTAL @djdongjin @thaJeztah |
| // The label may already be reserved, e.g. because selinux.ContainerLabels() | ||
| // just generated (and reserved) it, or because another container in the | ||
| // same pod is reusing the sandbox's label. | ||
| if err := s.Reserver(label); err != nil && !errors.Is(err, selinux.ErrMCSAlreadyExists) { |
Switch away from deprecated functionality. Signed-off-by: Kir Kolyshkin <[email protected]>
Drop internal/cri/seutil/seutil.go in favor of direct call to newly introduced selinux.SetProcessKind. Signed-off-by: Kir Kolyshkin <[email protected]>
479f5e0 to
ba3a464
Compare
|
Rebased |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 16 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
internal/cri/store/label/label.go:66
- The new behavior that treats
selinux.ErrMCSAlreadyExistsas non-fatal isn't covered by unit tests. Adding a test whereReserverreturnsselinux.ErrMCSAlreadyExistswould ensure this path stays intentional and prevents regressions that would make pod label reuse fail.
if _, ok := s.levels[level]; !ok {
// The label may already be reserved, e.g. because selinux.ContainerLabels()
// just generated (and reserved) it, or because another container in the
// same pod is reusing the sandbox's label.
if err := s.Reserver(label); err != nil && !errors.Is(err, selinux.ErrMCSAlreadyExists) {
return err
}
This is a draft until oc/selinux v1.15.0 is released; mostly to test opencontainers/selinux#271.This also includes #13392.
Update: bumped to v1.15.1