Skip to content
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

Stack complains about parent directory owned by different user #2187

Open
W4RH4WK opened this issue May 24, 2016 · 13 comments
Open

Stack complains about parent directory owned by different user #2187

W4RH4WK opened this issue May 24, 2016 · 13 comments

Comments

@W4RH4WK
Copy link

W4RH4WK commented May 24, 2016

I just encountered an issue where stack complains (and exists with !=0) when it wants to create a stack-root in a location owned by another user. This would be fine in general but even happens when the --allow-different-user flag is provided. Of course the user executing stack has write permissions inside that other directory.

If I manually create the folder beforehand (mkdir) stack doesn't complain at all.

@agocorona
Copy link

I have a similar problem under Docker. But creating the folder doesn't help to solve it:

Dockerfile:

FROM heroku/cedar

RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 575159689BEFB442 \
    && echo 'deb http://download.fpcomplete.com/debian jessie main'| tee /etc/apt/sources.list.d/fpco.list \
    && apt-get update &&  apt-get install stack -y
RUN stack setup --allow-different-user --compiler ghc-7.10.3
RUN apt-get install nodejs -y \
    && ln -s /usr/bin/nodejs /usr/bin/node
USER root
RUN  echo  "allow-different-user: true" > stack.yaml \
     && echo "compiler: ghcjs-0.2.0.20160414_ghc-7.10.3" >> stack.yaml \
     && echo "resolver: lts-6.0 " >> stack.yaml \
     && echo "compiler-check: match-exact" >> stack.yaml \
     && echo "setup-info:"   >> stack.yaml \
     && echo "  ghcjs:" >> stack.yaml \
     && echo "    source:" >> stack.yaml \
     && echo "      ghcjs-0.2.0.20160414_ghc-7.10.3:" >> stack.yaml \
     && echo "         url: https://s3.amazonaws.com/ghcjs/ghcjs-0.2.0.20160414_ghc-7.10.3.tar.gz"  >> stack.yaml \
     && echo "         sha1: 6d6f307503be9e94e0c96ef1308c7cf224d06be3"  >> stack.yaml \
     && cat stack.yaml \
     && mkdir -p /root/.stack/programs/x86_64-linux/ghcjs-0.2.0.20160414_ghc-7.10.3/src \
     && stack setup --allow-different-user   --compiler ghcjs-0.2.0.20160414_ghc-7.10.3

error:


.....
ghcjs-0.2.0.20160414_ghc-7.10.3:   10.82 MiB downloaded...
ghcjs-0.2.0.20160414_ghc-7.10.3:   10.91 MiB downloaded...
ghcjs-0.2.0.20160414_ghc-7.10.3:   11.02 MiB downloaded...
ghcjs-0.2.0.20160414_ghc-7.10.3:   11.09 MiB downloaded...
ghcjs-0.2.0.20160414_ghc-7.10.3:   11.13 MiB downloaded...
Downloaded ghcjs-0.2.0.20160414_ghc-7.10.3.
Unpacking GHCJS into /root/.stack/programs/x86_64-linux/ghcjs-0.2.0.20160414_ghc-7.10.3/src/ ...
Setting up GHCJS build environment
You are not the owner of '/root/.stack/programs/x86_64-linux/ghcjs-0.2.0.20160414_ghc-7.10.3/src/'. Aborting to protect file permissions.
Retry with '--allow-different-user' to disable this precaution.
....

@buckie
Copy link

buckie commented Oct 20, 2016

I've just run into this issue too, though it seems to be worse now. stack setup seemingly changes the permissions on the fly and then fails because of it. --allow-different-user has no effect:

