Skip to content

Commit 0be629d

Browse files
committed
Add support for confined SELinux users
The original SELinux support in Docker and Podman does not follow the default SELinux rules for how label transitions are supposed to be handled. Containers always switch their user and role to system_u:system_r, rather then maintain the collers user and role. For example unconfined_u:unconfined_r:container_t:s0:c1,c2 Advanced SELinux administrators want to confine users but still allow them to create containers from their role, but not allow them to launch a privileged container like spc_t. This means if a user running as container_user_u:container_user_r:container_user_t:s0 Ran a container they would get container_user_u:container_user_r:container_t:s0:c1,c2 If they run a privileged container they would run it with: container_user_u:container_user_r:container_user_t:s0 If they want to force the label they would get an error podman run --security-opt label=type:spc_t ... Should fail. Because the container_user_r can not run with the spc_t. SELinux rules would also prevent the user from forcing system_u user and the sytem_r role. Signed-off-by: Daniel J Walsh <[email protected]>
1 parent df7cb22 commit 0be629d

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

docs/containers.conf.5.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,13 @@ the container.
208208

209209
Indicates whether the container engine uses MAC(SELinux) container separation via labeling. This option is ignored on disabled systems.
210210

211+
label_users=false
212+
213+
label_users indicates whether to enforce confined users in containers on
214+
SELinux systems. This option causes containers to maintain the current user
215+
and role field of the calling process. By default SELinux containers run with
216+
the user system_u, and the role system_r.
217+
211218
**log_driver**=""
212219

213220
Logging driver for the container. Currently available options are k8s-file, journald, none and passthrough, with json-file aliased to k8s-file for scripting compatibility. The journald driver is used by default if the systemd journal is readable and writable. Otherwise, the k8s-file driver is used.

pkg/config/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ type ContainersConfig struct {
143143
// Labeling to separate containers (SELinux)
144144
EnableLabeling bool `toml:"label,omitempty"`
145145

146+
// EnableLabeledUsers indicates whether to enforce confined users with
147+
// containers on SELinux systems. This option causes containers to
148+
// maintain the current user and role field of the calling process.
149+
// Otherwise containers run with user system_u, and the role system_r.
150+
EnableLabeledUsers bool `toml:"label_users,omitempty"`
151+
146152
// Env is the environment variable list for container process.
147153
Env []string `toml:"env,omitempty"`
148154

pkg/config/config_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ var _ = Describe("Config", func() {
109109
defaultConfig, _ := NewConfig("")
110110
// EnableLabeling should match whether or not SELinux is enabled on the host
111111
gomega.Expect(defaultConfig.Containers.EnableLabeling).To(gomega.Equal(selinux.GetEnabled()))
112+
gomega.Expect(defaultConfig.Containers.EnableLabeledUsers).To(gomega.BeFalse())
112113
})
113114
})
114115

@@ -932,5 +933,6 @@ env=["foo=bar"]`
932933
gomega.Expect(err).ToNot(gomega.HaveOccurred())
933934
gomega.Expect(config.Containers.ApparmorProfile).To(gomega.Equal("overridden-default"))
934935
gomega.Expect(config.Containers.BaseHostsFile).To(gomega.Equal("/etc/hosts2"))
936+
gomega.Expect(config.Containers.EnableLabeledUsers).To(gomega.BeTrue())
935937
})
936938
})

pkg/config/containers.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,11 @@ default_sysctls = [
392392
# short-name aliases defined in containers-registries.conf(5).
393393
#compat_api_enforce_docker_hub = true
394394

395+
# The database backend of Podman. Supported values are "boltdb" (default) and
396+
# "sqlite". Please run `podman-system-reset` prior to changing the database
397+
# backend of an existing deployment, to make sure Podman can operate correctly.
398+
#database_backend="boltdb"
399+
395400
# Specify the keys sequence used to detach a container.
396401
# Format is a single character [a-Z] or a comma separated sequence of
397402
# `ctrl-<value>`, where `<value>` is one of:

pkg/config/testdata/containers_override.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ log_driver = "journald"
55
log_tag="{{.Name}}|{{.ID}}"
66
log_size_max = 100000
77
read_only=true
8+
label_users=true
89

910
[engine]
1011
image_parallel_copies=10

0 commit comments

Comments
 (0)