Live data from Hacker News

Environment variables are a legacy mess: Let's dive deep into them

allvpv.org

151–160 of 194 posts

Re: Environment variables are a legacy mess: Let's dive deep into them

#151
post #94
post #89

Earlier quoted context omitted.

Yes, you can consider all processes running under the same user as able to peek at each other's data. This is the point of running under the same uid: sharing data.One uid should be considered one security domain, with any separators inside it being guardrails, not brick walls. If you want to prevent other processes from peeking into your process, run it under a different uid. Again. that's the point. A bunch of good…

I think this part of Unix is exceedingly problematic. I want to be able to run program that don't have the ability to do anything that I, personally, can do. Ideally this would be doable without nasty kludges or root's help. Linux has some ways to accomplish this, for example: - seccomp. It can be done quite securely, but running general purpose software in seccomp is not necessarily a good way to prevent it from act…

Yes, if we talk about interactive use, where the user may want to run a program with isolation on a whim, and can't be bothered to prepare a separate account for it.

Namespaces, to my mind, are a huge help, starting from trivial chroot and nsenter, all the way to bubblewrap [2] and containers (rootless, of course).

Also, with a properly prepared disk image, and the OS state frozen when everything heavyweight has started already, you can spawn a full-blown VM in well under a second, and run a questionable binary in it.

It would be fun to have "domains" within a user account, with their own views of the file system, network, process tree, etc, and an easy way to interactively run programs in different domains. Again, it's pretty doable; whoever creates an ergonomic product to do it, will win! (Well, not really, because most developers sadly run macOS, which lacks all these niceties, but has its own mechanisms, not very accessible to the user.)

[1]: https://quintessence.sh/blog/bwrap-guide-linux/

Re: Environment variables are a legacy mess: Let's dive deep into them

#152
post #134

One of the worst things about Environment variables among others discussed here is the implicit and opaque nature of them. Majority of applications rely on them in the *nix world. Even if more explicit and obvious ways of configuration files or remote services (consul/etcd, et al.) and command line arguments are supported env vars are traditionally supported as well. But as mentioned in the article it is just a globa…

Heh, you can put hjkl in that neo conservatism bucket. Vi hjkl are the way they are because of a dumb terminal from 40+ years ago, which had fewer units sold than the Nokia N9 smartphone.

Re: Environment variables are a legacy mess: Let's dive deep into them

#153

I can't recommend Varlock [1] enough. A great way to manage env vars in a project. It lets you define which ones are necessary or optional, their types, and where they should be fetched from. [1] https://varlock.dev/

I use https://mise.jdx.dev/

Re: Environment variables are a legacy mess: Let's dive deep into them

#154

To give an illustration of how bad this can get: At a past firm, I was trying to debug how a particular ENV var was getting set. I started out thinking it was something simple like the user's .bashrc or equivalent. I quickly realized that there were roughly 10 "layers" of env var loadings happening where the first couple layers were: - firm wide - region - business unit - department - team etc etc I ended up having t…

"One namespace ought to be enough for anybody".

Re: Environment variables are a legacy mess: Let's dive deep into them

#155
post #54

Earlier quoted context omitted.

> Environment variables are often used to pass secrets around. But, despite its ubiquity, I believe that's a bad practice: I think environment variables are recommended to pass configuration parameters, and also secrets, in containerized applications managed by container orchestration systems. By design, other processes cannot inspect what environment variables are running in a container. Also, environment variables…

Please note that in my OP, I never mentioned containers. Let's say, as a developer, I need to do some API interactions with GitHub. So, in a terminal, using 1Password's cli tool `op`, I load my GH API token and pass it to my Python script that is doing the API calls. Presumably, the reason I use that process is because I want to keep that token's exposure isolated to that script and I don't want the token exposed on…

> The Claude agent running in a different CLI session (as an example) also now has access to my GitHub token. Or, any extension I've ever loaded in VS Code also has access.

If you're giving untrusted software full access to your system, you're not in a position to complain about the system not being secure enough. Security starts by making mindful decisions according to your threat model. No system can keep you secure from yourself. I mean, it can, but it wouldn't be a system you have control over (see Apple, etc.).

There are many solutions that can mitigate the risks you mention. They might not be as convenient as what you're doing now, but they exist. You can also choose to not use software that siphons your data, or exposes you to countless vulnerabilities, but that's a separate matter.

Re: Environment variables are a legacy mess: Let's dive deep into them

#156
post #142

Earlier quoted context omitted.

It's not your (unprivileged user account's) place to decide the security posture of the entire system, that's why you're running into issues with root. Even Yama, an LSM, requires root (or de facto equivalent) for initial setup (as it should). Namespaces, if done incorrectly, can significantly increase the attack surface of the entire system (mount namespaces especially need to be treated with care) and same with reg…

> It's not your (unprivileged user account's) place to decide the security posture of the entire system, that's why you're running into issues with root. Tell that to literally any unprivileged user who would like to run any sort of software without exposing their entire account to any possible code execution bug or malicious code in the software they're running. > The real security barrier on most operating systems…

Apple's "App Sandbox" stuff helps quite a bit with this sort of thing. I realize that doesn't solve the Linux / generic Unix case. https://developer.apple.com/documentation/security/app-sandb...

Re: Environment variables are a legacy mess: Let's dive deep into them

#157
post #24

Earlier quoted context omitted.

If are like most users you have secrets stored in read-protected files in ~/.ssh. There's nothing wrong with that.

They are (should be) encrypted though, and not usable by someone who might somehow gain access to your ~/.ssh files.

No, the private keys are not encrypted. If there were, where would you store the encryption key for decrypting them?

Re: Environment variables are a legacy mess: Let's dive deep into them

#158
post #83

Earlier quoted context omitted.

"MY_APP_SECRET_KEY=bla myapp" hardly accomplishes anything substantial over "myapp --secret-key=blah" It's just a less robust and less well-supported command-line interface. It's not supported by most gui launchers, PowerShell, nor many cron implementations, for example.

The command line can be read by any user on the host (with `ps auxww` for example) while the environment cannot. You should never pass secrets on the command line.

Environment variables are not more secure than command line parameters! It's such a common misconception that because environment variables are "not seen" they can serve as a secure channel. They emphatically cannot.

Re: Environment variables are a legacy mess: Let's dive deep into them

#159

Earlier quoted context omitted.

In a shell script, set -u. It’ll terminate if you reference an unset variable. In other languages, check that the var you pulled in isn’t falsey before proceeding.

> In a shell script, set -u Won't help. I'm _running a program_ want to configure it with environment variables, not _writing a program_ that I expect the user to configure for himself. > falsey There are more than two programming languages in the world.

> There are more than two programming languages in the world.

Great, then you know how to check it in your language of choice.

Re: Environment variables are a legacy mess: Let's dive deep into them

#160
My favorite environment variable trivium (that's the singular of trivia) is that PS1 and a few others that "everyone" thinks of as environment variables are not environment variables but shell variables. PS1 doesn't even show up in "env" output!
Post reply on HN