Skip to content

[9.3.0] Improve path validation in remote repository contents cache. - #30579

Closed
iancha1992 wants to merge 5 commits into
bazelbuild:release-9.3.0from
iancha1992:cp30520_2
Closed

iancha1992 wants to merge 5 commits into
bazelbuild:release-9.3.0from
iancha1992:cp30520_2

Conversation

@iancha1992

Copy link
Copy Markdown
Contributor

Validate node names in remote tree to ensure they don't contain separators, uplevel references, or absolute paths. Ensure injected paths and symlink targets remain within the repository directory.

PiperOrigin-RevId: 956519847
Change-Id: I0a2a91dd827be37fff78146637c7e55dc9c876df

Description

Motivation

Build API Changes

No

Checklist

  • I have added tests for the new use cases (if any).
  • I have updated the documentation (if applicable).

Release Notes

RELNOTES: None

Commit c37a6a1 and 61574a9

meisterT and others added 2 commits August 4, 2026 14:58
Validate node names in remote tree to ensure they don't contain separators, uplevel references, or absolute paths. Ensure injected paths and symlink targets remain within the repository directory.

PiperOrigin-RevId: 956519847
Change-Id: I0a2a91dd827be37fff78146637c7e55dc9c876df
…d#30517)

### Description

When a repo is injected from the remote repo contents cache, `.bzl` and `REPO.bazel` files are prefetched to the native file system and reads of such paths are redirected there. Symlinks are only injected into the in-memory overlay, so bazelbuild#30031 made the read side resolve symbolic links first, which serves a symlinked `.bzl` file from the regular file it points at.

That only helps if the target's own name happens to make it eligible for prefetching, e.g. `helper.bzl -> real_helper.bzl`. A symlink such as `helper.bzl -> real_helper.txt` resolves to a path that was never prefetched and thus falls back to a lazy blob download while the package that loads it is being evaluated.

This PR collects symlinks whose name makes them eligible for prefetching during injection and, once the repo has been injected in full and their targets can be resolved, adds those targets to the set of files to prefetch. The read side now also considers the path before symlink resolution, so the prefetched target is used no matter which end of the chain is named like a loaded file.

### Motivation

Loading a `.bzl` file that is a symlink to a differently named file costs a sequential round-trip to the remote cache in the middle of the loading phase, which is exactly what prefetching `.bzl` files during injection is meant to avoid: the loads between `.bzl` files form a DAG that can only be discovered layer by layer, so each such read serializes with the next.

Follow-up to bazelbuild#30031.

### Build API Changes

No

### Checklist

- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes

RELNOTES: None

Closes bazelbuild#30517.

PiperOrigin-RevId: 958506915
Change-Id: Ic9e740883683a626aebc17d5686f7c3e3426878c
@iancha1992
iancha1992 requested review from Wyverald, coeuvre and tjgq August 4, 2026 22:00
@iancha1992
iancha1992 requested a review from a team as a code owner August 4, 2026 22:00
@iancha1992 iancha1992 added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. team-Remote-Exec Issues and PRs for the Execution (Remote) team awaiting-review PR is awaiting review from an assigned reviewer labels Aug 4, 2026
@iancha1992
iancha1992 enabled auto-merge August 4, 2026 22:00
@iancha1992
iancha1992 marked this pull request as draft August 4, 2026 22:40
auto-merge was automatically disabled August 4, 2026 22:40

Pull request was converted to draft

@iancha1992 iancha1992 closed this Aug 13, 2026
@github-actions github-actions Bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Aug 13, 2026
bazel-io pushed a commit to bazel-io/bazel that referenced this pull request Sep 2, 2026
…azelbuild#30713)

### Description

When a repo is injected from the remote repo contents cache, `.bzl` and
`REPO.bazel` files are prefetched to the native file system and reads of
such paths are redirected there. Symlinks are only injected into the
in-memory overlay, so bazelbuild#30031 made the read side resolve symbolic links
first, which serves a symlinked `.bzl` file from the regular file it
points at.

That only helps if the target's own name happens to make it eligible for
prefetching, e.g. `helper.bzl -> real_helper.bzl`. A symlink such as
`helper.bzl -> real_helper.txt` resolves to a path that was never
prefetched and thus falls back to a lazy blob download while the package
that loads it is being evaluated.

This PR collects symlinks whose name makes them eligible for prefetching
during injection and, once the repo has been injected in full and their
targets can be resolved, adds those targets to the set of files to
prefetch. The read side now also considers the path before symlink
resolution, so the prefetched target is used no matter which end of the
chain is named like a loaded file.

### Motivation

Loading a `.bzl` file that is a symlink to a differently named file
costs a sequential round-trip to the remote cache in the middle of the
loading phase, which is exactly what prefetching `.bzl` files during
injection is meant to avoid: the loads between `.bzl` files form a DAG
that can only be discovered layer by layer, so each such read serializes
with the next.

Follow-up to bazelbuild#30031.

### Build API Changes

No

### Checklist

- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes

RELNOTES: None

Closes bazelbuild#30517.

PiperOrigin-RevId: 958506915
Change-Id: Ic9e740883683a626aebc17d5686f7c3e3426878c
(cherry picked from commit 61574a9)


This PR also carries the prerequisite commit
bazelbuild@c37a6a1
("Improve path validation in remote repository contents cache."), which
touches the same injection code path and landed on master first.

Replaces bazelbuild#30579, which bundles the same two commits but does not build
on this branch: it hand-authors a new
`remote_external_overlay_file_system` target in
`src/main/java/com/google/devtools/build/lib/remote/BUILD` that depends
on `//src/main/proto:failure_details_java_proto` (the branch uses
`//src/main/protobuf`), so the target does not even analyze, and its
test uses `EventBusEventHandler`, which does not exist on this branch.

9.3.0 adaptation: The
`src/main/java/com/google/devtools/build/lib/remote/BUILD` split is not
needed because that package still has a single monolithic `remote`
target here, which already covers
`RemoteExternalOverlayFileSystem.java`; the same goes for the
`remote_external_overlay_file_system` entry in
`src/test/java/com/google/devtools/build/lib/remote/BUILD`, where only
the new `//src/main/java/com/google/devtools/build/lib/cmdline` dep is
required. The new test constructs the `Reporter` as `new Reporter(new
EventBus())` since `EventBusEventHandler` was introduced by a
master-only refactoring.

Closes bazelbuild#30520

---------

Co-authored-by: twerth <[email protected]>
Co-authored-by: Ian (Hee) Cha <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. team-Remote-Exec Issues and PRs for the Execution (Remote) team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants