DopplerHQ / cli

The official CLI for interacting with your Doppler secrets and configuration.
https://docs.doppler.com
Apache License 2.0
218 stars 44 forks source link

[BUG] Env variables not populated if running as sudo. #287

Closed RemiKalbe closed 2 years ago

RemiKalbe commented 2 years ago

Describe the bug If I run a program as sudo, the env variables that should be populated by doppler, aren't.

To Reproduce A simple javascript file

console.log("ENV: " + process.env.MY_AMAZING_VAR);

If I run

doppler run -- node test.js

I get back

ENV: My amazing var's value

But if I run as root

doppler run -- sudo node test.js

I get

ENV: undefined

Expected behavior To have my ENV var populated, whether or not I use sudo.

Desktop (please complete the following information):

CLI Version: Version 3.36.0

RemiKalbe commented 2 years ago

If I run it like so

sudo doppler run -- node test.js

It works, but I'll keep this issue open in case it should also works as I described.

Piccirello commented 2 years ago

This is a feature of the sudo command. You must pass the --preserve-env flag (or -E) to retain these variables in your new shell.

https://man7.org/linux/man-pages/man8/sudo.8.html