Skip to content

Commit 80fa9fe

Browse files
authored
Merge pull request containerd#5135 from AkihiroSuda/default-config-crypt
add imgcrypt stream processors to the default config
2 parents 548d984 + ecb881e commit 80fa9fe

File tree

13 files changed

+88
-59
lines changed

13 files changed

+88
-59
lines changed

cmd/containerd/command/config.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ import (
2020
gocontext "context"
2121
"io"
2222
"os"
23+
"path/filepath"
2324

2425
"github.com/BurntSushi/toml"
26+
"github.com/containerd/containerd/defaults"
27+
"github.com/containerd/containerd/images"
2528
"github.com/containerd/containerd/pkg/timeout"
2629
"github.com/containerd/containerd/services/server"
2730
srvconfig "github.com/containerd/containerd/services/server/config"
31+
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2832
"github.com/urfave/cli"
2933
)
3034

@@ -113,3 +117,49 @@ var configCommand = cli.Command{
113117
},
114118
},
115119
}
120+
121+
func platformAgnosticDefaultConfig() *srvconfig.Config {
122+
return &srvconfig.Config{
123+
Version: 1,
124+
Root: defaults.DefaultRootDir,
125+
State: defaults.DefaultStateDir,
126+
GRPC: srvconfig.GRPCConfig{
127+
Address: defaults.DefaultAddress,
128+
MaxRecvMsgSize: defaults.DefaultMaxRecvMsgSize,
129+
MaxSendMsgSize: defaults.DefaultMaxSendMsgSize,
130+
},
131+
DisabledPlugins: []string{},
132+
RequiredPlugins: []string{},
133+
StreamProcessors: streamProcessors(),
134+
}
135+
}
136+
137+
func streamProcessors() map[string]srvconfig.StreamProcessor {
138+
const (
139+
ctdDecoder = "ctd-decoder"
140+
basename = "io.containerd.ocicrypt.decoder.v1"
141+
)
142+
decryptionKeysPath := filepath.Join(defaults.DefaultConfigDir, "ocicrypt", "keys")
143+
ctdDecoderArgs := []string{
144+
"--decryption-keys-path", decryptionKeysPath,
145+
}
146+
ctdDecoderEnv := []string{
147+
"OCICRYPT_KEYPROVIDER_CONFIG=" + filepath.Join(defaults.DefaultConfigDir, "ocicrypt", "ocicrypt_keyprovider.conf"),
148+
}
149+
return map[string]srvconfig.StreamProcessor{
150+
basename + ".tar.gzip": {
151+
Accepts: []string{images.MediaTypeImageLayerGzipEncrypted},
152+
Returns: ocispec.MediaTypeImageLayerGzip,
153+
Path: ctdDecoder,
154+
Args: ctdDecoderArgs,
155+
Env: ctdDecoderEnv,
156+
},
157+
basename + ".tar": {
158+
Accepts: []string{images.MediaTypeImageLayerEncrypted},
159+
Returns: ocispec.MediaTypeImageLayer,
160+
Path: ctdDecoder,
161+
Args: ctdDecoderArgs,
162+
Env: ctdDecoderEnv,
163+
},
164+
}
165+
}

cmd/containerd/command/config_linux.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,9 @@
1717
package command
1818

1919
import (
20-
"github.com/containerd/containerd/defaults"
2120
srvconfig "github.com/containerd/containerd/services/server/config"
2221
)
2322

2423
func defaultConfig() *srvconfig.Config {
25-
return &srvconfig.Config{
26-
Version: 1,
27-
Root: defaults.DefaultRootDir,
28-
State: defaults.DefaultStateDir,
29-
GRPC: srvconfig.GRPCConfig{
30-
Address: defaults.DefaultAddress,
31-
MaxRecvMsgSize: defaults.DefaultMaxRecvMsgSize,
32-
MaxSendMsgSize: defaults.DefaultMaxSendMsgSize,
33-
},
34-
DisabledPlugins: []string{},
35-
RequiredPlugins: []string{},
36-
}
24+
return platformAgnosticDefaultConfig()
3725
}

cmd/containerd/command/config_unsupported.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,10 @@ import (
2424
)
2525

