Skip to content

feat(Storage): allow bypassing StreamWrapper permissions check to reduce cost/latency - #9733

Open
salilg-eng wants to merge 7 commits into
googleapis:mainfrom
salilg-eng:fix/streamwrapper-bypass
Open

salilg-eng wants to merge 7 commits into
googleapis:mainfrom
salilg-eng:fix/streamwrapper-bypass

Conversation

@salilg-eng

@salilg-eng salilg-eng commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1182

Description:
When using is_readable or stat via the PHP stream wrapper, the library currently tries to determine the stat mode by calling $this->bucket->isWritable(). This triggers an expensive Class-A API call (getResumeUri) to write an empty object. This leads to high latency, additional cost, and failure on read-only buckets.
This PR introduces an opt-in bypass feature using stream context options. By setting stat_permission_check => false in the stream context for the gs protocol, users can safely bypass this API call. When bypassed, the stream wrapper will optimistically assume the bucket has read/write permissions (mode 100666), deferring actual permission checks to the subsequent read/write operations (which correctly throw 403 if unauthorized).
Example Usage:

stream_context_set_default([
    'gs' => ['stat_permission_check' => false]
]);
is_readable('gs://my-bucket/file.txt'); // No Class-A network call is made

@salilg-eng
salilg-eng requested review from a team as code owners September 25, 2026 08:37
@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Sep 25, 2026
@google-cla

google-cla Bot commented Sep 25, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@salilg-eng
salilg-eng force-pushed the fix/streamwrapper-bypass branch from 5bde1ac to 1059410 Compare September 25, 2026 08:42

@kalragauri kalragauri 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.

Please use standard GitHub closing syntax in the PR description so the public issue is linked properly: Fixes #1182

Comment thread Storage/tests/Unit/StreamWrapperTest.php
Comment thread Storage/tests/System/StreamWrapper/UrlStatTest.php
Comment thread Storage/src/StreamWrapper.php
Comment thread Storage/src/StreamWrapper.php
@salilg-eng
salilg-eng requested a review from kalragauri October 6, 2026 11:10
Comment thread Storage/tests/System/StreamWrapper/UrlStatTest.php Outdated
@salilg-eng
salilg-eng force-pushed the fix/streamwrapper-bypass branch from d1f9c83 to 111b938 Compare October 11, 2026 08:15
@salilg-eng
salilg-eng force-pushed the fix/streamwrapper-bypass branch from 111b938 to eff99dd Compare October 11, 2026 08:17
Comment thread Storage/src/StreamWrapper.php
Comment thread Storage/src/StreamWrapper.php Outdated
@salilg-eng
salilg-eng requested a review from bshaffer October 13, 2026 18:28

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the Cloud Storage API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Checking gs bucket readability, fails when bucket is not writeable.

3 participants