-
Notifications
You must be signed in to change notification settings - Fork 112
Add OCI index detection for Nydus alternatives #669
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
Open
Fricounet
wants to merge
2
commits into
containerd:main
Choose a base branch
from
DataDog:fricounet/upstream/index-detect
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,9 @@ on: | |
| auth-type: | ||
| required: true | ||
| type: string | ||
| index-detect: | ||
| required: false | ||
| type: boolean | ||
|
|
||
| env: | ||
| DOCKER_USER: testuser | ||
|
|
@@ -28,7 +31,8 @@ jobs: | |
| cache-dependency-path: "go.sum" | ||
| - name: Test | ||
| run: | | ||
| AUTH_TYPE='${{ inputs.auth-type }}' | ||
| export AUTH_TYPE='${{ inputs.auth-type }}' | ||
| export INDEX_DETECT='${{ inputs.index-detect }}' | ||
|
Comment on lines
+34
to
+35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, use |
||
| ./tests/helpers/kind.sh | ||
| - name: Dump logs | ||
| if: failure() | ||
|
|
||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| # Index Detection | ||
|
|
||
| ## Overview | ||
|
|
||
| Index Detection is a feature that automatically discovers Nydus alternative manifests within OCI index manifests. This enables transparent fallback to optimized Nydus images when available while keeping the original index manifest OCI compliant, allowing non-Nydus clients to pull regular OCI images. | ||
|
|
||
| ## Motivation | ||
|
|
||
| The Index Detection feature addresses several limitations of the existing Referrer API-based detection: | ||
|
|
||
| - **Registry Support**: Not all registries support the Referrer API | ||
| - **Supply Chain Security**: Referrer API relies on external changes to the manifest, creating potential supply chain risks | ||
| - **Universal Compatibility**: Index detection works with all OCI-compliant registries | ||
|
|
||
| Unlike referrer-based detection, Index Detection packages everything into a single manifest, eliminating supply chain concerns while maintaining universal registry support. | ||
|
|
||
| ## How It Works | ||
|
|
||
| ### Detection Process | ||
|
|
||
| 1. **Index Manifest Parsing**: When a manifest digest is encountered, the system fetches and parses the original OCI index manifest | ||
| 2. **Platform Matching**: The system finds the original manifest descriptor within the index | ||
| 3. **Nydus Alternative Search**: It searches for platform-compatible manifests that contain: | ||
| - `platform.os.features` containing `nydus.remoteimage.v1`, or | ||
| - `artifactType` set to `application/vnd.nydus.image.manifest.v1+json` | ||
| 4. **Validation**: The found manifest is validated to ensure it's a valid Nydus manifest with metadata layers | ||
| 5. **Caching**: Results are cached to avoid repeated API calls for the same digest | ||
|
|
||
| Both `platform.os.features` and `artifactType` are looked at because index manifests built using `merge-platform` before acceleration-service: v0.2.19 or nydus: v2.3.5 will have `platform.os.features` configured while images built after will have `artifactType` configured. | ||
|
|
||
| ### Detection Priority | ||
|
|
||
| When both Index Detection and Referrer Detection are available, Index Detection takes priority due to its superior supply chain security properties. | ||
|
|
||
| ## Configuration | ||
|
|
||
| Index Detection is controlled by the `EnableIndexDetect` configuration option in the experimental features section: | ||
|
|
||
| ```toml | ||
| [experimental] | ||
| enable_index_detect = true | ||
| ``` | ||
|
|
||
| ## Building Compatible Images | ||
|
|
||
| To create images compatible with Index Detection, use the `nydusify convert` command with the `--merge-platform` flag: | ||
|
|
||
| ```bash | ||
| nydusify convert --merge-platform <source-image> <target-image> | ||
| ``` | ||
|
|
||
| This creates an OCI index manifest containing both the original image and the Nydus alternative: | ||
|
|
||
| ```json | ||
| { | ||
| "schemaVersion": 2, | ||
| "manifests": [ | ||
| { | ||
| "mediaType": "application/vnd.oci.image.manifest.v1+json", | ||
| "digest": "sha256:a63dfddecc661e4ad05896418b2f3774022269c3bf5b7e01baaa6e851a3a4a23", | ||
| "size": 2320, | ||
| "platform": { | ||
| "architecture": "amd64", | ||
| "os": "linux" | ||
| } | ||
| }, | ||
| { | ||
| "mediaType": "application/vnd.oci.image.manifest.v1+json", | ||
| "digest": "sha256:bb82dd8ee111bfe5fdf12145b6ed553da9c15de17f54b1f658d95ff26a65a01c", | ||
| "size": 3229, | ||
| "platform": { | ||
| "architecture": "amd64", | ||
| "os": "linux" | ||
| }, | ||
| "artifactType": "application/vnd.nydus.image.manifest.v1+json" | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| ## Comparison with Referrer Detection | ||
|
|
||
| | Aspect | Index Detection | Referrer Detection | | ||
| |--------|----------------|-------------------| | ||
| | Registry Support | Universal | Limited | | ||
| | Supply Chain Security | Secure (single manifest) | Potential risks (external refs) | | ||
| | OCI Compliance | Full compliance | Requires Referrer API | | ||
| | Cache Behavior | Immutable (digest-based) | May require invalidation | | ||
| | Detection Priority | Higher | Lower | |
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * Copyright (c) 2025. Nydus Developers. All rights reserved. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package filesystem | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| snpkg "github.com/containerd/containerd/v2/pkg/snapshotters" | ||
| "github.com/containerd/log" | ||
| "github.com/opencontainers/go-digest" | ||
| "github.com/pkg/errors" | ||
| ) | ||
|
|
||
| func (fs *Filesystem) IndexDetectEnabled() bool { | ||
| return fs.indexMgr != nil | ||
| } | ||
|
|
||
| // CheckIndexAlternative attempts to find a nydus alternative manifest in the original OCI index manifest | ||
| func (fs *Filesystem) CheckIndexAlternative(ctx context.Context, labels map[string]string) bool { | ||
| if !fs.IndexDetectEnabled() { | ||
| return false | ||
| } | ||
|
|
||
| ref, ok := labels[snpkg.TargetRefLabel] | ||
| if !ok { | ||
| return false | ||
| } | ||
|
|
||
| manifestDigest := digest.Digest(labels[snpkg.TargetManifestDigestLabel]) | ||
| if manifestDigest.Validate() != nil { | ||
| return false | ||
| } | ||
|
|
||
| log.G(ctx).WithField("ref", ref).WithField("digest", manifestDigest.String()).Debug("attempting index-based nydus detection") | ||
| if _, err := fs.indexMgr.CheckIndexAlternative(ctx, ref, manifestDigest); err != nil { | ||
| return false | ||
| } | ||
|
|
||
| return true | ||
| } | ||
|
|
||
| // TryFetchMetadataFromIndex attempts to fetch metadata from the nydus index alternative | ||
| func (fs *Filesystem) TryFetchMetadataFromIndex(ctx context.Context, labels map[string]string, metadataPath string) error { | ||
| ref, ok := labels[snpkg.TargetRefLabel] | ||
| if !ok { | ||
| return fmt.Errorf("empty label %s", snpkg.TargetRefLabel) | ||
| } | ||
|
|
||
| manifestDigest := digest.Digest(labels[snpkg.TargetManifestDigestLabel]) | ||
| if err := manifestDigest.Validate(); err != nil { | ||
| return fmt.Errorf("invalid label %s=%s", snpkg.TargetManifestDigestLabel, manifestDigest) | ||
| } | ||
|
|
||
| if err := fs.indexMgr.TryFetchMetadata(ctx, ref, manifestDigest, metadataPath); err != nil { | ||
| return errors.Wrap(err, "try fetch metadata") | ||
| } | ||
|
|
||
| return nil | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
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.
exportare needed so that the env variables get picked up inkind.sh. Without it, they won't. Which makes me think that theauth-type: criactually did not work as expected previously 😅