Skip to content

Commit 763f124

Browse files
authored
Merge pull request #497 from cgwalters/doc-selinux
docs: Move selinux into image info, add toplevel gotcha
2 parents 6ba7938 + 9e768e8 commit 763f124

File tree

2 files changed

+56
-42
lines changed

2 files changed

+56
-42
lines changed

docs/src/bootc-images.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,57 @@ project which handles bootloader installs and upgrades. The invocation of
8484
`bootc install` will always run `bootupd` to perform installations.
8585
Additionally, `bootc upgrade` will currently not upgrade the bootloader;
8686
you must invoke `bootupctl update`.
87+
88+
# SELinux
89+
90+
Container runtimes such as `podman` and `docker` commonly
91+
apply a "coarse" SELinux policy to running containers.
92+
See [container-selinux](https://github.com/containers/container-selinux/blob/main/container_selinux.8).
93+
It is very important to understand that non-bootc base
94+
images do not (usually) have any embedded `security.selinux` metadata
95+
at all; all labels on the toplevel container image
96+
are *dynamically* generated per container invocation,
97+
and there are no individually distinct e.g. `etc_t` and
98+
`usr_t` types.
99+
100+
In contrast, with the current OSTree backend for bootc,
101+
when the base image is built, label metadata is included
102+
in special metadata files in `/sysroot/ostree` that correspond
103+
to components of the base image.
104+
105+
When a bootc container is deployed, the system
106+
will use these default SELinux labels.
107+
Further non-OSTree layers will be dynamically labeled
108+
using the base policy.
109+
110+
Hence, at the current time it will *not* work to override
111+
the labels for files in derived layers by using e.g.
112+
113+
```
114+
RUN semanage fcontext -a -t httpd_sys_content_t "/web(/.*)?"
115+
```
116+
117+
(This command will write to `/etc/selinux/policy/$policy/`)
118+
119+
It will *never* work to do e.g.:
120+
121+
```
122+
RUN chcon -t foo_t /usr/bin/foo
123+
```
124+
125+
Because the container runtime state will deny the attempt to
126+
"physically" set the `security.selinux` extended attribute.
127+
In contrast per above, future support for custom labeling
128+
will by default be done by customizing the policy file_contexts.
129+
130+
### Toplevel directories
131+
132+
In particular, a common problem is that inside a container image,
133+
it's easy to create arbitrary toplevel directories such as
134+
e.g. `/app` or `/aimodel` etc. But in some SELinux policies
135+
such as Fedora derivatives, these will be labeled as `default_t`
136+
which few domains can access.
137+
138+
References:
139+
140+
- <https://github.com/ostreedev/ostree-rs-ext/issues/510>

docs/src/building/bootc-runtime.md

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -81,46 +81,6 @@ system is deployed.
8181

8282
## SELinux
8383

84-
Container runtimes such as `podman` and `docker` commonly
85-
apply a "coarse" SELinux policy to running containers.
86-
See [container-selinux](https://github.com/containers/container-selinux/blob/main/container_selinux.8).
87-
It is very important to understand that non-bootc base
88-
images do not (usually) have any embedded `security.selinux` metadata
89-
at all; all labels on the toplevel container image
90-
are *dynamically* generated per container invocation,
91-
and there are no individually distinct e.g. `etc_t` and
92-
`usr_t` types.
84+
For more on the intersection of SELinux and current bootc (OSTree container)
85+
images, see [bootc images - SELinux](../bootc-images.md#SELinux).
9386

94-
In contrast, with the current OSTree backend for bootc,
95-
when the base image is built, label metadata is included
96-
in special metadata files in `/sysroot/ostree` that correspond
97-
to components of the base image.
98-
99-
When a bootc container is deployed, the system
100-
will use these default SELinux labels.
101-
Further non-OSTree layers will be dynamically labeled
102-
using the base policy.
103-
104-
Hence, at the current time it will *not* work to override
105-
the labels for files in derived layers by using e.g.
106-
107-
```
108-
RUN semanage fcontext -a -t httpd_sys_content_t "/web(/.*)?"
109-
```
110-
111-
(This command will write to `/etc/selinux/policy/$policy/`)
112-
113-
It will *never* work to do e.g.:
114-
115-
```
116-
RUN chcon -t foo_t /usr/bin/foo
117-
```
118-
119-
Because the container runtime state will deny the attempt to
120-
"physically" set the `security.selinux` extended attribute.
121-
In contrast per above, future support for custom labeling
122-
will by default be done by customizing the policy file_contexts.
123-
124-
References:
125-
126-
- <https://github.com/ostreedev/ostree-rs-ext/issues/510>

0 commit comments

Comments
 (0)