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

configure /tmp/.zef directory for root / none root users #563

Closed
melezhik opened this issue Jul 11, 2024 · 7 comments · Fixed by #564
Closed

configure /tmp/.zef directory for root / none root users #563

melezhik opened this issue Jul 11, 2024 · 7 comments · Fixed by #564

Comments

@melezhik
Copy link

melezhik commented Jul 11, 2024

Context

sudo zef install SomeModule --force
# note - now without sudo
zef install SomeModule --force

Expected Behavior

both command should succeed

Actual Behavior

the second command fails with error

[task run: task.bash - bash: zef install Term::TablePrint]
[task stdout]
17:19:17 :: ===> Searching for: Term::TablePrint
[task stderr]
17:19:20 :: failed to create directory: /tmp/.zef/1720707556.113470/1720707560.113470.5062.5381259584265
17:19:20 :: task exit status: 1

The reason is zef is trying do to something with files located at /tmp/.zef/ directory which was created with root user during first run:

$ stat /tmp/.zef/
  File: /tmp/.zef/
  Size: 4096      	Blocks: 8          IO Block: 4096   directory
Device: 8,17	Inode: 280422      Links: 3
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2024-07-11 17:20:37.803299584 +0300
Modify: 2024-07-11 17:18:48.158533802 +0300
Change: 2024-07-11 17:18:48.158533802 +0300
 Birth: 2024-07-11 17:18:48.158533802 +0300

Your Environment

$ eval $(/opt/sparrowdo/rakudo/rakudo-moar-2024.06-01-linux-x86_64-gcc/scripts/set-env.sh --quiet)

$ raku -v
Welcome to Rakudo™ v2024.06.
Implementing the Raku® Programming Language v6.d.
Built on MoarVM version 2024.06.

Debian12

@ugexe
Copy link
Owner

ugexe commented Jul 11, 2024

fwiw you can work around this by setting ZEF_CONFIG_TEMPDIR or changing the appropriate field in the config file

@melezhik
Copy link
Author

melezhik commented Jul 11, 2024 via email

@ugexe
Copy link
Owner

ugexe commented Jul 11, 2024

Potentially. But it is just using $*TMPDIR from core raku. I wonder if raku should consider writable permissions when it picks the value for that dynamic variable

@niner
Copy link
Collaborator

niner commented Jul 12, 2024

The problem is not $*TMPDIR itself but using a fixed subdirectory of that. That's bad practice also from a security standpoint. Predictable temp file names can be exploited via symlinks.

I suggest using something like `$*TMPDIR ~ flat('a'..'z', 'A'..'Z', 0..9, '_').roll(8).join ~ '.zef' instead

@melezhik
Copy link
Author

The problem is not $*TMPDIR itself but using a fixed subdirectory of that. That's bad practice also from a security standpoint. Predictable temp file names can be exploited via symlinks.

I suggest using something like `$*TMPDIR ~ flat('a'..'z', 'A'..'Z', 0..9, '_').roll(8).join ~ '.zef' instead

Still does not guarantee collisions?

@niner
Copy link
Collaborator

niner commented Jul 12, 2024

There would be a 1 in 248,155,780,267,521 chance of a collision. In other words it just won't happen. But if you are afraid, just make that prefix longer.

@ugexe
Copy link
Owner

ugexe commented Jul 20, 2024

For now I'll be changing the TempDir configuration entry from $*TMPDIR/.zef/{time}.{$*PID} to $*TMPDIR/.zef.{time}.{$*PID}. That is still a somewhat predictable-ish path, but I think it is a good enough solution for the time being.

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

Successfully merging a pull request may close this issue.

3 participants