Skip to content
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

Added event for default stable rule "Remove Bulk Data from Disk" #109

Merged
merged 8 commits into from
Mar 26, 2024

Conversation

GLVSKiriti
Copy link
Contributor

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind documentation

/kind tests

/kind feature

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area commands

/area pkg

/area events

What this PR does / why we need it:
Added an event for the default stable rule "Remove Bulk Data from Disk" which is very important to test because sometimes bulk data removal can be done with the intention to destroy data, possibly interrupting availability to systems.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

@GLVSKiriti
Copy link
Contributor Author

Kindly tell me if any changes required!!

Copy link
Member

@leogr leogr left a comment

Choose a reason for hiding this comment

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

I guess we need to clean up the temp dir.


func RemoveBulkDataFromDisk(h events.Helper) error {
// Creates temporary data for testing, avoiding critical file deletion.
tmpDir, err := os.MkdirTemp(os.TempDir(), "created-by-falco-event-generator")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
tmpDir, err := os.MkdirTemp(os.TempDir(), "created-by-falco-event-generator")
tmpDir, err := os.MkdirTemp(os.TempDir(), "created-by-falco-event-generator")
defer os.RemoveAll(tmpDir) // clean up

Copy link
Contributor Author

@GLVSKiriti GLVSKiriti Mar 23, 2024

Choose a reason for hiding this comment

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

@leogr why again defer os.RemoveAll(tmpDir) as we already removing it with shred command in the same code at last

cmd := exec.Command("shred", "-u", tmpDir)
err = cmd.Run()
return err

Copy link
Member

Choose a reason for hiding this comment

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

I did not consider that, you're likely right.

Just one doubt: what happens if shred fails? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

irrespective of shred exist or not ! the rule is triggering in this case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See here mkfs utility is not there in my system. Also the rule is triggering irrespective of utility existence

abcd

Signed-off-by: GLVS Kiriti <[email protected]>
@GLVSKiriti GLVSKiriti requested a review from leogr March 22, 2024 16:29
@GLVSKiriti
Copy link
Contributor Author

GLVSKiriti commented Mar 22, 2024

@leogr This is also working fine i.e, it produces warning message on left terminal

removebulkdata


func RemoveBulkDataFromDisk(h events.Helper) error {
// Creates temporary data for testing, avoiding critical file deletion.
tmpDir, err := os.MkdirTemp(os.TempDir(), "created-by-falco-event-generator")
Copy link
Member

Choose a reason for hiding this comment

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

I did not consider that, you're likely right.

Just one doubt: what happens if shred fails? 🤔

events/syscall/remove_bulk_data_from_disk.go Outdated Show resolved Hide resolved
As with shred we can remove a file not a directory

Signed-off-by: GLVS Kiriti <[email protected]>
@GLVSKiriti
Copy link
Contributor Author

@leogr This is also working fine i.e, it produces warning message on left terminal

removebulkdata

Just updated and test is also successful now!!

Question: whether to skip action if shred utility not exists?

IMO Instead of directly skipping action can we just run the command so that rule triggers? and if shred not exists clean up happens and remove the file by

    defer os.Remove(filename)

@GLVSKiriti GLVSKiriti requested a review from leogr March 25, 2024 17:46
@leogr
Copy link
Member

leogr commented Mar 26, 2024

Question: whether to skip action if shred utility not exists?

My original idea was that we should skip the action whenever the preconditions are not met. Here's a clear example of a skipped action due to a missing utility:

path, err := exec.LookPath("crontab")
if err != nil {
// if we don't have a crontab, just bail
return &events.ErrSkipped{
Reason: "crontab utility not found in path",
}
}

That being said, if just trying to execute the shred command, the rule will be triggered (even when the utility is missing), then I am ok with your proposal 👇

IMO Instead of directly skipping action can we just run the command so that rule triggers?

In such a case, please just leave a code comment to explain why what we are doing.

Thanks

GLVSKiriti and others added 2 commits March 26, 2024 14:38
Signed-off-by: GLVSKiriti <[email protected]>
@GLVSKiriti
Copy link
Contributor Author

IMO Instead of directly skipping action can we just run the command so that rule triggers?

In such a case, please just leave a code comment to explain why what we are doing.

Just added the comments!

Co-authored-by: Leonardo Grasso <[email protected]>
Signed-off-by: GLVSKiriti <[email protected]>
@GLVSKiriti GLVSKiriti requested a review from leogr March 26, 2024 11:57
@poiana
Copy link

poiana commented Mar 26, 2024

LGTM label has been added.

Git tree hash: b66fe657a922e9ba9a76595b8ff7b093333a0c53

@poiana
Copy link

poiana commented Mar 26, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: GLVSKiriti, leogr

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana poiana merged commit cde96d9 into falcosecurity:main Mar 26, 2024
4 checks passed
@GLVSKiriti GLVSKiriti deleted the removeBlukDataFromDisk branch March 26, 2024 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants