Skip to content

Add dmverity support to the erofs snapshotter using go-dmverity#12502

Merged
AkihiroSuda merged 1 commit intocontainerd:mainfrom
aadhar-agarwal:aadagarwal/integrate-with-goverity
Apr 1, 2026
Merged

Add dmverity support to the erofs snapshotter using go-dmverity#12502
AkihiroSuda merged 1 commit intocontainerd:mainfrom
aadhar-agarwal:aadagarwal/integrate-with-goverity

Conversation

@aadhar-agarwal
Copy link
Copy Markdown
Contributor

@aadhar-agarwal aadhar-agarwal commented Nov 11, 2025

Add dm-verity support for EROFS layers in containerd

This PR introduces block-level data integrity verification for EROFS container layers using device-mapper verity (dm-verity):

  • Integrates go-dmverity to natively create Merkle hash trees and dm-verity devices for EROFS blobs.
  • Adds new configuration: dmverity_mode for the snapshotter and enable_dmverity for the differ.
  • EROFS layers are formatted with a dm-verity hash tree; metadata is stored in layer.erofs.dmverity alongside the blob.
  • At runtime, each layer is mounted via a dm-verity device (read-only) and verified.
  • Mount options for dm-verity are passed via the mount manager and applied per layer.
  • Extensive tests cover formatting, mounting, idempotency, error cases, and end-to-end workflow.
  • Non-Linux environments gracefully handle unsupported dm-verity operations.

Note: When enabled, it requires a Linux kernel with dm-verity support and the dm_verity module loaded. If using the veritysetup cli is preferred, please refer to #12457

Add dmverity support to the erofs snapshotter

Copy link
Copy Markdown
Member

@hsiangkao hsiangkao left a comment

Choose a reason for hiding this comment

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

just some premature comments.

Comment thread plugins/snapshots/erofs/erofs.go Outdated
Comment thread plugins/snapshots/erofs/erofs.go Outdated
Comment thread plugins/snapshots/erofs/erofs.go Outdated
Comment thread plugins/snapshots/erofs/erofs.go Outdated
Comment thread plugins/snapshots/erofs/erofs.go Outdated
Comment thread docs/snapshotters/erofs.md Outdated
@aadhar-agarwal aadhar-agarwal force-pushed the aadagarwal/integrate-with-goverity branch 3 times, most recently from 54dd70b to 197f481 Compare November 13, 2025 01:49
@vnmxcmnjane-hub

This comment was marked as spam.

@aadhar-agarwal aadhar-agarwal force-pushed the aadagarwal/integrate-with-goverity branch 7 times, most recently from bbee8ed to 487f0ee Compare November 14, 2025 21:56
@aadhar-agarwal aadhar-agarwal marked this pull request as ready for review November 14, 2025 21:58
@aadhar-agarwal
Copy link
Copy Markdown
Contributor Author

@dmcgowan, @AkihiroSuda, @cpuguy83, @fuweid

Could you please take a look when you get a chance? :)

@aadhar-agarwal aadhar-agarwal force-pushed the aadagarwal/integrate-with-goverity branch from 487f0ee to fec3969 Compare November 14, 2025 23:02
Copy link
Copy Markdown
Member

@ChengyuZhu6 ChengyuZhu6 left a comment

Choose a reason for hiding this comment

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

@aadhar-agarwal Good work! Some comments:

Comment thread internal/dmverity/dmverity_linux.go Outdated
Comment thread internal/dmverity/dmverity_linux.go Outdated
Comment thread plugins/mount/erofs/plugin_linux.go Outdated
Comment thread plugins/snapshots/erofs/erofs.go
Comment thread plugins/diff/erofs/dmverity_linux.go Outdated
@aadhar-agarwal aadhar-agarwal force-pushed the aadagarwal/integrate-with-goverity branch 2 times, most recently from 9ec4e15 to ad06e8f Compare November 17, 2025 22:01
@aadhar-agarwal aadhar-agarwal force-pushed the aadagarwal/integrate-with-goverity branch 2 times, most recently from f0275dc to 5df7f8a Compare January 8, 2026 23:30
Copy link
Copy Markdown
Member

@ChengyuZhu6 ChengyuZhu6 left a comment

Choose a reason for hiding this comment

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

@aadhar-agarwal Would you mind updating the code with dmverity? To fix linting issues, I have updated some API names in go-dmverity: https://github.com/containerd/go-dmverity/pull/5/files

@aadhar-agarwal aadhar-agarwal force-pushed the aadagarwal/integrate-with-goverity branch 2 times, most recently from 021ce01 to 30d3d12 Compare January 9, 2026 18:52
@aadhar-agarwal
Copy link
Copy Markdown
Contributor Author

@aadhar-agarwal Would you mind updating the code with dmverity? To fix linting issues, I have updated some API names in go-dmverity: https://github.com/containerd/go-dmverity/pull/5/files

Updated!

@dmcgowan dmcgowan added the area/storage Image Storage label Jan 9, 2026
@aadhar-agarwal
Copy link
Copy Markdown
Contributor Author

aadhar-agarwal commented Jan 22, 2026

Open Question for reviewers:

Before attempting to optimize this, I wanted to get guidance on whether it's the right approach.

Summary
When using EROFS with dm-verity, I'm seeing duplicate device setup/teardown during container creation. Each layer pays ~50ms overhead that could potentially be avoided.

Observation
During CreateContainer, containerd creates a temporary mount (via withReadonlyFS()) to read passwd and group. This triggers:

  1. Create dm-verity device (~22ms)
  2. Mount EROFS
  3. Read files
  4. Unmount EROFS
  5. Close dm-verity device (~26ms)

