-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add escape hatch for GODEBUG=x509negativeserial #6371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7d7a7aa
65a6c35
467305f
6163c03
72f7933
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -281,6 +281,17 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...CLIOption) | |
| } | ||
| filterResourceAttributesEnvvar() | ||
|
|
||
| // early return if GODEBUG is already set or the docker context is | ||
| // the default context, i.e. is a virtual context where we won't override | ||
| // any GODEBUG values. | ||
| if v := os.Getenv("GODEBUG"); cli.currentContext == DefaultContextName || v != "" { | ||
| return nil | ||
| } | ||
| meta, err := cli.contextStore.GetMetadata(cli.currentContext) | ||
| if err == nil { | ||
| setGoDebug(meta) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
|
|
@@ -474,6 +485,57 @@ func (cli *DockerCli) getDockerEndPoint() (ep docker.Endpoint, err error) { | |
| return resolveDockerEndpoint(cli.contextStore, cn) | ||
| } | ||
|
|
||
| // setGoDebug is an escape hatch that sets the GODEBUG environment | ||
| // variable value using docker context metadata. | ||
| // | ||
| // { | ||
| // "Name": "my-context", | ||
| // "Metadata": { "GODEBUG": "x509negativeserial=1" } | ||
| // } | ||
| // | ||
| // WARNING: Setting x509negativeserial=1 allows Go's x509 library to accept | ||
| // X.509 certificates with negative serial numbers. | ||
| // This behavior is deprecated and non-compliant with current security | ||
| // standards (RFC 5280). Accepting negative serial numbers can introduce | ||
| // serious security vulnerabilities, including the risk of certificate | ||
| // collision or bypass attacks. | ||
| // This option should only be used for legacy compatibility and never in | ||
| // production environments. | ||
| // Use at your own risk. | ||
| func setGoDebug(meta store.Metadata) { | ||
| fieldName := "GODEBUG" | ||
| godebugEnv := os.Getenv(fieldName) | ||
| // early return if GODEBUG is already set. We don't want to override what | ||
| // the user already sets. | ||
| if godebugEnv != "" { | ||
| return | ||
| } | ||
|
|
||
| var cfg any | ||
| var ok bool | ||
| switch m := meta.Metadata.(type) { | ||
| case DockerContext: | ||
| cfg, ok = m.AdditionalFields[fieldName] | ||
| if !ok { | ||
| return | ||
| } | ||
| case map[string]any: | ||
| cfg, ok = m[fieldName] | ||
| if !ok { | ||
| return | ||
| } | ||
| default: | ||
| return | ||
| } | ||
|
|
||
| v, ok := cfg.(string) | ||
| if !ok { | ||
| return | ||
| } | ||
Benehiko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // set the GODEBUG environment variable with whatever was in the context | ||
| _ = os.Setenv(fieldName, v) | ||
|
Comment on lines
+535
to
+536
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wonder if that would override what we currently set in our go.mod on buildx repo: https://github.com/docker/buildx/blob/67218bef58f934f3f19f66346891ea4fbdc1ad4e/go.mod#L187-L188
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think it merges the key-value pairs that are specified by the
e.g. will result in
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we specify
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok looks good thx!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, thanks for checking! I was curious indeed how those options would interact with a Curious; does that
Benehiko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| func (cli *DockerCli) initialize() error { | ||
| cli.init.Do(func() { | ||
| cli.dockerEndpoint, cli.initErr = cli.getDockerEndPoint() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.