Skip to content

Add missing type transitions for overlay-containers directories#446

Merged
lsm5 merged 1 commit intocontainers:mainfrom
Rolv-Apneseth:overlay_transition_rules
Mar 11, 2026
Merged

Add missing type transitions for overlay-containers directories#446
lsm5 merged 1 commit intocontainers:mainfrom
Rolv-Apneseth:overlay_transition_rules

Conversation

@Rolv-Apneseth
Copy link
Contributor

@Rolv-Apneseth Rolv-Apneseth commented Mar 11, 2026

I'm coming here from coreos/fedora-coreos-tracker#2095, as we're seeing failures in one of our tests due to the files in the overlay-containers directory being marked for re-labelling. This was the output the author of the 6e2a14b shared:

Would relabel /home/foo/.local/share/containers/storage/overlay-containers/f857f27662ab22b7c502a531d61790b7c120dbedc70820962bb45c285aa03cc3/userdata/artifacts from unconfined_u:object_r:container_ro_file_t:s0 to unconfined_u:object_r:data_home_t:s0

But in our test we're now seeing:

Would relabel /var/home/core/.local/share/containers/storage/overlay-containers from system_u:object_r:data_home_t:s0 to system_u:object_r:container_ro_file_t:s0
Would relabel /var/home/core/.local/share/containers/storage/overlay-containers/containers.lock from system_u:object_r:data_home_t:s0 to system_u:object_r:container_ro_file_t:s0
Would relabel /var/home/core/.local/share/containers/storage/overlay-containers/volatile-containers.json from system_u:object_r:data_home_t:s0 to system_u:object_r:container_ro_file_t:s0

So, to my (very limited) understanding, their directory was created with the correct label because artifacts is already covered by an existing rule, and restorecon incorrectly wanted to relabel it. Then, in our case, the added context rules mean that everything under overlay-containers is mislabelled and restorecon correctly wants to relabel them. I believe I've been able to replicate this locally with a mix of podman pull alpine and manually creating directories, and this patch does seem to do the trick, but I do hope I'm not misunderstanding how this all works.

In summary: commit 6e2a14b added file context rules for overlay-containers, but did not add the corresponding type transition rules, causing these directories to be created with data_home_t instead of container_ro_file_t. This PR adds the missing filetrans_pattern rules for overlay-containers and overlay2-containers so they're created with the correct labels.

Summary by Sourcery

Bug Fixes:

  • Ensure overlay-containers and overlay2-containers directories are created with container_ro_file_t (or equivalent) via file transition rules, preventing mislabeling as data_home_t and avoiding unnecessary relabel attempts by restorecon.

Commit 6e2a14b added file context rules for overlay-containers, but did
not add the corresponding type transition rules, causing these
directories to be created with data_home_t instead of
container_ro_file_t. This commit adds the missing filetrans_pattern
rules for overlay-containers and overlay2-containers.

Signed-off-by: Rolv Apneseth <[email protected]>
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 11, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds SELinux file transition rules so overlay-containers and overlay2-containers directories under users’ container storage are automatically created with the correct container_ro_file_t type instead of data_home_t, complementing the previously-added file context rules.

File-Level Changes

Change Details Files
Add SELinux file transition patterns for overlay-containers directories so they are created with container_ro_file_t instead of data_home_t.
  • Introduce filetrans_pattern rules mapping container/process types to container_ro_file_t for overlay-containers paths under user home container storage.
  • Align the new transition rules with the existing file context specifications that already label overlay-containers content as container_ro_file_t.
  • Ensure restorecon no longer reports relabel operations for overlay-containers directories that are now created with the correct label.
container.if
Extend the same SELinux file transition handling to overlay2-containers directories.
  • Add filetrans_pattern rules for overlay2-containers paths mirroring the overlay-containers transitions.
  • Keep naming and path patterns consistent with existing overlay and overlay2 policy rules to avoid divergence.
  • Guarantee that overlay2-containers directories created by container engines receive container_ro_file_t by default.
container.if

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 - 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.

@gemini-code-assist
Copy link

Summary of Changes

Hello, 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 addresses a critical SELinux labeling bug affecting container storage directories. By introducing specific type transition rules, it ensures that overlay-containers and overlay2-containers directories are correctly assigned the container_ro_file_t label upon creation. This prevents mislabeling as data_home_t, thereby eliminating unnecessary restorecon operations and resolving test failures related to incorrect file contexts.

Highlights

  • SELinux Type Transitions: Added missing filetrans_pattern rules for overlay-containers and overlay2-containers directories to ensure they are created with the container_ro_file_t SELinux label.
  • Bug Fix: Resolved an issue where overlay-containers directories were incorrectly labeled as data_home_t, leading to restorecon relabeling attempts and test failures.

🧠 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
  • container.if
    • Added filetrans_pattern rules for overlay-containers and overlay2-containers directories.
Activity
  • No activity recorded for this pull request.
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 correctly adds the missing filetrans_pattern rules for overlay-containers and overlay2-containers to ensure they are created with the correct SELinux labels. This resolves an issue where these directories were being mislabeled. I've included one suggestion to improve the code's maintainability by sorting the related rules alphabetically.

Comment on lines 607 to +614
filetrans_pattern($1, data_home_t, container_ro_file_t, dir, "overlay")
filetrans_pattern($1, data_home_t, container_ro_file_t, dir, "overlay-images")
filetrans_pattern($1, data_home_t, container_ro_file_t, dir, "overlay-layers")
filetrans_pattern($1, data_home_t, container_ro_file_t, dir, "overlay-containers")
filetrans_pattern($1, data_home_t, container_ro_file_t, dir, "overlay2")
filetrans_pattern($1, data_home_t, container_ro_file_t, dir, "overlay2-images")
filetrans_pattern($1, data_home_t, container_ro_file_t, dir, "overlay2-layers")
filetrans_pattern($1, data_home_t, container_ro_file_t, dir, "overlay2-containers")

Choose a reason for hiding this comment

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

medium

For better readability and long-term maintainability, it would be beneficial to keep these related filetrans_pattern rules sorted alphabetically by the directory name. This makes it easier to find specific rules and see what's covered at a glance.

    filetrans_pattern($1, data_home_t, container_ro_file_t, dir, "overlay")
    filetrans_pattern($1, data_home_t, container_ro_file_t, dir, "overlay-containers")
    filetrans_pattern($1, data_home_t, container_ro_file_t, dir, "overlay-images")
    filetrans_pattern($1, data_home_t, container_ro_file_t, dir, "overlay-layers")
    filetrans_pattern($1, data_home_t, container_ro_file_t, dir, "overlay2")
    filetrans_pattern($1, data_home_t, container_ro_file_t, dir, "overlay2-containers")
    filetrans_pattern($1, data_home_t, container_ro_file_t, dir, "overlay2-images")
    filetrans_pattern($1, data_home_t, container_ro_file_t, dir, "overlay2-layers")

Copy link
Member

@lsm5 lsm5 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

@containers/container-selinux-maintainers PTAL

@lsm5
Copy link
Member

lsm5 commented Mar 11, 2026

@containers/container-selinux-maintainers let's get this in before #443 so it can be included in v2.247.0.

@lsm5
Copy link
Member

lsm5 commented Mar 11, 2026

@ca-hu PTAL

@lsm5 lsm5 merged commit 6c488a9 into containers:main Mar 11, 2026
31 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.

2 participants