Fix NODE_EXTRA_CA_CERTS missing from LaunchAgent environment on macOS#22929
Fix NODE_EXTRA_CA_CERTS missing from LaunchAgent environment on macOS#22929Clawborn wants to merge 1 commit intoopenclaw:mainfrom
Conversation
launchd services do not inherit the shell environment, so Node's undici/fetch cannot locate the macOS system CA bundle (/etc/ssl/cert.pem). This causes TLS verification failures for all HTTPS requests (e.g. Telegram, webhooks) when the gateway runs as a LaunchAgent, while the same gateway works fine in a terminal. Add NODE_EXTRA_CA_CERTS defaulting to /etc/ssl/cert.pem on macOS in both buildServiceEnvironment and buildNodeServiceEnvironment. User-supplied NODE_EXTRA_CA_CERTS is always respected and takes precedence. Fixes openclaw#22856 Co-authored-by: Clawborn <tianrun.yang103@gmail.com>
arosstale
left a comment
There was a problem hiding this comment.
Correct fix for a well-known macOS launchd issue — services don't inherit the shell environment so Node's TLS stack can't find the system CA bundle. Defaulting to /etc/ssl/cert.pem (the macOS system root) when NODE_EXTRA_CA_CERTS is unset is the right approach. User-provided value is respected via ??. Tests cover both paths.
|
@steipete This fix is needed — the missing The PR is approved and the approach is solid (default to |
|
Thanks for the PR. Superseded by #27915. |
Problem
When OpenClaw runs as a macOS LaunchAgent (installed via
openclaw gateway install), Node'sundici/fetchcannot locate the system CA bundle becauselaunchddoes not inherit the shell environment. This causes TLS verification failures for all HTTPS connections (Telegram, webhooks, etc.), while the same gateway works fine in a foreground terminal session.Root cause:
buildServiceEnvironmentandbuildNodeServiceEnvironmentinservice-env.tsdid not includeNODE_EXTRA_CA_CERTSin the generated plist environment.Fixes #22856.
Fix
Set
NODE_EXTRA_CA_CERTSto/etc/ssl/cert.pem(the macOS system CA bundle) by default when building the service environment on macOS. A user-suppliedNODE_EXTRA_CA_CERTSin the host environment always takes precedence.The same default is applied to both
buildServiceEnvironment(gateway) andbuildNodeServiceEnvironment(node service) since both run under launchd on macOS.Changes
src/daemon/service-env.ts: addNODE_EXTRA_CA_CERTSto the service environment on macOS, falling back to/etc/ssl/cert.pemwhen not set by the usersrc/daemon/service-env.test.ts: add 4 tests covering the default and user-override cases for both environment buildersGreptile Summary
Fixes TLS verification failures for HTTPS connections when OpenClaw runs as a macOS LaunchAgent by setting
NODE_EXTRA_CA_CERTSto the macOS system CA bundle path (/etc/ssl/cert.pem). The issue occurs because launchd services don't inherit the shell environment, preventing Node's undici/fetch from locating system certificates.NODE_EXTRA_CA_CERTSenvironment variable to bothbuildServiceEnvironmentandbuildNodeServiceEnvironmentfunctions/etc/ssl/cert.pemon macOS (Darwin platform only)NODE_EXTRA_CA_CERTSvalues as overridesConfidence Score: 5/5
Last reviewed commit: 35c5a8e