Skip to content
This repository was archived by the owner on Mar 22, 2018. It is now read-only.

Conversation

@mbarnes
Copy link
Contributor

@mbarnes mbarnes commented Mar 29, 2016

This is part of the problem I was having with my cloud-init testing.

Forgot to add root's own public key to /root/.ssh/authorized_keys.

Forgot to add root's own public key to /root/.ssh/authorized_keys.
with open(keyfile + '.pub') as inpf:
with open(authorized_keys, 'a') as outf:
outf.writelines(inpf.readlines())
os.chmod(authorized_keys, stat.S_IRUSR | stat.S_IWUSR)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should set the mode as part of the open call so it's atomic. Unfortunately AFAIK Python makes this annoying, you have to drop to os.open I think.

Funny enough I fixed this in Homu recently in servo/homu#18

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Will fix in the morning.

@ashcrow ashcrow added the bug label Mar 30, 2016
Use os.open() so we can specify permissions if creating the output file.
@mbarnes
Copy link
Contributor Author

mbarnes commented Mar 30, 2016

⬆️ fixup

authorized_keys = '/root/.ssh/authorized_keys'
with open(keyfile + '.pub') as inpf:
with open(authorized_keys, 'a') as outf:
with os.open(authorized_keys, os.O_APPEND,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe os.open(...) will end up giving you an int as a response and won't work with the with statement by itself. Maybe wrap this with os.fdopen()?

In [11]: type(os.open('/tmp/testing', os.O_APPEND))
Out[11]: int

In [12]: type(open('/tmp/testing', 'a'))
Out[12]: _io.TextIOWrapper

In [13]: with os.fdopen(os.open('/tmp/testing', os.O_APPEND)) as f:
   ....:     print(type(f))
   ....:     
<class '_io.TextIOWrapper'>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you're right. Must've botched something in my testing to not catch that...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I forgot to disconnect/reconnect the ISO image with that change. D'oh!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's just being human 😆

@mbarnes
Copy link
Contributor Author

mbarnes commented Mar 30, 2016

⬆️ Third time's a charm?

'-t', 'rsa', '-f', keyfile])
except FileNotFoundError:
print('Missing /usr/bin/ssh-keygen', file=sys.stderr)
raise
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Not worth fixing in this PR but I'm OCD about raise providing a class and at least one arg à la:

raise Exception('Missing /usr/bin/ssh-keygen')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to re-raise the current exception, but maybe I'm doing it wrong?

But it's really just to signal to cloud-init that the script failed so cloud-init can swallow all the error details and log something generic and not very helpful. 😡

@ashcrow
Copy link
Collaborator

ashcrow commented Mar 30, 2016

LGTM

@cgwalters-bot try

@cgwalters-bot
Copy link

⌛ Trying commit 147d29d with merge 91cb0ba...

cgwalters-bot pushed a commit that referenced this pull request Mar 30, 2016
Forgot to add root's own public key to /root/.ssh/authorized_keys.

Closes: #74
Approved by: <try>
@cgwalters-bot
Copy link

☀️ Test successful - travis
State: approved= try=True

@ashcrow
Copy link
Collaborator

ashcrow commented Mar 30, 2016

@cgwalters-bot r+

@cgwalters-bot
Copy link

📌 Commit 147d29d has been approved by ashcrow

@cgwalters-bot
Copy link

⌛ Testing commit 147d29d with merge f041ece...

@cgwalters-bot
Copy link

☀️ Test successful - travis
Approved by: ashcrow
Pushing f041ece to master...

@cgwalters-bot cgwalters-bot changed the title cloud-init: Fix SSH authentication [merged] cloud-init: Fix SSH authentication Mar 30, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants