Skip to content

Conversation

@thesayyn
Copy link
Collaborator

Creates bazel validation actions for the debian13 targets to ensure that no layer violates the merged-usr conventions. This ensures both upstream debian packages and intermediate layers created by both distroless and rules_distroless is mergedusr compliant.

@thesayyn thesayyn requested a review from loosebazooka October 29, 2025 21:13
@gemini-code-assist
Copy link

Summary of Changes

Hello @thesayyn, 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 implements a crucial validation step for OCI images built using Bazel, specifically targeting Debian 13. By integrating a new Bazel aspect, it automatically checks for violations of the merged-usr filesystem hierarchy standard within image layers. This proactive measure helps maintain consistency and prevents potential issues arising from non-compliant file structures in both base images and custom layers.

Highlights

  • Merged-usr Validation: Introduced Bazel validation actions for debian13 targets to enforce merged-usr conventions, ensuring compliance for both upstream Debian packages and intermediate layers.
  • New Bazel Aspect: Added a new Bazel aspect, validate_usr_symlinks, which uses bsdtar and gawk to inspect OCI image layers for merged-usr violations.
  • Dependency Updates: Included gawk as a new Bazel dependency and updated bazel_skylib and rules_cc versions.
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 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 counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

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 a Bazel aspect to validate merged-usr compliance for debian13 targets, which is a valuable addition for ensuring the correctness of the built container images. The implementation is generally sound, but I've identified a critical issue in the validation logic that would lead to incorrect failures on valid images. Additionally, I've provided several suggestions to enhance the maintainability and extensibility of the new validation aspect.

# https://salsa.debian.org/md/usrmerge/-/tree/master/debian?ref_type=heads
_VALIDATE_SYMLINKS = """\
BEGIN {
prefixes = "./bin|./sbin|./usr/sbin|./lib|./lib32|./lib64|./libx32"

Choose a reason for hiding this comment

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

critical

The prefixes variable in the awk script includes ./usr/sbin. In a merged-usr system, /usr/sbin is an actual directory, not a symlink. The paths that are converted to symlinks are /bin, /sbin, /lib, etc., which point to their counterparts inside /usr. By including ./usr/sbin in the check for non-symlinks, this script will incorrectly flag valid merged-usr layouts, causing validation to fail. The ./usr/sbin path should be removed from the prefixes.

Suggested change
prefixes = "./bin|./sbin|./usr/sbin|./lib|./lib32|./lib64|./libx32"
prefixes = "./bin|./sbin|./lib|./lib32|./lib64|./libx32"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i don't this is true, or i have understood the merged-usr completely wrong.
https://github.com/floppym/merge-usr/blob/15dd02207bdee7ca6720d7024e8c0ffdc166ed23/merge-usr#L20 clearly indicates that ./usr/sbin is a symlink to ./usr/bin.

Copy link
Member

Choose a reason for hiding this comment

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

hrmm.. actualy debian seems to want to keep them separate:

https://salsa.debian.org/md/usrmerge/raw/master/debian/README.Debian

* Will usrmerge also merge /usr/bin/ and /usr/sbin/?
No.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In that case yes, this is an oversight.

if (length(VIOLATIONS) > 0) {
exit 1
}
print "" > "{validation_output}"

Choose a reason for hiding this comment

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

medium

Instead of using string replacement to pass the validation output file path to the awk script, it's cleaner to use an awk variable passed with the -v flag. This change prepares the script to accept such a variable. I'll suggest the corresponding change to the ctx.actions.run call in another comment.

Suggested change
print "" > "{validation_output}"
print "" > validation_output_file

Comment on lines +34 to +35
if target.label.name.find("debian13") == -1:
return []

Choose a reason for hiding this comment

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

medium

The aspect is hardcoded to only run on targets with "debian13" in their name. This is brittle and will require code changes to support other distributions or versions. A more flexible and maintainable approach would be to use Bazel tags. You could apply a specific tag (e.g., "validate-merged-usr") to the targets that need this validation, and then check for this tag within the aspect. This also makes the intent clearer in the target definitions.

You would then need to add tags = ["validate-merged-usr"] to the relevant oci_image targets that are based on debian13.

Suggested change
if target.label.name.find("debian13") == -1:
return []
if "validate-merged-usr" not in ctx.rule.attr.tags:
return []

Comment on lines +63 to +66
arguments = [
_VALIDATE_SYMLINKS.replace("{validation_output}", validation_output.path),
output.path,
],

Choose a reason for hiding this comment

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

medium

To accompany the change in _VALIDATE_SYMLINKS, this updates the arguments to pass the output file path as a variable to awk using the -v flag. This is a cleaner way to pass parameters.

        arguments = [
            "-v",
            "validation_output_file=" + validation_output.path,
            _VALIDATE_SYMLINKS,
            output.path,
        ],

@github-actions
Copy link
Contributor

github-actions bot commented Oct 29, 2025

🌳 🔄 Image Check
This pull request doesn't make any changes to the images. 👍
You can check the details in the report here

Co-authored-by: gemini-code-assist[bot]
<176961590+gemini-code-assist[bot]@users.noreply.github.com>
@thesayyn thesayyn force-pushed the validate_merged_usr branch from d9c6e07 to a3bf482 Compare October 29, 2025 21:57
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.

3 participants