Skip to content

P0: Fix Machine-scope security for ProgramData bin (prevent Users write)#30

Merged
Kinin-Code-Offical merged 1 commit intomainfrom
p0/programdata-bin-perms
Dec 21, 2025
Merged

P0: Fix Machine-scope security for ProgramData bin (prevent Users write)#30
Kinin-Code-Offical merged 1 commit intomainfrom
p0/programdata-bin-perms

Conversation

@Kinin-Code-Offical
Copy link
Owner

@Kinin-Code-Offical Kinin-Code-Offical commented Dec 21, 2025

Closes #13

Summary:

  • Tighten ProgramData root/bin ACLs to remove Users modify.
  • Keep logs user-writable while restricting binaries to read/execute.

Tests:

  • npm ci (PASS)
  • npm run lint (PASS)
  • npm test (PASS)
  • npm run build (PASS)
  • npm run package (PASS)
  • npm run smoke:exe (PASS)
  • npm run installer (PASS)
  • npm run stage (PASS)

Rollback:

  • Revert this commit to restore prior directory permissions.

Summary by Sourcery

Enhancements:

  • Harden CloudSQLCTL ProgramData directory ACLs so that only admins and the system have full control, with standard users limited to read/execute for binaries and modify for logs.

Copilot AI review requested due to automatic review settings December 21, 2025 23:29
@sourcery-ai
Copy link

sourcery-ai bot commented Dec 21, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts Windows installer directory ACLs under ProgramData for CloudSQLCTL to restrict Users from modifying binaries while retaining write access only for logs, tightening machine-scope security.

Flow diagram for installer setting tightened ACLs on ProgramData directories

flowchart TD
    A[Start installer] --> B[Create CloudSQLCTL root directory]
    B --> C[Set ACL: admins-full, system-full, users-readexec]
    C --> D[Create logs directory]
    D --> E[Set ACL: admins-full, system-full, users-modify]
    E --> F[Create bin directory]
    F --> G[Set ACL: admins-full, system-full, users-readexec]
    G --> H[Create secrets directory]
    H --> I[Set ACL: admins-full, system-full]
    I --> J[Continue rest of installation]
Loading

File-Level Changes

Change Details Files
Harden ProgramData CloudSQLCTL directory permissions to separate readonly binaries from writable logs.
  • Change root CloudSQLCTL ProgramData directory ACL from users-modify to admins-full, system-full, and users-readexec
  • Change CloudSQLCTL logs directory ACL to admins-full, system-full, and users-modify so only logs remain user-writable
  • Change CloudSQLCTL bin directory ACL from users-modify to admins-full, system-full, and users-readexec to prevent Users from modifying installed binaries
installer/cloudsqlctl.iss

Assessment against linked issues

Issue Objective Addressed Explanation
#13 Remove Users write/modify permission from the ProgramData CloudSQLCTL bin directory in the machine-scope installer configuration.
#13 Ensure overall ProgramData ACLs remain appropriate (users can still read/execute binaries and write logs while machine/admin accounts retain full control).

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Changing the directory ACLs in the installer will only affect newly created directories, so if you need to fix permissions on existing installations you may want to add upgrade logic (e.g., a custom action or script) that explicitly resets ACLs on the existing ProgramData\CloudSQLCTL tree.
  • Double‑check whether non‑admin processes need to drop or update binaries under ProgramData\CloudSQLCTL\bin (e.g., auto‑updaters or self‑updating tools); if so, you may need a more targeted mechanism than removing Users modify rights entirely on that directory.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Changing the directory ACLs in the installer will only affect newly created directories, so if you need to fix permissions on existing installations you may want to add upgrade logic (e.g., a custom action or script) that explicitly resets ACLs on the existing ProgramData\CloudSQLCTL tree.
- Double‑check whether non‑admin processes need to drop or update binaries under ProgramData\CloudSQLCTL\bin (e.g., auto‑updaters or self‑updating tools); if so, you may need a more targeted mechanism than removing Users modify rights entirely on that directory.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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.

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +49 to +51
Name: "{commonappdata}\CloudSQLCTL"; Permissions: admins-full system-full users-readexec
Name: "{commonappdata}\CloudSQLCTL\logs"; Permissions: admins-full system-full users-modify
Name: "{commonappdata}\CloudSQLCTL\bin"; Permissions: admins-full system-full users-readexec

Choose a reason for hiding this comment

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

P1 Badge Keep ProgramData home writable for user state

These ACL changes make {commonappdata}\CloudSQLCTL and \bin read/exec-only for standard users, but the installer still sets machine-scope env vars (CLOUDSQLCTL_HOME/CLOUDSQLCTL_PROXY_PATH) so the runtime resolves PATHS to the ProgramData location and then writes config.json, temp, gcloud, and proxy.pid under that directory (see src/core/config.ts, src/core/gcloud-installer.ts, src/core/proxy.ts). With read/exec only on the home/bin, non-admin users will now fail to write config or PID files after a machine install, which is a regression from the prior users-modify ACLs. This will surface anytime a non-admin runs the CLI on a machine-wide install.

Useful? React with 👍 / 👎.

