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
utils: use SystemRandom when generating random password. #204
Conversation
As noticed by Seth Arnold, non-deterministic SystemRandom should be used when creating security sensitive random strings. LP: #1860795
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just as a comment... there is a long string of issues using random in early boot.
- https://bugs.launchpad.net/cloud-images/+bug/1584147
- https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1780062
- https://bugs.launchpad.net/ubuntu/+source/cloud-init/+bug/1727358
summary: be careful with random. Especially if you're attempting to get "Better random".
Yes this will cause to block and wait on randomness. However, RANDOM in setting user passwords is not used by default in most cloud types. And recent kernels have more realiable earlier access to devrandom pools, and we try to push our cloud partners to provide hwrng exposed to the virtual machines too. At the moment, I'd rather boot slowly / fail to boot, than to provision machines with quickly crackable passwords or those that provide a side-channel to establish the machine seed remotely. |
|
perhaps we should also add a warning to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be using the secrets module when it's available?
However, RANDOM in setting user passwords is not used by default in most cloud types.
Azure doesn't do it by default, but password auth is a first-class option in their UI. I'd like us to be sure that we aren't going to see enormous differences in boot time there before we release this.
| @@ -397,9 +397,10 @@ def translate_bool(val, addons=None): | |||
|
|
|||
|
|
|||
| def rand_str(strlen=32, select_from=None): | |||
| r = random.SystemRandom() | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SystemRandom docs say that it is "Not available on all systems." Specifically, it is not available on systems where os.urandom would raise NotImplementedError:
On a Unix-like system, random bytes are read from the /dev/urandom device. If the /dev/urandom device is not available or not readable, the NotImplementedError exception is raised.
cloud-init is used on BSD systems, so we cannot assume that we are running on top of the Linux kernel. I don't know the state of urandom on BSDs, but I would like to know that we won't be breaking behaviour there.
|
Use CVE-2020-8631. Thanks |
most Unix systems these days symlink |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're going to land this and perform testing on (a) a KVM instance with user-data that uses this code path, and (b) an Azure instance with a fabric-generated password. If (a) indicates issues, we'll update the docs to indicate that people may see blocking if they use this path. If (b) indicates issues, we'll dig into the specifics.
As noticed by Seth Arnold, non-deterministic SystemRandom should be used when creating security sensitive random strings.
As noticed by Seth Arnold, non-deterministic SystemRandom should be
used when creating security-sensitive random strings.
LP: #1860795