ethp2p: write the runtime TLS private key owner-only (0o600) - #1051
Conversation
Per review (zclawz on #1049): the generated ethp2p private-key PEM was written with default file permissions (0o666 before umask), leaving it group/world-readable under common umasks. A copy of key.pem plus the signed cert is enough to impersonate this node's ethp2p QUIC listener for the cert lifetime, which defeats this PR's whole point (no shared/committed keypair). Thread a permissions arg through ethp2pWritePem and create the key with 0o600; the cert (public) keeps the default. 0o600 carries no group/other bits so the file is owner-only regardless of umask. Verified on disk: key.pem = -rw------- (600), cert.pem = -rw-r--r-- (644).
|
Approved from my side. The latest revision addresses my blocker. What changed since my previous pass:
I do not see a remaining blocker in the permission fix. Validation I ran:
As usual, leaving this as a regular PR comment rather than a formal GitHub approval review. |
Review follow-up (zclawz on #1051): createFile's .permissions only applies when the file is CREATED. A key.pem that an already-merged-#1049 node wrote with the default 0o666 keeps that lax mode when this code rewrites it in place (truncate=true), so the fix only covered fresh installs. Explicitly setPermissions(0o600) on the key after open, while the file is still empty (before the key bytes are written) so the secret is never briefly present at a looser mode. The public cert passes null and keeps the umask'd create default — it must not be force-set to 0o666 (world-writable). Verified: a pre-existing key.pem at 0o666 is tightened to 0o600 in place after the node runs (cert stays untouched).
|
Good catch — you're right, Verified the pre-existing-file case directly: seeded |
Follow-up to #1049 addressing the blocking review finding from @zclawz.
Problem
ethp2pWritePemcreated the generated ethp2p private-key PEM ({database_path}/ethp2p/key.pem) with Zig's default file permissions (0o666before umask), leaving it group/world-readable under common umasks. A copy ofkey.pemplus the signed cert is enough to impersonate this node's ethp2p QUIC listener for the cert lifetime — which defeats #1049's whole point (no shared/committed keypair).Fix
Thread a
permissionsargument throughethp2pWritePemand create the private key with0o600; the cert (public) keeps the default.0o600carries no group/other bits, so umask can only clear bits — the key is owner-only regardless of the process umask (addresses the "do not rely on umask" note).Verified on disk
Ran a node with
ZEAM_ETHP2P=1under umask 022:zig build -Dethp2p=truegreen.