Skip to content

Commit 6f98609

Browse files
committed
base_image: add SELinux relabeling for Fedora virt-builder images
Fedora guest images created on Debian hosts fail to boot because the filesystem lacks proper SELinux contexts. All binaries fail with exit code 127 (command not found) as SELinux blocks execution of files with unlabeled_t context. Add --selinux-relabel flag to virt-builder invocations when building Fedora images. This flag applies correct SELinux contexts during image creation, before first boot, ensuring all files have proper contexts when Fedora starts. The implementation uses separate tasks for Fedora and non-Fedora builds rather than conditional argv construction to avoid passing empty string arguments. This ensures the flag is only present for Fedora builds and cleanly omitted otherwise. Generated-by: Claude AI Signed-off-by: Daniel Gomez <[email protected]>
1 parent 88f94e7 commit 6f98609

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

playbooks/roles/base_image/tasks/base-image.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,30 @@
3232
dest: "{{ command_file.path }}"
3333
mode: "u=rw"
3434

35+
- name: Generate a new base image for {{ base_image_os_version }} (Fedora with SELinux relabeling)
36+
become: true
37+
become_method: ansible.builtin.sudo
38+
ansible.builtin.command:
39+
argv:
40+
- "virt-builder"
41+
- "{{ base_image_os_version }}"
42+
- "--arch"
43+
- "{{ ansible_machine }}"
44+
- "-o"
45+
- "{{ base_image_pathname }}"
46+
- "--size"
47+
- "{{ libvirt_image_size }}"
48+
- "--format"
49+
- "raw"
50+
- "--commands-from-file"
51+
- "{{ command_file.path }}"
52+
- "--selinux-relabel"
53+
creates: "{{ base_image_pathname }}"
54+
when:
55+
- libvirt_uri_system|bool
56+
- guestfs_fedora is defined
57+
- guestfs_fedora|bool
58+
3559
- name: Generate a new base image for {{ base_image_os_version }}
3660
become: true
3761
become_method: ansible.builtin.sudo
@@ -52,6 +76,29 @@
5276
creates: "{{ base_image_pathname }}"
5377
when:
5478
- libvirt_uri_system|bool
79+
- not (guestfs_fedora is defined and guestfs_fedora|bool)
80+
81+
- name: Generate a new base image for {{ base_image_os_version }} (Fedora with SELinux relabeling)
82+
ansible.builtin.command:
83+
argv:
84+
- "virt-builder"
85+
- "{{ base_image_os_version }}"
86+
- "--arch"
87+
- "{{ ansible_machine }}"
88+
- "-o"
89+
- "{{ base_image_pathname }}"
90+
- "--size"
91+
- "{{ libvirt_image_size }}"
92+
- "--format"
93+
- "raw"
94+
- "--commands-from-file"
95+
- "{{ command_file.path }}"
96+
- "--selinux-relabel"
97+
creates: "{{ base_image_pathname }}"
98+
when:
99+
- not libvirt_uri_system|bool
100+
- guestfs_fedora is defined
101+
- guestfs_fedora|bool
55102

56103
- name: Generate a new base image for {{ base_image_os_version }}
57104
ansible.builtin.command:
@@ -71,6 +118,7 @@
71118
creates: "{{ base_image_pathname }}"
72119
when:
73120
- not libvirt_uri_system|bool
121+
- not (guestfs_fedora is defined and guestfs_fedora|bool)
74122

75123
- name: Set proper ownership on base image for rcloud access (system libvirt)
76124
become: true

0 commit comments

Comments
 (0)