Skip to content

fix: create mTLS private key temp files with owner-only permissions - #453

Merged
KarstenSchnitter merged 1 commit into
mainfrom
fix/pem-file-owner-only-permissions
Oct 15, 2026
Merged

KarstenSchnitter merged 1 commit into
mainfrom
fix/pem-file-owner-only-permissions

Conversation

@KarstenSchnitter

Copy link
Copy Markdown
Contributor

PemFileCreator previously used File.createTempFile, which creates files with permissions determined by the process umask. On systems with a permissive umask (e.g. 022), the private key files were world-readable until the JVM process exited and deleted them.

Switch to Files.createTempFile with a PosixFilePermissions attribute of rw------- so the file is created with owner-only read/write permissions atomically, eliminating the race window. A fallback for non-POSIX filesystems (Windows) uses File.setReadable/setWritable to restrict access after creation.

PemFileCreator previously used File.createTempFile, which creates files
with permissions determined by the process umask. On systems with a
permissive umask (e.g. 022), the private key files were world-readable
until the JVM process exited and deleted them.

Switch to Files.createTempFile with a PosixFilePermissions attribute of
rw------- so the file is created with owner-only read/write permissions
atomically, eliminating the race window. A fallback for non-POSIX
filesystems (Windows) uses File.setReadable/setWritable to restrict
access after creation.

Signed-off-by: Karsten Schnitter <k.schnitter@sap.com>

@dkhsap dkhsap left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@KarstenSchnitter
KarstenSchnitter merged commit efaba09 into main Oct 15, 2026
4 of 5 checks passed
@KarstenSchnitter
KarstenSchnitter deleted the fix/pem-file-owner-only-permissions branch October 15, 2026 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants