TLS handshake failure to OpenAI GPT-4o API behind corporate proxy

TLS Handshake Failure to OpenAI GPT‑4o API Behind a Corporate Proxy

Problem

The production microservice running in a Kubernetes cluster cannot establish a TLS connection to https://api.openai.com/v1/chat/completions. The request fails with a certificate verification error and, after a retry, a timeout during the TLS negotiation phase.

Typical log excerpt (application layer)


2026-11-22T14:03:12.487Z ERROR request-id=7f3c2a8b-1d4e-4b9a-9f2e-5c9d2c8a1e6b msg="HTTP request failed"
error="tls: failed to verify certificate: x509: certificate signed by unknown authority"
stacktrace:
  github.com/openai/gpt4o/client.doRequest(...)
  github.com/myservice/ai/handler.handleChat(...)

Network‑level log (proxy)


[2026-11-22 14:03:13] PROXY_ERR: TLS handshake timeout for client 10.2.5.12:54321 -> api.openai.com:443
[2026-11-22 14:03:13] PROXY_ERR: Certificate verification failed (unknown CA) for api.openai.com

Root Cause

The corporate outbound proxy performs TLS interception (also called SSL/TLS inspection). It terminates the client TLS session, validates the server certificate against its own trusted root store, and then re‑encrypts the traffic with a proxy‑generated certificate signed by an internal Certificate Authority (CA). The Kubernetes pods do not trust this internal CA, so the OpenAI client library aborts the handshake with x509: certificate signed by unknown authority. When the proxy cannot complete the inspection within its configured timeout (often due to large request bodies or strict inspection policies), it aborts the handshake, leading to the observed timeout.

Debug

Follow these steps to confirm the hypothesis.

  1. Validate direct connectivity (bypass proxy)

kubectl exec -ti $(kubectl get pod -l app=myservice -o jsonpath='{.items[0].metadata.name}') -- \
  curl -v https://api.openai.com/v1/models 2>&1 | grep "SSL"

Expected output (when proxy is bypassed):


*   Trying 104.18.12.34:443...
* Connected to api.openai.com (104.18.12.34) port 443 (#0)
* TLS 1.3 handshake, Client hello (1):
...
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384

If the request succeeds, the issue is proxy‑related.

  1. Inspect the proxy’s presented certificate

kubectl exec -ti $(kubectl get pod -l app=myservice -o jsonpath='{.items[0].metadata.name}') -- \
  openssl s_client -connect api.openai.com:443 -servername api.openai.com 

Look for a Issuer that matches the corporate CA (e.g., CN=CorpProxyCA) instead of a public CA such as DigiCert. The output will also contain Verify return code: 21 (unable to verify the first certificate) when the pod does not trust the proxy CA.

  1. Check the pod’s trusted root store

kubectl exec -ti $(kubectl get pod -l app=myservice -o jsonpath='{.items[0].metadata.name}') -- \
  cat /etc/ssl/certs/ca-certificates.crt | grep -i "CorpProxyCA"

If nothing is returned, the internal CA is missing.

  1. Review proxy configuration

Corporate proxy configuration is typically stored in a ConfigMap or a sidecar environment variable (HTTPS_PROXY, NO_PROXY). Verify that the service is using the proxy:


kubectl exec -ti $(kubectl get pod -l app=myservice -o jsonpath='{.items[0].metadata.name}') -- \
  env | grep -i proxy

Typical output:


HTTPS_PROXY=http://proxy.corp.local:3128
NO_PROXY=localhost,127.0.0.1,.svc,.cluster.local

Solution

Two complementary approaches are recommended: trust the corporate CA inside the container image, and configure the proxy to allow TLS pass‑through for the OpenAI endpoint.

1. Add the corporate proxy CA to the container image

Update the Dockerfile to copy the CA bundle and run update-ca-certificates (Debian/Ubuntu) or trust (Alpine).

Before

FROM golang:1.22-alpine AS build
...
FROM alpine:3.20
COPY --from=build /app/myservice /usr/local/bin/myservice
ENTRYPOINT ["/usr/local/bin/myservice"]

After

FROM golang:1.22-alpine AS build
...
FROM alpine:3.20
# Install ca-certificates and add corporate CA
RUN apk add --no-cache ca-certificates
COPY corp-proxy-ca.crt /usr/local/share/ca-certificates/corp-proxy-ca.crt
RUN update-ca-certificates
COPY --from=build /app/myservice /usr/local/bin/myservice
ENTRYPOINT ["/usr/local/bin/myservice"]

Make sure corp-proxy-ca.crt is the PEM‑encoded root certificate provided by the security team.

2. Configure proxy bypass for OpenAI

If the organization permits, add the OpenAI domain to the NO_PROXY list so the client connects directly, avoiding TLS interception.

Before


env:
  - name: HTTPS_PROXY
    value: http://proxy.corp.local:3128
  - name: NO_PROXY
    value: localhost,127.0.0.1,.svc,.cluster.local

After


env:
  - name: HTTPS_PROXY
    value: http://proxy.corp.local:3128
  - name: NO_PROXY
    value: localhost,127.0.0.1,.svc,.cluster.local,api.openai.com

Apply the changes with a rolling update:


kubectl rollout restart deployment/myservice

Verify

After the rollout, repeat the direct connectivity test (step 1 in Debug). The TLS handshake should now succeed without verification errors.


*   Trying 104.18.12.34:443...
* Connected to api.openai.com (104.18.12.34) port 443 (#0)
* TLS 1.3 handshake, Client hello (1):
...
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384

Additionally, check the application logs for successful API calls:


2026-11-22T14:07:45.112Z INFO request-id=7f3c2a8b-1d4e-4b9a-9f2e-5c9d2c8a1e6b msg="OpenAI response received" status=200 model=gpt-4o

Confirm that monitoring alerts for TLS errors have cleared for at least one full evaluation window (e.g., 5 minutes).

Prevent

  • Certificate management pipeline: Automate the injection of corporate root CAs into all base images used for outbound services.
  • Proxy policy documentation: Maintain an explicit list of external services that require NO_PROXY entries to avoid TLS interception.
  • Health‑check endpoint: Add a lightweight health check that performs a TLS handshake to api.openai.com and reports success/failure to Prometheus.
  • Alerting: Create a Prometheus rule that fires on tls_handshake_failure_total{destination="api.openai.com"} to catch regressions early.
  • Periodic audit: Run a CI job that validates the presence of the corporate CA in the final image and the existence of the required NO_PROXY entry.

FAQ

  1. Why does the error appear only in production and not in local development?
    Production pods route outbound traffic through the corporate proxy, which performs TLS interception. Local machines usually connect directly, so the proxy’s internal CA is never encountered.
  2. Can I disable TLS verification in the OpenAI client to work around the issue?
    Disabling verification (InsecureSkipVerify) defeats the security purpose of the proxy and is not recommended. It also violates OpenAI’s usage policy.
  3. What if the corporate security team refuses to add the OpenAI domain to NO_PROXY?
    In that case, the only viable solution is to import the proxy’s root CA into the container image (as shown in the “Add corporate CA” step) and ensure the client trusts it.
  4. How do I know which CA the proxy uses?
    Capture the certificate chain with openssl s_client -connect api.openai.com:443 -servername api.openai.com. The Issuer field of the leaf certificate will show the proxy’s CA name.
  5. Is there a performance impact when bypassing the proxy for OpenAI calls?
    Bypassing the proxy removes the inspection step, typically reducing latency by 30‑50 ms per request. The impact is negligible compared to the benefit of reliable TLS handshakes.

Related Topic Hub: LLM Systems Troubleshooting Hub