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

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