Then during StartContainer, for the same layer:

  1. Create dm-verity device again (~22ms)
  2. Mount EROFS

The second dm-verity setup is identical to the first - same image, same verification.

Logs (alpine container with single layer):

# CreateContainer - temp mount for reading /etc/passwd, /etc/group
23:06:02.662  activating mount name=readonly-fs-662671502-xSx3
23:06:02.663  detected dm-verity metadata, setting up dm-verity device
23:06:02.663  opening dm-verity device device-name=containerd-erofs-1
23:06:02.685  dm-verity device created successfully                    # +22ms
23:06:02.691  attempting to close dm-verity device device=containerd-erofs-1
23:06:02.717  dm-verity device closed successfully                     # +26ms

# StartContainer - same layer, same device recreated
23:06:02.795  activating mount name=6ef600517a9df...
23:06:02.795  detected dm-verity metadata, setting up dm-verity device
23:06:02.795  opening dm-verity device device-name=containerd-erofs-1  # same!
23:06:02.816  dm-verity device created successfully                    # +21ms

Scale
With ~10 layers, this adds 500-700ms to container startup.

Questions
This seems like a design-level question rather than something I should hack around:

  1. Is this expected behavior? The temp mount is supposed to be temporary, so full cleanup makes sense.
  2. Should dm-verity-backed snapshotters handle this differently? Or is this just the cost of verification?

I don't want to add complexity (like keeping devices open after temp unmount) without understanding the intended behavior.

Copy link
Copy Markdown
Member

@ChengyuZhu6 ChengyuZhu6 left a comment

Choose a reason for hiding this comment

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

I tested the code, but found the following error when trying to run the container:

# ctr run --snapshotter erofs -t ubuntu:22.04 erofs-test sh 
ctr: failed to create erofs mount for parent 1: dm-verity mode is 'on' but .dmverity metadata not found for layer /var/lib/containerd/io.containerd.snapshotter.v1.erofs/snapshots/1/layer.erofs"

Did we miss anything?

@aadhar-agarwal
Copy link
Copy Markdown
Contributor Author

aadhar-agarwal commented Jan 23, 2026

I tested the code, but found the following error when trying to run the container:

# ctr run --snapshotter erofs -t ubuntu:22.04 erofs-test sh 
ctr: failed to create erofs mount for parent 1: dm-verity mode is 'on' but .dmverity metadata not found for layer /var/lib/containerd/io.containerd.snapshotter.v1.erofs/snapshots/1/layer.erofs"

Did we miss anything?

Hi @ChengyuZhu6, thanks for testing! I tried this and it works for me.

$ sudo ctr run --snapshotter erofs -t docker.io/library/ubuntu:22.04 erofs-test sh
#

A couple different reasons this may be happening:

  1. Missing config in differ/snapshotter
[plugins."io.containerd.differ.v1.erofs"]
  enable_dmverity = true

[plugins."io.containerd.snapshotter.v1.erofs"]
  dmverity_mode = "on"
  1. The existing snapshots could have been created before dm-verity was enabled. Then, the dmverity_mode = "on" setting was enabled. This setting requires .dmverity metadata for each layer, but layers unpacked earlier (when dm-verity was disabled) don't have this metadata. Could you try cleaning up the snapshots and trying again? I’ll update the error message to point out this possibility and add a note to the documentation describing the behavior. Failing in this case is appropriate because the "on" mode is explicitly strict.

@hsiangkao
Copy link
Copy Markdown
Member

I tested the code, but found the following error when trying to run the container:

# ctr run --snapshotter erofs -t ubuntu:22.04 erofs-test sh 
ctr: failed to create erofs mount for parent 1: dm-verity mode is 'on' but .dmverity metadata not found for layer /var/lib/containerd/io.containerd.snapshotter.v1.erofs/snapshots/1/layer.erofs"

Did we miss anything?

@ChengyuZhu6 Can you confirm if it works?
@dmcgowan @fuweid @AkihiroSuda could we take a look at this for v2.3?

@anniecherk anniecherk mentioned this pull request Feb 4, 2026
Copy link
Copy Markdown
Member

@ChengyuZhu6 ChengyuZhu6 left a comment

Choose a reason for hiding this comment

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

LGTM

@aadhar-agarwal
Copy link
Copy Markdown
Contributor Author

I tested the code, but found the following error when trying to run the container:

# ctr run --snapshotter erofs -t ubuntu:22.04 erofs-test sh 
ctr: failed to create erofs mount for parent 1: dm-verity mode is 'on' but .dmverity metadata not found for layer /var/lib/containerd/io.containerd.snapshotter.v1.erofs/snapshots/1/layer.erofs"

Did we miss anything?

@ChengyuZhu6 Can you confirm if it works? @dmcgowan @fuweid @AkihiroSuda could we take a look at this for v2.3?

Kind ping @dmcgowan, @fuweid, @AkihiroSuda, @cpuguy83

Could I please get another review on this PR in order to land this for the 2.3 milestone? :)

Comment thread internal/dmverity/dmverity_linux.go Outdated
Comment thread plugins/mount/erofs/plugin_linux.go Outdated
Comment thread internal/dmverity/dmverity.go Outdated
Comment thread plugins/mount/erofs/plugin_linux.go
@hsiangkao
Copy link
Copy Markdown
Member

@ChengyuZhu6 can we tag a release for github.com/containerd/go-dmverity anyway since it's merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

9 participants