Skip to content

fix(identity): create key/cert files with target mode from the start - #156

Merged
jamofer merged 1 commit into
mainfrom
fix/sec3-private-key-exclusive-create
Jul 21, 2026
Merged

fix(identity): create key/cert files with target mode from the start#156
jamofer merged 1 commit into
mainfrom
fix/sec3-private-key-exclusive-create

Conversation

@jamofer

@jamofer jamofer commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

What

Create the identity key/cert files with their final mode instead of fopen+chmod-after-write.

Why

Audit SEC-3 (private-key TOCTOU). writePemWithMode did fopen(path, "w") — creating the file at 0666 & ~umask (typically 0644) — wrote the PKCS#8 private key bytes, then chmod 0600. Between write and chmod the private key was group/world-readable on disk.

How

open(path, O_WRONLY|O_CREAT|O_TRUNC, mode) + fchmod(fd, mode) before any bytes, via fdopen. The key is never observable at a wider mode; also forces exact perms regardless of umask.

Testing

  • make test green (384/384), make release clean
  • Manual: freshly generated agent.key is 600, agent.crt 644 from creation

Notes

Linux identity only. Windows identity (ACL-based) and pin_store (writes public fingerprints, not secrets) are out of scope here; track separately if wanted.

@jamofer
jamofer force-pushed the fix/sec3-private-key-exclusive-create branch from fbfea72 to 4fe2602 Compare July 21, 2026 21:48
@jamofer
jamofer merged commit 4c9c684 into main Jul 21, 2026
6 checks passed
@jamofer
jamofer deleted the fix/sec3-private-key-exclusive-create branch July 21, 2026 21:50
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.

1 participant