hooks: allow ignoring chdir permission errors for container hooks - #2035
Conversation
Summary of ChangesHello, 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 enhances the robustness of container hook execution, especially within user namespaces. It addresses issues where Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
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.
Code Review
This pull request introduces a can_ignore_chdir_errors flag to handle chdir permission errors for container hooks, which can occur when using user namespaces. The implementation correctly propagates this flag and enables it only for createContainer and startContainer hooks, which run within the container's namespace context. The logic to ignore only EACCES and EPERM errors is also correct. I have one suggestion to refactor a conditional block for better readability.
| if (cwd && chdir (cwd) < 0) | ||
| _safe_exit (EXIT_FAILURE); | ||
| { | ||
| if (can_ignore_chdir_errors && (errno == EACCES || errno == EPERM)) | ||
| { | ||
| /* Permission errors for chdir are ignored for container hooks that run in user namespace */ | ||
| } | ||
| else | ||
| _safe_exit (EXIT_FAILURE); | ||
| } |
There was a problem hiding this comment.
This logic is correct, but the empty if block can be avoided by inverting the condition. This can make the code more concise and arguably clearer about the intent to only act on the failure case.
if (cwd && chdir (cwd) < 0)
{
// For some hooks running in user namespaces, chdir can fail with permission errors.
// If can_ignore_chdir_errors is set, we ignore EACCES and EPERM.
if (!can_ignore_chdir_errors || (errno != EACCES && errno != EPERM))
_safe_exit (EXIT_FAILURE);
}|
TMT tests failed. @containers/packit-build please check. |
1 similar comment
|
TMT tests failed. @containers/packit-build please check. |
68259d3 to
82c25d9
Compare
kolyshkin
left a comment
There was a problem hiding this comment.
So it looks like we want to ignore chdir failures in those hooks that are run inside container. I might be wrong here but maybe it makes sense to s/can_ignore_chdir_errors/in_container/g (or some such) for clarity and overall generalization (and fix comments accordingly).
Also, do we need to add a check if we're running inside userns?
| _safe_exit (EXIT_FAILURE); | ||
| { | ||
| /* For some hooks running in user namespaces, chdir can fail with permission errors. | ||
| If can_ignore_chdir_errors is set, we ignore EACCES and EPERM. */ |
There was a problem hiding this comment.
This line seems redundant, I'd remove it. It is very clear from the code that we ignore EACCES and EPERM if can_ignore_chdir_errors is set.
82c25d9 to
b8e0a48
Compare
I've changed the check to be used only when running in a user namespace so it is limited to that case |
b8e0a48 to
4ac5bc1
Compare
When running containers with user namespaces (--userns nomap/auto), createContainer and startContainer hooks may fail with EACCES/EPERM when attempting to chdir to directories they don't have permission to access due to user namespace restrictions. This change adds a can_ignore_chdir_errors flag that allows these specific permission errors to be ignored for hooks that run in the container namespace context, while maintaining strict error handling for all other cases. Fixes issue with NVIDIA CDI hooks and other container hooks failing in user namespace scenarios. Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com> Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
4ac5bc1 to
3414373
Compare
|
rebased! |
When running containers with user namespaces (--userns nomap/auto), createContainer and startContainer hooks may fail with EACCES/EPERM when attempting to chdir to directories they don't have permission to access due to user namespace restrictions. This change adds a can_ignore_chdir_errors flag that allows these specific permission errors to be ignored for hooks that run in the container namespace context, while maintaining strict error handling for all other cases.
Fixes issue with NVIDIA CDI hooks and other container hooks failing in user namespace scenarios.