root@e39d656bbcbe:/pact# stack setup
Downloaded lts-6.19 build plan.
Fetched package index.
Populated index cache.
Preparing to install GHCJS to an isolated location.
This will not interfere with any system-level installation.
Downloaded ghcjs-0.2.0.9006019_ghc-7.10.3.
Setting up GHCJS build environmentYou are not the owner of '/root/.stack/programs/x86_64-linux/ghcjs-0.2.0.9006019_ghc-7.10.3/src/'. Aborting to protect file permissions.
Retry with '--allow-different-user' to disable this precaution.
root@e39d656bbcbe:/pact# ls -lart /root/.stack/programs/x86_64-linux/ghcjs-0.2.0.9006019_ghc-7.10.3/src/
total 84
drwxr-xr-x  2 1000 1000  4096 Sep 28 08:56 utils
drwxr-xr-x  2 1000 1000  4096 Sep 28 08:56 test
drwxr-xr-x  2 1000 1000  4096 Sep 28 08:56 src-bin
drwxr-xr-x  4 1000 1000  4096 Sep 28 08:56 src
drwxr-xr-x  7 1000 1000  4096 Sep 28 08:56 lib
drwxr-xr-x  3 1000 1000  4096 Sep 28 08:56 include
drwxr-xr-x  2 1000 1000  4096 Sep 28 08:56 doc
drwxr-xr-x  2 1000 1000  4096 Sep 28 08:56 cbits
-rw-r--r--  1 1000 1000 10047 Sep 28 08:56 Setup.hs
-rw-r--r--  1 1000 1000  6309 Sep 28 08:56 README.markdown
-rw-r--r--  1 1000 1000  1098 Sep 28 08:56 LICENSE
drwxr-xr-x 10 1000 1000  4096 Sep 28 08:56 .
-rw-r--r--  1 1000 1000    37 Sep 28 10:21 stack.yaml
-rw-r--r--  1 1000 1000 13744 Sep 28 10:21 ghcjs.cabal
drwxr-xr-x  4 root root  4096 Oct 20 19:13 ..
root@e39d656bbcbe:/pact# chown -R root:root /root/.stack/programs/x86_64-linux/ghcjs-0.2.0.9006019_ghc-7.10.3/src/
root@e39d656bbcbe:/pact# ls -lart /root/.stack/programs/x86_64-linux/ghcjs-0.2.0.9006019_ghc-7.10.3/src/
total 84
drwxr-xr-x  2 root root  4096 Sep 28 08:56 utils
drwxr-xr-x  2 root root  4096 Sep 28 08:56 test
drwxr-xr-x  2 root root  4096 Sep 28 08:56 src-bin
drwxr-xr-x  4 root root  4096 Sep 28 08:56 src
drwxr-xr-x  7 root root  4096 Sep 28 08:56 lib
drwxr-xr-x  3 root root  4096 Sep 28 08:56 include
drwxr-xr-x  2 root root  4096 Sep 28 08:56 doc
drwxr-xr-x  2 root root  4096 Sep 28 08:56 cbits
-rw-r--r--  1 root root 10047 Sep 28 08:56 Setup.hs
-rw-r--r--  1 root root  6309 Sep 28 08:56 README.markdown
-rw-r--r--  1 root root  1098 Sep 28 08:56 LICENSE
drwxr-xr-x 10 root root  4096 Sep 28 08:56 .
-rw-r--r--  1 root root    37 Sep 28 10:21 stack.yaml
-rw-r--r--  1 root root 13744 Sep 28 10:21 ghcjs.cabal
drwxr-xr-x  4 root root  4096 Oct 20 19:13 ..
root@e39d656bbcbe:/pact# stack setup
Preparing to install GHCJS to an isolated location.
This will not interfere with any system-level installation.
Already downloaded.
Setting up GHCJS build environmentYou are not the owner of '/root/.stack/programs/x86_64-linux/ghcjs-0.2.0.9006019_ghc-7.10.3/src/'. Aborting to protect file permissions.
Retry with '--allow-different-user' to disable this precaution.
root@e39d656bbcbe:/pact# ls -lart /root/.stack/programs/x86_64-linux/ghcjs-0.2.0.9006019_ghc-7.10.3/src/
total 84
drwxr-xr-x  2 1000 1000  4096 Sep 28 08:56 utils
drwxr-xr-x  2 1000 1000  4096 Sep 28 08:56 test
drwxr-xr-x  2 1000 1000  4096 Sep 28 08:56 src-bin
drwxr-xr-x  4 1000 1000  4096 Sep 28 08:56 src
drwxr-xr-x  7 1000 1000  4096 Sep 28 08:56 lib
drwxr-xr-x  3 1000 1000  4096 Sep 28 08:56 include
drwxr-xr-x  2 1000 1000  4096 Sep 28 08:56 doc
drwxr-xr-x  2 1000 1000  4096 Sep 28 08:56 cbits
-rw-r--r--  1 1000 1000 10047 Sep 28 08:56 Setup.hs
-rw-r--r--  1 1000 1000  6309 Sep 28 08:56 README.markdown
-rw-r--r--  1 1000 1000  1098 Sep 28 08:56 LICENSE
drwxr-xr-x 10 1000 1000  4096 Sep 28 08:56 .
-rw-r--r--  1 1000 1000    37 Sep 28 10:21 stack.yaml
-rw-r--r--  1 1000 1000 13744 Sep 28 10:21 ghcjs.cabal
drwxr-xr-x  4 root root  4096 Oct 20 19:14 ..
root@e39d656bbcbe:/pact#

Here's the dockerfile and relevant stack.yaml:

FROM ubuntu:16.04
MAINTAINER Will <[email protected]>

RUN apt-get -y update && apt-get -y upgrade

RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 575159689BEFB442 && \
    echo 'deb http://download.fpcomplete.com/ubuntu xenial main' >> /etc/apt/sources.list.d/fpco.list && \
    apt-get -y update && \
    apt-get install -y libtool pkg-config build-essential autoconf automake rlwrap htop tmux libevent-dev libncurses-dev stack wget curl npm

RUN cd && mkdir .stack

COPY ./stack.yaml /pact/stack.yaml
COPY ./pact.cabal /pact/pact.cabal

CMD ["/bin/bash"]
resolver: lts-6.19
# GHCJS build
compiler: ghcjs-0.2.0.9006019_ghc-7.10.3
compiler-check: match-exact

setup-info:
  ghcjs:
    source:
      ghcjs-0.2.0.9006019_ghc-7.10.3:
        url: http://ghcjs.tolysz.org/lts-6.19-9006019.tar.gz
        sha1: ef4264d5a93b269ee4ec8f9d5139da030331d65a

@dplusic
Copy link

dplusic commented Sep 12, 2017

Workaround: TAR_OPTIONS=--no-same-owner stack setup

@mgsloan
Copy link
Contributor

mgsloan commented Sep 12, 2017

@dplusic That's good to know, thanks! Makes sense to me to have stack just always pass in that flag.

@hasufell
Copy link
Contributor

hasufell commented Oct 1, 2020

Still exists in 2020 and I don't understand why stack would care about the permissions.

@J4NS-R
Copy link

J4NS-R commented Jul 11, 2021

If anyone is experiencing this issue when trying to run stack in a GitHub Action, you can work around it by manually setting the file ownership to the running user. Just add this step before running stack:

- name: Permissions bug workaround
  run: "chown -R $(id -un):$(id -gn) ~"

@marcellodesales
Copy link

@

If anyone is experiencing this issue when trying to run stack in a GitHub Action, you can work around it by manually setting the file ownership to the running user. Just add this step before running stack:

- name: Permissions bug workaround
  run: "chown -R $(id -un):$(id -gn) ~"

I don't get that same problem using docker-compose builds :( This has to do on how the docker container is run by github actions... that really sucks ... I'm back to using docker-compose

paulcadman added a commit to anoma/juvix that referenced this issue Aug 30, 2022
This error occurs when building with stack:

```
Run stack install --system-ghc --ghc-options='-split-sections -optl-static'
4
Preventing creation of stack root '/github/home/.stack/'. Parent directory '/github/home/' is owned by someone else.
5
Error: Process completed with exit code 1.
```

commercialhaskell/stack#2187
paulcadman added a commit to anoma/juvix that referenced this issue Aug 30, 2022
This error occurs when building with stack:

```
Run stack install --system-ghc --ghc-options='-split-sections -optl-static'
4
Preventing creation of stack root '/github/home/.stack/'. Parent directory '/github/home/' is owned by someone else.
5
Error: Process completed with exit code 1.
```

commercialhaskell/stack#2187
@hasufell
Copy link
Contributor

Workaround: TAR_OPTIONS=--no-same-owner stack setup

This doesn't work (anymore?).

@mpilgrem
Copy link
Member

mpilgrem commented Feb 10, 2024

@hasufell, can you provide any more information about what you are experiencing? There is this code in Stack.Config.loadConfig (extract):

    unless config.allowDifferentUser $ do
      unless userOwnsStackRoot $
        throwM (UserDoesn'tOwnDirectory stackRoot)

but that is behind the unless config.allowDifferentUser test.

EDIT: There is also a distinct error Won'tCreateStackRootInDirectoryOwnedByDifferentUser, but that has a different text to the error reported by the original poster in 2016.

@mpilgrem
Copy link
Member

Looking at its code, Stack can be configured (the default is otherwise) to use a Stack root 'owned' by another user, but it cannot currently create a Stack root on a absolute path where the user does not 'own' any directory on that path.

None of this applies on Windows, and I don't know enough about Unix-like operating systems to know if that is a prudent approach.

@mpilgrem
Copy link
Member

Some history: #471

@simonmichael
Copy link
Contributor

simonmichael commented Apr 18, 2024

Here's a recent example of this, in a Github linux workflow.
https://github.com/simonmichael/hledger/actions/runs/8730436402/job/23954254751

@simonmichael
Copy link
Contributor

simonmichael commented Apr 18, 2024

I should clarify: stack is doing the right thing in my example ("Preventing creation of Stack root '/github/home/.stack/"), but it's another way to trigger this error message in a Github workflow (when using a container, there is confusion about the HOME path. For more info, see actions/runner#1146, actions/runner#863. Worked around with actions/runner#863 (comment) and stack's --allow-different-user flag).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests