forked from flatcar/scripts
-
Notifications
You must be signed in to change notification settings - Fork 6
selinux-policy: complete container log reader support #59
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
Merged
SeanDougherty
merged 4 commits into
aclmain
from
sdougherty/fix-container-logreader-policy
Aug 28, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
faca940
selinux-policy: narrow container log reader access
SeanDougherty e025ba1
selinux-policy: address log reader review feedback
SeanDougherty 0917cb1
selinux-policy: align log reader with upstream
SeanDougherty 51a7208
docs: clarify default SELinux mode
SeanDougherty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
acl/SPECS/selinux-policy/0061-container-Allow-log-reader-to-map-journals.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| From 1b6a1a2c7836d3601b7af8ac453f9b89163eda3a Mon Sep 17 00:00:00 2001 | ||
| From: Sean Dougherty <sdougherty@microsoft.com> | ||
| Date: Fri, 21 Aug 2026 22:12:09 +0000 | ||
| Subject: [PATCH] container: Allow log reader to map journals | ||
|
|
||
| Journal readers such as journalctl memory-map systemd journal files. Grant the | ||
| existing read-only journal interface so container_logreader_t can consume | ||
| persistent journals without receiving write or watch access. | ||
|
|
||
| Signed-off-by: Sean Dougherty <sdougherty@microsoft.com> | ||
| --- | ||
| policy/modules/services/container.te | 4 ++++ | ||
| 1 file changed, 4 insertions(+) | ||
|
|
||
| diff --git a/policy/modules/services/container.te b/policy/modules/services/container.te | ||
| index 2fe1b51..4559fb5 100644 | ||
| --- a/policy/modules/services/container.te | ||
| +++ b/policy/modules/services/container.te | ||
| @@ -614,6 +614,10 @@ logging_list_logs(container_logreader_t) | ||
| allow container_logreader_t logfile:lnk_file read_lnk_file_perms; | ||
| allow container_logreader_t container_log_t:file watch; | ||
|
|
||
| +optional_policy(` | ||
| + systemd_read_journal_files(container_logreader_t) | ||
| +') | ||
| + | ||
| ######################################## | ||
| # | ||
| # Common container engine local policy | ||
| -- | ||
| 2.45.4 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| # SELinux Container Domains | ||
|
|
||
| Azure Container Linux (ACL) enables SELinux in enforcing mode by default. | ||
| Operators can configure a node to use permissive mode for troubleshooting; | ||
| use `getenforce` to verify its current mode. Container workloads use SELinux | ||
| domains to limit their access to the host and to other containers. The | ||
| container runtime selects a domain and allocates an MCS category set for each | ||
| workload. | ||
|
|
||
| ## Workload domains | ||
|
|
||
| | Domain | Intended use | Host access | | ||
| | --- | --- | --- | | ||
| | `container_t` | Default container workload | No general access to host logs or host files | | ||
| | `container_logreader_t` | Opt-in log collector | Read-only access to objects labeled with an SELinux log type | | ||
| | `container_kvm_t` | Containerized KVM workload | KVM-specific device and process access | | ||
| | `spc_t` | Privileged container | Broad host access; may be unconfined when the unconfined policy module is enabled | | ||
|
|
||
| `container_engine_t` is reserved for the container engine itself and is not a | ||
| workload domain. | ||
|
|
||
| Use `container_t` unless the workload requires a documented specialized | ||
| domain. Do not use `spc_t` solely to collect logs. | ||
|
|
||
| ## Confined log collectors | ||
|
|
||
| `container_logreader_t` extends the normal confined container policy with | ||
| read, directory traversal, and symlink access to types carrying the `logfile` | ||
| attribute. Inotify watch access applies only to `container_log_t`, not to other | ||
| host log types. Access is based on the SELinux label, not the path. Inspect | ||
| host labels with: | ||
|
|
||
| ```bash | ||
| ls -ldZ /var/log | ||
| find /var/log -maxdepth 2 -type f -exec ls -lZ -- {} + | ||
| ``` | ||
|
|
||
| The domain intentionally does not grant: | ||
|
SeanDougherty marked this conversation as resolved.
|
||
|
|
||
| - Write, append, create, delete, rename, or relabel access to host logs. | ||
| - Blanket access to arbitrary host files beyond the common `container_domain` | ||
| policy it shares with `container_t`. | ||
| - The broad host privileges provided by `spc_t`. | ||
|
|
||
| Like Fedora, RHEL, and other distributions using `container-selinux`, ACL | ||
| allows this domain to read auditd-managed files labeled `auditd_log_t`. | ||
| Audit logs contain host-wide authentication, syscall, and AVC data; mount | ||
| `/var/log/audit` only when the collector requires that information. | ||
|
SeanDougherty marked this conversation as resolved.
SeanDougherty marked this conversation as resolved.
|
||
|
|
||
| ACL stores the systemd journal persistently under `/var/log/journal`. The | ||
| journal uses `systemd_journal_t` and can contain kernel audit and AVC records, | ||
| so it remains readable when mounted into the collector. Restrict mounted paths | ||
| when a collector should not receive audit data. | ||
|
|
||
| The host log path must still be mounted into the container. Make the mount | ||
| read-only as defense in depth, and do not relabel the host log directory. | ||
|
|
||
| ### Kubernetes example | ||
|
|
||
| ```yaml | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: host-log-reader | ||
| spec: | ||
| containers: | ||
| - name: collector | ||
| image: <collector-image> | ||
| securityContext: | ||
| seLinuxOptions: | ||
| type: container_logreader_t | ||
| volumeMounts: | ||
| - name: host-journal | ||
| mountPath: /host/var/log/journal | ||
| readOnly: true | ||
| volumes: | ||
| - name: host-journal | ||
| hostPath: | ||
| path: /var/log/journal | ||
| type: Directory | ||
| ``` | ||
|
|
||
| Cluster admission policy must allow the `container_logreader_t` type. Do not | ||
| set the pod to `privileged: true`. Add a separate read-only | ||
| `/var/log/audit` mount only when the collector must read auditd-managed files. | ||
|
|
||
| ### Podman example | ||
|
|
||
| ```bash | ||
| podman run --rm \ | ||
| --security-opt label=type:container_logreader_t \ | ||
| --volume /var/log/journal:/host/var/log/journal:ro \ | ||
| <collector-image> | ||
| ``` | ||
|
|
||
| Do not add `:z` or `:Z` to the volume. Those options relabel host content and | ||
| can interfere with host logging services. Add a separate | ||
| `/var/log/audit:/host/var/log/audit:ro` mount only when auditd files are | ||
| required. | ||
|
|
||
| ## MCS isolation | ||
|
|
||
| `container_logreader_t` remains an `mcs_constrained_type` and retains normal | ||
| container MCS isolation. ACL builds the targeted policy in MCS mode, where | ||
| standard host log file contexts resolve to level `s0`. A container at its | ||
| runtime-assigned level, such as `s0:c123,c456`, dominates `s0` and can use the | ||
| domain's read permissions without receiving an all-category level. | ||
|
SeanDougherty marked this conversation as resolved.
|
||
|
|
||
| Do not set `seLinuxOptions.level` to `s0:c0.c1023` and do not remove the | ||
| runtime-assigned categories. Either action weakens isolation from other | ||
| containers. | ||
|
|
||
| ## Validation | ||
|
|
||
| Confirm the selected process domain and mounted labels from the container: | ||
|
|
||
| ```bash | ||
| cat /proc/self/attr/current | ||
| ls -ldZ /host/var/log/journal | ||
|
SeanDougherty marked this conversation as resolved.
|
||
| journalctl --file='/host/var/log/journal/*/system.journal' -n 5 | ||
| ``` | ||
|
SeanDougherty marked this conversation as resolved.
|
||
|
|
||
| The process context should report `container_logreader_t`, and the journal | ||
| read should succeed when the collector image includes `journalctl`. A write | ||
|
SeanDougherty marked this conversation as resolved.
|
||
| attempt to a host log should fail. Stock ACL creates `/var/log/audit` but does | ||
| not run auditd, so the directory is normally empty. Hosts that add auditd | ||
| should treat access to its files as sensitive and mount them only when needed. | ||
| On the host, check unexpected SELinux denials with: | ||
|
|
||
| ```bash | ||
| journalctl -g 'avc: denied' --since -10min | ||
|
SeanDougherty marked this conversation as resolved.
|
||
| ``` | ||
|
SeanDougherty marked this conversation as resolved.
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.