Skip to content

feat: support opt-in TLS certificate verification - #637

Open
vishalshetagar wants to merge 2 commits into
PaloAltoNetworks:developfrom
vishalshetagar:feat/636-ssl-context
Open

vishalshetagar wants to merge 2 commits into
PaloAltoNetworks:developfrom
vishalshetagar:feat/636-ssl-context

Conversation

@vishalshetagar

Copy link
Copy Markdown

Summary

API connections currently have no supported option to enable TLS certificate verification. This adds ssl_context=None to PanDevice and passes it to pan-python, so callers can opt in through Firewall or Panorama:

import ssl
from panos.firewall import Firewall

ctx = ssl.create_default_context(cafile="/path/to/internal-ca.pem")
fw = Firewall("fw.example.com", api_key="...", ssl_context=ctx)

Omitting the context or passing None preserves the current behavior. The pinned pan-python version already supports this argument, so no dependency change is needed.

The context is also passed during API-key generation and through create_from_device(), including the returned device. Firewall requests routed through Panorama use Panorama's context, since Panorama is the TLS endpoint. Adds regression tests, constructor documentation, and a getting-started example.

Closes #636.

Validation

  • Python 3.8 and 3.9 on Windows: python -m pytest tests --ignore=tests/live -q passed on both, with 3,138 passed and 723 skipped each.
  • All eight new tests pass. Against the base revision, the seven tests for the new functionality fail and the unchanged-default test passes.
  • A local HTTPS server confirmed trusted connections succeed and untrusted certificates or hostname mismatches reject requests before credentials or API keys are sent. Also checked key generation, discovery, Panorama proxying, and the unchanged default.
  • Black, isort, and git diff --check pass. Sphinx builds with the same three warnings as the base revision.
  • Flake8 and Bandit findings are unchanged from the base revision. The lint comparison used a temporary copy of the existing .flake8 configuration with its invalid indentation corrected; the repository configuration is unchanged.

No live firewall or Panorama was used for validation.

Copilot AI balanced review requested due to automatic review settings November 29, 2026 07:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@viveksingh-network viveksingh-network left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for picking this up so quickly. I've reviewed the change and run the test suite locally (all passing). The implementation matches the approach in #636: default behaviour unchanged, and the context is applied to API calls, keygen, create_from_device() and Panorama-proxied connections.

A couple of suggestions from the operational side, mainly for the docs:

Connecting by IP address: many PAN-OS management certificates are issued for a hostname only. With ssl.create_default_context(), connecting via IP will fail hostname verification unless the certificate includes that IP as a SAN. Worth a sentence in the docs so users don't assume verification is broken.
Device-side setup: it may help to mention that the management certificate is set under Device > Setup > Management > SSL/TLS Service Profile, so users know where the certificate being verified comes from.
Client certificates (#554): the same ssl_context can carry a client certificate via load_cert_chain(), so this PR may also address #554. Possibly worth a one-line doc example.
None of these are blockers. LGTM from my side, pending maintainer review.

@vishalshetagar

Copy link
Copy Markdown
Author

Thanks @viveksingh-network for the review and suggestions. Added all three documentation updates in e3e0e37: the IP/SAN requirement, the management SSL/TLS Service Profile location, and a load_cert_chain() example.

The docs build passes, and I verified client-certificate connections against a local HTTPS server. I haven’t tested that against a live PAN-OS device, so I’m not claiming #554 is fully resolved yet.

Please take another look when you have a chance.

This branch has not been deployed

No deployments
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.

Feature request: option to enable TLS certificate verification (ssl_context)

3 participants