fix: improve k3s AppArmor profile with comprehensive permissions#26
Merged
sbaerlocher merged 2 commits intomainfrom Jan 15, 2026
Merged
fix: improve k3s AppArmor profile with comprehensive permissions#26sbaerlocher merged 2 commits intomainfrom
sbaerlocher merged 2 commits intomainfrom
Conversation
- Set k3s_config_dir to mode 0700 during initial creation in main.yml - Remove redundant permission setting in security.yml - Fixes idempotency issue where permissions were changed on every run Previously, the directory was created with 0755 in main.yml and then changed to 0700 in security.yml, causing the task to always report 'changed' status even when no actual changes were needed.
AppArmor Profile Enhancements: - Add sys_chroot, sys_ptrace, dac_override capabilities for container operations - Add xtables-nft-multi, nft, modprobe subprocess execution permissions - Expand proc/sys access from net/** to ** for full system parameter access - Add file locking (k flag) to k3s data directory for proper lock handling - Add /etc/rancher/node/** access for node configuration - Add detailed process and system info access (/proc/*/stat, cpuset, mountinfo, etc.) - Add /run/** and /var/run/** access for runtime files - Add ptrace (read) permission for containerd process management - Add comprehensive comments for each permission section Configuration Change: - Disable AppArmor profile by default (k3s_apparmor_profile: false) - K3s requires many system operations that are complex to whitelist correctly - Users can enable with detailed profile if needed for their environment This profile now supports full K3s functionality including: - Container lifecycle management - Network configuration (iptables/nftables) - Kernel module loading - Process tracing and monitoring - File locking for etcd and other components
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Enhances the K3s AppArmor profile with comprehensive permissions required for full K3s functionality, and disables it by default due to complexity.
Changes
AppArmor Profile Enhancements
Additional Capabilities:
sys_chroot- Container namespace operationssys_ptrace- Process tracing for containerddac_override- File access control overrideSubprocess Execution:
/usr/sbin/xtables-nft-multi- iptables/nftables management/usr/sbin/nft- nftables operations/usr/sbin/modprobe- Kernel module loadingExpanded File Access:
/proc/sys/**- Full system parameter access (was/proc/sys/net/**)/sys/**- Full sysfs access (was/sys/fs/cgroup/**)/var/lib/rancher/k3s/**rwixk- Addedkflag for file locking/etc/rancher/node/**- Node configuration access/run/**and/var/run/**- Runtime filesProcess Information:
/proc/*/stat,/proc/*/cpuset,/proc/*/mountinfo,/proc/*/cgroup/proc/sys/fs/pipe-max-size/etc/machine-id/sys/devices/virtual/dmi/id/product_uuidAdditional Permissions:
ptrace (read)- Required for containerd process managementConfiguration Change
k3s_apparmor_profiledefault fromtruetofalseRationale
K3s performs many low-level system operations that are difficult to whitelist correctly in AppArmor:
The enhanced profile supports these operations, but is disabled by default to prevent operational issues. Users with strict security requirements can enable it after testing in their environment.
Test Plan
🤖 Generated with Claude Code