Skip to content

dashmate: replace a renewed gateway TLS key through a fresh inode #5506

Open

Description

@shumkov

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 ssl directory 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 at 0600 in the same directory, then rename each 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions