perf: avoid unconditional chmod -R in enforce_misp_data_permissions#378
Open
LSI-ZuagrastaWastl wants to merge 1 commit intoMISP:masterfrom
Open
perf: avoid unconditional chmod -R in enforce_misp_data_permissions#378LSI-ZuagrastaWastl wants to merge 1 commit intoMISP:masterfrom
chmod -R in enforce_misp_data_permissions#378LSI-ZuagrastaWastl wants to merge 1 commit intoMISP:masterfrom
Conversation
…are actually incorrect Replace the three unconditional `chmod -R` calls with targeted `find` expressions that only touch files whose permissions are actually incorrect.
Collaborator
|
Wow TIL. Will test and merge it at the next opportunity. LGTM, thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
enforce_misp_data_permissions()inentrypoint_nginx.shends each permission block with an unconditionalchmod -R u+w,g+woverapp/filesandapp/tmp. On deployments with large numbers of attachments or events, this causes significant startup delays on everydocker compose up, even when permissions are already correct.see Issue: #377
Two additional issues exist in the same function:
-not -perm 550and-not -perm 770without a leading/are interpreted as exact octal matches byfind, not as bitmask checks. This means files that already have more bits set (e.g.0750) are unnecessarilychmod'd every run.chmod -R u+w,g+w <dir>traverses and syscalls every single file, regardless of whether any permission bit is actually wrong.Fix
Replace the three unconditional
chmod -Rcalls with targetedfindexpressions that only touch files whose permissions are actually incorrect:Why
-perm /0550instead of-perm 0550From
man find:-not -perm 0550would re-chmod any file with mode0750,0555,0755, etc. — i.e. files that already have equal or broader permissions — which is incorrect.-not -perm /0550correctly skips files that already satisfy the minimum required bits.Impact
compose up(steady state): thefindfilter short-circuits immediately for every file that already has correct permissions, reducing the number ofchmodsyscalls from all files to files with wrong permissions, which in a stable deployment is ~0.compose up.Testing
Tested on a deployment with ~80GB files in
app/files. Startup permission phase went from ~5-10 minutes to under 1 minute on the secondcompose up.