Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@robbertkl
Copy link
Contributor

@robbertkl robbertkl commented Feb 14, 2024

Description

After setup.d/mail_state.sh moves files/dirs from the container itself to /var/mail-state, they retains their SELinux security context labels, which are bound to the current container. When using named volumes, this leads to the files/dirs becoming inaccessible.

This PR lets the setup script apply the security context from the mail-state directory after moving, so they are still accessible when a new container is created that re-uses a named volume. The result is that the moved files will have the same security context as if they were created by the script.

This also explains the issue only occurs with the mail-state volume. In the other volumes only new files are created, instead of files being moved.

Fixes #3887

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (non-breaking change that does improve existing functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (README.md or the documentation under docs/)
  • If necessary, I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have added information about changes made in this PR to CHANGELOG.md

@casperklein
Copy link
Member

casperklein commented Feb 14, 2024

LGTM 👍

I am not very firm with SELinux. Can this introduce any unwanted side-effects/problems on systems, not using SELinux security context?

@robbertkl
Copy link
Contributor Author

robbertkl commented Feb 14, 2024

I am not very firm with SELinux. Can this introduce any unwanted side-effects/problems on systems, not using SELinux security context?

I've added ignoring the exit status (in case the scripts use set -e) and discarding stderr so there won't be any error message for non SELinux systems.

If the system supports SELinux but it's "Permissive" instead of "Enforcing", the chcon isn't really needed for it to work, although it prevents a lot of audit messages so is still nice to have. On a system without SELinux (I've tested on an old RancherOS host with linux 4.14) chcon fails and outputs an error; it doesn't do any harm (so shouldn't have any side effects), but I've now ignored the error so it doesn't pollute the container log.

Copy link
Member

@casperklein casperklein left a comment

Choose a reason for hiding this comment

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

Two changes to align with the style elsewhere used in DMS.

@robbertkl
Copy link
Contributor Author

Thanks, fixed!

casperklein
casperklein previously approved these changes Feb 14, 2024
@robbertkl robbertkl force-pushed the fix/mailstate-selinux-context branch from d37f2de to 3d778b4 Compare February 15, 2024 11:01
@robbertkl robbertkl removed their assignment Feb 15, 2024
@robbertkl
Copy link
Contributor Author

@polarathene Just curious, did you assign me to update my branch? Just did and unassigned myself again, hope that's ok.

@georglauterbach
Copy link
Member

georglauterbach commented Feb 15, 2024

I re-assigned you; this makes finding PRs for maintainers easier. It's just a visibility-thing, not strictly relevant to any actions that we need you to take.

Copy link
Member

@polarathene polarathene left a comment

Choose a reason for hiding this comment

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

I'll apply this.

Copy link
Member

@polarathene polarathene left a comment

Choose a reason for hiding this comment

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

LGTM! Like @casperklein I don't have the SELinux expertise to provide much feedback.

I'd merge but not sure if @georglauterbach wants to block for their own review.

@georglauterbach
Copy link
Member

Go ahead and merge, not time to review this one :)

@polarathene polarathene merged commit a815bf5 into docker-mailserver:master Feb 16, 2024
@robbertkl robbertkl deleted the fix/mailstate-selinux-context branch February 16, 2024 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/scripts area/security kind/bug/fix A fix (PR) for a confirmed bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug report: SELinux incompatibility using named volumes

4 participants