@@ -125,6 +125,24 @@ var runtimeExecCommand = &cli.Command{
125
125
Aliases : []string {"x" },
126
126
Usage : "Run the command in parallel if multiple containers are selected" ,
127
127
},
128
+ & cli.StringFlag {
129
+ Name : flagTLSSNI ,
130
+ Usage : "Server name used in the TLS client to check server certificates against" ,
131
+ Aliases : []string {"tls-server-name" },
132
+ Value : "localhost" ,
133
+ },
134
+ & cli.StringFlag {
135
+ Name : flagTLSCA ,
136
+ Usage : "Path to the streaming TLS CA certificate" ,
137
+ },
138
+ & cli.StringFlag {
139
+ Name : flagTLSCert ,
140
+ Usage : "Path to the streaming TLS certificate" ,
141
+ },
142
+ & cli.StringFlag {
143
+ Name : flagTLSKey ,
144
+ Usage : "Path to the streaming TLS key" ,
145
+ },
128
146
},
129
147
Action : func (c * cli.Context ) error {
130
148
if c .NArg () < 1 {
@@ -200,6 +218,11 @@ var runtimeExecCommand = &cli.Command{
200
218
transport : c .String (transportFlag ),
201
219
}
202
220
221
+ opts .tlsConfig , err = tlsConfigFromFlags (c )
222
+ if err != nil {
223
+ return fmt .Errorf ("get TLS config from flags: %w" , err )
224
+ }
225
+
203
226
funcs := []func () error {}
204
227
for _ , id := range ids {
205
228
funcs = append (funcs , func () error {
@@ -210,7 +233,7 @@ var runtimeExecCommand = &cli.Command{
210
233
fmt .Println (id + ":" )
211
234
}
212
235
if c .Bool ("sync" ) {
213
- exitCode , err := ExecSync (runtimeClient , optsCopy )
236
+ exitCode , err := ExecSync (runtimeClient , & optsCopy )
214
237
if err != nil {
215
238
return fmt .Errorf ("execing command in container %s synchronously: %w" , id , err )
216
239
}
@@ -220,7 +243,7 @@ var runtimeExecCommand = &cli.Command{
220
243
} else {
221
244
ctx , cancel := context .WithCancel (c .Context )
222
245
defer cancel ()
223
- err = Exec (ctx , runtimeClient , optsCopy )
246
+ err = Exec (ctx , runtimeClient , & optsCopy )
224
247
if err != nil {
225
248
return fmt .Errorf ("execing command in container %s: %w" , id , err )
226
249
}
@@ -241,10 +264,37 @@ var runtimeExecCommand = &cli.Command{
241
264
},
242
265
}
243
266
267
+ const (
268
+ flagTLSSNI = "tls-sni"
269
+ flagTLSCA = "tls-ca"
270
+ flagTLSCert = "tls-cert"
271
+ flagTLSKey = "tls-key"
272
+ )
273
+
274
+ func tlsConfigFromFlags (ctx * cli.Context ) (* rest.TLSClientConfig , error ) {
275
+ cfg := & rest.TLSClientConfig {
276
+ ServerName : ctx .String (flagTLSSNI ),
277
+ CAFile : ctx .String (flagTLSCA ),
278
+ CertFile : ctx .String (flagTLSCert ),
279
+ KeyFile : ctx .String (flagTLSKey ),
280
+ }
281
+ if cfg .CAFile == "" && cfg .CertFile == "" && cfg .KeyFile == "" {
282
+ return & rest.TLSClientConfig {Insecure : true }, nil
283
+ }
284
+ if cfg .CAFile == "" || cfg .CertFile == "" || cfg .KeyFile == "" {
285
+ return nil , fmt .Errorf (
286
+ "all three flags --%s, --%s and --%s are required for TLS streaming" ,
287
+ flagTLSCA , flagTLSCert , flagTLSKey ,
288
+ )
289
+ }
290
+
291
+ return cfg , nil
292
+ }
293
+
244
294
// ExecSync sends an ExecSyncRequest to the server, and parses
245
295
// the returned ExecSyncResponse. The function returns the corresponding exit
246
296
// code beside an general error.
247
- func ExecSync (client internalapi.RuntimeService , opts execOptions ) (int , error ) {
297
+ func ExecSync (client internalapi.RuntimeService , opts * execOptions ) (int , error ) {
248
298
request := & pb.ExecSyncRequest {
249
299
ContainerId : opts .id ,
250
300
Cmd : opts .cmd ,
@@ -271,7 +321,7 @@ func ExecSync(client internalapi.RuntimeService, opts execOptions) (int, error)
271
321
}
272
322
273
323
// Exec sends an ExecRequest to server, and parses the returned ExecResponse.
274
- func Exec (ctx context.Context , client internalapi.RuntimeService , opts execOptions ) error {
324
+ func Exec (ctx context.Context , client internalapi.RuntimeService , opts * execOptions ) error {
275
325
request := & pb.ExecRequest {
276
326
ContainerId : opts .id ,
277
327
Cmd : opts .cmd ,
@@ -305,11 +355,11 @@ func Exec(ctx context.Context, client internalapi.RuntimeService, opts execOptio
305
355
}
306
356
307
357
logrus .Debugf ("Exec URL: %v" , URL )
308
- return stream (ctx , opts .stdin , opts .tty , opts .transport , URL )
358
+ return stream (ctx , opts .stdin , opts .tty , opts .transport , URL , opts . tlsConfig )
309
359
}
310
360
311
- func stream (ctx context.Context , in , tty bool , transport string , parsedURL * url.URL ) error {
312
- executor , err := getExecutor (transport , parsedURL )
361
+ func stream (ctx context.Context , in , tty bool , transport string , parsedURL * url.URL , tlsConfig * rest. TLSClientConfig ) error {
362
+ executor , err := getExecutor (transport , parsedURL , tlsConfig )
313
363
if err != nil {
314
364
return fmt .Errorf ("get executor: %w" , err )
315
365
}
@@ -348,8 +398,8 @@ func stream(ctx context.Context, in, tty bool, transport string, parsedURL *url.
348
398
return t .Safe (func () error { return executor .StreamWithContext (ctx , streamOptions ) })
349
399
}
350
400
351
- func getExecutor (transport string , parsedURL * url.URL ) (exec remoteclient.Executor , err error ) {
352
- config := & rest.Config {TLSClientConfig : rest. TLSClientConfig { Insecure : true } }
401
+ func getExecutor (transport string , parsedURL * url.URL , tlsConfig * rest. TLSClientConfig ) (exec remoteclient.Executor , err error ) {
402
+ config := & rest.Config {TLSClientConfig : * tlsConfig }
353
403
354
404
switch transport {
355
405
case transportSpdy :
0 commit comments