Skip to content

set up default IDMappings when none are set and userns=auto#27988

Open
vmsh0 wants to merge 1 commit into
containers:mainfrom
vmsh0:idmappings_defaults
Open

set up default IDMappings when none are set and userns=auto#27988
vmsh0 wants to merge 1 commit into
containers:mainfrom
vmsh0:idmappings_defaults

Conversation

@vmsh0
Copy link
Copy Markdown
Contributor

@vmsh0 vmsh0 commented Jan 29, 2026

This PR originates from podman-py#499.

The rationale is to make the behavior of userns=auto a bit more consistent, by setting up default IDMappings when none are provided. Before this patch, Podman would just ignore the userns parameter silently, resulting in a container with non-private userns. This is not ideal from the point of view of security, and it can also be confusing (it was to me at least).

After this patch, e.g. API call POST libpod/containers/create UserNS='{"NSMode":"auto"}' results in a container with private userns, as imo one could reasonably expect.

Checklist

Ensure you have completed the following checklist for your pull request to be reviewed:

  • Certify you wrote the patch or otherwise have the right to pass it on as an open-source patch by signing all
    commits. (git commit -s). (If needed, use git commit -s --amend). The author email must match
    the sign-off email address. See CONTRIBUTING.md
    for more information.
  • Referenced issues using Fixes: #00000 in commit message (if applicable)
  • Tests have been added/updated (or no tests are needed)
  • Documentation has been updated (or no documentation changes are needed)
  • All commits pass make validatepr (format/lint checks)
  • Release note entered in the section below (or None if no user-facing changes)

Does this PR introduce a user-facing change?

libpod API sets up default IDMappings during container creation when userns is set to 'auto'

@vmsh0 vmsh0 force-pushed the idmappings_defaults branch from 11d8520 to 7ee48a0 Compare January 29, 2026 19:12
return nil, nil, nil, err
}
s.IDMappings = mappings
s.Annotations[define.UserNsAnnotation] = string(s.UserNS.NSMode)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm thinking if we can guarantee that s.Annotations is not nil in all cases in this function. Quick search shows there are places in the code checking if Annotations is nil, so it probably can happen.

Maybe you could add

if s.Annotations == nil {
    s.Annotations = make(map[string]string)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, pushed. Now I'm also unconditionally setting up the annotation, so it also works when a client requests creation with explicit IDMappings but no annotation.

@vmsh0 vmsh0 force-pushed the idmappings_defaults branch from 7ee48a0 to 8353072 Compare January 30, 2026 14:38
@vmsh0
Copy link
Copy Markdown
Contributor Author

vmsh0 commented Jan 30, 2026

I have also submitted #27998, which will fail the test added to this PR, so if the plan is to accept the other PR I will update the test in this one

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 2, 2026

A friendly reminder that this PR had no activity for 30 days.

Copy link
Copy Markdown
Member

@Honny1 Honny1 left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM

PTAL @containers/podman-maintainers

Copy link
Copy Markdown
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

LGTM

@github-actions github-actions Bot removed the stale-pr label Mar 12, 2026
@Honny1
Copy link
Copy Markdown
Member

Honny1 commented Apr 29, 2026

@vmsh0, can you please rebase on main?

Signed-off-by: Riccardo Paolo Bestetti <pbl@bestov.io>
@vmsh0 vmsh0 force-pushed the idmappings_defaults branch from 8353072 to c38fd80 Compare April 29, 2026 11:55
@Honny1 Honny1 requested a review from jankaluza April 29, 2026 12:06
@jankaluza
Copy link
Copy Markdown
Member

LGTM if tests pass.

@vmsh0
Copy link
Copy Markdown
Contributor Author

vmsh0 commented Apr 29, 2026

The usual tests + some new ones are still failing for this and #27998, but the failures still look unrelated by these patches imho

@Honny1
Copy link
Copy Markdown
Member

Honny1 commented Apr 29, 2026

I re-run failed tests.

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.

4 participants