diff options
| author | Yuriy Andamasov <yuriy@vyos.io> | 2026-06-02 17:49:20 +0300 |
|---|---|---|
| committer | Yuriy Andamasov <yuriy@vyos.io> | 2026-10-04 12:13:18 +0300 |
| commit | bc1a054e14eaabd17326d63fa99c19c0a867130d (patch) | |
| tree | bc4a1b3fa781ff539afe7573e8e064646e4bc608 /python | |
| parent | fce6b4074f85a8112ba4de64bf2cee94eab704cd (diff) | |
| download | vyos-1x-bc1a054e14eaabd17326d63fa99c19c0a867130d.tar.gz vyos-1x-bc1a054e14eaabd17326d63fa99c19c0a867130d.zip | |
http-api-client: T8955: enable TLS verification by default
ApiClientConfig.verify_tls defaulted to False and ApiClient unconditionally
silenced urllib3's InsecureRequestWarning, so TLS peer verification was off by
default. The sole consumer, src/op_mode/config_sync.py, builds the client
without passing verify_tls and therefore connected to a *remote* secondary VyOS
node over HTTPS without verifying the certificate -- a MITM exposure on the
channel that carries the API key and the full configuration.
- ApiClientConfig.verify_tls now defaults to True and accepts bool | str;
a string is forwarded to requests as a CA bundle path (verify=<path>).
- InsecureRequestWarning is suppressed only when verification is explicitly
disabled (verify_tls is False), not when a CA path or True is set.
- config_sync reads an optional verify_tls from the secondary runtime settings,
defaulting to False to preserve current behaviour for self-signed secondaries.
The insecurity is now explicit at the call site instead of hidden in the
library default. Exposing a CA certificate (PKI reference) and peer
fingerprint pinning under service config-sync secondary is follow-up T9396.
🤖 Generated by [robots](https://vyos.io)
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/http_api_client.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/python/vyos/http_api_client.py b/python/vyos/http_api_client.py index ae16cfa54..f0783e3fc 100644 --- a/python/vyos/http_api_client.py +++ b/python/vyos/http_api_client.py @@ -51,7 +51,11 @@ class ApiClientConfig: key: str port: int = 443 timeout: Optional[int] = None - verify_tls: bool = False + # TLS peer verification, forwarded verbatim to requests' ``verify``: + # True - verify against the system CA store (secure default) + # False - disable verification (insecure; opt-in only) + # "<path>" - verify against a custom CA bundle file/dir + verify_tls: bool | str = True class ApiClient: @@ -60,7 +64,8 @@ class ApiClient: Design goals: - minimal surface area (thin wrapper around requests) - consistent error handling + typed exceptions - - safe defaults for VyOS typical self-signed HTTPS usage (verify_tls=False) + - secure defaults (verify_tls=True); deployments using self-signed + certificates opt into verify_tls=False or supply a CA bundle path """ _DEFAULT_HEADERS = { @@ -77,7 +82,9 @@ class ApiClient: self._session = requests.Session() self._session.headers.update(self._DEFAULT_HEADERS) - if not config.verify_tls: + # Only silence the insecure-request warning when verification has been + # explicitly disabled. A CA bundle path or True must keep warnings on. + if config.verify_tls is False: urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) @property |
