Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit 859003a

Browse files
stream: struct for x509 key pair, update the docs, error management
Signed-off-by: JulienBalestra <[email protected]>
1 parent b82b524 commit 859003a

3 files changed

Lines changed: 34 additions & 11 deletions

File tree

docs/config.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,16 @@ The explanation and default value of each configuration item are as follows:
2424
# systemd_cgroup enables systemd cgroup support.
2525
systemd_cgroup = false
2626

27-
# enable_tls_streaming enables the TLS streaming support.
27+
# enable_tls_streaming enables the TLS streaming support.
28+
# It generates a self-sign certificate unless the following x509_key_pair_streaming are both set.
2829
enable_tls_streaming = false
30+
31+
# "plugins.cri.x509_key_pair_streaming" constains a x509 valid key pair to stream with tls.
32+
[plugins.cri.x509_key_pair_streaming]
33+
# tls_cert_file is the filepath to the certificate paired with the "tls_key_file"
34+
tls_cert_file = ""
35+
# tls_key_file is the filepath to the private key paired with the "tls_cert_file"
36+
tls_key_file = ""
2937

3038
# max_container_log_line_size is the maximum log line size in bytes for a container.
3139
# Log line longer than the limit will be split into multiple lines. -1 means no

pkg/config/config.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,22 @@ type PluginConfig struct {
114114
SystemdCgroup bool `toml:"systemd_cgroup" json:"systemdCgroup"`
115115
// EnableTLSStreaming indicates to enable the TLS streaming support.
116116
EnableTLSStreaming bool `toml:"enable_tls_streaming" json:"enableTLSStreaming"`
117-
// TLSCertFileStreaming is the path to a certificate file
118-
TLSCertFileStreaming string `toml:"tls_cert_file_streaming" json:"tlsCertFileStreaming"`
119-
// TLSKeyFileStreaming is the path to a private key file
120-
TLSKeyFileStreaming string `toml:"tls_key_file_streaming" json:"tlsKeyFileStreaming"`
117+
// X509KeyPairStreaming is a x509 key pair used for TLS streaming
118+
X509KeyPairStreaming `toml:"x509_key_pair_streaming" json:"x509KeyPairStreaming"`
121119
// MaxContainerLogLineSize is the maximum log line size in bytes for a container.
122120
// Log line longer than the limit will be split into multiple lines. Non-positive
123121
// value means no limit.
124122
MaxContainerLogLineSize int `toml:"max_container_log_line_size" json:"maxContainerLogSize"`
125123
}
126124

125+
// X509KeyPairStreaming contains the x509 configuration for streaming
126+
type X509KeyPairStreaming struct {
127+
// TLSCertFile is the path to a certificate file
128+
TLSCertFile string `toml:"tls_cert_file" json:"tlsCertFile"`
129+
// TLSKeyFile is the path to a private key file
130+
TLSKeyFile string `toml:"tls_key_file" json:"tlsKeyFile"`
131+
}
132+
127133
// Config contains all configurations for cri server.
128134
type Config struct {
129135
// PluginConfig is the config for CRI plugin.
@@ -156,10 +162,14 @@ func DefaultConfig() PluginConfig {
156162
},
157163
NoPivot: false,
158164
},
159-
StreamServerAddress: "127.0.0.1",
160-
StreamServerPort: "0",
161-
EnableSelinux: false,
162-
EnableTLSStreaming: false,
165+
StreamServerAddress: "127.0.0.1",
166+
StreamServerPort: "0",
167+
EnableSelinux: false,
168+
EnableTLSStreaming: false,
169+
X509KeyPairStreaming: X509KeyPairStreaming{
170+
TLSKeyFile: "",
171+
TLSCertFile: "",
172+
},
163173
SandboxImage: "k8s.gcr.io/pause:3.1",
164174
StatsCollectPeriod: 10,
165175
SystemdCgroup: false,

pkg/server/streaming.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,22 @@ func newStreamServer(c *criService, addr, port string) (streaming.Server, error)
4646
config.Addr = net.JoinHostPort(addr, port)
4747
run := newStreamRuntime(c)
4848
if !c.config.EnableTLSStreaming {
49+
if c.config.X509KeyPairStreaming.TLSCertFile != "" || c.config.X509KeyPairStreaming.TLSKeyFile != "" {
50+
return nil, errors.Errorf("X509KeyPairStreaming.TLSCertFile and/or X509KeyPairStreaming.TLSKeyFile are set but EnableTLSStreaming is not set")
51+
}
4952
return streaming.NewServer(config, run)
5053
}
51-
if c.config.TLSCertFileStreaming != "" && c.config.TLSKeyFileStreaming != "" {
52-
tlsCert, err := tls.LoadX509KeyPair(c.config.TLSCertFileStreaming, c.config.TLSKeyFileStreaming)
54+
if c.config.X509KeyPairStreaming.TLSCertFile != "" && c.config.X509KeyPairStreaming.TLSKeyFile != "" {
55+
tlsCert, err := tls.LoadX509KeyPair(c.config.X509KeyPairStreaming.TLSCertFile, c.config.X509KeyPairStreaming.TLSKeyFile)
5356
if err != nil {
5457
return nil, errors.Wrap(err, "failed to load x509 key pair for stream server")
5558
}
5659
config.TLSConfig = &tls.Config{
5760
Certificates: []tls.Certificate{tlsCert},
5861
}
5962
return streaming.NewServer(config, run)
63+
} else if c.config.X509KeyPairStreaming.TLSCertFile != "" || c.config.X509KeyPairStreaming.TLSKeyFile != "" {
64+
return nil, errors.Errorf("must set both X509KeyPairStreaming.TLSCertFile and X509KeyPairStreaming.TLSKeyFile")
6065
}
6166
// generating self-sign certs
6267
tlsCert, err := newTLSCert()

0 commit comments

Comments
 (0)