hotfix(globalpatches) use OpenSSL to seed PRNG #1754
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note: this is a hotfix to be manually merged in both master and next
Summary
This changes the seeding technique for LuaJIT's PRNG from using a
combination of
time (s precision) + worker PID
to using OpenSSL'sRAND_bytes()
.Reasoning: in modern deployment setups such as application containers
and AWS AMIs (etc...), it is a common practise to deploy from a forked
VM, resulting in high probability of collision for PIDs at a seconds
precision. This could result in duplicated PRNG seeds, which is
ultimately the PRNG used to generate UUIDs in Kong, by the use of
lua-resty-jit-uuid.
Solution: in order to have a higher entropy when seeding LuaJIT's PRNG,
a proposed fix was to use
/dev/urandom
. This implementation howeveruses OpenSSL's
RAND_bytes()
, which has the advantage of returning anerror if the entropy is estimated to be too low. However, this won't
cover use cases where the VM has been forked, resulting in multiple VM
clones with a high entropy, but equal to that of the other clones. We
suggest that such deployment environment increase their cloned VMs
entropy before starting Kong.
Full changelog
RAND_bytes()
to read random bytesprecision, just in case
kong
lua shared dict. This dictionary's purpose isto hold essential data through Kong's lifecycle, and should eventually
only be used through
safe_set()
(an abstraction for this could beenvisaged later on, but is not the purpose of this patch)
consulted via the
/
endpoint. There is currently no way to re-seed allthe workers at once unless by sending
SIGHUP
, because only 1 workerwould be receiving such a request through the Kong Admin API.
debug.traceback()
calls to use lvl 2 of the call stack, toshow the actual caller of our patched
math.randomseed()
Issues resolved
Fix #1751 #1739 #1623