News for hackers. Stuff that matters.
Re:Switching from pyenv, rbenv, goenv and nvm to asdf by js2 on Tuesday April 05, 2022 @09:24AM (#30918661)
> Everything was fine until I kinda felt my config.fish file got bloated and somehow nvm was kinda slowing down my shell startup.

I'm quite happy with direnv to avoid this problem.

https://direnv.net/

Funny enough, it was submitted to HN most recently just yesterday:

https://news.ycombinator.com/item?id=30908321

direnv is complementary to the various language-version tools, so it obviates needing asdf:

https://github.com/direnv/direnv/wiki#project-layouts

But it seems some folks combine the two:

https://blog.mikecordell.com/2021/12/18/better-project-envir...

Re:Switching from pyenv, rbenv, goenv and nvm to asdf by qbasic_forever on Tuesday April 05, 2022 @01:19PM (#30921853)
direnv is nice but it really makes me uneasy if it catches on for modern collaborative development.

You are giving people a _ton_ of trust when cloning a repo or pull request that has a .envrc which will be automatically executed by direnv. This file could do anything from steal your SSH keys to delete your entire home directory or worse. And the only thing preventing that from happening is the suggestion of "oh be sure to eyeball the .envrc file and make sure it looks ok, then run this command to enable it". People will just google for the first "how to I unblock .envrc file" and blindly run the command, then oops. Or a determined attacker will just obfuscate what they're doing so the .envrc looks fine but you failed to realize some esoteric bash-isms were actually invoking an obfuscated script and... oops. It's just begging for a supply chain disaster on a similar scale as npm's infamous issues.

VS code and some vim extensions have similar issues with automatic project-specific configurations that allow arbitrary code execution too, and neither have a good solution beyond 'just read all the code and understand it to make sure it's not going to hurt you'. It's not really a unique thing to direnv.

We really need a better model for collaboration and consistent dev environments. I think containers and docker/chroot/etc. environments with explicit opt in of your local resources, configs, files, etc. are a much more sane and security conscious path towards it. A script executing to setup my python environment for a project should never, ever have access or even know about my personal password store database for example (unless I explicitly decide it should).

Re:Switching from pyenv, rbenv, goenv and nvm to asdf by Nextgrid on Tuesday April 05, 2022 @01:34PM (#30922126)
Direnv maintains a local cache of the scripts it's allowed to execute. It will not execute a brand new script and instead ask you to manually run "direnv allow".
Re:Switching from pyenv, rbenv, goenv and nvm to asdf by qbasic_forever on Tuesday April 05, 2022 @01:38PM (#30922199)
Yes, that's why I explicitly mentioned this:

> And the only thing preventing that from happening is the suggestion of "oh be sure to eyeball the .envrc file and make sure it looks ok, then run this command to enable it". People will just google for the first "how to I unblock .envrc file" and blindly run the command, then oops. Or a determined attacker will just obfuscate what they're doing so the .envrc looks fine but you failed to realize some esoteric bash-isms were actually invoking an obfuscated script and... oops.

You need to be absolutely sure you've read and understand every single line in the .envrc file, and every single line in any script it may be invoking, before you run direnv allow. Otherwise you are giving code from the internet a blank check to do anything on your machine with your user account.

I personally do not think bash/shell is a sensible language to trust that you can quickly or easily determine from a visual check alone if a script might be doing nefarious things.

Re:Switching from pyenv, rbenv, goenv and nvm to asdf by Nextgrid on Tuesday April 05, 2022 @02:03PM (#30922584)
I use direnv to source environment variables - the only scripts I use it for consist of "export" statements. Anything beyond that and I'll be questioning it.

Sure, you can trick idiots into running malicious code, but I don't think you need direnv for that - any pip/npm install can run anything and so does curl|bash.

Re:Switching from pyenv, rbenv, goenv and nvm to asdf by oauea on Wednesday April 06, 2022 @08:56AM (#30931445)
How is that any different from actually running the software that requires the direnv?
Re:Switching from pyenv, rbenv, goenv and nvm to asdf by qbasic_forever on Wednesday April 06, 2022 @12:29PM (#30934164)
The pull request scenario is what scares me. Someone sends you a drive by pull request that has a ton of changes and you don't notice they slipped an obfuscated bash quirk into the .envrc (along with legitimate changes to the file) that invokes their obfuscated nasty script. You pull down the change, approve the envrc (looks fine!), and poof there goes your home directory or worse.
Re:Switching from pyenv, rbenv, goenv and nvm to asdf by oauea on Wednesday April 06, 2022 @05:22PM (#30937564)
The same goes for your unit tests or just the application itself though
Re:Switching from pyenv, rbenv, goenv and nvm to asdf by DandyDev on Tuesday April 05, 2022 @01:37PM (#30922186)
direnv actually won't run anything until you explicitly allow it to. And if the .env file changes, you have to re-allow direnv to read and execute it.

Seems safe to me

Re:Switching from pyenv, rbenv, goenv and nvm to asdf by qbasic_forever on Tuesday April 05, 2022 @01:43PM (#30922269)
Unfortunately like the other comment you didn't read what I said and my concern about this approach. Please see my response: https://news.ycombinator.com/item?id=30922199
Re:Switching from pyenv, rbenv, goenv and nvm to asdf by hardwaresofton on Tuesday April 05, 2022 @06:39PM (#30926013)
I don’t include the env file in the source, but rather include a sample in the README.

If I wanted to include it, I use something like git-crypt and encrypt the contents

Re:Switching from pyenv, rbenv, goenv and nvm to asdf by kot-behemoth on Tuesday April 05, 2022 @10:32AM (#30919513)
I use direnv myself, and it's great. However, for anyone trying it out I'd caution that it doesn't play well with conda - the Python package management system (see this open issue https://github.com/direnv/direnv/issues/326). It can be a dealbreaker for some.
Re:Switching from pyenv, rbenv, goenv and nvm to asdf by wyufro on Tuesday April 05, 2022 @11:28AM (#30920259)
Indeed, direnv and asdf integrates, such that PATH is set to the values exposed by your .tool-config. This avoids the asdf shim and makes executing the tools slightly faster. Good when you have to run them over and over in a script.
Re:Switching from pyenv, rbenv, goenv and nvm to asdf by sph on Tuesday April 05, 2022 @03:00PM (#30923383)
direnv is a killer tool in my arsenal. Writing 12 factor apps without it (especially managing configuration) is an exercise in pain and frustration.