@Kinin-Code-Offical Kinin-Code-Offical merged commit 67667fe into main Dec 21, 2025
9 checks passed
@Kinin-Code-Offical Kinin-Code-Offical deleted the p0/programdata-bin-perms branch December 21, 2025 23:31
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request addresses a security vulnerability by tightening directory permissions for the CloudSQLCTL installation in ProgramData. The changes restrict Users group from having modify permissions on the root directory and bin directory (where binaries are stored), while maintaining write access to the logs directory. This prevents unprivileged users from tampering with executable files in a machine-wide installation.

Key changes:

  • Restricted root CloudSQLCTL directory from users-modify to users-readexec
  • Restricted bin directory from users-modify to users-readexec to protect binaries
  • Maintained users-modify on logs directory to allow non-admin users to write logs
  • Added explicit admins-full system-full permissions to all directories for clarity

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Name: "{commonappdata}\CloudSQLCTL\bin"; Permissions: users-modify
Name: "{commonappdata}\CloudSQLCTL"; Permissions: admins-full system-full users-readexec
Name: "{commonappdata}\CloudSQLCTL\logs"; Permissions: admins-full system-full users-modify
Name: "{commonappdata}\CloudSQLCTL\bin"; Permissions: admins-full system-full users-readexec
Copy link

Copilot AI Dec 21, 2025

Choose a reason for hiding this comment

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

The restrictive permissions on the bin directory (users-readexec) will prevent non-admin users from updating or installing the proxy binary. After the installer runs and sets CLOUDSQLCTL_PROXY_PATH environment variable to point to this machine-scope location, the application will resolve PATHS to use SYSTEM_PATHS. When non-admin users run commands like 'cloudsqlctl install', 'cloudsqlctl update', or 'cloudsqlctl setup', these commands call downloadProxy which writes to PATHS.PROXY_EXE in the bin directory. This write operation will fail with permission denied errors.

Consider one of these approaches:

  1. Add admin privilege checks before attempting to download to machine-scope paths, and gracefully fall back to user-scope paths for non-admin users
  2. Make the bin directory writable by a specific group (e.g., a CloudSQLCTL Users group) that can be managed separately
  3. Document that proxy updates require admin privileges when installed machine-wide
Suggested change
Name: "{commonappdata}\CloudSQLCTL\bin"; Permissions: admins-full system-full users-readexec
Name: "{commonappdata}\CloudSQLCTL\bin"; Permissions: admins-full system-full users-modify

Copilot uses AI. Check for mistakes.
Name: "{commonappdata}\CloudSQLCTL\bin"; Permissions: users-modify
Name: "{commonappdata}\CloudSQLCTL"; Permissions: admins-full system-full users-readexec
Name: "{commonappdata}\CloudSQLCTL\logs"; Permissions: admins-full system-full users-modify
Name: "{commonappdata}\CloudSQLCTL\bin"; Permissions: admins-full system-full users-readexec
Copy link

Copilot AI Dec 21, 2025

Choose a reason for hiding this comment

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

The scripts subdirectory is not defined in the [Dirs] section but is used by the application (see src/system/ps1.ts line 33). When generateScripts is called, it will create this directory with inherited permissions from the parent CloudSQLCTL directory. With the new users-readexec permissions on the parent, non-admin users won't be able to write scripts to this location. The selfHeal function calls generateScripts without checking admin status, which could cause failures.

Add an explicit [Dirs] entry for the scripts directory with appropriate permissions, similar to how the logs directory is configured to allow writes.

Suggested change
Name: "{commonappdata}\CloudSQLCTL\bin"; Permissions: admins-full system-full users-readexec
Name: "{commonappdata}\CloudSQLCTL\bin"; Permissions: admins-full system-full users-readexec
Name: "{commonappdata}\CloudSQLCTL\scripts"; Permissions: admins-full system-full users-modify

Copilot uses AI. Check for mistakes.
Name: "{commonappdata}\CloudSQLCTL"; Permissions: users-modify
Name: "{commonappdata}\CloudSQLCTL\logs"; Permissions: users-modify
Name: "{commonappdata}\CloudSQLCTL\bin"; Permissions: users-modify
Name: "{commonappdata}\CloudSQLCTL"; Permissions: admins-full system-full users-readexec
Copy link

Copilot AI Dec 21, 2025

Choose a reason for hiding this comment

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

The root CloudSQLCTL directory now has users-readexec permissions, which prevents non-admin users from creating new subdirectories or files. While this improves security for the bin and secrets directories, it may break functionality for other operations. For example:

  • Creating PID files (proxy.pid is written to HOME, see src/core/proxy.ts line 63)
  • Creating config files (config.json in HOME, see src/system/paths.ts line 14)
  • Creating temp directories (see src/system/paths.ts line 15)

These paths are resolved to SYSTEM_PATHS.HOME (ProgramData) after installation, and the writes will fail for non-admin users. Consider adding explicit directory entries for directories that need write access, or ensure the application properly handles permission errors and falls back to user-scope paths.

Suggested change
Name: "{commonappdata}\CloudSQLCTL"; Permissions: admins-full system-full users-readexec
Name: "{commonappdata}\CloudSQLCTL"; Permissions: admins-full system-full users-modify

Copilot uses AI. Check for mistakes.
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.

P0: Fix Machine-scope security for ProgramData bin (prevent Users write)

1 participant