Skip to content

Add support for OS_INSECURE environment variable#279

Merged
stephenfin merged 2 commits intogophercloud:mainfrom
larsks:fix/os-insecure
Apr 9, 2026
Merged

Add support for OS_INSECURE environment variable#279
stephenfin merged 2 commits intogophercloud:mainfrom
larsks:fix/os-insecure

Conversation

@larsks
Copy link
Copy Markdown
Contributor

@larsks larsks commented Apr 9, 2026

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

larsks added 2 commits April 9, 2026 10:05
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>
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
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might backwards: normally env vars take priority over file-based (clouds.yaml) configuration. What does openstacksdk do here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
	}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that's backwards from how I'd have expected this to work but at least it's consistent. Thanks for the context.

@stephenfin stephenfin merged commit cd2167a into gophercloud:main Apr 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants