Blame SOURCES/bz2072421-1-all-agents-unify-ssl-parameters.patch

975d71
From 999f2f8b4dc7d258679daf8c3f13d9b317ff4435 Mon Sep 17 00:00:00 2001
975d71
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
975d71
Date: Thu, 7 Apr 2022 13:11:12 +0200
975d71
Subject: [PATCH] all agents: unify ssl parameters to avoid having to use --ssl
975d71
 when using --ssl-secure/--ssl-insecure for some agents
975d71
975d71
THIS MIGHT BREAK SETUPS USING fence_docker or fence_pve!
975d71
---
975d71
 agents/cisco_ucs/fence_cisco_ucs.py         |  9 +++++----
975d71
 agents/docker/fence_docker.py               |  9 ++++++---
975d71
 agents/rhevm/fence_rhevm.py                 |  8 ++++----
975d71
 agents/vmware_rest/fence_vmware_rest.py     |  8 ++++----
975d71
 agents/vmware_soap/fence_vmware_soap.py     |  2 +-
975d71
 agents/vmware_vcloud/fence_vmware_vcloud.py |  4 ++--
975d71
 agents/zvm/fence_zvmip.py                   |  8 +++++---
975d71
 lib/fencing.py.py                           |  6 ++++++
975d71
 tests/data/metadata/fence_docker.xml        |  4 ++--
975d71
 13 files changed, 64 insertions(+), 31 deletions(-)
975d71
975d71
diff --git a/agents/cisco_ucs/fence_cisco_ucs.py b/agents/cisco_ucs/fence_cisco_ucs.py
975d71
index 2280dbbc7..b85379a73 100644
975d71
--- a/agents/cisco_ucs/fence_cisco_ucs.py
975d71
+++ b/agents/cisco_ucs/fence_cisco_ucs.py
975d71
@@ -99,7 +99,7 @@ def get_list(conn, options):
975d71
 
975d71
 def send_command(opt, command, timeout):
975d71
 	## setup correct URL
975d71
-	if "--ssl" in opt or "--ssl-secure" in opt or "--ssl-insecure" in opt:
975d71
+	if "--ssl-secure" in opt or "--ssl-insecure" in opt:
975d71
 		url = "https:"
975d71
 	else:
975d71
 		url = "http:"
975d71
@@ -114,13 +114,14 @@ def send_command(opt, command, timeout):
975d71
 	conn.setopt(pycurl.POSTFIELDS, command.encode("ascii"))
975d71
 	conn.setopt(pycurl.WRITEFUNCTION, web_buffer.write)
975d71
 	conn.setopt(pycurl.TIMEOUT, timeout)
975d71
-	if "--ssl" in opt or "--ssl-secure" in opt:
975d71
+
975d71
+	if "--ssl-secure" in opt:
975d71
 		conn.setopt(pycurl.SSL_VERIFYPEER, 1)
975d71
 		conn.setopt(pycurl.SSL_VERIFYHOST, 2)
975d71
-
975d71
-	if "--ssl-insecure" in opt:
975d71
+	elif "--ssl-insecure" in opt:
975d71
 		conn.setopt(pycurl.SSL_VERIFYPEER, 0)
975d71
 		conn.setopt(pycurl.SSL_VERIFYHOST, 0)
975d71
+
975d71
 	conn.perform()
975d71
 	result = web_buffer.getvalue().decode()
975d71
 
975d71
diff --git a/agents/docker/fence_docker.py b/agents/docker/fence_docker.py
975d71
index fef87da86..004402518 100644
975d71
--- a/agents/docker/fence_docker.py
975d71
+++ b/agents/docker/fence_docker.py
975d71
@@ -43,7 +43,7 @@ def get_list(conn, options):
975d71
 
975d71
 
975d71
 def send_cmd(options, cmd, post = False):
