-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BZ #1693136 - always add a newline before writing the REX key #304
Conversation
also strip any possibly present newlines from the key before writing
@@ -707,6 +708,7 @@ def install_ssh_key_from_string(foreman_ssh_key): | |||
print_generic("Foreman's SSH key already present in %s" % options.remote_exec_authpath) | |||
return | |||
output = os.fdopen(os.open(options.remote_exec_authpath, os.O_WRONLY | os.O_CREAT, OWNER_ONLY_FILE), 'a') | |||
output.write("\n") | |||
output.write(foreman_ssh_key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this now need a newline at the end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, the file will just not have an ending \n
, which I think is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I've seen some tools fail on that so perhaps better to be safe than sorry?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OpenSSH is fine with this. And adding a newline here would technically add two newslines between each key we added. Or we'd need to read the whole file, strip()
it, and then add stuff, which I'd like to avoid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's already likely the user has a line ending so you might be injecting additional newlines anyway. But I'm fine either way.
@@ -707,6 +708,7 @@ def install_ssh_key_from_string(foreman_ssh_key): | |||
print_generic("Foreman's SSH key already present in %s" % options.remote_exec_authpath) | |||
return | |||
output = os.fdopen(os.open(options.remote_exec_authpath, os.O_WRONLY | os.O_CREAT, OWNER_ONLY_FILE), 'a') | |||
output.write("\n") | |||
output.write(foreman_ssh_key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's already likely the user has a line ending so you might be injecting additional newlines anyway. But I'm fine either way.
also strip any possibly present newlines from the key before writing