From 362eca6691a43c85657ab8e772a452e106890f8d Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Wed, 4 Oct 2023 15:51:11 +0200 Subject: [PATCH] containers.conf: add `privileged` field to containers table As requested in containers/podman/issues/20000, add a `privileged` field to the containers table in containers.conf. I was hesitant to add such a field at first (for security reasons) but I understand that such a field can come in handy when using modules - certain workloads require a privileged container. Signed-off-by: Valentin Rothberg --- cmd/podman/common/create.go | 2 +- cmd/podman/containers/exec.go | 3 +- docs/source/markdown/options/privileged.md | 5 +++- go.mod | 2 +- go.sum | 4 +-- pkg/api/handlers/libpod/containers_create.go | 5 +++- test/system/800-config.bats | 28 +++++++++++++++++-- .../containers/common/libimage/copier.go | 2 +- .../containers/common/libimage/filters.go | 2 +- .../common/libnetwork/netavark/network.go | 4 +-- .../containers/common/pkg/config/config.go | 14 +++++++++- .../common/pkg/config/containers.conf | 12 ++++++++ .../common/pkg/config/containers.conf-freebsd | 12 ++++++++ vendor/modules.txt | 2 +- 14 files changed, 81 insertions(+), 16 deletions(-) diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go index 3af1f1f15c..8082bc8f87 100644 --- a/cmd/podman/common/create.go +++ b/cmd/podman/common/create.go @@ -348,7 +348,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions, _ = cmd.RegisterFlagCompletionFunc(podIDFileFlagName, completion.AutocompleteDefault) createFlags.BoolVar( &cf.Privileged, - "privileged", false, + "privileged", podmanConfig.ContainersConfDefaultsRO.Containers.Privileged, "Give extended privileges to container", ) createFlags.BoolVarP( diff --git a/cmd/podman/containers/exec.go b/cmd/podman/containers/exec.go index c7952c3686..36be01479a 100644 --- a/cmd/podman/containers/exec.go +++ b/cmd/podman/containers/exec.go @@ -53,6 +53,7 @@ var ( ) func execFlags(cmd *cobra.Command) { + podmanConfig := registry.PodmanConfig() flags := cmd.Flags() flags.SetInterspersed(false) @@ -71,7 +72,7 @@ func execFlags(cmd *cobra.Command) { _ = cmd.RegisterFlagCompletionFunc(envFileFlagName, completion.AutocompleteDefault) flags.BoolVarP(&execOpts.Interactive, "interactive", "i", false, "Keep STDIN open even if not attached") - flags.BoolVar(&execOpts.Privileged, "privileged", false, "Give the process extended Linux capabilities inside the container. The default is false") + flags.BoolVar(&execOpts.Privileged, "privileged", podmanConfig.ContainersConfDefaultsRO.Containers.Privileged, "Give the process extended Linux capabilities inside the container. The default is false") flags.BoolVarP(&execOpts.Tty, "tty", "t", false, "Allocate a pseudo-TTY. The default is false") userFlagName := "user" diff --git a/docs/source/markdown/options/privileged.md b/docs/source/markdown/options/privileged.md index 5cca2ad5e0..4f968c2b43 100644 --- a/docs/source/markdown/options/privileged.md +++ b/docs/source/markdown/options/privileged.md @@ -16,5 +16,8 @@ mode (**--systemd=always**). A privileged container turns off the security features that isolate the container from the host. Dropped Capabilities, limited devices, read-only mount points, Apparmor/SELinux separation, and Seccomp filters are all disabled. +Due to the disabled security features, the privileged field should almost never +be set as containers can easily break out of confinement. -Rootless containers cannot have more privileges than the account that launched them. +Containers running in a user namespace (e.g., rootless containers) cannot have +more privileges than the user that launched them. diff --git a/go.mod b/go.mod index d422cfddda..ef87ed9314 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/containernetworking/cni v1.1.2 github.com/containernetworking/plugins v1.3.0 github.com/containers/buildah v1.32.0 - github.com/containers/common v0.56.1-0.20231002091908-745eaa498509 + github.com/containers/common v0.56.1-0.20231005124809-b4ef9cdeab5b github.com/containers/conmon v2.0.20+incompatible github.com/containers/gvisor-tap-vsock v0.7.1 github.com/containers/image/v5 v5.28.0 diff --git a/go.sum b/go.sum index a1567bf711..ab3cad47ae 100644 --- a/go.sum +++ b/go.sum @@ -249,8 +249,8 @@ github.com/containernetworking/plugins v1.3.0 h1:QVNXMT6XloyMUoO2wUOqWTC1hWFV62Q github.com/containernetworking/plugins v1.3.0/go.mod h1:Pc2wcedTQQCVuROOOaLBPPxrEXqqXBFt3cZ+/yVg6l0= github.com/containers/buildah v1.32.0 h1:uz5Rcf7lGeStj7iPTBgO4UdhQYZqMMzyt9suDf16k1k= github.com/containers/buildah v1.32.0/go.mod h1:sN3rA3DbnqekNz3bNdkqWduuirYDuMs54LUCOZOomBE= -github.com/containers/common v0.56.1-0.20231002091908-745eaa498509 h1:og5WEvZ2R4WMaO7L3F+Nfq0vfhtIZBxfG6BOVpG+Vfs= -github.com/containers/common v0.56.1-0.20231002091908-745eaa498509/go.mod h1:8whK9BaTeJqaSTAM0r2A7OdW+XVS+4X9SVh0D6zxpek= +github.com/containers/common v0.56.1-0.20231005124809-b4ef9cdeab5b h1:LIHpr2o8WakQ48q2GAQZlMAG+zsVJPOQSLraxP7j9fI= +github.com/containers/common v0.56.1-0.20231005124809-b4ef9cdeab5b/go.mod h1:8gifkvVxN1oOHJ9Yp/SHWcN6MlxdC0gZCF2+MaWjErc= github.com/containers/conmon v2.0.20+incompatible h1:YbCVSFSCqFjjVwHTPINGdMX1F6JXHGTUje2ZYobNrkg= github.com/containers/conmon v2.0.20+incompatible/go.mod h1:hgwZ2mtuDrppv78a/cOBNiCm6O0UMWGx1mu7P00nu5I= github.com/containers/gvisor-tap-vsock v0.7.1 h1:+Rc+sOPplrkQb/BUXeN0ug8TxjgyrIqo/9P/eNS2A4c= diff --git a/pkg/api/handlers/libpod/containers_create.go b/pkg/api/handlers/libpod/containers_create.go index 480cc656eb..9264d72d36 100644 --- a/pkg/api/handlers/libpod/containers_create.go +++ b/pkg/api/handlers/libpod/containers_create.go @@ -13,6 +13,7 @@ import ( "github.com/containers/podman/v4/pkg/specgen" "github.com/containers/podman/v4/pkg/specgen/generate" "github.com/containers/podman/v4/pkg/specgenutil" + "github.com/sirupsen/logrus" ) // CreateContainer takes a specgenerator and makes a container. It returns @@ -31,7 +32,8 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) { UseImageHosts: conf.Containers.NoHosts, }, ContainerSecurityConfig: specgen.ContainerSecurityConfig{ - Umask: conf.Containers.Umask, + Umask: conf.Containers.Umask, + Privileged: conf.Containers.Privileged, }, } @@ -39,6 +41,7 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) { utils.Error(w, http.StatusInternalServerError, fmt.Errorf("decode(): %w", err)) return } + logrus.Errorf("Privileged: %v", sg.ContainerSecurityConfig.Privileged) if sg.Passwd == nil { t := true sg.Passwd = &t diff --git a/test/system/800-config.bats b/test/system/800-config.bats index e09cda1590..2f3984fc84 100644 --- a/test/system/800-config.bats +++ b/test/system/800-config.bats @@ -188,12 +188,34 @@ EOF cat > $conf_tmp <