Skip to content

fix(cli): don't let an unreadable .env (EACCES) break extension loading#28059

Open
manumishra12 wants to merge 3 commits into
google-gemini:mainfrom
manumishra12:fix/27894-cloudshell-env-eacces
Open

fix(cli): don't let an unreadable .env (EACCES) break extension loading#28059
manumishra12 wants to merge 3 commits into
google-gemini:mainfrom
manumishra12:fix/27894-cloudshell-env-eacces

Conversation

@manumishra12

@manumishra12 manumishra12 commented Jun 20, 2026

Copy link
Copy Markdown

Summary

Fixes #27894 — the extension system failing to load when a workspace .env is unreadable (EACCES under a sandbox) — at the root cause identified in the issue's effort analysis, plus a related hardening on the Cloud Shell path.

Root-cause fix (extension loading)

  • getScopedEnvContents (extensionSettings.ts) read the extension settings .env with an unguarded fsSync.readFileSync. If the file exists but is unreadable (EACCES), the error propagated and aborted the entire extension build (Skipping extension … EACCES … No extensions installed). Now the stat/read/parse is wrapped in try/catch, the unreadable file is skipped, and resolution continues (keychain secrets etc.) — mirroring the resilient handling in loadEnvironment().
  • _buildExtension (extension-manager.ts) now respects advanced.ignoreLocalEnv: when set, it skips the workspace-local .env read entirely, honoring the user's intent and avoiding the inaccessible file (exactly what the issue asks for).

Related hardening (Cloud Shell)

setUpCloudShellEnvironment (settings.ts) had the same unguarded-read pattern; wrapped it in try/catch too so an unreadable .env can't crash Cloud Shell startup.

Tests

Added a regression test: makes the workspace .env unreadable (chmod 000) and asserts extension settings still resolve without throwing — it fails without the getScopedEnvContents fix (real EACCES) and passes with it. Full extensionSettings + extension-manager suites pass (49 tests); prettier/eslint/typecheck clean.

setUpCloudShellEnvironment read the resolved .env with an unguarded
fs.readFileSync. If the file exists but cannot be read (e.g. EACCES under a
sandbox), the error propagated and crashed early startup — which cascades
into downstream failures such as the extension system failing to load.

Wrap the read/parse in try/catch and fall back to the Cloud Shell default,
mirroring the resilient handling already used in loadEnvironment. Adds a
regression test for the EACCES case (which fails without this change).

Related to google-gemini#27894
@manumishra12 manumishra12 requested a review from a team as a code owner June 20, 2026 12:31
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request improves the stability of the CLI startup process within Cloud Shell environments. By handling potential file access errors gracefully, it prevents the application from crashing when it encounters an unreadable .env file, ensuring a more resilient startup sequence that aligns with existing error handling patterns in the codebase.

Highlights

  • Robustness Improvement: Wrapped the .env file reading logic in setUpCloudShellEnvironment with a try/catch block to prevent startup crashes when the file is unreadable due to EACCES errors.
  • Regression Testing: Added a new test case that mocks an EACCES error during file reading to ensure the application falls back to default settings instead of crashing.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions github-actions Bot added the size/m A medium sized PR label Jun 20, 2026
@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 117
  • Additions: +105
  • Deletions: -12
  • Files changed: 5

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces error handling when reading and parsing the .env file in Cloud Shell environments to prevent startup crashes when the file is unreadable (e.g., due to EACCES permissions issues), along with a corresponding unit test. Feedback on this PR highlights a security vulnerability where the GOOGLE_CLOUD_PROJECT environment variable from an untrusted workspace is only sanitized if sandboxing is enabled. It is recommended to always sanitize this variable when the workspace is untrusted to prevent potential command injection.

Comment thread packages/cli/src/config/settings.ts Outdated
@gemini-cli gemini-cli Bot added priority/p2 Important but can be addressed in a future release. area/extensions Issues related to Gemini CLI extensions capability labels Jun 20, 2026
manumishra12 and others added 2 commits June 21, 2026 12:28
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This addresses the actual root cause of google-gemini#27894 (the extension system failing
to load when a workspace .env is unreadable), as identified in the issue's
effort analysis:

- getScopedEnvContents (extensionSettings.ts) read the extension settings
  `.env` with an unguarded fsSync.readFileSync. If the file exists but is
  unreadable (EACCES under a sandbox), the error propagated and aborted the
  entire extension build. Wrap the stat/read/parse in try/catch and skip the
  file on error, mirroring the resilient handling in loadEnvironment().
- _buildExtension (extension-manager.ts) now respects `advanced.ignoreLocalEnv`
  and skips the workspace-local .env read entirely when it is set, honoring the
  user's intent and avoiding the inaccessible file altogether.

Adds a regression test that makes the workspace .env unreadable (chmod 000)
and asserts extension settings still resolve without throwing (fails without
the getScopedEnvContents fix).
@manumishra12 manumishra12 changed the title fix(cli): don't crash in Cloud Shell when .env is unreadable (EACCES) fix(cli): don't let an unreadable .env (EACCES) break extension loading Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/extensions Issues related to Gemini CLI extensions capability priority/p2 Important but can be addressed in a future release. size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gemini CLI Bug Report: Extension System Failure on Sandbox EACCES

2 participants