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

Cache directory resolving to root folder if HOME environment is not present #4871

Open
freef4ll opened this issue May 4, 2022 · 1 comment

Comments

@freef4ll
Copy link

freef4ll commented May 4, 2022

Expected behavior

The environmental variable $HOME not to be dependent on the cache directory location resolving, since non-cache settings are being resolved correctly.

Actual behavior

Package manager is not able to determine the cache directory to use and reverts to try to use /.cache, for which it it won't be able to have permissions to do so. For example strace shows the following system calls where the configuration directory is being resolved correctly:

1683338 13:06:58 openat(AT_FDCWD, "/tmp/_home_actions_.swiftpm.lock", O_WRONLY|O_CREAT|O_CLOEXEC, 0666) = 6
1683338 13:06:58 flock(6, LOCK_EX)      = 0
1683338 13:06:58 geteuid()              = 1000
1683338 13:06:58 getegid()              = 1000
1683338 13:06:58 openat(AT_FDCWD, "/etc/passwd", O_RDONLY|O_CLOEXEC) = 7
1683338 13:06:58 lseek(7, 0, SEEK_CUR)  = 0
1683338 13:06:58 fstat(7, {st_mode=S_IFREG|0644, st_size=969, ...}) = 0
1683338 13:06:58 read(7, "root:x:0:0:root:/root:/bin/bash\n"..., 4096) = 969
1683338 13:06:58 close(7)               = 0
1683338 13:06:58 lstat("/home/actions/.swiftpm/configuration", {st_mode=S_IFDIR|0755, st_size=6, ...}) = 0 <-- home directory being resolved correctly
1683338 13:06:58 openat(AT_FDCWD, "/etc/passwd", O_RDONLY|O_CLOEXEC) = 7
1683338 13:06:58 lseek(7, 0, SEEK_CUR)  = 0
1683338 13:06:58 fstat(7, {st_mode=S_IFREG|0644, st_size=969, ...}) = 0
1683338 13:06:58 read(7, "root:x:0:0:root:/root:/bin/bash\n"..., 4096) = 969
1683338 13:06:58 close(7)               = 0
1683338 13:06:58 openat(AT_FDCWD, "/etc/group", O_RDONLY|O_CLOEXEC) = 7
1683338 13:06:58 lseek(7, 0, SEEK_CUR)  = 0
1683338 13:06:58 fstat(7, {st_mode=S_IFREG|0644, st_size=473, ...}) = 0
1683338 13:06:58 read(7, "root:x:0:\ndaemon:x:1:\nbin:x:2:\ns"..., 4096) = 473
1683338 13:06:58 close(7)               = 0
1683338 13:06:58 flock(6, LOCK_UN)      = 0
1683338 13:06:58 close(6)               = 0
1683338 13:06:58 lstat("/home/actions/.swiftpm/configuration", {st_mode=S_IFDIR|0755, st_size=6, ...}) = 0
1683338 13:06:58 getpid()               = 339974
1683338 13:06:58 openat(AT_FDCWD, "/home/actions/.swiftpm/configuration/TemporaryFile.cyQtsq", O_RDWR|O_CREAT|O_EXCL, 0600) = 6
1683338 13:06:58 unlink("/home/actions/.swiftpm/configuration/TemporaryFile.cyQtsq") = 0
1683338 13:06:58 close(6)               = 0
1683338 13:06:58 lstat("/.cache/org.swift.swiftpm", 0x7ffe6f4be480) = -1 ENOENT (No such file or directory)
1683338 13:06:58 lstat("/.cache/org.swift.swiftpm", 0x7ffe6f4be460) = -1 ENOENT (No such file or directory)
1683338 13:06:58 lstat("/.cache/org.swift.swiftpm", 0x7ffe6f4be360) = -1 ENOENT (No such file or directory)
1683338 13:06:58 lstat("/.cache", 0x7ffe6f4be360) = -1 ENOENT (No such file or directory)
1683338 13:06:58 lstat("/.cache", 0x7ffe6f4be260) = -1 ENOENT (No such file or directory)
1683338 13:06:58 lstat("/", {st_mode=S_IFDIR|0755, st_size=29, ...}) = 0
1683338 13:06:58 mkdir("/.cache", 0777) = -1 EACCES (Permission denied) <--- no permission to write to root 
1683338 13:06:58 futex(0x7f74a2bc89b0, FUTEX_WAKE_PRIVATE, 2147483647) = 0
1683338 13:06:58 futex(0x7f74a24163b0, FUTEX_WAKE_PRIVATE, 2147483647) = 0
1683338 13:06:58 futex(0x7f74a2311a84, FUTEX_WAKE_PRIVATE, 2147483647) = 0
1683338 13:06:58 futex(0x7f74a242d420, FUTEX_WAKE_PRIVATE, 2147483647) = 0
1683338 13:06:58 futex(0x555bde4b5be0, FUTEX_WAKE_PRIVATE, 2147483647) = 0
1683338 13:06:58 ioctl(2, TCGETS, 0x7ffe6f4be3b0) = -1 ENOTTY (Inappropriate ioctl for device)
1683338 13:06:58 futex(0x555bde438680, FUTEX_WAKE_PRIVATE, 2147483647) = 0
1683338 13:06:58 futex(0x7f74a2bc8fb8, FUTEX_WAKE_PRIVATE, 2147483647) = 0
1683338 13:06:58 write(2, "warning: ", 9) = 9
1683338 13:06:58 write(2, "Failed creating default cache lo"..., 111) = 111

Steps to reproduce

Simplest way to reproduce would be to allow the /nonexistent home directory to be present and writable for user nobody via a docker container; (or in a working non-root user Linux environment just unset HOME) :

docker run -ti --user nobody -v /var/tmp:/nonexistent  swift:5.6-focal  /bin/bash

# In the container 
git -C /tmp  clone https://github.com/apple/swift-nio-examples.git
cd /tmp/swift-nio-examples/json-rpc/

unset HOME
swift package test
warning: Failed creating default cache location, Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission."
[...]

The same is happening in 5.7 nightly if executed under swiftlang/swift:nightly-focal instead of swift:5.6-focal, but here the warning is better:

warning: /.cache/org.swift.swiftpm is not accessible or not writable, disabling user-level cache features.

$ swift --version
Swift version 5.7-dev (LLVM cd62c186b914a47, Swift c58d4dba34ef37a)
Target: x86_64-unknown-linux-gnu

The background for this is that Github Runner setup scripts can unset all environment flags, and then the cache can run into this (actions/runner#1864)

Swift Package Manager version/commit hash

$ swift --version
Swift version 5.6.1 (swift-5.6.1-RELEASE)
Target: x86_64-unknown-linux-gnu

[the Swift Package Manager tag/commit hash]

Swift & OS version

$ swift --version && uname -a
Swift version 5.7-dev (LLVM cd62c186b914a47, Swift c58d4dba34ef37a)
Target: x86_64-unknown-linux-gnu
Linux 80f85cd927fb 5.4.0-109-generic #123-Ubuntu SMP Fri Apr 8 09:10:54 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
@tomerd
Copy link
Contributor

tomerd commented May 5, 2022

thanks for reporting @freef4ll iiuc SwiftPM disables the shared cache in this case, but otherwise operational. Is that correct?

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

2 participants