Do not change permissions for system-wide folders with ssh authorized_keys#149
Do not change permissions for system-wide folders with ssh authorized_keys#149ask0n wants to merge 1 commit into
Conversation
|
Hi Anton, thanks for submitting this pull request! To accept it, we will need you to sign the cloud-init CLA. You can find instructions on how to do that in our HACKING doc. This looks like it's fixing https://bugs.launchpad.net/cloud-init/+bug/1839061, but I think the fix here is too simplistic. We do need to create |
|
Hi @OddBloke
Correct, this happens exactly on line https://github.com/canonical/cloud-init/blob/master/cloudinit/ssh_util.py#L260. Which totally makes sense. On that line cloud-init changes something which was created by cloud-init. but this will not help if you want to use your AMI within different accounts of configuration that doesn't have that "fix" in runcmd. |
|
Aha, thanks for the explanation! I'll want to double-check with people who have touched this code before (because there may be some deeper reason for doing this twice that neither of us know of), but I think it's worth you signing the CLA so that we can land this if they're happy. :-) |
|
Sure, CLA is signed, just got confirmation form Sally. |
|
Great, thanks! We unfortunately need you to do a manual step to prove that your GitHub and Launchpad accounts are owned by the same person. Look for "For first-time signers, or for existing contributors who have already signed the agreement in Launchpad" in https://cloudinit.readthedocs.io/en/latest/topics/hacking.html and follow the steps there. |
raharper
left a comment
There was a problem hiding this comment.
I've a suggested change.
|
I spent some time putting together a unittest for this: However, it seems since this PR was started, the multiple AuthorizationKeyFile PR #60 This means that cloud-init no longer runs ensure_dir on the AuthorizedKeysFile paths, only on default user's ~/.ssh; I've tested your scenario where we have a system-level test-user with a key in /etc/ssh/authorized_keys/ dir with mode 0755 and a test-user owned key file. AuthorizedKeyFiles On new instance, the Ubuntu user is created, the provided ssh_authorized_keys value is added to /home/ubuntu/.ssh/.authorized key file. No change is made to /etc/ssh/authorized_keys/ dir. test-user can ssh in. The default user cannot as sshd is now looking only in /etc/ssh/authorized_keys/%u in which there is no 'ubuntu' file with keys. The default user's ~/.ssh/authorized_keys file only has the public key from user-data. Test-user does not have a ~/.ssh dir at all. Would you be able to test your scenario out on an Ubuntu Focal image and confirm that you're desired use-case is function? If it is, then I think we can close this PR. |
|
Hello! Thank you for this proposed change to cloud-init. This pull request is now marked as stale as it has not seen any activity in 14 days. If no activity occurs within the next 7 days, this pull request will automatically close. If you are waiting for code review and you are seeing this message, apologies! Please reply, tagging powersj, and he will ensure that someone takes a look soon. (If the pull request is closed, please do feel free to reopen it if you wish to continue working on it.) |
|
i wonder if @github-actions bot should directly @ the person who opened the issue / pr in this ⬆️ message (in this case @ask0n ) |
cloud-init’s code by default makes a wrong assumption that all users using private
.sshfolder for authorized_keys.But
AuthorizedKeysFiledirective in sshd_config could be used to have a system-wide folder with user keys, which are managed by the configuration management systems, for example puppet.The idea is to have a configuration like
AuthorizedKeysFile /etc/ssh/authorized_keys/%uto prevent users manage their authorized_keys or to rootkit other users from user who had a sudo permissions on host.Folder
/etc/ssh/authorized_keys/and all files inside are owned by root because user shouldn’t be able to modify this files. When cloud-init change mode to 700 for such folder it breaks whole concept.For private
.sshfolder cloud-init sets permission on line https://github.com/canonical/cloud-init/blob/master/cloudinit/ssh_util.py#L260 there is no need to set this permission again for system-wide folder.Steps to reproduce:
test-usermkdir /etc/ssh/authorized_keys/chmod 755 /etc/ssh/authorized_keys/chown root /etc/ssh/authorized_keys//etc/ssh/sshd_configfile:test-userinto/etc/ssh/authorized_keys/test-user/etc/ssh/authorized_keys/but afterchmod 700usertest-userwill not be able to login into newly launched instance.