|
| 1 | +--- |
| 2 | +# AppArmor User Namespace Fix for Ubuntu 24.04+ |
| 3 | +# |
| 4 | +# Ubuntu 24.04 restricts unprivileged user namespace creation by default, |
| 5 | +# which breaks Chromium-based apps (Chrome, Brave, VSCode, Electron apps), |
| 6 | +# Flatpak, Snap sandboxes, and many other applications. |
| 7 | +# |
| 8 | +# Error: apparmor="DENIED" operation="userns_create" |
| 9 | +# |
| 10 | +# This task disables the restriction via sysctl. |
| 11 | +# Reference: https://ubuntu.com/blog/ubuntu-24-04-lts-and-unprivileged-user-namespace-restrictions |
| 12 | +# |
| 13 | +# Note: This is the recommended approach for developer workstations. |
| 14 | +# For servers, use per-application AppArmor profiles instead. |
| 15 | + |
| 16 | +- name: Check if AppArmor userns restriction sysctl exists |
| 17 | + ansible.builtin.stat: |
| 18 | + path: /proc/sys/kernel/apparmor_restrict_unprivileged_userns |
| 19 | + register: userns_sysctl |
| 20 | + |
| 21 | +- name: Disable AppArmor unprivileged user namespace restriction |
| 22 | + when: userns_sysctl.stat.exists |
| 23 | + block: |
| 24 | + - name: Create sysctl config to allow unprivileged user namespaces |
| 25 | + ansible.builtin.copy: |
| 26 | + content: | |
| 27 | + # Allow unprivileged user namespace creation |
| 28 | + # Required for Chromium-based apps (Chrome, Brave, VSCode, Electron), |
| 29 | + # Flatpak, Snap sandboxes, and many other applications. |
| 30 | + # |
| 31 | + # Ubuntu 24.04+ restricts this by default for security, but it breaks |
| 32 | + # too many legitimate desktop applications. |
| 33 | + # |
| 34 | + # Reference: https://ubuntu.com/blog/ubuntu-24-04-lts-and-unprivileged-user-namespace-restrictions |
| 35 | + kernel.apparmor_restrict_unprivileged_userns = 0 |
| 36 | + dest: /etc/sysctl.d/99-allow-unprivileged-userns.conf |
| 37 | + mode: '0644' |
| 38 | + register: sysctl_file |
| 39 | + |
| 40 | + - name: Apply sysctl setting immediately |
| 41 | + ansible.builtin.command: |
| 42 | + cmd: sysctl -p /etc/sysctl.d/99-allow-unprivileged-userns.conf |
| 43 | + when: sysctl_file.changed |
| 44 | + changed_when: true |
0 commit comments