Skip to content

fix(cli): create rclone credentials with private permissions - #1924

Merged
phernandez merged 6 commits into
mainfrom
codex/security-rclone-permissions
Oct 28, 2026
Merged

phernandez merged 6 commits into
mainfrom
codex/security-rclone-permissions

Conversation

@phernandez

@phernandez phernandez commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Why

Rclone credentials inherit ordinary filesystem permissions. Under umask 000, a real configuration call creates a 0777 directory and a 0666 credential file. Existing loose files and backups remain exposed. Fixes #1914.

What Changed

Create/tighten the rclone directory to 0700 and config/backup files to 0600 before writing credential bytes. Preserve other remote sections and backup content.

Implementation Details

Use explicit creation modes and tighten existing files before writing through the opened handle. Backup copying uses a private destination rather than copy2's ordinary file creation. POSIX regressions use a real temporary home and permissive umask without mocks. Windows keeps its native ACL semantics; POSIX mode assertions skip there.

Stacked on #1923; only rclone permission handling and its tests are new here.

Testing

  • Before the fix: both new/existing configuration permission regressions failed.
  • uv run pytest tests/cli/cloud/test_rclone_permissions.py tests/cli/cloud/test_rclone_config_and_bmignore_filters.py -q --no-cov: 15 passed.
  • just fast-check: passed, including repository type checking.
  • just doctor: passed sandboxed write/index/search self-test.

Existing configs are tightened on discovery, before parsing can fail. The malformed-config regression failed before that fix. Reads and writes retain the original locale-default encoding.

Risks / Follow-ups

Existing rclone directory permissions are intentionally tightened to owner-only, including access to its other configured remotes. Backups retain content but no longer copy source timestamps. This is a local credential-file fix, not a claim of remote exposure.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T21:40:57.464055Z 4e83be3 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c37677bc7f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 4e83be378c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Base automatically changed from codex/security-find-replace-budget to main October 28, 2026 22:18
@phernandez
phernandez changed the base branch from codex/security-find-replace-budget to main October 28, 2026 22:18
@phernandez
phernandez merged commit df611b0 into main Oct 28, 2026
55 checks passed
@phernandez
phernandez deleted the codex/security-rclone-permissions branch October 28, 2026 22:18
phernandez added a commit that referenced this pull request Oct 28, 2026
## Why

Atomic writes stage content in a file created with ordinary permissions,
then restore the target's mode only after writing. Under umask 000,
rewriting a private 0600 note stages its bytes in a 0666 file. Fixes
#1906.

## What Changed

Create the content-bearing staging inode with mode 0600 from the outset
for both text and binary writers. Preserve the target's final
permissions; newly created targets retain their normal umask-derived
final mode.

## Implementation Details

Capture the existing target mode, or determine the umask-derived mode
using an empty probe in a private temporary directory for a new target.
This avoids mutating the process-wide umask and prevents an observer
from opening the content inode before permissions tighten. Existing
publication-time chmod remains in place, preserving read-only and shared
target behavior. No content reaches the staging file until reservation
returns.

Stacked on #1924; only atomic staging permissions and their regression
tests are new here.

## Testing

- Before the fix: all three real staging regressions failed under umask
000. A later real-open observer also failed against chmod-after-create,
reproducing the descriptor-retention gap; the inode now starts private.
- `uv run pytest tests/utils/test_atomic_staging_permissions.py
tests/utils/test_file_utils.py -q --no-cov`: 60 passed.
- `just fast-check`: passed, including repository type checking.
- `just doctor`: passed sandboxed write/index/search self-test.

## Risks / Follow-ups

This closes the staging-content permission window without changing final
file modes or the atomic rename protocol. POSIX permission regressions
skip Windows, which uses native ACL semantics.

---------

Signed-off-by: phernandez <[email protected]>
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.

Create rclone credential directories and files with owner-only permissions

1 participant