Skip to content

Seed random on init#2461

Merged
estesp merged 3 commits intocontainerd:masterfrom
dmcgowan:seed_rand
Jul 13, 2018
Merged

Seed random on init#2461
estesp merged 3 commits intocontainerd:masterfrom
dmcgowan:seed_rand

Conversation

@dmcgowan
Copy link
Copy Markdown
Member

We switched to using math/rand for generating IDs but currently it is only being seeded as a side effect of importing stringid from docker/docker. For ctr I don't think anything will be seeding random. By default, without seeding math/rand at all, all global calls will use a rand seeded by 1.

Signed-off-by: Derek McGowan <[email protected]>
@dmcgowan dmcgowan force-pushed the seed_rand branch 2 times, most recently from 108ab14 to 2e37b07 Compare July 12, 2018 23:37
@codecov-io
Copy link
Copy Markdown

Codecov Report

Merging #2461 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2461   +/-   ##
=======================================
  Coverage   45.04%   45.04%           
=======================================
  Files          92       92           
  Lines        9424     9424           
=======================================
  Hits         4245     4245           
  Misses       4496     4496           
  Partials      683      683
Flag Coverage Δ
#linux 49.29% <ø> (ø) ⬆️
#windows 41.33% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cb4bf20...1c6929c. Read the comment docs.

@ehazlett
Copy link
Copy Markdown
Member

Code LGTM. Do we want to add a note in the docs that specifies a hard minimum kernel of 3.17? We recommend 4.x in general and 3.18 for btrfs which seems fine to me but I wasn't sure if we wanted to be specific.

@crosbymichael
Copy link
Copy Markdown
Member

LGTM

@dmcgowan
Copy link
Copy Markdown
Member Author

Do we want to add a note in the docs that specifies a hard minimum kernel of 3.17? We recommend 4.x in general and 3.18 for btrfs which seems fine to me but I wasn't sure if we wanted to be specific.

The hard requirement being for the getrandom syscall? I am not too concerned with it failing as UnixNano() can provide sufficient entropy. The additional random is just to fill in more entropy when it can.

@ehazlett
Copy link
Copy Markdown
Member

LGTM

Copy link
Copy Markdown
Member

@estesp estesp left a comment

Choose a reason for hiding this comment

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

LGTM

@estesp estesp merged commit cef05f1 into containerd:master Jul 13, 2018
Comment thread pkg/seed/seed.go
@@ -0,0 +1,38 @@
/*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this belongs in pkg, as it is not really reusable.

Copy link
Copy Markdown
Member Author

@dmcgowan dmcgowan Jul 17, 2018

Choose a reason for hiding this comment

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

not really reusable

Or not useful? After some more discussion might update this package to seed on init and import where seeding might be necessary. Seeding is kind of a complicated issue because it has a global effect and normally that burden is put on importers. Maybe we should just fully encapsulate the non-crypto rand and have a package level seed. Not sure, ideas welcome to make this more useful and non-opinionated.

@stevvooe
Copy link
Copy Markdown
Member

Was crypto/rand a bottleneck or is this just more support broken systems?

@dmcgowan
Copy link
Copy Markdown
Member Author

Was crypto/rand a bottleneck or is this just more support broken systems?

I am not sure I fully understand what causes a system to have no entropy. Whether a system problem or not, the lack of entropy was causing containerd to hang on startup even though no entropy is required and no cryptographic operation is required to startup. The low entry environments will still have issues pulling images, but those can hang/block until it has enough entropy to proceed.

@hairyhenderson
Copy link
Copy Markdown
Contributor

Was crypto/rand a bottleneck or is this just more support broken systems?

There are plenty of broken systems that would probably run into this (i.e. VMs where the hypervisor is misconfigured and the RNG isn't being properly exposed), but there are also plenty of properly-working systems where this is an issue - especially in the low-cost/embedded bare-metal space.

I am not sure I fully understand what causes a system to have no entropy.

The most common cause for me and my particular use-case is that the system has just booted and has no HWRNG, so it takes a few seconds for the kernel's other entropy-gathering mechanisms to do anything, and 2+ minutes to gather enough entropy for the CRNG to be initialized.

See #2451 and linked issues in LinuxKit for more details.

@dmcgowan dmcgowan deleted the seed_rand branch September 10, 2019 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants