Skip to content

Commit 0a2eaa4

Browse files
Benehikovvoland
authored andcommitted
Add escape hatch for GODEBUG=x509negativeserial
Signed-off-by: Alano Terblanche <[email protected]> (cherry picked from commit 7d7a7aa) Signed-off-by: Paweł Gronowski <[email protected]>
1 parent d26f1fd commit 0a2eaa4

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

cli/command/cli.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...CLIOption)
282282
}
283283
filterResourceAttributesEnvvar()
284284

285+
cli.setAllowNegativex509()
286+
285287
return nil
286288
}
287289

@@ -475,6 +477,43 @@ func (cli *DockerCli) getDockerEndPoint() (ep docker.Endpoint, err error) {
475477
return resolveDockerEndpoint(cli.contextStore, cn)
476478
}
477479

480+
// setAllowNegativex509 is an escape hatch that sets the GODEBUG=x509negativeserial
481+
// environment variable for this process and sub-processes (such as CLI plugins)
482+
func (cli *DockerCli) setAllowNegativex509() {
483+
cn := cli.CurrentContext()
484+
meta, err := cli.ContextStore().GetMetadata(cn)
485+
if err != nil {
486+
return
487+
}
488+
489+
fieldName := "allowx509negativeserialdonotuse"
490+
491+
var config any
492+
var ok bool
493+
switch m := meta.Metadata.(type) {
494+
case DockerContext:
495+
config, ok = m.AdditionalFields[fieldName]
496+
if !ok {
497+
return
498+
}
499+
case map[string]any:
500+
config, ok = m[fieldName]
501+
if !ok {
502+
return
503+
}
504+
default:
505+
return
506+
}
507+
508+
v, ok := config.(string)
509+
if !ok {
510+
return
511+
}
512+
if v == "1" {
513+
_ = os.Setenv("GODEBUG", "x509negativeserial=1")
514+
}
515+
}
516+
478517
func (cli *DockerCli) initialize() error {
479518
cli.init.Do(func() {
480519
cli.dockerEndpoint, cli.initErr = cli.getDockerEndPoint()

0 commit comments

Comments
 (0)