Blame SOURCES/bz1773890-fence_scsi-add-hash-key-value-support.patch

21d5fd
From baf8d524e89d7f6c716e8241a12d8135debadfcc Mon Sep 17 00:00:00 2001
21d5fd
From: Ondrej Famera <ondrej@famera.cz>
21d5fd
Date: Sun, 20 Oct 2019 20:13:40 +0900
21d5fd
Subject: [PATCH 1/4] add new method for autogenerating SCSI key
21d5fd
21d5fd
this methos generates second part of SCSI key based on hash of cluster
21d5fd
node name instead of currently used ID based approach which can brake if
21d5fd
the nodes get removed from cluster but whole cluster is not restarted
21d5fd
because the IDs changes. With hash approach hashes stays same.
21d5fd
Note that there is theoretical risk that hashes could colide.
21d5fd
---
21d5fd
 agents/scsi/fence_scsi.py          | 32 ++++++++++++++++++++++++++++--
21d5fd
 tests/data/metadata/fence_scsi.xml |  5 +++++
21d5fd
 2 files changed, 35 insertions(+), 2 deletions(-)
21d5fd
21d5fd
diff --git a/agents/scsi/fence_scsi.py b/agents/scsi/fence_scsi.py
21d5fd
index 5580e08b..4cc9b66c 100644
21d5fd
--- a/agents/scsi/fence_scsi.py
21d5fd
+++ b/agents/scsi/fence_scsi.py
21d5fd
@@ -202,9 +202,20 @@ def get_node_id(options):
21d5fd
 
21d5fd
 	return match.group(1) if match else fail_usage("Failed: unable to parse output of corosync-cmapctl or node does not exist")
21d5fd
 
21d5fd
+def get_node_hash(options):
21d5fd
+	try:
21d5fd
+		return hashlib.md5(options["--plug"].encode('ascii')).hexdigest()
21d5fd
+	except ValueError:
21d5fd
+		# FIPS requires usedforsecurity=False and might not be
21d5fd
+		# available on all distros: https://bugs.python.org/issue9216
21d5fd
+		return hashlib.md5(options["--plug"].encode('ascii'), usedforsecurity=False).hexdigest()
21d5fd
+
21d5fd
 
21d5fd
 def generate_key(options):
21d5fd
-	return "%.4s%.4d" % (get_cluster_id(options), int(get_node_id(options)))
21d5fd
+	if options["--key_value"] == "hash":
21d5fd
+		return "%.4s%.4s" % (get_cluster_id(options), get_node_hash(options))
21d5fd
+	else:
21d5fd
+		return "%.4s%.4d" % (get_cluster_id(options), int(get_node_id(options)))
21d5fd
 
21d5fd
 
21d5fd
 # save node key to file
21d5fd
@@ -375,6 +386,19 @@ def define_new_opts():
21d5fd
 		"default" : "@VGS_PATH@",
21d5fd
 		"order": 300
21d5fd
 	}
21d5fd
+	all_opt["key_value"] = {
21d5fd
+		"getopt" : ":",
21d5fd
+		"longopt" : "key_value",
21d5fd
+		"help" : "--key_value=<id|hash>          SCSI key node generation method",
21d5fd
+		"required" : "0",
21d5fd
+		"shortdesc" : "Method used to generate the SCSI key. \"id\" (default) \
21d5fd
+uses the positional ID from \"corosync-cmactl nodelist\" output which can get inconsistent \
21d5fd
+when nodes are removed from cluster without full cluster restart. \"hash\" uses part of hash \
21d5fd
+made out of node names which is not affected over time but there is theoretical chance that \
21d5fd
+hashes can collide as size of SCSI key is quite limited.",
21d5fd
+		"default" : "id",
21d5fd
+		"order": 300
21d5fd
+	}
21d5fd
 
21d5fd
 
21d5fd
 def scsi_check_get_options(options):
21d5fd
@@ -440,7 +464,7 @@ def main():
21d5fd
 
21d5fd
 	device_opt = ["no_login", "no_password", "devices", "nodename", "port",\
21d5fd
 	"no_port", "key", "aptpl", "fabric_fencing", "on_target", "corosync_cmap_path",\
21d5fd
-	"sg_persist_path", "sg_turs_path", "logfile", "vgs_path", "force_on"]
21d5fd
+	"sg_persist_path", "sg_turs_path", "logfile", "vgs_path", "force_on", "key_value"]
21d5fd
 
21d5fd
 	define_new_opts()
21d5fd
 
21d5fd
@@ -517,6 +541,10 @@ def main():
21d5fd
 	if options["--key"] == "0" or not options["--key"]:
21d5fd
 		fail_usage("Failed: key cannot be 0", stop_after_error)
21d5fd
 
