nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
106.53k stars 29.03k forks source link

NODE_EXTRA_CA_CERTS does not work when set in env file #51426

Open slukes opened 8 months ago

slukes commented 8 months ago

Version

v21.5.0

Platform

Darwin MACM-YXGQWMKDQK 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul 5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000 arm64

Subsystem

No response

What steps will reproduce the bug?

Run node --env-file ./config/.env.development

With env file containing NODE_EXTRA_CA_CERTS

The variable is not taken into account.

Run same script but exporting the variable first, it is correctly taken into account.

How often does it reproduce? Is there a required condition?

Always!

What is the expected behavior? Why is that the expected behavior?

The ca cert should be taken into account

What do you see instead?

It is not correctly taken into account and I get errors about self signed certificates

Additional information

No response

tniessen commented 8 months ago

cc @anonrig

MrJithil commented 8 months ago

Please help with console.log(process.env) for debugging purpose. Just to verify the env variable is set but the path specified is getting wrong while using --env-file flag. After I will write a reproducing snippets.

sosoba commented 8 months ago

Doc says:

The NODE_EXTRA_CA_CERTS environment variable is only read when the Node.js process is first launched. Changing the value at runtime [..] has no effect on the current process.

xsbchen commented 8 months ago

for now, i think it not supported to set NODE_EXTRA_CA_CERTS in env file, may need to note this on the document

slukes commented 8 months ago

Please help with console.log(process.env) for debugging purpose. Just to verify the env variable is set but the path specified is getting wrong while using --env-file flag. After I will write a reproducing snippets.

I can confirm that the variable is getting correctly set 😄. (I can't share my whole process.env with you)

xsbchen commented 8 months ago

@slukes I checked the code, in the start process, it will use NODE_EXTRA_CA_CERTS from process env to init openssl first, then load the file from --env-file, so it will not work for setting NODE_EXTRA_CA_CERTS in --env-file, maybe you need to set it before you start node

xsbchen commented 8 months ago

@anonrig if it expects to work, I want to try to fix it

slukes commented 7 months ago

@anonrig if we can do anything to help please let me know!

senicko commented 1 month ago

Hi, just wanted to say that it would be amazing to be able to set this in .env 🥺