Skip to content

Commit 8bc62c9

Browse files
author
Derek
committed
fix: desktop template improvements
- Add AppArmor user namespace fix for Chrome/Brave/VSCode on Ubuntu 24.04 - Fix duplicate browser icons by removing com.google.Chrome.desktop and com.brave.Browser.desktop after installation - Improve avatar deployment with proper AccountsService config - Change LibreOffice default filter from true to false - Add handler for update-desktop-database
1 parent cba4f27 commit 8bc62c9

7 files changed

Lines changed: 108 additions & 4 deletions

File tree

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
---
2-
# Docker role handlers
2+
# Developer role handlers
33

44
- name: Inform user to logout
55
ansible.builtin.debug:
66
msg: |
77
IMPORTANT: Log out and back in for Docker group membership to take effect.
88
You can then run Docker commands without sudo.
9+
10+
- name: update desktop database
11+
ansible.builtin.command:
12+
cmd: update-desktop-database /usr/share/applications
13+
changed_when: true
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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

ansible/roles/developer/tasks/avatar.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,38 @@
1919
- branding_enabled | default(true)
2020
- avatar_file | default('') | length > 0
2121

22+
- name: Ensure AccountsService user config file exists
23+
ansible.builtin.file:
24+
path: "/var/lib/AccountsService/users/{{ actual_user }}"
25+
state: touch
26+
mode: '0600'
27+
modification_time: preserve
28+
access_time: preserve
29+
when:
30+
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
31+
- has_gnome | default(false)
32+
- branding_enabled | default(true)
33+
- avatar_file | default('') | length > 0
34+
35+
- name: Ensure [User] section exists in AccountsService config
36+
ansible.builtin.lineinfile:
37+
path: "/var/lib/AccountsService/users/{{ actual_user }}"
38+
regexp: '^\[User\]'
39+
line: "[User]"
40+
insertbefore: BOF
41+
mode: '0600'
42+
when:
43+
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
44+
- has_gnome | default(false)
45+
- branding_enabled | default(true)
46+
- avatar_file | default('') | length > 0
47+
2248
- name: Configure AccountsService to use custom avatar for current user
2349
ansible.builtin.lineinfile:
2450
path: "/var/lib/AccountsService/users/{{ actual_user }}"
2551
regexp: '^Icon='
2652
line: "Icon=/var/lib/AccountsService/icons/{{ actual_user }}"
27-
create: true
53+
insertafter: '^\[User\]'
2854
mode: '0600'
2955
when:
3056
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']

ansible/roles/developer/tasks/brave.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@
4949
state: present
5050
update_cache: true
5151

52+
# Remove duplicate desktop file that causes two icons in GNOME app menu
53+
# Brave packages com.brave.Browser.desktop for XDG portal but puts NoDisplay=true
54+
# at the end of the file (after Actions) where GNOME doesn't parse it
55+
- name: Remove duplicate Brave desktop file
56+
ansible.builtin.file:
57+
path: /usr/share/applications/com.brave.Browser.desktop
58+
state: absent
59+
notify: update desktop database
60+
5261
when: ansible_facts['distribution'] == 'Ubuntu'
5362

5463
# ============================================================================

ansible/roles/developer/tasks/chrome.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@
5252
state: present
5353
update_cache: true
5454

55+
# Remove duplicate desktop file that causes two icons in GNOME app menu
56+
# Chrome packages com.google.Chrome.desktop for XDG portal but puts NoDisplay=true
57+
# at the end of the file (after Actions) where GNOME doesn't parse it
58+
- name: Remove duplicate Chrome desktop file
59+
ansible.builtin.file:
60+
path: /usr/share/applications/com.google.Chrome.desktop
61+
state: absent
62+
notify: update desktop database
63+
5564
when: ansible_facts['distribution'] == 'Ubuntu'
5665

5766
# ============================================================================

ansible/roles/developer/tasks/desktop.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
state: present
1919
when:
2020
- ansible_facts['distribution'] == 'Fedora'
21-
- install_libreoffice | default(true)
21+
- install_libreoffice | default(false)
2222

2323
- name: Set default target to graphical (Fedora)
2424
ansible.builtin.command:
@@ -59,7 +59,7 @@
5959
state: present
6060
when:
6161
- ansible_facts['distribution'] == 'Ubuntu'
62-
- install_libreoffice | default(true)
62+
- install_libreoffice | default(false)
6363

6464
- name: Set default target to graphical (Ubuntu)
6565
ansible.builtin.command:

ansible/roles/developer/tasks/main.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@
7777
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
7878
- has_gnome | default(false)
7979

80+
# Fix AppArmor user namespace restriction (Ubuntu 24.04+)
81+
# This allows Chromium-based apps (Chrome, Brave, VSCode, Electron) to work
82+
# Uses global sysctl: kernel.apparmor_restrict_unprivileged_userns = 0
83+
- name: Fix AppArmor user namespace restriction for desktop apps
84+
ansible.builtin.include_tasks:
85+
file: apparmor_userns.yml
86+
apply:
87+
tags: ['security', 'apparmor']
88+
tags: ['security', 'apparmor']
89+
when: ansible_facts['distribution'] == 'Ubuntu'
90+
8091
- name: Configure OS repositories (mirrors, performance)
8192
ansible.builtin.include_tasks:
8293
file: repository.yml

0 commit comments

Comments
 (0)