PM2 Cluster Mode does not work with NODE_EXTRA_CA_CERTS certificates
What's going wrong?
When you start an application in "fork" mode with the "NODE_EXTRA_CA_CERTS" environment variable set, the application is able to communicate with API servers without issue.
When you start the exact same application in "cluster" mode instead, the application cannot communicate with API servers.
How could we reproduce this issue?
- Create a simple application that uses the NODE_EXTRA_CA_CERTS environment variable with a path to a certificate to communicate with an API.
- Run the application in "fork" mode to see a working application.
- Run the application in "cluster" mode to see that it doesn't work.
Supporting information
Nodejs version 20.17.0 Same issue in multiple host environments (Apple Silicon, Linux, etc)
Linking this as it feels related: #3117
I tested the same patch found in #3117 and it works.
Just wondering if this will ever be fixed as #3117 was closed without being implemented?
Wow, I just found this issue, this is exactly the issue that I am having, do anybody know if there was a fix for this?
Tracked this down - God.nodeApp in lib/God/ClusterMode.js calls cluster.fork({pm2_env: JSON.stringify(env_copy), windowsHide: true}), so NODE_EXTRA_CA_CERTS (and any other app env var) only reaches the worker after pm2 parses pm2_env and assigns it onto process.env, well after Node's own TLS bootstrap already ran. Confirmed this locally with a private CA - process.env.NODE_EXTRA_CA_CERTS was correct inside the worker, the request still failed with UNABLE_TO_VERIFY_LEAF_SIGNATURE.
#3117 fixed this for that one var back in 2017 but it never got merged. Opened #6156 with the same idea generalized to any string-typed env var, plus a regression test that reproduces the failure and passes with the fix.