Add support for OS_INSECURE environment variable#279
Merged
stephenfin merged 2 commits intogophercloud:mainfrom Apr 9, 2026
Merged
Add support for OS_INSECURE environment variable#279stephenfin merged 2 commits intogophercloud:mainfrom
stephenfin merged 2 commits intogophercloud:mainfrom
Conversation
When calling NewServiceClient it was not possible to configure TLS certificate validation using environment variables. This change adds support for the `OS_INSECURE` environment variable, which is parsed as a boolean value. When truthy, we disable certificate validation. Signed-off-by: Lars Kellogg-Stedman <lars@redhat.com>
Move TLS configuration into a PrepareTLSConfig helper function so that we can test the support for OS_INSECURE added in the previous commit. Signed-off-by: Lars Kellogg-Stedman <lars@redhat.com>
stephenfin
requested changes
Apr 9, 2026
Comment on lines
811
to
825
| // Define whether or not SSL API requests should be verified. | ||
| // First, check if the INSECURE environment variable is set. | ||
| var insecurePtr *bool | ||
| if v := env.Getenv(envPrefix + "INSECURE"); v != "" { | ||
| insecure, err := strconv.ParseBool(v) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to parse %sINSECURE: %w", envPrefix, err) | ||
| } | ||
| insecurePtr = &insecure | ||
| } | ||
| // Next, check if the cloud entry sets verify (inverted to insecure). | ||
| if cloud.Verify != nil { | ||
| // Here we take the boolean pointer negation. | ||
| insecure := !*cloud.Verify | ||
| insecurePtr = &insecure | ||
| } |
Contributor
There was a problem hiding this comment.
I think this might backwards: normally env vars take priority over file-based (clouds.yaml) configuration. What does openstacksdk do here?
Contributor
Author
There was a problem hiding this comment.
I was just following the existing logic in the code; e.g., the following that handles OS_CACERT:
// Check if a custom CA cert was provided.
// First, check if the CACERT environment variable is set.
var caCertPath string
if v := env.Getenv(envPrefix + "CACERT"); v != "" {
caCertPath = v
}
// Next, check if the cloud entry sets a CA cert.
if v := cloud.CACertFile; v != "" {
caCertPath = v
}
Contributor
There was a problem hiding this comment.
Okay, that's backwards from how I'd have expected this to work but at least it's consistent. Thanks for the context.
stephenfin
approved these changes
Apr 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When calling NewServiceClient it was not possible to configure TLS
certificate validation using environment variables. This change adds
support for the
OS_INSECUREenvironment variable, which is parsed asa boolean value. When truthy, we disable certificate validation.
Signed-off-by: Lars Kellogg-Stedman lars@redhat.com