Skip to content

fix: Enforce owner-only permissions on local files on POSIX#251

Merged
aviatco merged 11 commits into
microsoft:mainfrom
aviatco:dev/aviatcohen/fixWorldReadablePermission
Jun 23, 2026
Merged

fix: Enforce owner-only permissions on local files on POSIX#251
aviatco merged 11 commits into
microsoft:mainfrom
aviatco:dev/aviatcohen/fixWorldReadablePermission

Conversation

@aviatco

@aviatco aviatco commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

📥 Pull Request

✨ Description of new changes

This pull request enforces strict owner-only (0o600) permissions on all sensitive files managed by the CLI on POSIX systems, ensuring that files written to disk are never world-readable. It introduces a new utility function to tighten permissions on any pre-existing files, updates file and directory creation to consistently use secure permissions, and adds comprehensive tests to verify these behaviors. These changes significantly improve the security posture of the CLI regarding file access.

Security and Permissions Enforcement

  • Added restrict_existing_file utility to ensure files are tightened to owner-only permissions (0o600) on POSIX, and refactored code to use this for all sensitive files, including authentication caches and log files. (src/fabric_cli/utils/fab_secure_io.py, src/fabric_cli/core/fab_auth.py, src/fabric_cli/core/fab_logger.py) [1] [2] [3] [4] [5] [6] [7] [8]
  • Defined constants OWNER_ONLY_FILE_MODE (0o600) and OWNER_ONLY_DIR_MODE (0o700) for consistent permission use across the codebase. (src/fabric_cli/utils/fab_secure_io.py)
  • Updated directory and file creation helpers to use these constants and improved docstrings for clarity. (src/fabric_cli/utils/fab_secure_io.py)

Testing

  • Added new tests to verify that sensitive files are always tightened to owner-only permissions, including after successful or failed token acquisition and for pre-existing files. (tests/test_core/test_fab_auth.py, tests/test_utils/test_fab_secure_io.py) [1] [2]

Changelog

  • Added a changelog entry describing the fix for enforcing owner-only permissions on local files so they are no longer world-readable. (.changes/unreleased/fixed-20260618-123845.yaml)

@aviatco aviatco requested a review from a team as a code owner June 21, 2026 09:44
Copilot AI review requested due to automatic review settings June 21, 2026 09:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the Fabric CLI’s local security posture on POSIX systems by enforcing owner-only permissions for sensitive files (notably the MSAL token cache and log files), and adds tests to validate permission tightening behavior.

Changes:

  • Added restrict_existing_file() plus OWNER_ONLY_FILE_MODE/OWNER_ONLY_DIR_MODE constants, and refactored restricted file/dir helpers to use them.
  • Tightened permissions for MSAL’s on-disk cache via FabAuth.acquire_token() (including a finally block) and for log files/rotations in the logger.
  • Added POSIX-only tests covering permission tightening for pre-existing files and the auth cache file across success and error paths.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/fabric_cli/utils/fab_secure_io.py Introduces reusable permission constants and restrict_existing_file(), and refactors restricted file/dir creation to use them.
src/fabric_cli/core/fab_auth.py Ensures MSAL cache file permissions are tightened before use and after token acquisition (finally).
src/fabric_cli/core/fab_logger.py Tightens permissions for existing log files and rotated backups via restrict_existing_file().
src/fabric_cli/errors/auth.py Adds a centralized token_acquisition_failed() error-message helper.
tests/test_utils/test_fab_secure_io.py Adds POSIX-only unit tests for restrict_existing_file() and write_restricted_file().
tests/test_core/test_fab_auth.py Adds POSIX-only tests verifying cache file permission tightening after token acquisition success/failure and updates an error-message assertion.
.changes/unreleased/fixed-20260618-123845.yaml Adds changelog entry for the permission enforcement fix.

Comment thread src/fabric_cli/core/fab_auth.py Outdated
Comment thread src/fabric_cli/utils/fab_secure_io.py Outdated
Comment thread tests/test_core/test_fab_auth.py Outdated
Comment thread .changes/unreleased/fixed-20260618-123845.yaml Outdated
Comment thread src/fabric_cli/core/fab_auth.py Outdated
Comment thread src/fabric_cli/core/fab_auth.py Outdated
Co-authored-by: Alon Yeshurun <98805507+ayeshurun@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 21, 2026 10:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Comment thread src/fabric_cli/utils/fab_secure_io.py Outdated
Comment thread src/fabric_cli/core/fab_auth.py Outdated
Comment thread src/fabric_cli/errors/auth.py Outdated
Comment thread src/fabric_cli/core/fab_auth.py Outdated
Comment thread tests/test_core/test_fab_auth.py
Copilot AI review requested due to automatic review settings June 21, 2026 11:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread src/fabric_cli/errors/auth.py Outdated
ayeshurun
ayeshurun previously approved these changes Jun 21, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 23, 2026 07:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Comment thread tests/test_core/test_fab_auth.py
Comment thread src/fabric_cli/utils/fab_secure_io.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 23, 2026 07:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread src/fabric_cli/utils/fab_secure_io.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 23, 2026 07:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread src/fabric_cli/core/fab_auth.py Outdated
ayeshurun
ayeshurun previously approved these changes Jun 23, 2026
@aviatco aviatco merged commit ce79563 into microsoft:main Jun 23, 2026
10 checks passed
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.

3 participants