Skip to content

[Server] Write the generated private key atomically #2366

Backlog

Description

@shba24

Is your feature request related to a problem? Please describe.

When server.token-signing-private-key-file is not set, the server generates its key in the configuration folder on first start (deprecated since #2081). writeOwnerOnly writes private_key.der by deleting the file, creating it readable by its owner only, and then writing the key. If the process stops between the create and the write, an empty private_key.der is left next to public_key.der. The next start sees both files, does not generate a new key, and fails to read the empty one, until someone removes it.

It fails closed, the window is short, and it only affects the deprecated key-folder path.

Raised in the review of #2081 (#2081 (comment)).

Describe the solution you would like

Write the key to a temporary file in the same folder, created readable by its owner only, then move it into place with Files.move(..., StandardCopyOption.ATOMIC_MOVE).

Activity

  1. added
    enhancement
    on Nov 24, 2026
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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions