Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 2178612

Summary: Add a SELinux boolean which allows qemu guest agent to write SSH keys
Product: Red Hat Enterprise Linux 9 Reporter: Andrej Krejcir <akrejcir>
Component: selinux-policyAssignee: Nikola Knazekova <nknazeko>
Status: CLOSED ERRATA QA Contact: Milos Malik <mmalik>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 9.2CC: demeng, lvrabec, mmalik, mtessun, nknazeko, ovasik, pvlasin, sgott, zpytela
Target Milestone: rcKeywords: Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: selinux-policy-38.1.9-1.el9_2 Doc Type: Enhancement
Doc Text:
Feature: Add SELinux boolean to allow qemu guest agent to manage SSH keys Reason: QEMU Guest Agent 5.2.0 added some new features including commands for managing guest ssh keys. Result: QEMU Guest Agent can manage ssh home directory by enabling the virt_qemu_ga_manage_ssh SELinux boolean.
Story Points: ---
Clone Of:
: 2179027 (view as bug list) Environment:
Last Closed: 2023-05-09 08:17:18 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2179027    

Description Andrej Krejcir 2023-03-15 12:30:04 UTC
Description of problem:

By default selinux blocks qemu guest agent from accessing SSH key files.
Currently there is a boolean to allow reading keys "virt_qemu_ga_read_ssh", but there is no boolean to allow writing keys.

Version-Release number of selected component (if applicable):
selinux-policy  38.1.8-1.el9 

How reproducible:
100%

Steps to Reproduce:
1. Start a VM with RHEL 9.2 guest image. I've used "rhel-guest-image-9.2-20230220.9.x86_64.qcow2"

virt-customize -a rhel-9.2.qcow2 \
  --ssh-inject root \
  --root-password password:pass123 \
  --uninstall cloud-init \
  --connect qemu:///system

virt-install --name test-vm \
  --vcpus 2 \
  --cpu host \
  --memory 2048 \
  --rng /dev/urandom \
  --disk rhel-9.2.qcow2 \
  --os-variant=rhel9.0 \
  --import \
  --boot uefi \
  --noautoconsole \
  --connect qemu:///system


2. Try to set SSH keys using qemu guest agent.
virsh -c qemu:///system set-user-sshkeys test-vm root --file ~/.ssh/id_rsa.pub

Fails with error message:
error: internal error: unable to execute QEMU agent command 'guest-ssh-add-authorized-keys': failed to write to '/root/.ssh/authorized_keys': Failed to create file “/root/.ssh/authorized_keys.SUES11”: Permission denied


Additional info:

Reading the keys fails similarly, if the "virt_qemu_ga_read_ssh" boolean is not set in the guest.

virsh -c qemu:///system get-user-sshkeys test-vm root

fails with:
error: internal error: unable to execute QEMU agent command 'guest-ssh-get-authorized-keys': failed to read '/root/.ssh/authorized_keys': Failed to open file “/root/.ssh/authorized_keys”: Permission denied


After the boolean is set,

virsh -c qemu:///system get-user-sshkeys test-vm root

Succeeds and prints the key.

Comment 21 errata-xmlrpc 2023-05-09 08:17:18 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (selinux-policy bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:2483