975d71
-	url = "http%s://%s:%s/v%s/%s" % ("s" if "--ssl" in options else "", options["--ip"], options["--ipport"], options["--api-version"], cmd)
975d71
+	url = "http%s://%s:%s/v%s/%s" % ("s" if "--ssl-secure" in options or "--ssl-insecure" in options else "", options["--ip"], options["--ipport"], options["--api-version"], cmd)
975d71
 	conn = pycurl.Curl()
975d71
 	output_buffer = io.BytesIO()
975d71
 	if logging.getLogger().getEffectiveLevel() < logging.WARNING:
975d71
@@ -55,7 +55,8 @@ def send_cmd(options, cmd, post = False):
975d71
 		conn.setopt(pycurl.POSTFIELDSIZE, 0)
975d71
 	conn.setopt(pycurl.WRITEFUNCTION, output_buffer.write)
975d71
 	conn.setopt(pycurl.TIMEOUT, int(options["--shell-timeout"]))
975d71
-	if "--ssl" in options:
975d71
+
975d71
+	if "--ssl-secure" in options:
975d71
 		if not (set(("--tlscert", "--tlskey", "--tlscacert")) <= set(options)):
975d71
 			fail_usage("Failed. If --ssl option is used, You have to also \
975d71
 specify: --tlscert, --tlskey and --tlscacert")
975d71
@@ -63,7 +64,7 @@ def send_cmd(options, cmd, post = False):
975d71
 		conn.setopt(pycurl.SSLCERT, options["--tlscert"])
975d71
 		conn.setopt(pycurl.SSLKEY, options["--tlskey"])
975d71
 		conn.setopt(pycurl.CAINFO, options["--tlscacert"])
975d71
-	else:
975d71
+	elif "--ssl-insecure" in options:
975d71
 		conn.setopt(pycurl.SSL_VERIFYPEER, 0)
975d71
 		conn.setopt(pycurl.SSL_VERIFYHOST, 0)
975d71
 
975d71
@@ -136,6 +137,8 @@ def main():
975d71
 
975d71
 	device_opt = ["ipaddr", "no_password", "no_login", "port", "method", "web", "tlscert", "tlskey", "tlscacert", "ssl", "api_version"]
975d71
 
975d71
+	all_opt["ssl"]["default"] = "1"
975d71
+
975d71
 	options = check_input(device_opt, process_input(device_opt))
975d71
 
975d71
 	docs = { }
975d71
diff --git a/agents/rhevm/fence_rhevm.py b/agents/rhevm/fence_rhevm.py
975d71
index 25aecbe58..5f74d06f6 100644
975d71
--- a/agents/rhevm/fence_rhevm.py
975d71
+++ b/agents/rhevm/fence_rhevm.py
975d71
@@ -85,7 +85,7 @@ def send_command(opt, command, method="GET"):
975d71
 		logging.debug("auto-detected API version: " + opt["--api-version"])
975d71
 
975d71
 	## setup correct URL
975d71
-	if "--ssl" in opt or "--ssl-secure" in opt or "--ssl-insecure" in opt:
975d71
+	if "--ssl-secure" in opt or "--ssl-insecure" in opt:
975d71
 		url = "https:"
975d71
 	else:
975d71
 		url = "http:"
975d71
@@ -126,11 +126,11 @@ def send_command(opt, command, method="GET"):
975d71
 			conn.setopt(pycurl.COOKIEJAR, cookie_file)
975d71
 
975d71
 	conn.setopt(pycurl.TIMEOUT, int(opt["--shell-timeout"]))
975d71
-	if "--ssl" in opt or "--ssl-secure" in opt:
975d71
+
975d71
+	if "--ssl-secure" in opt:
975d71
 		conn.setopt(pycurl.SSL_VERIFYPEER, 1)
975d71
 		conn.setopt(pycurl.SSL_VERIFYHOST, 2)
975d71
-
975d71
-	if "--ssl-insecure" in opt:
975d71
+	elif "--ssl-insecure" in opt:
975d71
 		conn.setopt(pycurl.SSL_VERIFYPEER, 0)
975d71
 		conn.setopt(pycurl.SSL_VERIFYHOST, 0)
975d71
 
975d71
diff --git a/agents/vmware_rest/fence_vmware_rest.py b/agents/vmware_rest/fence_vmware_rest.py
975d71
index e49fd5663..4b884fc62 100644
975d71
--- a/agents/vmware_rest/fence_vmware_rest.py
975d71
+++ b/agents/vmware_rest/fence_vmware_rest.py
975d71
@@ -69,7 +69,7 @@ def connect(opt):
975d71
 	conn = pycurl.Curl()
975d71
 
975d71
 	## setup correct URL
975d71
-	if "--ssl" in opt or "--ssl-secure" in opt or "--ssl-insecure" in opt:
975d71
+	if "--ssl-secure" in opt or "--ssl-insecure" in opt:
975d71
 		conn.base_url = "https:"
975d71
 	else:
975d71
 		conn.base_url = "http:"
975d71
@@ -89,11 +89,11 @@ def connect(opt):
975d71
 	conn.setopt(pycurl.USERPWD, opt["--username"] + ":" + opt["--password"])
975d71
 
975d71
 	conn.setopt(pycurl.TIMEOUT, int(opt["--shell-timeout"]))
975d71
-	if "--ssl" in opt or "--ssl-secure" in opt:
975d71
+
975d71
+	if "--ssl-secure" in opt:
975d71
 		conn.setopt(pycurl.SSL_VERIFYPEER, 1)
975d71
 		conn.setopt(pycurl.SSL_VERIFYHOST, 2)
975d71
-
975d71
-	if "--ssl-insecure" in opt:
975d71
+	elif "--ssl-insecure" in opt:
975d71
 		conn.setopt(pycurl.SSL_VERIFYPEER, 0)
975d71
 		conn.setopt(pycurl.SSL_VERIFYHOST, 0)
975d71
 
975d71
diff --git a/agents/vmware_soap/fence_vmware_soap.py b/agents/vmware_soap/fence_vmware_soap.py
975d71
index 2cd45e0b3..51fb0f147 100644
975d71
--- a/agents/vmware_soap/fence_vmware_soap.py
975d71
+++ b/agents/vmware_soap/fence_vmware_soap.py
975d71
@@ -34,7 +34,7 @@ def send(self, request):
975d71
 def soap_login(options):
975d71
 	run_delay(options)
975d71
 
975d71
-	if "--ssl" in options or "--ssl-secure" in options or "--ssl-insecure" in options:
975d71
+	if "--ssl-secure" in options or "--ssl-insecure" in options:
975d71
 		if "--ssl-insecure" in options:
975d71
 			import ssl
975d71
 			import urllib3
975d71
diff --git a/agents/vmware_vcloud/fence_vmware_vcloud.py b/agents/vmware_vcloud/fence_vmware_vcloud.py
975d71
index 42372a83d..7626b82bb 100644
975d71
--- a/agents/vmware_vcloud/fence_vmware_vcloud.py
975d71
+++ b/agents/vmware_vcloud/fence_vmware_vcloud.py
975d71
@@ -60,7 +60,7 @@ def connect(opt):
975d71
         conn = pycurl.Curl()
975d71
 
975d71
         ## setup correct URL
975d71
-        if "--ssl" in opt or "--ssl-secure" in opt or "--ssl-insecure" in opt:
975d71
+        if "--ssl-secure" in opt or "--ssl-insecure" in opt:
975d71
                 conn.base_url = "https:"
975d71
         else:
975d71
                 conn.base_url = "http:"
975d71
@@ -76,7 +76,7 @@ def connect(opt):
975d71
         conn.setopt(pycurl.USERPWD, opt["--username"] + ":" + opt["--password"])
975d71
 
975d71
         conn.setopt(pycurl.TIMEOUT, int(opt["--shell-timeout"]))
975d71
-        if "--ssl" in opt or "--ssl-secure" in opt:
975d71
+        if "--ssl-secure" in opt:
975d71
                 conn.setopt(pycurl.SSL_VERIFYPEER, 1)
975d71
                 conn.setopt(pycurl.SSL_VERIFYHOST, 2)
975d71
         elif "--ssl-insecure" in opt:
975d71
diff --git a/agents/zvm/fence_zvmip.py b/agents/zvm/fence_zvmip.py
975d71
index e8f849eda..90ca95d45 100644
975d71
--- a/agents/zvm/fence_zvmip.py
975d71
+++ b/agents/zvm/fence_zvmip.py
975d71
@@ -26,7 +26,7 @@ def open_socket(options):
975d71
 	except socket.gaierror:
975d71
 		fail(EC_LOGIN_DENIED)
975d71
 
975d71
-	if "--ssl" in options:
975d71
+	if "--ssl-secure" in options or "--ssl-insecure" in options:
975d71
 		import ssl
975d71
 		sock = socket.socket()
975d71
 		sslcx = ssl.create_default_context()
975d71
@@ -132,7 +132,7 @@ def get_list_of_images(options, command, data_as_plug):
975d71
 	images = set()
975d71
 
975d71
 	if output_len > 3*INT4:
975d71
-		recvflag = socket.MSG_WAITALL if "--ssl" not in options else 0
975d71
+		recvflag = socket.MSG_WAITALL if "--ssl-secure" not in options and "--ssl-insecure" not in options else 0
975d71
 		array_len = struct.unpack("!i", conn.recv(INT4))[0]
975d71
 		data = ""
975d71
 
975d71
diff --git a/lib/fencing.py.py b/lib/fencing.py.py
975d71
index 696388d55..b746ede8b 100644
975d71
--- a/lib/fencing.py.py
975d71
+++ b/lib/fencing.py.py
975d71
@@ -789,6 +789,12 @@ def check_input(device_opt, opt, other_conditions = False):
975d71
 	if "--password-script" in options:
975d71
 		options["--password"] = os.popen(options["--password-script"]).read().rstrip()
975d71
 
975d71
+	if "--ssl-secure" in options or "--ssl-insecure" in options:
975d71
+		options["--ssl"] = ""
975d71
+
975d71
+	if "--ssl" in options and "--ssl-insecure" not in options:
975d71
+		options["--ssl-secure"] = ""
975d71
+
975d71
 	if os.environ.get("PCMK_service") == "pacemaker-fenced" and "--disable-timeout" not in options:
975d71
 		options["--disable-timeout"] = "1"
975d71
 
975d71
diff --git a/tests/data/metadata/fence_docker.xml b/tests/data/metadata/fence_docker.xml
975d71
index 723e72280..51c7c470a 100644
975d71
--- a/tests/data/metadata/fence_docker.xml
975d71
+++ b/tests/data/metadata/fence_docker.xml
975d71
@@ -20,7 +20,7 @@
975d71
 	</parameter>
975d71
 	<parameter name="ipport" unique="0" required="0">
975d71
 		<getopt mixed="-u, --ipport=[port]" />
975d71
-		<content type="integer" default="80"  />
975d71
+		<content type="integer" default="443"  />
975d71
 		<shortdesc lang="en">TCP/UDP port to use for connection with device</shortdesc>
975d71
 	</parameter>
975d71
 	<parameter name="method" unique="0" required="0">
975d71
@@ -43,7 +43,7 @@
975d71
 	</parameter>
975d71
 	<parameter name="ssl" unique="0" required="0">
975d71
 		<getopt mixed="-z, --ssl" />
975d71
-		<content type="boolean"  />
975d71
+		<content type="boolean" default="1"  />
975d71
 		<shortdesc lang="en">Use SSL connection with verifying certificate</shortdesc>
975d71
 	</parameter>
975d71
 	<parameter name="ssl_insecure" unique="0" required="0">