21d5fd
+	if "--key_value" in options\
21d5fd
+	and (options["--key_value"] != "id" and options["--key_value"] != "hash"):
21d5fd
+		fail_usage("Failed: key_value has to be 'id' or 'hash'", stop_after_error)
21d5fd
+
21d5fd
 	if options["--action"] == "validate-all":
21d5fd
 		sys.exit(0)
21d5fd
 
21d5fd
diff --git a/tests/data/metadata/fence_scsi.xml b/tests/data/metadata/fence_scsi.xml
21d5fd
index b8cdabd1..56c6224d 100644
21d5fd
--- a/tests/data/metadata/fence_scsi.xml
21d5fd
+++ b/tests/data/metadata/fence_scsi.xml
21d5fd
@@ -105,6 +105,11 @@ When used as a watchdog device you can define e.g. retry=1, retry-sleep=2 and ve
21d5fd
 		<getopt mixed="--corosync-cmap-path=[path]" />
21d5fd
 		<shortdesc lang="en">Path to corosync-cmapctl binary</shortdesc>
21d5fd
 	</parameter>
21d5fd
+	<parameter name="key_value" unique="0" required="0">
21d5fd
+		<getopt mixed="--key_value=<id|hash>" />
21d5fd
+		<content type="string" default="id"  />
21d5fd
+		<shortdesc lang="en">Method used to generate the SCSI key. "id" (default) uses the positional ID from "corosync-cmactl nodelist" output which can get inconsistent when nodes are removed from cluster without full cluster restart. "hash" uses part of hash made out of node names which is not affected over time but there is theoretical chance that hashes can collide as size of SCSI key is quite limited.</shortdesc>
21d5fd
+	</parameter>
21d5fd
 	<parameter name="sg_persist_path" unique="0" required="0">
21d5fd
 		<getopt mixed="--sg_persist-path=[path]" />
21d5fd
 		<shortdesc lang="en">Path to sg_persist binary</shortdesc>
21d5fd
21d5fd
From ee7a5ea238b4b3312384e4cfd9edd392c311d17a Mon Sep 17 00:00:00 2001
21d5fd
From: Ondrej Famera <ondrej@famera.cz>
21d5fd
Date: Fri, 1 Nov 2019 13:16:58 +0900
21d5fd
Subject: [PATCH 2/4] rename 'key_value' to 'key-value' for manual invokation
21d5fd
21d5fd
---
21d5fd
 agents/scsi/fence_scsi.py          | 12 ++++++------
21d5fd
 tests/data/metadata/fence_scsi.xml |  2 +-
21d5fd
 2 files changed, 7 insertions(+), 7 deletions(-)
21d5fd
21d5fd
diff --git a/agents/scsi/fence_scsi.py b/agents/scsi/fence_scsi.py
21d5fd
index 4cc9b66c..7d515e16 100644
21d5fd
--- a/agents/scsi/fence_scsi.py
21d5fd
+++ b/agents/scsi/fence_scsi.py
21d5fd
@@ -212,7 +212,7 @@ def get_node_hash(options):
21d5fd
 
21d5fd
 
21d5fd
 def generate_key(options):
21d5fd
-	if options["--key_value"] == "hash":
21d5fd
+	if options["--key-value"] == "hash":
21d5fd
 		return "%.4s%.4s" % (get_cluster_id(options), get_node_hash(options))
21d5fd
 	else:
21d5fd
 		return "%.4s%.4d" % (get_cluster_id(options), int(get_node_id(options)))
21d5fd
@@ -388,8 +388,8 @@ def define_new_opts():
21d5fd
 	}
