Skip to content

Commit fff2cc2

Browse files
author
Derek
committed
fix: replace PAM GPU group approach with udev world-readable rule
1 parent d3cc620 commit fff2cc2

2 files changed

Lines changed: 48 additions & 44 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
# RDP Role - Handlers
3+
4+
- name: reload udev rules
5+
ansible.builtin.command: udevadm control --reload-rules
6+
changed_when: true
7+
8+
- name: trigger udev rules
9+
ansible.builtin.command: udevadm trigger --subsystem-match=drm
10+
changed_when: true
Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,40 @@
11
---
2-
# GPU Group Configuration for VirGL/virtio-gl Acceleration
3-
# Ensures all non-system users can access GPU render nodes for hardware acceleration
4-
# Without this, gnome-remote-desktop sessions fall back to software rendering (CPU-intensive)
2+
# GPU Access Configuration for VirGL/virtio-gl Acceleration
3+
# Uses udev rule to make /dev/dri/* world-readable (mode 0666).
4+
# Any process can access the GPU without needing render/video group membership.
5+
#
6+
# Conditional: only runs if /dev/dri exists (GPU present).
7+
# Works for both VirGL (VM) and physical GPUs (AMD/NVIDIA).
58

69
# ============================================================================
7-
# ENSURE GPU GROUPS EXIST
10+
# DETECT GPU PRESENCE
811
# ============================================================================
912

10-
- name: Ensure render group exists
11-
ansible.builtin.group:
12-
name: render
13-
state: present
14-
system: true
15-
when:
16-
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
17-
- has_gnome
18-
19-
- name: Ensure video group exists
20-
ansible.builtin.group:
21-
name: video
22-
state: present
23-
system: true
13+
- name: Check if /dev/dri exists (GPU present)
14+
ansible.builtin.stat:
15+
path: /dev/dri
16+
register: dri_device
2417
when:
2518
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
2619
- has_gnome
2720

2821
# ============================================================================
29-
# ADD ALL NON-SYSTEM USERS TO GPU GROUPS
22+
# UDEV RULE FOR WORLD-READABLE GPU DEVICES
3023
# ============================================================================
3124

32-
- name: Get list of non-system users (UID 1000-60000)
33-
ansible.builtin.shell:
34-
cmd: "awk -F: '$3 >= 1000 && $3 < 60000 && $1 != \"nobody\" {print $1}' /etc/passwd"
35-
register: non_system_users
36-
changed_when: false
37-
when:
38-
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
39-
- has_gnome
40-
41-
- name: Add non-system users to render and video groups
42-
ansible.builtin.user:
43-
name: "{{ item }}"
44-
groups:
45-
- render
46-
- video
47-
append: true
48-
loop: "{{ non_system_users.stdout_lines | default([]) }}"
25+
- name: Deploy udev rule for GPU device permissions
26+
ansible.builtin.copy:
27+
dest: /etc/udev/rules.d/99-gpu-open-access.rules
28+
mode: "0644"
29+
content: |
30+
# Allow all processes GPU access without render/video group membership
31+
# Managed by Ansible (dfe-developer rdp role)
32+
SUBSYSTEM=="drm", MODE="0666"
4933
when:
5034
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
5135
- has_gnome
52-
- non_system_users.stdout_lines is defined
53-
- non_system_users.stdout_lines | length > 0
36+
- dri_device.stat.exists | default(false)
37+
notify: reload udev rules
5438

5539
# ============================================================================
5640
# VERIFY GPU ACCESS
@@ -63,16 +47,26 @@
6347
when:
6448
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
6549
- has_gnome
50+
- dri_device.stat.exists | default(false)
6651

67-
- name: Display GPU group configuration status
52+
- name: Display GPU configuration status
6853
ansible.builtin.debug:
6954
msg: |
70-
GPU Groups configured for VirGL acceleration:
71-
- Users added to render/video groups: {{ non_system_users.stdout_lines | default([]) | join(', ') }}
72-
- Render device (/dev/dri/renderD128): {{ 'PRESENT' if render_device.stat.exists | default(false) else 'NOT FOUND (not a VM or no virtio-gl)' }}
55+
GPU access configured via udev rule (world-readable):
56+
- Rule: /etc/udev/rules.d/99-gpu-open-access.rules
57+
- /dev/dri: PRESENT
58+
- Render device (/dev/dri/renderD128): {{ 'PRESENT' if render_device.stat.exists | default(false) else 'NOT FOUND' }}
7359
74-
Note: Users must log out and back in for group changes to take effect.
75-
For RDP sessions, restart gnome-remote-desktop: systemctl restart gnome-remote-desktop
60+
All processes can access GPU devices without group membership.
61+
when:
62+
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
63+
- has_gnome
64+
- dri_device.stat.exists | default(false)
65+
66+
- name: Display GPU skipped status
67+
ansible.builtin.debug:
68+
msg: "No GPU detected (/dev/dri not present) - skipping GPU configuration"
7669
when:
7770
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
7871
- has_gnome
72+
- not (dri_device.stat.exists | default(false))

0 commit comments

Comments
 (0)