Skip to content
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

Mask /sys/devices/virtual/powercap #20501

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libpod/container_internal_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,8 @@ func (c *Container) generateSpec(ctx context.Context) (s *spec.Spec, cleanupFunc
}
}

c.addMaskedPaths(&g)

return g.Config, cleanupFunc, nil
}

Expand Down
4 changes: 4 additions & 0 deletions libpod/container_internal_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,7 @@ func (c *Container) getPlatformRunPath() (string, error) {
}
return runPath, nil
}

func (c *Container) addMaskedPaths(g *generate.Generator) {
// There are currently no FreeBSD-specific masked paths
}
6 changes: 6 additions & 0 deletions libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,3 +805,9 @@ func (c *Container) makePlatformMtabLink(etcInTheContainerFd, rootUID, rootGID i
func (c *Container) getPlatformRunPath() (string, error) {
return "/run", nil
}

func (c *Container) addMaskedPaths(g *generate.Generator) {
if !c.config.Privileged {
Copy link
Member

Choose a reason for hiding this comment

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

should we also add && len(g.Config.Linux.MaskedPaths) != 0 as check here? if umask=all is set it would mean we do not add the path which seems more desirable.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @Luap99, it'd be better to have a way to not mask it.

Otherwise we have no way to have an unmasked /sys in the container and I think that breaks mounting /sys in a nested container

g.AddLinuxMaskedPaths("/sys/devices/virtual/powercap")
}
}
23 changes: 23 additions & 0 deletions test/e2e/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,29 @@ var _ = Describe("Podman run", func() {
Expect(session.OutputToString()).To(Not(BeEmpty()))
})

It("podman run powercap is masked", func() {
Skip("CI VMs do not have access to powercap")

testCtr1 := "testctr"
run := podmanTest.Podman([]string{"run", "-d", "--name", testCtr1, ALPINE, "top"})
run.WaitWithDefaultTimeout()
Expect(run).Should(ExitCleanly())

exec := podmanTest.Podman([]string{"exec", "-ti", testCtr1, "ls", "/sys/devices/virtual/powercap"})
exec.WaitWithDefaultTimeout()
Expect(exec).To(ExitWithError())

testCtr2 := "testctr2"
run2 := podmanTest.Podman([]string{"run", "-d", "--privileged", "--name", testCtr2, ALPINE, "top"})
run2.WaitWithDefaultTimeout()
Expect(run2).Should(ExitCleanly())

exec2 := podmanTest.Podman([]string{"exec", "-ti", testCtr2, "ls", "/sys/devices/virtual/powercap"})
exec2.WaitWithDefaultTimeout()
Expect(exec2).Should(ExitCleanly())
Expect(exec2.OutputToString()).Should(Not(BeEmpty()))
})

It("podman run security-opt unmask on /sys/fs/cgroup", func() {

SkipIfCgroupV1("podman umask on /sys/fs/cgroup will fail with cgroups V1")
Expand Down