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

bashlex is creating python files at import time #51

Closed
GabrielL opened this issue Sep 19, 2019 · 4 comments
Closed

bashlex is creating python files at import time #51

GabrielL opened this issue Sep 19, 2019 · 4 comments

Comments

@GabrielL
Copy link

Hi,

I am using bashlex, installed system wide (in a container, but that's not the issue), and when I try to import it as an unprivileged user, it shows some errors:

# sudo -u user python -c "import bashlex"
Unable to create '/usr/lib/python3.7/site-packages/bashlex/parsetab.py'
[Errno 13] Permission denied: '/usr/lib/python3.7/site-packages/bashlex/parsetab.py'

tracking the issue, it seems that https://github.com/idank/bashlex/blob/master/bashlex/yacc.py#L3291 is the call that write this file.

@idank
Copy link
Owner

idank commented Sep 19, 2019

Can you run the import once as root? It looks like it can't write the generated file because it doesn't have permissions. Once the file is created, it should just read it.

Alternatively, install the package in user home directory so it has access.

@GabrielL
Copy link
Author

Can you run the import once as root? It looks like it can't write the generated file because it doesn't have permissions. Once the file is created, it should just read it.

Alternatively, install the package in user home directory so it has access.

That is not an option for me. The user I run can't write into installed python packages, and this is exactly the point.

Here is a sample (reduced) of the situation I am in:

Dockerfile:

FROM python
RUN pip install bashlex
RUN useradd -u 1000 -m -d /user user
WORKDIR /user
USER user

and the execution:

docker run $image_name python -c "import bashlex"

I could run that as root, but packages should be able to be run without extra manipulation.

@idank
Copy link
Owner

idank commented Sep 19, 2019

Perhaps bashlex as a package should run the initial import as a post install sort of thing, while it's still running as the correct user.

This is the first I've heard of someone hitting this issue, and sadly I don't have the time to work on a fix. Suggest you workaround this somehow or maybe you can figure out if what I suggested above is a good approach and implement it.

@samlikins
Copy link

I was unable to reproduce this issue.

Created the following Dockerfile:

FROM python
RUN pip install bashlex
RUN useradd -u 1000 -m -d /user user
WORKDIR /user
USER user

Built the Docker image:

$ docker build -t bashlex .
[+] Building 1.2s (9/9) FINISHED                                                                                                                      
 => [internal] load build definition from Dockerfile                                                                                             0.0s
 => => transferring dockerfile: 37B                                                                                                              0.0s
 => [internal] load .dockerignore                                                                                                                0.0s
 => => transferring context: 2B                                                                                                                  0.0s
 => [internal] load metadata for docker.io/library/python:latest                                                                                 0.9s
 => [auth] library/python:pull token for registry-1.docker.io                                                                                    0.0s
 => [1/4] FROM docker.io/library/python@sha256:b9683fa80e22970150741c974f45bf1d25856bd76443ea561df4e6fc00c2bc17                                  0.0s
 => CACHED [2/4] RUN pip install bashlex                                                                                                         0.0s
 => CACHED [3/4] RUN useradd -u 1000 -m -d /user user                                                                                            0.0s
 => CACHED [4/4] WORKDIR /user                                                                                                                   0.0s
 => exporting to image                                                                                                                           0.1s
 => => exporting layers                                                                                                                          0.0s
 => => writing image sha256:9f42a4e360035637e39ac0dece9140af0d1432ed7db56e8f8622efe577ed403e                                                     0.0s
 => => naming to docker.io/library/bashlex

Ran the command reported to cause error:

$ docker run bashlex python -c "import bashlex"

No apparent errors occur.

@idank idank closed this as completed Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants