Skip to content

Commit 7d7a7aa

Browse files
committed
Add escape hatch for GODEBUG=x509negativeserial
Signed-off-by: Alano Terblanche <[email protected]>
1 parent 09cd4ea commit 7d7a7aa

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
@@ -281,6 +281,8 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...CLIOption)
281281
}
282282
filterResourceAttributesEnvvar()
283283

284+
cli.setAllowNegativex509()
285+
284286
return nil
285287
}
286288

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

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

0 commit comments

Comments
 (0)