From 354147b7c7f49a19441655b9ebd1f788123c1b0e Mon Sep 17 00:00:00 2001 From: Paulo Matias Date: Mon, 22 Aug 2016 10:05:20 -0300 Subject: [PATCH] Clean final newline when distributing SSH keys When a pattern containing newlines is given to grep, it treats each line as a different pattern, and ORs these patterns together. The empty string always matches, therefore grep always returns a successful match. Change-Id: I881c90979995e060d24988438a710376e54331b8 Closes-Bug: #1615624 --- templates/nova-key-insert.sh.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/nova-key-insert.sh.j2 b/templates/nova-key-insert.sh.j2 index e02120a4..ac5555e8 100644 --- a/templates/nova-key-insert.sh.j2 +++ b/templates/nova-key-insert.sh.j2 @@ -19,7 +19,7 @@ fi {% for item in groups['nova_compute'] %} {% if hostvars[item]['nova_pubkey'] is defined %} -KEY="{{ hostvars[item]['nova_pubkey'] | b64decode }}" +KEY="{{ hostvars[item]['nova_pubkey'] | b64decode | trim }}" if ! grep -q -w "${KEY}" "${USER_HOME}/.ssh/authorized_keys"; then echo "${KEY}" | tee -a "${USER_HOME}/.ssh/authorized_keys" EXIT_CODE=3