Skip to content
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

Merged
merged 1 commit into from
Apr 1, 2019

Conversation

evgeni
Copy link
Member

@evgeni evgeni commented Apr 1, 2019

also strip any possibly present newlines from the key before writing

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)
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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)
Copy link
Member

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.

@evgeni evgeni merged commit 3568cd7 into master Apr 1, 2019
evgeni added a commit that referenced this pull request Apr 1, 2019
* Ensure REX keys are written with proper newlines (BZ #1693136, #304)
* Document how to run bootstrap.py on EL8 (#303)
@evgeni evgeni deleted the bz1693136 branch April 1, 2019 13:18
@evgeni evgeni mentioned this pull request Apr 1, 2019
evgeni added a commit that referenced this pull request Apr 1, 2019
* Ensure REX keys are written with proper newlines (BZ #1693136, #304)
* Document how to run bootstrap.py on EL8 (#303)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants