diff --git a/.jules/sentinel.md b/.jules/sentinel.md new file mode 100644 index 0000000..3f4e897 --- /dev/null +++ b/.jules/sentinel.md @@ -0,0 +1,4 @@ +## 2025-01-31 - Secure File Creation with 1Password CLI +**Vulnerability:** Race condition in `tools/setup-ssh-keys.sh` where private keys were written to disk with default permissions before being restricted, exposing them to other users on the system. +**Learning:** Shell redirection `>` creates files with default umask (often 022/644) before `chmod` can run. +**Prevention:** Use `(umask 077; command > file)` subshell pattern to ensure sensitive files are created with 0600 permissions atomically. diff --git a/tools/setup-ssh-keys.sh b/tools/setup-ssh-keys.sh index bde52fd..9960c12 100755 --- a/tools/setup-ssh-keys.sh +++ b/tools/setup-ssh-keys.sh @@ -153,7 +153,9 @@ cmd_restore() { chmod 700 "$SSH_DIR" # Read private key from 1Password and save locally - op read "op://$VAULT/$KEY_NAME/private_key" > "$PRIVATE_KEY_FILE" + # Use umask 077 to ensure the file is created with 0600 permissions + (umask 077; op read "op://$VAULT/$KEY_NAME/private_key" > "$PRIVATE_KEY_FILE") + # chmod is redundant if umask worked, but good for clarity/double-check chmod 600 "$PRIVATE_KEY_FILE" # Read public key from 1Password and save locally