-
Notifications
You must be signed in to change notification settings - Fork 44
fcontext is painfully slow #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
RE many contexts at once - this not good CM methodology, but if we make it elegant we can consider it. Can you suggest a syntax? selinux_policy_fcontext '/var/www' do
action :delete
end
# Caching that fcontext does not exist
package 'apache'
# ^ Fcontext is created because of package installation
selinux_policy_fcontext '/var/www' do
action :delete
end
# ^ Will not do anything because cached as does not exist When I was looking at speeding these things up, I looked into using custom Python scripts instead of In your case, since you want batching, I suggest you create a python script that modifies the store or an SELinux module, depending on your needs / time you can spend on this. WDYT? |
Yes, I see the point. It's a common situation in software development: you have a very nice design, but then in the end you find that it isn't all that performant, and you have to tweak it. Another example where the same problem surfaced was multipackage support in the package resource, as well as the multipackage cookbook. Also a situation where the gospel CM way ended up extremely slow. Same thing with video drivers. You could have the software draw every pixel individually, but the more smarts you put in the driver (and the hardware) the better performance you get. Your analysis on why it is so slow is close to correct. It does seem to be the "load/save" that takes forever. But it's not quite that. selinux works based on transactions. The loading and saving is actually fast, but starting and finishing a transactions is extremely expensive. That is why semanage -i even exists: everything you submit through that call is processed in a single transaction. You can submit 100 fcontexts all at once with semanage -i, and it will take about the same amount of time as a single fcontext with semanage fcontext -a. On the design: The fcontext resource code could do basically the same thing as the package resource: allow passing an array of file/directory names, and an array of secontexts. That said: I actually already had a solution based on the selinux cookbook. That cookbook used arrays of attributes to manage booleans, and I extended that concept to also work for fcontexts and ports. Sadly, my PR for that improvement was rejected. When I wanted to switch to the selinux_policy cookbook, I ran into the performance issue. Another way would be to model this batch after the multipackage cookbook. Use one resource just to collect the requests. Use a different resource (or multipackage actually uses the same one) to check all of the requested fcontexts against what's already there, and then - if necessary - install all the missing ones at once with semanage -i. You are right about caching. My design suggestion would solve that. You'd retrieve the fcontexts only immediately before generating the input for semanage -i. |
Well, if you have a concrete suggestion for batching in some way, even Nitzan Raz On Thu, Nov 3, 2016 at 10:46 AM, Kevin Keane notifications@github.com
|
This idea is taken from https://supermarket.chef.io/cookbooks/multipackage . I think there are also some useful implementation ideas in that cookbook; it uses an accumulator pattern.
And similar for booleans
|
I like Lamont's work but this multipackage thing seems hella ugly.
Not sure how complicated it'll be to implement though. |
I think there should be several considerations here. For one, optimizations often tend to be ugly. It's the nature of the beast. And to some extent, it is also a matter of taste. I find multipackage quite neat, although I could imagine two improvements (both of which may end up not having much value in real life). I would argue for a multipackage-style solution for several reasons:
If I am right about your approach being sequence dependent, it could only be used within one cookbook. For that, the much simpler suggestion of expanding the resource to accept multiple path/fcontext pairs (much as package now accepts multiple package names) would be much more straightforward.
If you do go for your proposal, how about changing the action from ":nothing" to ":collect"? A second suggestion could be to add a chef handler that completes the transaction at the end of the run (that would deal with sequence-related issues). |
Widely used? Iunno, doesn't seem so popular according to my quick checks. I'll admit I'm not working with Chef so much, so I may be out of sync.
Just like with notifications. Looks weird to me that you'd want to do that, but whatevs To sum up, I don't like the idea of collecting these resources implicitly ( |
Yeah, I completely hear you about the drawbacks - there seem to be advantages and drawbacks on both sides, and reasonable minds can disagree on what's more important. I just like the consistency in the pattern, but your points have merit, too. And in the end, it's your call. What I care about most is solving the performance problem. Exactly how to do that is secondary - it seems like we have at least three different designs floating around, which is a lot better than having no ideas! |
So, to sum up - I'd gladly read bits of code if you (or anyone) wanna slide some my way. |
Should be solved by #60 |
I didn't have a chance to test it yet, but I don't see how #60 would address the issue. The slowness does not occur during restorecon, but rather is due to semanage fcontext being called frequently, once for each selinux_policy_fcontext resource. semanage fcontext basically does three things: open an selinux transaction, update the fcontext database, and close the selinux transaction. Updating the fcontext database is actually very fast, but the transactions operations are very slow. |
Yeah I got confused again, sorry. Will not be solved by #60 |
Closing due to inactivity. If this is still an issue please reopen or open another issue. Alternatively drop by the #sous-chefs channel on the Chef Community Slack and we'll be happy to help! Thanks, |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Each selinux_policy_fcontext resource takes a very long time to run - five to ten seconds on my system. This is of course due to the underlying semanage utility also being slow.
When adding many fcontexts, that slow down my cookbook to unacceptable levels (from 2 to about 20 minutes) - not just the first time, but on every run because testing the guards also takes a long time.
The semanage utility supports importing many fcontexts (and booleans and ports) at once (semanage -i), which is dramatically faster.
Also, testing if a context already exists could be optimized by caching the output from semanage fcontext -ln
Similar optimizations should also be possible for booleans and ports, although it is, at least for me, less critical.
The text was updated successfully, but these errors were encountered: