Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 683646 - net-misc/openssh: openrc init script unconditionally generates potentially unnecessary keys
Summary: net-misc/openssh: openrc init script unconditionally generates potentially un...
Status: RESOLVED WONTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal enhancement
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-16 20:23 UTC by Michael Yagliyan
Modified: 2019-04-17 19:17 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Yagliyan 2019-04-16 20:23:19 UTC
The sshd init script runs `ssh-keygen -A` which generates a default set of keys in /etc/ssh/, but if I specifically have a configuration to not use certain keys, there's no clean way to prevent the init script from generating them anyway.

Another Linux distribution (Alpine Linux) addressed this issue by introducing an option in /etc/conf.d/sshd (they named it "SSHD_DISABLE_KEYGEN") to disable generating keys:
https://git.alpinelinux.org/aports/commit/?id=a439ca13411b044211fcb9a8137647ce4033b448

I think it's a good idea, and I think Gentoo should do the same.
Comment 1 Mike Gilbert gentoo-dev 2019-04-17 11:12:55 UTC
Sounds like pointless complexity to me. The keys are really only generated once per system.
Comment 2 Michael Yagliyan 2019-04-17 13:28:53 UTC
Not sure what you mean.  Are you saying the current logic of having keys be generated as part of the init script is pointless complexity, or are you saying that adding a configuration option to disable it would be pointless complexity?

FWIW I'd also accept just not generating the keys at all as part of the init script, but I'm not sure where they would be generated then -- as part of the ebuild maybe, if no keys exist?  I wonder how other distributions do it.

Or if it is decided that it *must* be in the init script as a safety check, then instead of adding a configuration option to disable it the logic could be changed to only generate the keys if there are none at all in /etc/ssh/.
Comment 3 Mike Gilbert gentoo-dev 2019-04-17 15:16:03 UTC
Adding a variable to optionally disable key generation in the init script is pointless complexity.

ssh-keygen -A will skip key creation if the keys are already there. It would only re-generate them if you remove the keys.
Comment 4 Michael Yagliyan 2019-04-17 15:39:28 UTC
I mean, you can argue that it's complexity you're unwilling to add, but I wouldn't call it pointless.  Gentoo is all about having fine control over one's system, and I don't want to use DSA or ECDSA keys.  So the point is to not have the system generating keys I won't use and don't want used accidentally.

If the keys are supposed to be generated once per system, then why would you have the init script generating keys it deems as missing on every stop and start of sshd?  Is that generally considered a good practice?  I'm not asking hypothetically, I'm actually not sure.

Also (though this is sort of beside the point), depending on one's security and threat models, you actually may want to generate these keys more often than just once.
Comment 5 Michael Yagliyan 2019-04-17 15:41:32 UTC
To clarify, ssh-keygen is regenerating the DSA and ECDSA keys I've deleted despite the presence of RSA and ED25519 keys.
Comment 6 Thomas Deutschmann (RETIRED) gentoo-dev 2019-04-17 19:17:40 UTC
The keys are generated as part of the init script because we have to support things like 'live' environments (see bug 675922 for a recent example).

We cannot determine which keys you are using. Next user could file same bug because his/her configuration uses different name/location and therefore doesn't need 'default' keys.

It's not really worth to talk about this given that there isn't really any IO involved when keys exists (which is the normal state) and file size is.. c'mon.

IF you, for some reason, don't want that keys and always delete because you use a configuration management tool, I recommend to roll your own runscript without ssh-keygen call as well.