Implement safeRemoveAll API to validate filesystem mounts#651
Open
Implement safeRemoveAll API to validate filesystem mounts#651
Conversation
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.
Issue #, if available:
N/A - New feature implementation
Description of changes:
[Draft PR] Adding SafeRemoveAll feature to validate filesystem mounts while deletion.
This PR introduces a new
SafeRemoveAllwrapper function in theinternal/systempackage that provides safe directory removal with mount point detection and optional unmounting capabilities. This replaces allos.RemoveAll()calls throughout the codebase to prevent accidental deletion of mounted filesystems.Key Changes:
Core Implementation:
SafeRemoveAllfunction with configurable behavior:allowUnmount: Controls whether to attempt unmounting detected mount pointsforceUnmount: Enables aggressive unmount methods when graceful unmount failsPlatform-Specific Files:
safe_remove_linux.go: Linux syscall-based force unmount (MNT_DETACH,MNT_FORCE)safe_remove_other.go: Fallback implementation for non-Linux platformsos.RemoveAll()when mount utilities are unsupportedCodebase Integration:
os.RemoveAll()calls across multiple packages:internal/cleanup,internal/flows,internal/kubectlinternal/kubelet,internal/cni,internal/containerdinternal/ssm,internal/tracker,internal/artifactinternal/iamrolesanywhere,internal/iamauthenticatorSafeRemoveAll(path, false, false)(safe mode)Dependencies:
k8s.io/mount-utils v0.33.2for cross-platform mount operationsTesting (if applicable):
Unit Tests:
safe_remove_test.go)Integration Tests:
uninstall-with-mounted-filesystemhelpers.shfor mount point testingTest Results: