Skip to content

Commit

Permalink
fix: mount /sys/kernel/security conditionally
Browse files Browse the repository at this point in the history
When running in containers, specifically on Docker Desktop VMs, the
securityfs might be missing.

Fixes #9431

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
(cherry picked from commit 0e6c983)
  • Loading branch information
smira committed Nov 13, 2024
1 parent 83abb66 commit 5044a41
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/app/machined/pkg/system/services/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ func (k *Kubelet) Runner(r runtime.Runtime) (runner.Runner, error) {
ID: k.ID(r),
ProcessArgs: append([]string{"/usr/local/bin/kubelet"}, spec.Args...),
}

// Set the required kubelet mounts.
mounts := []specs.Mount{
{Type: "bind", Destination: "/dev", Source: "/dev", Options: []string{"rbind", "rshared", "rw"}},
{Type: "sysfs", Destination: "/sys", Source: "/sys", Options: []string{"bind", "ro"}},
{Type: "securityfs", Destination: "/sys/kernel/security", Source: "/sys/kernel/security", Options: []string{"bind", "ro"}},
{Type: "bind", Destination: constants.CgroupMountPath, Source: constants.CgroupMountPath, Options: []string{"rbind", "rshared", "rw"}},
{Type: "bind", Destination: "/lib/modules", Source: "/lib/modules", Options: []string{"bind", "ro"}},
{Type: "bind", Destination: "/etc/kubernetes", Source: "/etc/kubernetes", Options: []string{"bind", "rshared", "rw"}},
Expand All @@ -138,6 +138,12 @@ func (k *Kubelet) Runner(r runtime.Runtime) (runner.Runner, error) {
{Type: "bind", Destination: "/var/log/pods", Source: "/var/log/pods", Options: []string{"rbind", "rshared", "rw"}},
}

if _, err := os.Stat("/sys/kernel/security"); err == nil {
mounts = append(mounts,
specs.Mount{Type: "securityfs", Destination: "/sys/kernel/security", Source: "/sys/kernel/security", Options: []string{"bind", "ro"}},
)
}

// Add extra mounts.
// TODO(andrewrynhard): We should verify that the mount source is
// allowlisted. There is the potential that a user can expose
Expand Down

0 comments on commit 5044a41

Please sign in to comment.