-
Notifications
You must be signed in to change notification settings - Fork 842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error out when stack is run as root/sudo #471
Comments
Thanks @radix. @manny-fp Perhaps you have thoughts on this? |
Yeah big +1, I'm up for an error and exit unless |
There are two Docker-related cases that come to mind where you might want to run stack as root:
So +1 from me. |
-1. I don't see why this behavior is wanted. Running as root is common nowadays, both in docker and with various virtual machines to simplify deployment. When I fork out $5 to buy a VM for some testing, root is what I get, and there is no reason to add a non-root user to such a machine. I would not want this behavior. I suggest stack only print a warning, if anything at all. I'd like to understand what problem this is solving that is worth making the semantics of stack depend on |
Creating a non privileged user is IMO part of a "simple" deployment. There is no need to break the least amount of (EDIT:) permissions rule to attribute deployments with "simple". |
It is pretty common to run Docker stuff as root when using "trusted" containers, and I think it'll cause enough users grief if we prevent it that this shouldn't be an error. But running as root is different than running under |
How can you differentiate between running as root and running under In both cases I get
|
The condition we'd really looking for is when Stack is running as |
…skell#471 Users other than the owner of the ~/.stack directory are now prevented from using a stack installation in order to avoid problems with file permissions. To disable this precaution users can pass the --allow-different-user flag or use the 'allow-different-user' configuration option in their ~/.stack/config.yaml. On Windows, the new flag and configuration options have no effect.
Looks like I should really get this done. :) |
…skell#471 Users other than the owner of the ~/.stack directory are now prevented from using a stack installation in order to avoid problems with file permissions. To disable this precaution users can pass the --allow-different-user flag or use the 'allow-different-user' configuration option in their ~/.stack/config.yaml. On Windows, the new flag and configuration options have no effect.
Add 'allow-different-user' flag and configuration option #471
Fixed with #1599. |
…skell#471, fix commercialhaskell#1777 Users other than the owner of the ~/.stack directory are now prevented from using a stack installation in order to avoid problems with file permissions. To disable this precaution users can pass the --allow-different-user flag or use the 'allow-different-user' configuration option in their ~/.stack/config.yaml. On Windows, the new flag and configuration options have no effect. When stack is re-spawned in Docker, the ownership check is skipped (see commercialhaskell#1777). This reverts commits 0a89c9c and 218e7dd.
To summarize, for a non expert both in stack and docker, what I have to do run a program in a docker image that uses a script hardcoded that uses stack and does not include the --allow-different-user? flag? |
@agocorona You can set Running stack should work in the docker container without changing user, though, hmm. |
The problem is that the project config is also created automatically I found another workaround: creating an user in the docker instance and running everithing under this user:
|
Maybe I'm wrong about this, but I think stack still can't bootstrap ghcjs when running as root. The requirement to add What's the expected behavior for bootstrapping compilers when running as root? |
@agocorona creating a user in the docker image creates endless pain when you want to mount your build environment into the docker container. that's definitively an anti-pattern, and a reason why I'm doing that currently with stack, because it's the only way to get it to work with ghcjs, but it's awful, and there's nothing but this feature request that is creating all of this pain. |
@alexanderkjeldaas .Yes I experienced these problems. I agree with you. stack shouldn't care about permissions more than the user of stack itself and the Operating System. It should not dictate what are good or bad practices, specially since the usage cases evolve fast. My experience is that --allow-different-user do not work in medium to large compilations for unknown reasons. For this reason I use cabal under docker, but in this case, stack is imposed. |
Here's another class of common use cases where this is a problem: building a project located on a file system that does not fully support the native permissions system of the shell you are running in. More specifically, you will run into this when your project is in NTFS and you try to build with stack from a unix-like environment. There are many combinations:
In these kinds of cases, all of the files you create show as being owned by root, even though you are not root. So stack refuses to run, claiming that you are not the owner, even though actually you yourself created the files normally without sudo. |
adding:
in config.yaml in the /.stack/config.yaml solved all my problems. It seems to be more general than adding it to the command line |
Thanks, @agocorona. I would list the situation I ran into just FYI: running Windows Subsystem for Linux, having the source code (of hledger) on a Windows drive and trying to compile the project results in the "another-user" error (Retry with '--allow-different-user' to disable this precaution.) |
It's probably wrong to run stack as root, at least in almost all cases. This came up in another thread: #464 (comment)
The text was updated successfully, but these errors were encountered: