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

erofs-snapshotter: protect layer blobs with FS_IMMUTABLE_FL #11431

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hsiangkao
Copy link
Contributor

@hsiangkao hsiangkao commented Feb 25, 2025

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:

 # 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(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.)

@dosubot dosubot bot added the area/runtime Runtime label Feb 25, 2025
@hsiangkao
Copy link
Contributor Author

image

@@ -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)
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs Triage
Development

Successfully merging this pull request may close these issues.

3 participants