-
Notifications
You must be signed in to change notification settings - Fork 13
Refactor filesystem.go and adapt tests to use a real file system #71
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
base: main
Are you sure you want to change the base?
Conversation
// any sensitive data on disk in production. | ||
func NewFilesystemOnDisk(log logr.Logger, basePath string) (*Filesystem, error) { | ||
if !filepath.IsAbs(basePath) { | ||
return nil, fmt.Errorf("baseDir must be an absolute path") |
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.
Starting from this PR, we no longer support the weird relative path notation. All paths have to be absolute.
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.
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: Tim Ramlot <[email protected]>
ca97148
to
e846f8c
Compare
// If a fsGroup is defined, Chown the directory to that group. | ||
if fsGroup != nil { | ||
if err := os.Chown(f.dataPathForVolumeID(meta.VolumeID), -1, int(*fsGroup)); err != nil { | ||
if err := os.Lchown(f.dataPathForVolumeID(meta.VolumeID), -1, int(*fsGroup)); err != nil { |
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.
Chown vs Lchown:
If the file is a symbolic link, it changes the uid and gid of the link itself.
This seems more secure. However, since the dataPathForVolumeID
is a folder, this should not change anything.
@@ -171,11 +195,6 @@ func (f *Filesystem) WriteMetadata(volumeID string, meta metadata.Metadata) erro | |||
func (f *Filesystem) RegisterMetadata(meta metadata.Metadata) (bool, error) { | |||
existingMeta, err := f.ReadMetadata(meta.VolumeID) | |||
if errors.Is(err, ErrNotFound) { | |||
// Ensure directory structure for the volume exists | |||
if err := f.ensureVolumeDirectory(meta.VolumeID); err != nil { |
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.
This is now called in WriteMetadata
instead.
} | ||
|
||
// Data directory should be read and execute only to the fs user and group. | ||
if err := os.MkdirAll(f.dataPathForVolumeID(volumeID), 0550); err != nil { |
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.
This was moved to WriteFiles
, since we don't need it in WriteMetadata
(the other caller of this function).
Adds tests to prevent bugs like #70 in the future.
Refactors filesystem.go to only accept absolute paths instead of the weird current relative absolute paths (due to
os.DirFS("/")
), fixing #15.NOTE: we will have to modify all csi-drivers that use this lib to only accept/ input absolute paths