getPersistentNetKeys dumps the node's unprotected privkey in plaintext into the specified --data-dir. When the node is restarted, it attempts to reload the private key from disk. By default, the private key is stored in the --data-dir which on my system (MacOs) resolves to /Users/tintin/Library/Application Support/Nimbus/BeaconNode/privkey.protobuf. The file is written using nim's writeFile() which depending on the system's setting for umask may create world-readable files (e.g. MacOS default: umask 22 -> writeFile() creates a file with 644 (rw-r--r--)).
Under normal circumstances, however, the folder permissions (/User/tintin/Library/...) restrict access to a world-readable file in the subfolder to the currently logged in user.
However, the private key might be exposed on systems where the default is not a directory in userhome or the --data-dir was overridden to be a shared folder. Now, this is arguably insecure on its own but it is nevertheless recommended, to add another layer of protection for the privkey material to prevent it from accidentally being leaked.
consider enforcing strict folder permission (+u+g-o) for the datadir (if it does not exist yet) (not world-readable)
consider enforcing strict file permissions for privkey material (when creating it) (note: a potential race between writeFile() and setFilepermissions())
consider encrypting cached key material with a user unlock/or application specific key. Scenario: other process running as the user accesses privkey (generally hard to prevent this scenario and may arguably always be bypassed unless some level of interaction is required)
check and warn if file permissions are set insecurely
dblcheck uses of writeFile as uses might not be aware that it may create world-readable files.
Description
getPersistentNetKeys
dumps the node's unprotected privkey in plaintext into the specified--data-dir
. When the node is restarted, it attempts to reload the private key from disk. By default, the private key is stored in the--data-dir
which on my system (MacOs) resolves to/Users/tintin/Library/Application Support/Nimbus/BeaconNode/privkey.protobuf
. The file is written using nim'swriteFile()
which depending on the system's setting forumask
may create world-readable files (e.g. MacOS default: umask 22 -> writeFile() creates a file with644 (rw-r--r--)
).Under normal circumstances, however, the folder permissions (
/User/tintin/Library/...
) restrict access to a world-readable file in the subfolder to the currently logged in user.However, the private key might be exposed on systems where the default is not a directory in userhome or the
--data-dir
was overridden to be a shared folder. Now, this is arguably insecure on its own but it is nevertheless recommended, to add another layer of protection for the privkey material to prevent it from accidentally being leaked.How to reproduce
Manually override the datadir to be in a shared folder:
Check file permissions:
Details
https://github.com/status-im/nim-beacon-chain/blob/b0470d7318d05901d4cd6fd2fd635965480817c8/beacon_chain/eth2_network.nim#L1069-L1083
Recommendation
writeFile
as uses might not be aware that it may create world-readable files.