Bug 1008589

Summary: qemu+ssh fails if bashrc contains banners
Product: [Community] Virtualization Tools Reporter: Jonathan Lebon <jlebon>
Component: libvirtAssignee: Libvirt Maintainers <libvirt-maint>
Status: CLOSED WONTFIX QA Contact:
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: unspecifiedCC: acathrow, eblake, pmoore
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-09-16 16:30:13 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:

Description Jonathan Lebon 2013-09-16 16:17:38 UTC
Description of problem:

If a user's bashrc contains print statements, libvirt cannot cope with it (it tries to interpret them as libvirtd messages maybe?).

Version-Release number of selected component (if applicable):

libvirt-1.0.5.5-1.fc19.x86_64

How reproducible:

Every time

Steps to Reproduce:
1. add 'echo this is text' to user ~/.bashrc file
2. virsh -c 'qemu+ssh://localhost/system' list --all

Actual results:

$ virsh -c 'qemu+ssh://localhost/system' list --all
user@localhost's password:
error: failed to connect to the hypervisor
error: no valid connection
error: packet 1952999791 bytes received from server too large, want 4194304
user@localhost's password: 
error: Failed to reconnect to the hypervisor

Expected results:
(what happens if you do not have the echo statement)

$ virsh -c 'qemu+ssh://localhost/system' list --all
user@localhost's password: 
 Id    Name                           State
----------------------------------------------------
 2     MyDomain                       running

Comment 1 Eric Blake 2013-09-16 16:30:13 UTC
In general, ALL ssh operations are liable to fail if you have a banner.  The bug is on your end for having a noisy remote shell login, and libvirt can't be taught how to work around every whim of every person's banner.  Instead, you should follow the usual conventions of fixing your .bashrc to output a banner ONLY for an interactive login, and to be silent for the case of remote command execution that does not require an interactive shell.

Comment 2 Daniel Berrangé 2013-09-16 16:31:27 UTC
(In reply to Jonathan Lebon from comment #0)
> Description of problem:
> 
> If a user's bashrc contains print statements, libvirt cannot cope with it
> (it tries to interpret them as libvirtd messages maybe?).

When libvirt connects over SSH, the stdin + stdout of the SSH connection are used to transport the RPC protocol. Anything else printed to stdout will of course corrupt the protocol.

> Steps to Reproduce:
> 1. add 'echo this is text' to user ~/.bashrc file

Really do not do this. If you want to a banner displayed to people at login time, the /etc/motd file can be used. This correctly displays the message on interactive shells, without corrupting data on non-interactive sessions as used by libvirt.

$ cat /etc/motd 
I am the motd
$ ssh localhost 
Last login: Mon Sep 16 17:26:51 2013 from localhost
I am the motd
# logout
Connection to localhost closed.
$ ssh localhost /bin/date
Mon 16 Sep 17:30:45 BST 2013

Comment 3 Eric Blake 2013-09-16 16:46:15 UTC
You don't necessarily have to use /etc/motd (since that gives the same banners to all users); for any per-user stuff, just be sure to use the same principles as what system profile does for /etc/motd. when writing your .bashrc:

# Limit banner to interactive logins
case $- in *i*)
  your noisy banner here ;;
esac