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

Permission error when packing to squashfs file on Linux #248

Open
2 tasks done
Kirill888 opened this issue Jan 17, 2023 · 2 comments
Open
2 tasks done

Permission error when packing to squashfs file on Linux #248

Kirill888 opened this issue Jan 17, 2023 · 2 comments
Labels
stale::recovered [bot] recovered after being marked as stale type::bug describes erroneous operation, use severity::* to classify the type

Comments

@Kirill888
Copy link
Contributor

Checklist

  • I added a descriptive title
  • I searched open reports and couldn't find a duplicate

What happened?

While running command like this

conda pack --format=squashfs -n test-env 

Things break when copying activate script over into temp location, this happens when

  1. Conda is installed by root
  2. Temp folder is on the same disk as conda

When creating temp copy of the environment squashfs plugin prefers to use hard-links when copying files on Linux

same_device = os.lstat(source).st_dev == os.lstat(os.path.dirname(target_abspath)).st_dev
if same_device:
copy_func = partial(os.link, follow_symlinks=False)
else:
copy_func = partial(shutil.copy2, follow_symlinks=False)

but this doesn't work when source file is not owned by the user running conda pack. This is the case when conda-pack is installed by root in base environment, while user running the packing is not root

copy_func(source, target_abspath)

Traceback (most recent call last):
  File "/opt/conda/lib/python3.10/site-packages/conda_pack/cli.py", line 157, in main
    pack(name=args.name,
  File "/opt/conda/lib/python3.10/site-packages/conda_pack/core.py", line 542, in pack
    return env.pack(output=output, format=format,
  File "/opt/conda/lib/python3.10/site-packages/conda_pack/core.py", line 386, in pack
    packer.finish()
  File "/opt/conda/lib/python3.10/site-packages/conda_pack/core.py", line 1142, in finish
    self.archive.add(source, target)
  File "/opt/conda/lib/python3.10/site-packages/conda_pack/formats.py", line 247, in add
    self._add(source, target)
  File "/opt/conda/lib/python3.10/site-packages/conda_pack/formats.py", line 487, in _add
    copy_func(source, target_abspath)
PermissionError: [Errno 1] Operation not permitted: '/opt/conda/lib/python3.10/site-packages/conda_pack/scripts/posix/activate' -> '/tmp/tmp9x4imir_/bin/activate'

in the above copy_func is partial(os.link, follow_symlinks=False). os.link should be used only when source and destination share:

  1. same device
  2. same owner (st_uid)

Conda Info

No response

Conda Config

No response

Conda list

No response

Additional Context

No response

@Kirill888 Kirill888 added the type::bug describes erroneous operation, use severity::* to classify the type label Jan 17, 2023
Copy link

Hi there, thank you for your contribution!

This issue has been automatically marked as stale because it has not had recent activity. It will be closed automatically if no further activity occurs.

If you would like this issue to remain open please:

  1. Verify that you can still reproduce the issue at hand
  2. Comment that the issue is still reproducible and include:
    - What OS and version you reproduced the issue on
    - What steps you followed to reproduce the issue

NOTE: If this issue was closed prematurely, please leave a comment.

Thanks!

@github-actions github-actions bot added the stale [bot] marked as stale due to inactivity label Jan 18, 2024
@Kirill888
Copy link
Contributor Author

issue remains with current code in main branch, hard-linking with ownership change is not possible and code assumes that conda is installed as the user running conda-pack.

Kirill888 added a commit to Kirill888/conda-pack that referenced this issue Jan 18, 2024
Can not create hard-link on Linux when source file is owned by root but
conda-pack runs as non-root user.
@github-actions github-actions bot added stale::recovered [bot] recovered after being marked as stale and removed stale [bot] marked as stale due to inactivity labels Jan 19, 2024
xhochy pushed a commit that referenced this issue Jan 21, 2024
* Fix in SquashFSArchive._add #248

Can not create hard-link on Linux when source file is owned by root but
conda-pack runs as non-root user.

* Add news file for pr 306
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale::recovered [bot] recovered after being marked as stale type::bug describes erroneous operation, use severity::* to classify the type
Projects
Status: No status
Development

No branches or pull requests

1 participant