Skip to content

BCR presubmit: run the outside-modules check when only metadata.json changes - #2771

Open
bilguunbicktivism wants to merge 1 commit into
bazelbuild:masterfrom
bilguunbicktivism:bcr-presubmit-metadata-only-gate
Open

BCR presubmit: run the outside-modules check when only metadata.json changes#2771
bilguunbicktivism wants to merge 1 commit into
bazelbuild:masterfrom
bilguunbicktivism:bcr-presubmit-metadata-only-gate

Conversation

@bilguunbicktivism

Copy link
Copy Markdown

validate_files_outside_of_modules_dir_are_not_modified() returns early when get_target_modules()
is empty:

def validate_files_outside_of_modules_dir_are_not_modified(modules):
    # If no modules are changed at the same time, then we don't need to perform this check.
    if not modules:
        return

get_target_modules() builds its list from the modules/<name>/<version>/ pattern
(bcr_presubmit.py:87-90), so a pull request that touches only modules/<name>/metadata.json
produces an empty list and the check is skipped — even when the same pull request also changes files
outside modules/. get_modules_with_metadata_change() does see that pull request, and
should_wait_bcr_maintainer_review() goes on to call should_bcr_validation_block_presubmit(), which
runs bazel run //tools:bcr_validation from the pull request's own checkout.

The change passes the metadata-change list to the check as well, and moves the
get_modules_with_metadata_change() call above it so both kinds of modules/ change are considered.

Behaviour, before and after

Driven against real temporary git repositories, running the old and the new guard body over the same
diff. The first two rows are controls — the second exists to show the guard is not simply firing on
everything, and the first to show the patch does not make ordinary module pull requests noisy:

case old guard new guard expected
clean version add, nothing outside modules/ skipped skipped skipped
version add + a file outside modules/ CAUGHT CAUGHT CAUGHT
metadata.json only + a file outside modules/ skipped CAUGHT CAUGHT

Happy to attach the harness if it is useful, or to turn it into a test in whatever form you prefer —
I left it out to keep the diff to one file.

Context

I reported this through the Google OSS VRP as issue 543941141. It was closed as
"not severe enough for us to track it as a security bug", and the response said: "Please feel free
to publicly disclose this issue on GitHub as a public issue."
This pull request is that disclosure,
with the fix attached rather than filed separately.

The behaviour is worth closing regardless of severity rating, because the skipped check is the one
that keeps a module pull request from carrying repository files, and the validation that follows it
executes tools/ from the pull request's checkout.

validate_files_outside_of_modules_dir_are_not_modified() returned early when
get_target_modules() was empty. That list is built from the
modules/<name>/<version>/ pattern, so a pull request touching only
modules/<name>/metadata.json produces no entries and the check is skipped —
even though the same pull request may also change files outside modules/, and
should_bcr_validation_block_presubmit() then runs //tools:bcr_validation from
that checkout.

Pass the metadata-change list to the check as well, and compute it before the
call so both kinds of modules/ change are considered.
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.

2 participants