Bug 2755 - [PATCH] sshd_config: allow directories in AuthorizedKeysFile=
Summary: [PATCH] sshd_config: allow directories in AuthorizedKeysFile=
Status: NEW
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: sshd (show other bugs)
Version: 7.5p1
Hardware: All Linux
: P5 enhancement
Assignee: Assigned to nobody
URL: https://github.com/openssh/openssh-po...
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-07 19:09 AEST by Luca BRUNO
Modified: 2023-01-12 16:12 AEDT (History)
6 users (show)

See Also:


Attachments
sshd_config: allow directories in AuthorizedKeysFile= (2.46 KB, patch)
2017-08-07 19:09 AEST, Luca BRUNO
no flags Details | Diff
sshd_config: allow directories in AuthorizedKeysFile= (4.71 KB, patch)
2020-06-18 19:38 AEST, Luca BRUNO
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Luca BRUNO 2017-08-07 19:09:32 AEST
Created attachment 3028 [details]
sshd_config: allow directories in AuthorizedKeysFile=

This patch enhances AuthorizedKeysFile= to accept directory paths
in addition to single files.

It provides an include semantics similar to `.d` / `run-parts(8)`
approach, offering a consistent way for different entities to add
public keys to a given account without single-file contention.
Comment 1 Luca BRUNO 2017-08-22 00:30:28 AEST
Gentle ping for a review.
Comment 2 Luca BRUNO 2017-09-22 19:33:29 AEST
As I got no answers so far, this is another gentle ping for a review.
Comment 3 Damien Miller 2017-09-23 12:49:54 AEST
We're late in preparations for the 7.6 release. We'll look at this after
Comment 4 Luca BRUNO 2018-02-06 06:44:19 AEDT
I guess this fell off the radar, but I'm still considering having this feature implemented and I'll be happy to go through a patch review.
Comment 5 Jakub Jelen 2018-02-06 21:46:17 AEDT
You can always use "AuthorizedKeysCommand", which will point to your script that will pull the keys from all the files in specific directory.

I am not sure if this is needed. It would make it all more complex, though it would be a nice addition.
Comment 6 Dusty Mabe 2019-01-29 03:17:17 AEDT
Hi Damien,

This is another item we are looking at that we'd like to use for our new CoreOS efforts. We could use the AuthorizedKeysCommand workaround as Jakub suggested in the short term, but we do think it would be better in the long term if AuthorizedKeysFile= could accept directories.

Would it be possible to evaluate if this is likely or unlikely to be accepted long term?

Thanks!
Comment 7 Dusty Mabe 2019-01-29 03:17:47 AEDT
I forgot to add a link for context: https://github.com/coreos/fedora-coreos-tracker/issues/139
Comment 8 Erik Sjölund 2019-02-12 06:10:50 AEDT
Comment on attachment 3028 [details]
sshd_config: allow directories in AuthorizedKeysFile=

Comments about the patch authorized-keys-d.patch

It seems all file operations are done as the priviledged user.
It would be more secure to change identity to the login user before doing this.

An example of changing identity can be seen in the function user_key_allowed2() in the file ssh/auth2-pubkey.c at the line:

temporarily_use_uid(pw);
Comment 9 Erik Sjölund 2019-02-12 08:33:15 AEDT
Regarding the order of files from readdir():

It seems readdir() has no guaranty about order: 

https://stackoverflow.com/questions/8977441/does-readdir-guarantee-an-order

I think the order could influence how access is given by the server if multiple keys allow access in different ways.  Because of that it would make sense to define an order in which the files are read. For simplicity I would suggest alphabetical order.

Some limits are probably needed regarding the maximum number of authorized files and the maximum filename length. Maybe those numbers could be configurable.

The allowed set of characters in the filenames should probably also be limited.
To make the alphabetical ordering easy to understand one could limit the allowed characters to be for instance

a-z 

or maybe a bit more generous:

a-z
0-9
_
Comment 10 Luca BRUNO 2020-06-18 19:38:04 AEST
Created attachment 3411 [details]
sshd_config: allow directories in AuthorizedKeysFile=

Patch v2
Comment 11 Luca BRUNO 2020-06-18 19:40:18 AEST
Thanks for the feedback! I've rebased and updated the patch to a v2 based on the comments above, please take a look.

I'm also keeping it mirrored at https://github.com/openssh/openssh-portable/pull/70, in case that makes it easier for review.
Comment 12 Benjamin Gilbert 2023-01-12 16:12:26 AEDT
ssh-key-dir <https://github.com/coreos/ssh-key-dir> was implemented as a workaround for the missing ~/.ssh/authorized_keys.d support.  It runs as an AuthorizedKeysCommand and has been shipping in Fedora CoreOS by default for a couple years now.