Skip to content

metadata: verify HTTPS certificates unless https_allow_insecure is set - #231

Open
AI-WFox wants to merge 1 commit into
cloudbase:masterfrom
AI-WFox:gitranks/219-tls-certificate-verification-disabled
Open

AI-WFox wants to merge 1 commit into
cloudbase:masterfrom
AI-WFox:gitranks/219-tls-certificate-verification-disabled

Conversation

@AI-WFox

@AI-WFox AI-WFox commented Nov 30, 2026

Copy link
Copy Markdown

Fixes #219.

BaseHTTPMetadataService._verify_https_request returned https_allow_insecure as the verify argument of requests.request. With the default (False), requests got verify=False and skipped certificate validation; setting the option to True turned validation on. That is the opposite of the option's documented meaning ("Whether to disable the validation of HTTPS certificates"), and it means every HTTPS metadata service built on this class (OpenStack HTTP, EC2, GCE, MAAS, CloudStack, Packet, Oracle Cloud) accepted any certificate by default (CWE-295).

Change

  • cloudbaseinit/metadata/services/base.py: return not self._https_allow_insecure. A configured https_ca_bundle still takes precedence, as before. The docstring now says what the method returns.
  • cloudbaseinit/tests/metadata/services/test_base.py: the old test asserted assertTrue(mock.sentinel.allow_insecure), which is always true, so it never checked the returned value. As requested in TLS certificate verification disabled by default in BaseHTTPMetadataService (CWE-295) #219, tests that fail first:
    • the default returns True;
    • https_allow_insecure=True returns False;
    • a CA bundle is returned with and without https_allow_insecure;
    • _http_request passes verify=True to requests.request by default.

Tests

  • python -m unittest cloudbaseinit.tests.metadata.services.test_base: 29 tests, OK.
  • With base.py reverted to master, 4 of the new tests fail (test_verify_https_request, test_verify_https_request_default_verifies, test_verify_https_request_allow_insecure, test_http_request_verifies_certificate_by_default).
  • python -m unittest discover -s cloudbaseinit/tests/metadata -t .: 309 tests; the only error is test_maasservice failing to import a dependency I did not install, and master gives the same single error.
  • flake8 on both files: clean.

Run on Windows, Python 3.13.

Compatibility

Deployments that reach an HTTPS metadata endpoint with an untrusted certificate under the default configuration will now fail certificate validation instead of silently accepting it. They should set https_ca_bundle (preferred) or, knowingly, https_allow_insecure = True. This probably deserves a line in the release notes.

This pull request was written by an AI agent (Claude Opus) and reviewed by me before submission.

Made with GitRanks Contribute and Claude Code (Opus) · Reviewed and submitted by @AI-WFox
Something off? Tell us or opt out in one step. Maintainers are always in control.

BaseHTTPMetadataService passed https_allow_insecure straight to the verify argument of requests, so the default (False) turned certificate validation off and setting the option to True turned it on, the opposite of its documented meaning (CWE-295). Return the negated value instead; a configured https_ca_bundle still takes precedence.

The existing test asserted on a sentinel rather than on the returned value, so it could not catch this. Replace it with tests for the default, for https_allow_insecure=True, for a CA bundle with and without the option, and for the verify value passed to requests.request.

Fixes cloudbase#219

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: gitranks[bot] <198371943+gitranks[bot]@users.noreply.github.com>
Signed-off-by: Pham Khanh Tam <84433497+AI-WFox@users.noreply.github.com>
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.

TLS certificate verification disabled by default in BaseHTTPMetadataService (CWE-295)

1 participant