[NEW PATCH] [WIP] Use vdsm-tool to set libvirt password (via gerrit-bot)
Federico Simoncelli
fsimonce at redhat.com
Thu Sep 8 15:21:54 UTC 2011
New patch submitted by Federico Simoncelli (fsimonce at redhat.com)
You can review this change at: http://gerrit.usersys.redhat.com/921
commit cfd565a2657a96c798e4a823206ebd72fd169920
Author: Federico Simoncelli <fsimonce at redhat.com>
Date: Thu Sep 8 10:49:00 2011 +0000
[WIP] Use vdsm-tool to set libvirt password
Change-Id: I952fe699f0110d173f0941713560125654edeac5
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 0aeeda4..871d93b 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -69,25 +69,11 @@ make check
%post
/usr/sbin/vdsm-tool install-sudoers
+/usr/sbin/vdsm-tool install-libvirtpass
# vdsm is intentionally on by default.
/sbin/chkconfig --add vdsmd
-# create vdsm "secret" password for libvirt, if none exists
-pfile=/etc/pki/%{vdsm_name}/keys/libvirt_password
-if [[ ! -f "$pfile" ]];
-then
- umask 077
- echo -n shibboleth > "$pfile"
- /bin/chown vdsm:kvm "$pfile"
- new_pwd=1
-fi
-if ! /usr/sbin/sasldblistusers2 -f /etc/libvirt/passwd.db 2>- | \
- /bin/grep -q '^vdsm at rhevh\b' || [[ -n "$new_pwd" ]] ;
-then
- /usr/sbin/saslpasswd2 -p -a libvirt vdsm at rhevh < "$pfile"
-fi
-
%preun
if [ "$1" -eq 0 ]
then
diff --git a/vdsm/vdsm-tool b/vdsm/vdsm-tool
index 615fe25..6841fdf 100755
--- a/vdsm/vdsm-tool
+++ b/vdsm/vdsm-tool
@@ -22,10 +22,15 @@ import os
import sys
import re
import getopt
+import subprocess
SUDOERS_FILE = "/etc/sudoers"
SUDOERS_LOCK = "/etc/sudoers.tmp"
+LIBVIRTPASS_DEFAULT = "shibboleth"
+LIBVIRTPASS_FILE = "/etc/pki/vdsm/keys/libvirt_password"
+LIBVIRTAUTH_FILE = "/etc/libvirt/passwd.db"
+
PATTERN_INCLUDEDIR = "^#includedir\s+/etc/sudoers.d"
PATTERN_VDSMFILE = "^#include\s+/etc/sudoers.d/50_vdsm"
@@ -73,8 +78,27 @@ def install_sudoers():
"#include /etc/sudoers.d/50_vdsm\n")
sudoers_lock.activate = True
+def install_libvirtpass():
+ if os.path.exists(LIBVIRTPASS_FILE):
+ return
+
+ fd = open_lock(LIBVIRTPASS_FILE)
+ try:
+ os.write(fd, LIBVIRTPASS_DEFAULT)
+ finally:
+ os.close(fd)
+
+ saslpw = subprocess.Popen(["saslpasswd2", "-p", "-a", "libvirt",
+ "vdsm at rhevh"], stdin=subprocess.PIPE)
+ saslpw.communicate(LIBVIRTPASS_DEFAULT)
+
+ ret = saslpw.wait()
+ if (ret != 0):
+ raise RuntimeError("Unable to set libvirt password")
+
commands = {
'install-sudoers': (install_sudoers, "adjust sudoers file for vdsm"),
+ 'install-libvirtpass': (install_libvirtpass, "add a password to access libvirt"),
}
def usage_and_exit(exit_code):
More information about the vdsm-patches
mailing list