2626
func defaultConfig() *srvconfig.Config {
27-
return &srvconfig.Config{
28-
Version: 1,
29-
Root: defaults.DefaultRootDir,
30-
State: defaults.DefaultStateDir,
31-
GRPC: srvconfig.GRPCConfig{
32-
Address: defaults.DefaultAddress,
33-
},
34-
Debug: srvconfig.Debug{
35-
Level: "info",
36-
Address: defaults.DefaultDebugAddress,
37-
},
38-
DisabledPlugins: []string{},
39-
RequiredPlugins: []string{},
27+
cfg := platformAgnosticDefaultConfig()
28+
cfg.Debug = srvconfig.Debug{
29+
Level: "info",
30+
Address: defaults.DefaultDebugAddress,
4031
}
32+
return cfg
4133
}

cmd/containerd/command/config_windows.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,9 @@
1717
package command
1818

1919
import (
20-
"github.com/containerd/containerd/defaults"
2120
srvconfig "github.com/containerd/containerd/services/server/config"
2221
)
2322

2423
func defaultConfig() *srvconfig.Config {
25-
return &srvconfig.Config{
26-
Version: 1,
27-
Root: defaults.DefaultRootDir,
28-
State: defaults.DefaultStateDir,
29-
GRPC: srvconfig.GRPCConfig{
30-
Address: defaults.DefaultAddress,
31-
MaxRecvMsgSize: defaults.DefaultMaxRecvMsgSize,
32-
MaxSendMsgSize: defaults.DefaultMaxSendMsgSize,
33-
},
34-
DisabledPlugins: []string{},
35-
RequiredPlugins: []string{},
36-
}
24+
return platformAgnosticDefaultConfig()
3725
}

cmd/containerd/command/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"runtime"
2828
"time"
2929

30+
"github.com/containerd/containerd/defaults"
3031
"github.com/containerd/containerd/errdefs"
3132
"github.com/containerd/containerd/log"
3233
"github.com/containerd/containerd/mount"
@@ -80,7 +81,7 @@ can be used and modified as necessary as a custom configuration.`
8081
cli.StringFlag{
8182
Name: "config,c",
8283
Usage: "path to the configuration file",
83-
Value: defaultConfigPath,
84+
Value: filepath.Join(defaults.DefaultConfigDir, "config.toml"),
8485
},
8586
cli.StringFlag{
8687
Name: "log-level,l",

cmd/containerd/command/main_unix.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import (
2727
"golang.org/x/sys/unix"
2828
)
2929

30-
const defaultConfigPath = "/etc/containerd/config.toml"
31-
3230
var handledSignals = []os.Signal{
3331
unix.SIGTERM,
3432
unix.SIGINT,

cmd/containerd/command/main_windows.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"fmt"
2222
"os"
23-
"path/filepath"
2423
"unsafe"
2524

2625
"github.com/Microsoft/go-winio/pkg/etw"
@@ -33,8 +32,7 @@ import (
3332
)
3433

3534
var (
36-
defaultConfigPath = filepath.Join(os.Getenv("programfiles"), "containerd", "config.toml")
37-
handledSignals = []os.Signal{
35+
handledSignals = []os.Signal{
3836
windows.SIGTERM,
3937
windows.SIGINT,
4038
}

defaults/defaults_unix.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ const (
3434
DefaultFIFODir = "/run/containerd/fifo"
3535
// DefaultRuntime is the default linux runtime
3636
DefaultRuntime = "io.containerd.runc.v2"
37+
// DefaultConfigDir is the default location for config files.
38+
DefaultConfigDir = "/etc/containerd"
3739
)

defaults/defaults_windows.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ var (
3030
// DefaultStateDir is the default location used by containerd to store
3131
// transient data
3232
DefaultStateDir = filepath.Join(os.Getenv("ProgramData"), "containerd", "state")
33+
34+
// DefaultConfigDir is the default location for config files.
35+
DefaultConfigDir = filepath.Join(os.Getenv("programfiles"), "containerd")
3336
)
3437

3538
const (

docs/cri/decryption.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,31 @@ In this model encryption is tied to worker nodes. The usecase here revolves arou
1515

1616
### Configuring image decryption for "node" key model
1717

18-
The default configuration does not handle decrypting encrypted container images.
18+
This is the default model since containerd v1.5.
1919

20-
An example for configuring the "node" key model for container image decryption:
21-
22-
Configure `cri` to enable decryption with "node" key model
20+
For containerd v1.4, you need to add the following configuration to `/etc/containerd/config.toml` and restart the `containerd` service manually.
2321
```toml
22+
version = 2
23+
2424
[plugins."io.containerd.grpc.v1.cri".image_decryption]
2525
key_model = "node"
26-
```
2726

28-
Configure `containerd` daemon [`stream_processors`](https://github.com/containerd/containerd/blob/master/docs/stream_processors.md) to handle the
29-
encrypted mediatypes.
30-
```toml
3127
[stream_processors]
3228
[stream_processors."io.containerd.ocicrypt.decoder.v1.tar.gzip"]
3329
accepts = ["application/vnd.oci.image.layer.v1.tar+gzip+encrypted"]
3430
returns = "application/vnd.oci.image.layer.v1.tar+gzip"
35-
path = "/usr/local/bin/ctd-decoder"
36-
args = ["--decryption-keys-path", "/keys"]
31+
path = "ctd-decoder"
32+
args = ["--decryption-keys-path", "/etc/containerd/ocicrypt/keys"]
33+
env= ["OCICRYPT_KEYPROVIDER_CONFIG=/etc/containerd/ocicrypt/ocicrypt_keyprovider.conf"]
3734
[stream_processors."io.containerd.ocicrypt.decoder.v1.tar"]
3835
accepts = ["application/vnd.oci.image.layer.v1.tar+encrypted"]
3936
returns = "application/vnd.oci.image.layer.v1.tar"
40-
path = "/usr/local/bin/ctd-decoder"
41-
args = ["--decryption-keys-path", "/keys"]
37+
path = "ctd-decoder"
38+
args = ["--decryption-keys-path", "/etc/containerd/ocicrypt/keys"]
39+
env= ["OCICRYPT_KEYPROVIDER_CONFIG=/etc/containerd/ocicrypt/ocicrypt_keyprovider.conf"]
4240
```
4341

44-
In this example, container image decryption is set to use the "node" key model. In addition, the decryption [`stream_processors`](https://github.com/containerd/containerd/blob/master/docs/stream_processors.md) are configured as specified in [containerd/imgcrypt project](https://github.com/containerd/imgcrypt), with the additional field `--decryption-keys-path` configured to specify where decryption keys are located locally in the node.
42+
In this example, container image decryption is set to use the "node" key model.
43+
In addition, the decryption [`stream_processors`](https://github.com/containerd/containerd/blob/master/docs/stream_processors.md) are configured as specified in [containerd/imgcrypt project](https://github.com/containerd/imgcrypt), with the additional field `--decryption-keys-path` configured to specify where decryption keys are located locally in the node.
4544

46-
After modify this config, you need restart the `containerd` service.
45+
The `$OCICRYPT_KEYPROVIDER_CONFIG` environment variable is used for [ocicrypt keyprovider protocol](https://github.com/containers/ocicrypt/blob/master/docs/keyprovider.md).

0 commit comments

Comments
 (0)