6d3351
From 3ffd39767ed4dec1233f91744184c518396acc8c Mon Sep 17 00:00:00 2001
6d3351
Message-Id: <3ffd39767ed4dec1233f91744184c518396acc8c@dist-git>
6d3351
From: John Ferlan <jferlan@redhat.com>
6d3351
Date: Thu, 25 May 2017 12:59:12 -0400
6d3351
Subject: [PATCH] virsh: Track when create pkttyagent
6d3351
6d3351
https://bugzilla.redhat.com/show_bug.cgi?id=1374126
6d3351
6d3351
Due to how the processing for authentication using polkit works, the
6d3351
virshConnect code must first "attempt" an virConnectOpenAuth and then
6d3351
check for a "special" return error code VIR_ERR_AUTH_UNAVAILABLE in
6d3351
order to attempt to "retry" the authentication after performing a creation
6d3351
of a pkttyagent to handle the challenge/response for the client.
6d3351
6d3351
However, if pkttyagent creation is not possible for the authentication
6d3351
being attempted (such as perhaps a "qemu+ssh://someuser@localhost/system"),
6d3351
then the same failure pattern would be returned and another attempt to
6d3351
create a pkttyagent would be done. This would continue "forever" until
6d3351
someone forced quit (e.g. ctrl-c) from virsh as the 'authfail' was not
6d3351
incremented when creating the pkttyagent.
6d3351
6d3351
So add a 'agentCreated' boolean to track if we've attempted to create the
6d3351
agent at least once and force a failure if that creation returned the same
6d3351
error pattern.
6d3351
6d3351
This resolves a possible never ending loop and will generate an error:
6d3351
6d3351
error: failed to connect to the hypervisor
6d3351
error: authentication unavailable: no polkit agent available to authenticate action 'org.libvirt.unix.manage'
6d3351
6d3351
NB: If the authentication was for a sufficiently privileged client, such as
6d3351
qemu+ssh://root@localhost/system, then the remoteDispatchAuthList "allows"
6d3351
the authentication to use libvirt since @callerUid would be 0.
6d3351
6d3351
(cherry picked from commit 2453501fc82d3b247affb6c9054dc65bf2f669b3)
6d3351
Signed-off-by: John Ferlan <jferlan@redhat.com>
6d3351
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
6d3351
---
6d3351
 tools/virsh.c | 5 ++++-
6d3351
 1 file changed, 4 insertions(+), 1 deletion(-)
6d3351
6d3351
diff --git a/tools/virsh.c b/tools/virsh.c
6d3351
index 7eb51ab7d..0b4365b0f 100644
6d3351
--- a/tools/virsh.c
6d3351
+++ b/tools/virsh.c
6d3351
@@ -145,6 +145,7 @@ virshConnect(vshControl *ctl, const char *uri, bool readonly)
6d3351
     bool keepalive_forced = false;
6d3351
     virPolkitAgentPtr pkagent = NULL;
6d3351
     int authfail = 0;
6d3351
+    bool agentCreated = false;
6d3351
 
6d3351
     if (ctl->keepalive_interval >= 0) {
6d3351
         interval = ctl->keepalive_interval;
6d3351
@@ -166,10 +167,12 @@ virshConnect(vshControl *ctl, const char *uri, bool readonly)
6d3351
             goto cleanup;
6d3351
 
6d3351
         err = virGetLastError();
6d3351
-        if (err && err->domain == VIR_FROM_POLKIT &&
6d3351
+        if (!agentCreated &&
6d3351
+            err && err->domain == VIR_FROM_POLKIT &&
6d3351
             err->code == VIR_ERR_AUTH_UNAVAILABLE) {
6d3351
             if (!pkagent && !(pkagent = virPolkitAgentCreate()))
6d3351
                 goto cleanup;
6d3351
+            agentCreated = true;
6d3351
         } else if (err && err->domain == VIR_FROM_POLKIT &&
6d3351
                    err->code == VIR_ERR_AUTH_FAILED) {
6d3351
             authfail++;
6d3351
-- 
6d3351
2.13.0
6d3351