Skip to content

Commit da1d967

Browse files
committed
Enable imgcrypt in cri pull
Signed-off-by: Derek McGowan <[email protected]>
1 parent 9857afd commit da1d967

File tree

2 files changed

+40
-37
lines changed

2 files changed

+40
-37
lines changed

internal/cri/server/images/image_pull.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ import (
3232
"sync/atomic"
3333
"time"
3434

35+
"github.com/containerd/errdefs"
36+
"github.com/containerd/imgcrypt"
37+
"github.com/containerd/imgcrypt/images/encryption"
3538
"github.com/containerd/log"
3639
distribution "github.com/distribution/reference"
3740
imagedigest "github.com/opencontainers/go-digest"
@@ -48,7 +51,6 @@ import (
4851
crilabels "github.com/containerd/containerd/v2/internal/cri/labels"
4952
snpkg "github.com/containerd/containerd/v2/pkg/snapshotters"
5053
"github.com/containerd/containerd/v2/pkg/tracing"
51-
"github.com/containerd/errdefs"
5254
)
5355

5456
// For image management:
@@ -583,15 +585,15 @@ func newTransport() *http.Transport {
583585
// encryptedImagesPullOpts returns the necessary list of pull options required
584586
// for decryption of encrypted images based on the cri decryption configuration.
585587
// Temporarily removed for v2 upgrade
586-
//func (c *CRIImageService) encryptedImagesPullOpts() []containerd.RemoteOpt {
587-
// if c.config.ImageDecryption.KeyModel == criconfig.KeyModelNode {
588-
// ltdd := imgcrypt.Payload{}
589-
// decUnpackOpt := encryption.WithUnpackConfigApplyOpts(encryption.WithDecryptedUnpack(&ltdd))
590-
// opt := containerd.WithUnpackOpts([]containerd.UnpackOpt{decUnpackOpt})
591-
// return []containerd.RemoteOpt{opt}
592-
// }
593-
// return nil
594-
//}
588+
func (c *CRIImageService) encryptedImagesPullOpts() []containerd.RemoteOpt {
589+
if c.config.ImageDecryption.KeyModel == criconfig.KeyModelNode {
590+
ltdd := imgcrypt.Payload{}
591+
decUnpackOpt := encryption.WithUnpackConfigApplyOpts(encryption.WithDecryptedUnpack(&ltdd))
592+
opt := containerd.WithUnpackOpts([]containerd.UnpackOpt{decUnpackOpt})
593+
return []containerd.RemoteOpt{opt}
594+
}
595+
return nil
596+
}
595597

596598
const (
597599
// defaultPullProgressReportInterval represents that how often the

internal/cri/server/images/image_pull_test.go

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ import (
2626
"github.com/stretchr/testify/assert"
2727
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
2828

29+
"github.com/containerd/platforms"
30+
2931
"github.com/containerd/containerd/v2/internal/cri/annotations"
3032
criconfig "github.com/containerd/containerd/v2/internal/cri/config"
3133
"github.com/containerd/containerd/v2/internal/cri/labels"
32-
"github.com/containerd/platforms"
3334
)
3435

3536
func TestParseAuth(t *testing.T) {
@@ -350,32 +351,32 @@ func TestDefaultScheme(t *testing.T) {
350351
}
351352

352353
// Temporarily remove for v2 upgrade
353-
//func TestEncryptedImagePullOpts(t *testing.T) {
354-
// for _, test := range []struct {
355-
// desc string
356-
// keyModel string
357-
// expectedOpts int
358-
// }{
359-
// {
360-
// desc: "node key model should return one unpack opt",
361-
// keyModel: criconfig.KeyModelNode,
362-
// expectedOpts: 1,
363-
// },
364-
// {
365-
// desc: "no key model selected should default to node key model",
366-
// keyModel: "",
367-
// expectedOpts: 0,
368-
// },
369-
// } {
370-
// test := test
371-
// t.Run(test.desc, func(t *testing.T) {
372-
// c, _ := newTestCRIService()
373-
// c.config.ImageDecryption.KeyModel = test.keyModel
374-
// got := len(c.encryptedImagesPullOpts())
375-
// assert.Equal(t, test.expectedOpts, got)
376-
// })
377-
// }
378-
//}
354+
func TestEncryptedImagePullOpts(t *testing.T) {
355+
for _, test := range []struct {
356+
desc string
357+
keyModel string
358+
expectedOpts int
359+
}{
360+
{
361+
desc: "node key model should return one unpack opt",
362+
keyModel: criconfig.KeyModelNode,
363+
expectedOpts: 1,
364+
},
365+
{
366+
desc: "no key model selected should default to node key model",
367+
keyModel: "",
368+
expectedOpts: 0,
369+
},
370+
} {
371+
test := test
372+
t.Run(test.desc, func(t *testing.T) {
373+
c, _ := newTestCRIService()
374+
c.config.ImageDecryption.KeyModel = test.keyModel
375+
got := len(c.encryptedImagesPullOpts())
376+
assert.Equal(t, test.expectedOpts, got)
377+
})
378+
}
379+
}
379380

380381
func TestSnapshotterFromPodSandboxConfig(t *testing.T) {
381382
defaultSnapshotter := "native"

0 commit comments

Comments
 (0)