From 6b53df95990bfac235313f24f80176948339b606 Mon Sep 17 00:00:00 2001 From: Philipp Moritz Date: Fri, 14 Aug 2020 00:10:31 -0700 Subject: [PATCH] Hash contents of SSH key instead of key path (#10103) --- python/ray/autoscaler/util.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/python/ray/autoscaler/util.py b/python/ray/autoscaler/util.py index f6e736e4b..2ae9af2de 100644 --- a/python/ray/autoscaler/util.py +++ b/python/ray/autoscaler/util.py @@ -103,8 +103,17 @@ def with_head_node_ip(cmds): def hash_launch_conf(node_conf, auth): hasher = hashlib.sha1() + # For hashing, we replace the path to the key with the + # key itself. This is to make sure the hashes are the + # same even if keys live at different locations on different + # machines. + full_auth = auth.copy() + for key_type in ["ssh_private_key", "ssh_public_key"]: + if key_type in auth: + with open(auth[key_type]) as key: + full_auth[key_type] = key.read() hasher.update( - json.dumps([node_conf, auth], sort_keys=True).encode("utf-8")) + json.dumps([node_conf, full_auth], sort_keys=True).encode("utf-8")) return hasher.hexdigest()