-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
erofs-snapshotter: protect layer blobs with FS_IMMUTABLE_FL #11431
base: main
Are you sure you want to change the base?
Conversation
0efcc32
to
fffcc32
Compare
@@ -507,6 +535,8 @@ func (s *snapshotter) Remove(ctx context.Context, key string) (err error) { | |||
if err != nil { | |||
return fmt.Errorf("unable to get directories for removal: %w", err) | |||
} | |||
// Clear IMMUTABLE_FL before removal, since this flag avoids it. | |||
_ = setImmutable(s.layerBlobPath(id), false) |
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.
I think we should return this error here.
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.
Yeah, will fix later.
I once thought administers manually house-keeping or unsupported fs use cases or lack of CAP_LINUX_IMMUTABLE due to MAC restriction.
But since setImmutable won't SETFLAGS if (GETFLAG & FS_IMMUTABLE_FL == 0), I'm fine with it now.
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.
Fixed, thanks for your comment!
As documented in ioctl_iflags(2): ``` FS_IMMUTABLE_FL The file is immutable: no changes are permitted to the file contents or metadata (permissions, timestamps, ownership, link count, and so on). (This restriction applies even to the superuser.) ``` For example, any user cannot delete/move layer blobs when FS_IMMUTABLE_FL is set: ``` sh # cd /var/lib/containerd/io.containerd.snapshotter.v1.erofs/snapshots/4 # mv layer{,1}.erofs mv: cannot move 'layer.erofs' to 'layer1.erofs': Operation not permitted # rm layer.erofs rm: cannot remove 'layer.erofs': Operation not permitted ``` Note that it's a best-effort approach for data loss prevention. IOWs, just warn out if FS_IMMUTABLE_FL cannot be set anyway (e.g., due to lack of support in the underlying filesystem.) Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
fffcc32
to
5fa6ddd
Compare
As documented in ioctl_iflags(2):
For example, any user cannot delete/move layer blobs when FS_IMMUTABLE_FL is set:
Note that it's a best-effort approach for data loss prevention(e.g. #10655). IOWs, just warn out if FS_IMMUTABLE_FL cannot be set anyway (e.g., due to lack of support in the underlying filesystem.)