-
Notifications
You must be signed in to change notification settings - Fork 392
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
Protected finding data #3779
Merged
NDStrahilevitz
merged 3 commits into
aquasecurity:main
from
NDStrahilevitz:protected_finding_data
Dec 31, 2023
Merged
Protected finding data #3779
NDStrahilevitz
merged 3 commits into
aquasecurity:main
from
NDStrahilevitz:protected_finding_data
Dec 31, 2023
Conversation
This file contains 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
NDStrahilevitz
commented
Dec 26, 2023
go.mod
Outdated
golang.org/x/text v0.14.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
kernel.org/pub/linux/libs/security/libcap/psx v1.2.68 // indirect | ||
) | ||
|
||
replace github.com/kubernetes/cri-api => k8s.io/cri-api v0.23.5-rc.0 | ||
|
||
replace github.com/aquasecurity/tracee/types => ./types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: types PR and bump
AlonZivony
approved these changes
Dec 26, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Due to the change in the previous types commit, a mutex was added to the detect.Finding struct. In order not to break existing usage, the new mutex was added not as a pointer. This would cause a mutex copy almost everywhere, making the change ineffective. As such, the struct must be passed as a reference everywhere instead.
b777b59
to
f72fd50
Compare
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.
1. Explain what the PR does
f72fd50 fix(finding): use thread safe finding data access
ff65fc6 chore(all): change all detect.Finding to pointers
156569e chore(go.mod): bump types
Fix #3748
2. Explain how to test it
Make sure no regression happens, this change should not fundamentally change current behavior, but rather allow correct signature authoring.
3. Design choice
I initially wanted to break the Finding struct by adding the following struct:
And add the thread-safe methods to that struct. This worked perfectly fine, with the api break being functionally not hard to fix with search and replaces. Only one problem happened, the output templates in tracee-rules were broken. I've made multiple attempts at fixing it, including adding custom json marshalling, but nothing worked. The only thing which worked with no breaking was keeping the existing
Data
field in place and untouched.This introduced the problem of adding the mutex into the existing struct: if we add the mutex as a pointer then using the thread-safe methods as is would cause a nil pointer reference panic. This means that either all users now need to initialize the mutex themselves, or use a constructor which is not enforced for use (except for the otherwise occuring crash). That meant that the mutex must be a non pointer value.
That lead to the problem of mutex copying. mutex copying is an issue, since the locks are now unshared, which would mean that our problem is left unresolved. the way to use non pointer mutexes is if the object itself (the finding) is always passed around as a reference. Which meant changing the whole codebase to do just that.
Why was I still ok with choosing this solution?