Skip to content
This repository has been archived by the owner on Oct 10, 2020. It is now read-only.

syscontainers: set SELinux label for files copied to the host #1143

Closed

Conversation

giuseppe
Copy link
Collaborator

@giuseppe giuseppe commented Dec 6, 2017

Signed-off-by: Giuseppe Scrivano [email protected]

@giuseppe
Copy link
Collaborator Author

giuseppe commented Dec 6, 2017

@jeremyeder this should also fix the issue we were discussing last week with files copied to the host not getting the right label

@@ -25,6 +26,10 @@ def copyfile(src, dest):
return True
else:
shutil.copy2(src, dest)
Copy link
Member

Choose a reason for hiding this comment

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

It's more robust to use setfscreatecon() to atomically create the file with the right context; see what ostree-sepolicy.c does.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks for the hint, I'll give it a try and update the patch. I'll need to check the "copy2" doesn't override it.

@@ -52,7 +57,7 @@ def file_checksum(path, blocksize=(1<<20)):
return h.hexdigest()

@staticmethod
def rm_add_files_to_host(old_installed_files_checksum, exports, prefix="/", files_template=None, values=None, rename_files=None):
def rm_add_files_to_host(old_installed_files_checksum, exports, prefix="/", files_template=None, values=None, rename_files=None, files_content=None):
Copy link
Contributor

@peterbaouoft peterbaouoft Dec 7, 2017

Choose a reason for hiding this comment

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

hi, quick question, is files_content used? it seems to fail the pylint check when running normal make for upstream repo(forgot to mention it yesterday)

[root@localhost atomic]# make
/usr/bin/python setup.py build
running build
running build_py
copying Atomic/rpm_host_install.py -> build/lib/Atomic
running build_scripts
/usr/bin/python -m pylint --disable=all --enable=E --enable=W --additional-builtins=_ *.py atomic Atomic tests/unit/*.py -d=no-absolute-import,print-statement,no-absolute-import,bad-builtin,catching-non-exception,raising-non-exception
No config file found, using default configuration
************* Module Atomic.rpm_host_install
W: 60,133: Unused argument 'files_content' (unused-argument)

--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, -0.00)

make: *** [Makefile:41: pylint-check] Error 4

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks to have noticed it. It is a piece from another patch I was working on, I dropped it in a fixup patch

@giuseppe giuseppe force-pushed the syscontainers-set-label branch from fadcd8d to 412e981 Compare December 8, 2017 11:59
@giuseppe giuseppe changed the title syscontainers: set selinux label for files copied to the host [WIP] syscontainers: set selinux label for files copied to the host Dec 8, 2017
@giuseppe
Copy link
Collaborator Author

giuseppe commented Dec 8, 2017

I've changed the implementation to use setfscreatecon_raw. I've marked the PR as WIP as I have not added a new test yet.

@peterbaouoft could you please verify if the firewalld system container still work with the new implementation and that the new files get a correct label?

@@ -74,7 +79,14 @@ def rm_add_files_to_host(old_installed_files_checksum, exports, prefix="/", file
# if there is a directory hostfs/ under exports, copy these files to the host file system.
hostfs = os.path.join(exports, "hostfs")
new_installed_files_checksum = {}
if os.path.exists(hostfs):
if not os.path.exists(hostfs):
return new_isntalled_files_checksum
Copy link
Contributor

Choose a reason for hiding this comment

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

could you please verify if the firewalld system container still work with the new implementation and that the new files get a correct label?

sure thing =)

Tho, seems like a typo here, shouldn't it be new_installed_files_checksum?

+ make pylint-check
python3 -m pylint --disable=all --enable=E --enable=W --additional-builtins=_ *.py atomic Atomic tests/unit/*.py -d=no-absolute-import,print-statement,no-absolute-import,bad-builtin,catching-non-exception,raising-non-exception
No config file found, using default configuration
************* Module Atomic.rpm_host_install
E: 83,19: Undefined variable 'new_isntalled_files_checksum' (undefined-variable)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

:/ yes thanks. Fixed in a newer version

@giuseppe giuseppe force-pushed the syscontainers-set-label branch 3 times, most recently from 774cb72 to 64b8eee Compare December 11, 2017 10:45
@giuseppe giuseppe changed the title [WIP] syscontainers: set selinux label for files copied to the host syscontainers: set SELinux label for files copied to the host Dec 11, 2017
@giuseppe giuseppe force-pushed the syscontainers-set-label branch 7 times, most recently from e65ff3e to 7ea2756 Compare December 11, 2017 13:18
@giuseppe giuseppe force-pushed the syscontainers-set-label branch from 7ea2756 to 4f9e964 Compare December 14, 2017 13:28
@giuseppe
Copy link
Collaborator Author

@peterbaouoft from my tests here, it solves the issue. Have you had a chance to verify this on your end?

@peterbaouoft
Copy link
Contributor

peterbaouoft commented Dec 15, 2017

@giuseppe , currently checking. The last time steve and I verified the first stage systemctl start firewalld will be able to start without the selinux problem after applying the patch fix.

However, recently I checked on the host I had, I am unable to run atomic run firewalld firewall-cmd --state saying that I get org.fedoraproject.FirewallD1.info is not registered. (even if systemctl start firewalld succeeds )

EDIT: Thanks for the fix. This patch fixes the problem we saw earlier for selinux issue, sadly not fixing atomic run firewalld firewall-cmd problem.
I will report further related failure details in the firewalld patch. But I think the atomic run related failures are not related to this patch, so I think patch works =).

@giuseppe
Copy link
Collaborator Author

@rhatdan are you fine with this PR?

@rhatdan
Copy link
Member

rhatdan commented Dec 18, 2017

Well this will cause the target to be labeled correctly and all of the content to have that label. Any content created under the label may or may not be labeled correctly.

So if you are copying a single file this will be fine, if you are copying a directory it could be a problem.

@giuseppe
Copy link
Collaborator Author

we copy each file separately so that selabel_lookup_raw+setfscreatecon_raw is done for each file. Doesn't that solve the problem with the directories labelling?

@rhatdan
Copy link
Member

rhatdan commented Dec 18, 2017

Yes that will solve the problem.

@rhatdan
Copy link
Member

rhatdan commented Dec 18, 2017

LGTM

@rhatdan
Copy link
Member

rhatdan commented Dec 18, 2017

@rh-atomic-bot r+

@rh-atomic-bot
Copy link

📌 Commit 4f9e964 has been approved by rhatdan

@rh-atomic-bot
Copy link

⌛ Testing commit 4f9e964 with merge 3241b63...

rh-atomic-bot pushed a commit that referenced this pull request Dec 18, 2017
Signed-off-by: Giuseppe Scrivano <[email protected]>

Closes: #1143
Approved by: rhatdan
@rh-atomic-bot
Copy link

☀️ Test successful - status-papr
Approved by: rhatdan
Pushing 3241b63 to master...

eyusupov pushed a commit to eyusupov/atomic that referenced this pull request Mar 10, 2018
Signed-off-by: Giuseppe Scrivano <[email protected]>

Closes: projectatomic#1143
Approved by: rhatdan
eyusupov pushed a commit to eyusupov/atomic that referenced this pull request Mar 10, 2018
Signed-off-by: Giuseppe Scrivano <[email protected]>

Closes: projectatomic#1143
Approved by: rhatdan
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants