-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: validate actions for merged-usr violations #1912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @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 Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| prefixes = "./bin|./sbin|./usr/sbin|./lib|./lib32|./lib64|./libx32" | |
| prefixes = "./bin|./sbin|./lib|./lib32|./lib64|./libx32" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we might even want to update this? https://github.com/bazel-contrib/rules_distroless/blob/63ccbe044b95329b4612bdecd281ec98b9db3ad7/apt/private/deb_postfix.bzl#L40
There was a problem hiding this comment.
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}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| print "" > "{validation_output}" | |
| print "" > validation_output_file |
| if target.label.name.find("debian13") == -1: | ||
| return [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| if target.label.name.find("debian13") == -1: | |
| return [] | |
| if "validate-merged-usr" not in ctx.rule.attr.tags: | |
| return [] |
| arguments = [ | ||
| _VALIDATE_SYMLINKS.replace("{validation_output}", validation_output.path), | ||
| output.path, | ||
| ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
🌳 🔄 Image Check |
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
d9c6e07 to
a3bf482
Compare
Creates bazel validation actions for the debian13 targets to ensure that no layer violates the
merged-usrconventions. This ensures both upstream debian packages and intermediate layers created by both distroless and rules_distroless is mergedusr compliant.