Skip to content

Conversation

giuseppe
Copy link
Member

@giuseppe giuseppe commented Aug 25, 2025

commit 4a27212 introduced the regression.

Detect when running inside a user namespace and treat the mounts in the same way as they would be treated if creating a new user namespace.

Closes: #1855

Summary by Sourcery

Bug Fixes:

  • Add a check for running inside an existing user namespace and set has_userns to enforce correct mount handling

commit 4a27212 introduced the
regression.

Detect when running inside a user namespace and treat the mounts in
the same way as they would be treated if creating a new user
namespace.

Closes: containers#1855

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Copy link

sourcery-ai bot commented Aug 25, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Introduces runtime detection of existing user namespaces when preparing mounts and applies the same mount handling logic as for newly created user namespaces to avoid regression.

Sequence diagram for mount preparation with user namespace detection

sequenceDiagram
    participant Container
    participant LinuxMountHandler
    participant UserNamespaceChecker
    Container->>LinuxMountHandler: prepare_and_send_mount_mounts()
    LinuxMountHandler->>UserNamespaceChecker: check_running_in_user_namespace()
    UserNamespaceChecker-->>LinuxMountHandler: is_in_userns (bool)
    LinuxMountHandler->>LinuxMountHandler: Set has_userns based on detection
    LinuxMountHandler->>LinuxMountHandler: Apply userns mount logic if has_userns
    LinuxMountHandler->>Container: Mounts prepared
Loading

Class diagram for user namespace detection in mount preparation

classDiagram
    class LinuxMountHandler {
        +prepare_and_send_mount_mounts(container, pid, sys)
        -has_userns: bool
        -mount_fds
    }
    class UserNamespaceChecker {
        +check_running_in_user_namespace(err): int
    }
    LinuxMountHandler --> UserNamespaceChecker: uses
    LinuxMountHandler : has_userns set by check_running_in_user_namespace()
    LinuxMountHandler : applies userns mount logic if has_userns
Loading

File-Level Changes

Change Details Files
Detect and treat mounts inside existing user namespaces like new user namespace mounts
  • Added a check for running in a user namespace when has_userns is false
  • Called check_running_in_user_namespace and handled negative return as error
  • Updated has_userns flag based on the detection result
src/libcrun/linux.c

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Collaborator

@flouthoc flouthoc left a comment

Choose a reason for hiding this comment

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

LGTM

@flouthoc flouthoc merged commit 32d10af into containers:main Aug 25, 2025
47 checks passed
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.

Regression: rootless podman does not consider user supplementary group when mounting volume/file

2 participants