21d5fd
 	all_opt["key_value"] = {
21d5fd
 		"getopt" : ":",
21d5fd
-		"longopt" : "key_value",
21d5fd
-		"help" : "--key_value=<id|hash>          SCSI key node generation method",
21d5fd
+		"longopt" : "key-value",
21d5fd
+		"help" : "--key-value=<id|hash>          SCSI key node generation method",
21d5fd
 		"required" : "0",
21d5fd
 		"shortdesc" : "Method used to generate the SCSI key. \"id\" (default) \
21d5fd
 uses the positional ID from \"corosync-cmactl nodelist\" output which can get inconsistent \
21d5fd
@@ -541,9 +541,9 @@ def main():
21d5fd
 	if options["--key"] == "0" or not options["--key"]:
21d5fd
 		fail_usage("Failed: key cannot be 0", stop_after_error)
21d5fd
 
21d5fd
-	if "--key_value" in options\
21d5fd
-	and (options["--key_value"] != "id" and options["--key_value"] != "hash"):
21d5fd
-		fail_usage("Failed: key_value has to be 'id' or 'hash'", stop_after_error)
21d5fd
+	if "--key-value" in options\
21d5fd
+	and (options["--key-value"] != "id" and options["--key-value"] != "hash"):
21d5fd
+		fail_usage("Failed: key-value has to be 'id' or 'hash'", stop_after_error)
21d5fd
 
21d5fd
 	if options["--action"] == "validate-all":
21d5fd
 		sys.exit(0)
21d5fd
diff --git a/tests/data/metadata/fence_scsi.xml b/tests/data/metadata/fence_scsi.xml
21d5fd
index 56c6224d..72800688 100644
21d5fd
--- a/tests/data/metadata/fence_scsi.xml
21d5fd
+++ b/tests/data/metadata/fence_scsi.xml
21d5fd
@@ -106,7 +106,7 @@ When used as a watchdog device you can define e.g. retry=1, retry-sleep=2 and ve
21d5fd
 		<shortdesc lang="en">Path to corosync-cmapctl binary</shortdesc>
21d5fd
 	</parameter>
21d5fd
 	<parameter name="key_value" unique="0" required="0">
21d5fd
-		<getopt mixed="--key_value=<id|hash>" />
21d5fd
+		<getopt mixed="--key-value=<id|hash>" />
21d5fd
 		<content type="string" default="id"  />
21d5fd
 		<shortdesc lang="en">Method used to generate the SCSI key. "id" (default) uses the positional ID from "corosync-cmactl nodelist" output which can get inconsistent when nodes are removed from cluster without full cluster restart. "hash" uses part of hash made out of node names which is not affected over time but there is theoretical chance that hashes can collide as size of SCSI key is quite limited.</shortdesc>
21d5fd
 	</parameter>
21d5fd
21d5fd
From 58105710876bd6a2220f92ea37d621991d68bf4b Mon Sep 17 00:00:00 2001
21d5fd
From: Ondrej Famera <ondrej@famera.cz>
21d5fd
Date: Fri, 1 Nov 2019 13:20:17 +0900
21d5fd
Subject: [PATCH 3/4] expand longdesc of fence_scsi to describe the impact of
21d5fd
 key_value option
21d5fd
21d5fd
---
21d5fd
 agents/scsi/fence_scsi.py          | 6 +++++-
21d5fd
 tests/data/metadata/fence_scsi.xml | 2 +-
21d5fd
 2 files changed, 6 insertions(+), 2 deletions(-)
21d5fd
21d5fd
diff --git a/agents/scsi/fence_scsi.py b/agents/scsi/fence_scsi.py
21d5fd
index 7d515e16..4b2bfe20 100644
21d5fd
--- a/agents/scsi/fence_scsi.py
21d5fd
+++ b/agents/scsi/fence_scsi.py
21d5fd
@@ -493,7 +493,11 @@ def main():
21d5fd
 devices must support SCSI-3 persistent reservations (SPC-3 or greater) as \
21d5fd
 well as the \"preempt-and-abort\" subcommand.\nThe fence_scsi agent works by \
21d5fd
 having each node in the cluster register a unique key with the SCSI \
21d5fd
-device(s). Once registered, a single node will become the reservation holder \
21d5fd
+device(s). Reservation key is generated from \"node id\" (default) or from \
21d5fd
+\"node name hash\" (recommended) by adjusting \"key_value\" option. \
21d5fd
+Using hash is recommended to prevent issues when removing nodes \
21d5fd
+from cluster without full cluster restart. \
21d5fd
+Once registered, a single node will become the reservation holder \
21d5fd
 by creating a \"write exclusive, registrants only\" reservation on the \
21d5fd
 device(s). The result is that only registered nodes may write to the \
21d5fd
 device(s). When a node failure occurs, the fence_scsi agent will remove the \
21d5fd
diff --git a/tests/data/metadata/fence_scsi.xml b/tests/data/metadata/fence_scsi.xml
21d5fd
index 72800688..6f914823 100644
21d5fd
--- a/tests/data/metadata/fence_scsi.xml
21d5fd
+++ b/tests/data/metadata/fence_scsi.xml
21d5fd
@@ -1,7 +1,7 @@
21d5fd
 
21d5fd
 <resource-agent name="fence_scsi" shortdesc="Fence agent for SCSI persistent reservation" >
21d5fd
 <longdesc>fence_scsi is an I/O fencing agent that uses SCSI-3 persistent reservations to control access to shared storage devices. These devices must support SCSI-3 persistent reservations (SPC-3 or greater) as well as the "preempt-and-abort" subcommand.
21d5fd
-The fence_scsi agent works by having each node in the cluster register a unique key with the SCSI device(s). Once registered, a single node will become the reservation holder by creating a "write exclusive, registrants only" reservation on the device(s). The result is that only registered nodes may write to the device(s). When a node failure occurs, the fence_scsi agent will remove the key belonging to the failed node from the device(s). The failed node will no longer be able to write to the device(s). A manual reboot is required.
21d5fd
+The fence_scsi agent works by having each node in the cluster register a unique key with the SCSI device(s). Reservation key is generated from "node id" (default) or from "node name hash" (recommended) by adjusting "key_value" option. Using hash is recommended to prevent issues when removing nodes from cluster without full cluster restart. Once registered, a single node will become the reservation holder by creating a "write exclusive, registrants only" reservation on the device(s). The result is that only registered nodes may write to the device(s). When a node failure occurs, the fence_scsi agent will remove the key belonging to the failed node from the device(s). The failed node will no longer be able to write to the device(s). A manual reboot is required.
21d5fd
 
21d5fd
 When used as a watchdog device you can define e.g. retry=1, retry-sleep=2 and verbose=yes parameters in /etc/sysconfig/stonith if you have issues with it failing.</longdesc>
21d5fd
 <vendor-url></vendor-url>
21d5fd
21d5fd
From 6a73919ab70d76fcf4ce19b4fd00e182e41f33b5 Mon Sep 17 00:00:00 2001
21d5fd
From: Ondrej Famera <ondrej@famera.cz>
21d5fd
Date: Sat, 16 Nov 2019 17:03:42 +0900
21d5fd
Subject: [PATCH 4/4] emphasize the recommendation to use 'hash' over 'id'
21d5fd
21d5fd
---
21d5fd
 agents/scsi/fence_scsi.py          | 2 +-
21d5fd
 tests/data/metadata/fence_scsi.xml | 2 +-
21d5fd
 2 files changed, 2 insertions(+), 2 deletions(-)
21d5fd
21d5fd
diff --git a/agents/scsi/fence_scsi.py b/agents/scsi/fence_scsi.py
21d5fd
index 4b2bfe20..9b6af556 100644
21d5fd
--- a/agents/scsi/fence_scsi.py
21d5fd
+++ b/agents/scsi/fence_scsi.py
21d5fd
@@ -494,7 +494,7 @@ def main():
21d5fd
 well as the \"preempt-and-abort\" subcommand.\nThe fence_scsi agent works by \
21d5fd
 having each node in the cluster register a unique key with the SCSI \
21d5fd
 device(s). Reservation key is generated from \"node id\" (default) or from \
21d5fd
-\"node name hash\" (recommended) by adjusting \"key_value\" option. \
21d5fd
+\"node name hash\" (RECOMMENDED) by adjusting \"key_value\" option. \
21d5fd
 Using hash is recommended to prevent issues when removing nodes \
21d5fd
 from cluster without full cluster restart. \
21d5fd
 Once registered, a single node will become the reservation holder \
21d5fd
diff --git a/tests/data/metadata/fence_scsi.xml b/tests/data/metadata/fence_scsi.xml
21d5fd
index 6f914823..b840f3cf 100644
21d5fd
--- a/tests/data/metadata/fence_scsi.xml
21d5fd
+++ b/tests/data/metadata/fence_scsi.xml
21d5fd
@@ -1,7 +1,7 @@
21d5fd
 
21d5fd
 <resource-agent name="fence_scsi" shortdesc="Fence agent for SCSI persistent reservation" >
21d5fd
 <longdesc>fence_scsi is an I/O fencing agent that uses SCSI-3 persistent reservations to control access to shared storage devices. These devices must support SCSI-3 persistent reservations (SPC-3 or greater) as well as the "preempt-and-abort" subcommand.
21d5fd
-The fence_scsi agent works by having each node in the cluster register a unique key with the SCSI device(s). Reservation key is generated from "node id" (default) or from "node name hash" (recommended) by adjusting "key_value" option. Using hash is recommended to prevent issues when removing nodes from cluster without full cluster restart. Once registered, a single node will become the reservation holder by creating a "write exclusive, registrants only" reservation on the device(s). The result is that only registered nodes may write to the device(s). When a node failure occurs, the fence_scsi agent will remove the key belonging to the failed node from the device(s). The failed node will no longer be able to write to the device(s). A manual reboot is required.
21d5fd
+The fence_scsi agent works by having each node in the cluster register a unique key with the SCSI device(s). Reservation key is generated from "node id" (default) or from "node name hash" (RECOMMENDED) by adjusting "key_value" option. Using hash is recommended to prevent issues when removing nodes from cluster without full cluster restart. Once registered, a single node will become the reservation holder by creating a "write exclusive, registrants only" reservation on the device(s). The result is that only registered nodes may write to the device(s). When a node failure occurs, the fence_scsi agent will remove the key belonging to the failed node from the device(s). The failed node will no longer be able to write to the device(s). A manual reboot is required.
21d5fd
 
21d5fd
 When used as a watchdog device you can define e.g. retry=1, retry-sleep=2 and verbose=yes parameters in /etc/sysconfig/stonith if you have issues with it failing.</longdesc>
21d5fd
 <vendor-url></vendor-url>