@@ -2,6 +2,8 @@ package plugin
2
2
3
3
import (
4
4
"context"
5
+ "crypto/sha256"
6
+ "encoding/hex"
5
7
"sort"
6
8
7
9
semver "github.com/Masterminds/semver/v3"
@@ -414,6 +416,7 @@ func (reg *Registry) LoadPlugins(ctx context.Context, plugins []config.Plugin) {
414
416
continue
415
417
}
416
418
419
+ var secureConfig * goplugin.SecureConfig
417
420
if ! reg .devMode {
418
421
// Checksum of the plugin.
419
422
if plugin .ID .Checksum == "" {
@@ -424,22 +427,24 @@ func (reg *Registry) LoadPlugins(ctx context.Context, plugins []config.Plugin) {
424
427
425
428
// Verify the checksum.
426
429
// TODO: Load the plugin from a remote location if the checksum didn't match?
427
- if sum , err := SHA256SUM (plugin .LocalPath ); err != nil {
430
+ checksum , err := hex .DecodeString (plugin .ID .Checksum )
431
+ if err != nil {
428
432
reg .Logger .Debug ().Str ("name" , plugin .ID .Name ).Err (err ).Msg (
429
- "Failed to calculate checksum" )
433
+ "Failed to decode checksum" )
430
434
continue
431
- } else if sum != plugin .ID .Checksum {
432
- reg .Logger .Debug ().Fields (
433
- map [string ]interface {}{
434
- "calculated" : sum ,
435
- "expected" : plugin .ID .Checksum ,
436
- "name" : plugin .ID .Name ,
437
- },
438
- ).Msg ("Checksum mismatch" )
435
+ }
436
+
437
+ if len (checksum ) != sha256 .Size {
438
+ reg .Logger .Debug ().Str ("name" , plugin .ID .Name ).Msg ("Invalid checksum length" )
439
439
continue
440
440
}
441
441
442
- span .AddEvent ("Verified plugin checksum" )
442
+ secureConfig = & goplugin.SecureConfig {
443
+ Checksum : checksum ,
444
+ Hash : sha256 .New (),
445
+ }
446
+
447
+ span .AddEvent ("Created secure config for validating plugin checksum" )
443
448
} else {
444
449
span .AddEvent ("Skipping plugin checksum verification (dev mode)" )
445
450
}
@@ -460,12 +465,12 @@ func (reg *Registry) LoadPlugins(ctx context.Context, plugins []config.Plugin) {
460
465
AllowedProtocols : []goplugin.Protocol {
461
466
goplugin .ProtocolGRPC ,
462
467
},
463
- // SecureConfig: nil ,
464
- Logger : logAdapter ,
465
- Managed : true ,
466
- MinPort : config .DefaultMinPort ,
467
- MaxPort : config .DefaultMaxPort ,
468
- AutoMTLS : true ,
468
+ SecureConfig : secureConfig ,
469
+ Logger : logAdapter ,
470
+ Managed : true ,
471
+ MinPort : config .DefaultMinPort ,
472
+ MaxPort : config .DefaultMaxPort ,
473
+ AutoMTLS : true ,
469
474
},
470
475
)
471
476
0 commit comments