Skip to content

Commit

Permalink
converter: move out encryption package
Browse files Browse the repository at this point in the history
Due to the introduction of the github.com/containers/ocicrypt package
in converter, which brings in many other dependencies, but encryption
should currently be an experimental optional feature, we need to move
this part of the codes out to reduce the burden on other projects that
reference the package.

Signed-off-by: Yan Song <yansong.ys@antgroup.com>
  • Loading branch information
imeoer committed Sep 28, 2023
1 parent 2cc7d81 commit b8df992
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
6 changes: 3 additions & 3 deletions pkg/converter/convert_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ func MergeLayers(ctx context.Context, cs content.Store, descs []ocispec.Descript
blobDesc.Annotations[label.NydusRefLayer] = layers[idx].OriginalDigest.String()
}

if len(opt.EncryptRecipients) != 0 {
if opt.Encrypt != nil {
blobDesc.Annotations[LayerAnnotationNydusEncryptedBlob] = "true"
}

Expand All @@ -1195,9 +1195,9 @@ func MergeLayers(ctx context.Context, cs content.Store, descs []ocispec.Descript
},
}

if len(opt.EncryptRecipients) != 0 {
if opt.Encrypt != nil {
// Encrypt the Nydus bootstrap layer.
bootstrapDesc, err = EncryptNydusBootstrap(ctx, cs, bootstrapDesc, opt.EncryptRecipients)
bootstrapDesc, err = opt.Encrypt(ctx, cs, bootstrapDesc)
if err != nil {
return nil, nil, errors.Wrap(err, "encrypt bootstrap layer")
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/converter/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (

type Compressor = uint32

type Encrypter = func(context.Context, content.Store, ocispec.Descriptor) (ocispec.Descriptor, error)

const (
CompressorNone Compressor = 0x0000_0001
CompressorZstd Compressor = 0x0000_0002
Expand Down Expand Up @@ -121,8 +123,8 @@ type MergeOption struct {
Backend Backend
// Timeout cancels execution once exceed the specified time.
Timeout *time.Duration
// Recipients to encrypt bootstrap, do not encrypt if empty.
EncryptRecipients []string
// Encrypt encrypts the bootstrap layer if it's specified.
Encrypt Encrypter
}

type UnpackOption struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package converter
package encryption

import (
"context"
Expand Down
18 changes: 11 additions & 7 deletions tests/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import (
"github.com/containerd/containerd/content/local"
"github.com/containerd/nydus-snapshotter/pkg/backend"
"github.com/containerd/nydus-snapshotter/pkg/converter"
"github.com/containerd/nydus-snapshotter/pkg/encryption"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)

const envNydusdPath = "NYDUS_NYDUSD"
Expand Down Expand Up @@ -811,13 +813,15 @@ func testImageConvertBasic(testOpt *ConvertTestOption) {
convertFunc := converter.LayerConvertFunc(*nydusOpts)
convertHooks := containerdconverter.ConvertHooks{
PostConvertHook: converter.ConvertHookFunc(converter.MergeOption{
WorkDir: nydusOpts.WorkDir,
BuilderPath: nydusOpts.BuilderPath,
FsVersion: nydusOpts.FsVersion,
ChunkDictPath: nydusOpts.ChunkDictPath,
Backend: testOpt.backend,
PrefetchPatterns: nydusOpts.PrefetchPatterns,
EncryptRecipients: testOpt.encryptRecipients,
WorkDir: nydusOpts.WorkDir,
BuilderPath: nydusOpts.BuilderPath,
FsVersion: nydusOpts.FsVersion,
ChunkDictPath: nydusOpts.ChunkDictPath,
Backend: testOpt.backend,
PrefetchPatterns: nydusOpts.PrefetchPatterns,
Encrypt: func(ctx context.Context, cs content.Store, desc ocispec.Descriptor) (ocispec.Descriptor, error) {
return encryption.EncryptNydusBootstrap(ctx, cs, desc, testOpt.encryptRecipients)
},
}),
}
convertFuncOpt := containerdconverter.WithIndexConvertFunc(
Expand Down

0 comments on commit b8df992

Please sign in to comment.