Repository navigation
Description
Problem
Older dashmate versions created the gateway's TLS private key (<home>/<config>/platform/gateway/ssl/private.key) at the process umask, so upgraded nodes can carry a group- and world-readable key. saveCertificateTask repairs the mode on the next renewal: it chmods the existing key to 0600 and then rewrites it in place.
Changing the mode does not revoke file descriptors. A local user who opened private.key while it was readable keeps that descriptor. Because the renewal truncates and rewrites the same inode, that descriptor can seek back to the start and read the new private key after the chmod. Restricting the mode only stops new opens.
The key is written in place on purpose. docker-compose.yml bind-mounts bundle.crt and private.key into the gateway as individual files, and a file bind mount follows the inode. If the renewal installed a new inode with write-to-temp-then-rename, the running gateway would keep reading the old file and serve the expired certificate.
So the in-place write and the file bind mount together prevent a renewal from replacing a key that was ever exposed.
Raised in review of #4283 (thread). That pull request does not change this code.
Proposal
Make an atomic key replacement visible to the running gateway, then install renewed keys through a fresh 0600 inode:
- bind-mount the
ssldirectory read-only (e.g. to/etc/ssl/dashmate/) instead of the two files, and point Envoy at the paths inside it; - in
saveCertificateTask, write the key and the bundle to temporary files created at0600in the same directory, thenrenameeach over its target. A descriptor opened on the old inode then only ever sees the old key; - check that Envoy picks up the replaced files the way it does today, either through its file watching or the existing restart after renewal.
Once the replacement no longer reuses the inode, a key that was exposed by the old umask is no longer exposed again by its renewal.
Scope
- Who can exploit it: only a local user on the masternode host who already opened the key while it was world-readable, and so could already read the previous key. Defense in depth, not a remote issue.
- Affected: only installations created by dashmate versions that wrote the key at the umask. New keys are created
0600.
Activity