specgen: permit --privileged and --cap-add

--cap-add is useful when running a privileged container with UID != 0,
so that individual capabilities can be added to the container process.

Closes: https://github.com/containers/podman/issues/13449

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano
2022-04-01 10:15:08 +02:00
parent d1f3a2d6a8
commit 1cd529b22d
2 changed files with 5 additions and 4 deletions

View File

@ -83,10 +83,6 @@ func (s *SpecGenerator) Validate() error {
// //
// ContainerSecurityConfig // ContainerSecurityConfig
// //
// capadd and privileged are exclusive
if len(s.CapAdd) > 0 && s.Privileged {
return exclusiveOptions("CapAdd", "privileged")
}
// userns and idmappings conflict // userns and idmappings conflict
if s.UserNS.IsPrivate() && s.IDMappings == nil { if s.UserNS.IsPrivate() && s.IDMappings == nil {
return errors.Wrap(ErrInvalidSpecConfig, "IDMappings are required when not creating a User namespace") return errors.Wrap(ErrInvalidSpecConfig, "IDMappings are required when not creating a User namespace")

View File

@ -535,6 +535,11 @@ var _ = Describe("Podman run", func() {
Expect(session).Should(Exit(0)) Expect(session).Should(Exit(0))
Expect(session.OutputToString()).To(ContainSubstring("0000000000000000")) Expect(session.OutputToString()).To(ContainSubstring("0000000000000000"))
session = podmanTest.Podman([]string{"run", "--user=1:1", "--cap-add=DAC_OVERRIDE", "--rm", ALPINE, "grep", "CapEff", "/proc/self/status"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expect(session.OutputToString()).To(ContainSubstring("0000000000000002"))
if os.Geteuid() > 0 { if os.Geteuid() > 0 {
if os.Getenv("SKIP_USERNS") != "" { if os.Getenv("SKIP_USERNS") != "" {
Skip("Skip userns tests.") Skip("Skip userns tests.")