-
Notifications
You must be signed in to change notification settings - Fork 48
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
Layers with symlinks differ depending on OS #23
Comments
@YorikSar Thx for this nice bug report! I never used Darwin and i don't know what could differ regarding symlinks... If you set It would be really useful if you could provide such diff on a simple image (containing a symlink) built on Linux and Darwin! |
I've ran this script on both systems: package main
import (
"io"
"log"
"os"
"github.com/nlewo/nix2container/nix"
"github.com/nlewo/nix2container/types"
)
func main() {
path := types.Path{
Path: "data/tar-directory",
}
t := nix.TarPaths(types.Paths{path})
out, err := os.Create("out.tar")
if err != nil {
log.Fatal(err)
}
_, err = io.Copy(out, t)
if err != nil {
log.Fatal(err)
}
} Results are (ran through Diff of --- darwin.txt 2022-06-07 12:09:58.000000000 +0400
+++ linux.txt 2022-06-07 12:10:05.000000000 +0400
@@ -74,18 +74,18 @@
0003020 72 79 2f 73 79 6d 6c 69 6e 6b 00 00 00 00 00 00
r y / s y m l i n k nul nul nul nul nul nul
0003040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul
*
-0003140 00 00 00 00 30 30 30 30 37 35 35 00 30 30 30 30
- nul nul nul nul 0 0 0 0 7 5 5 nul 0 0 0 0
+0003140 00 00 00 00 30 30 30 30 37 37 37 00 30 30 30 30
+ nul nul nul nul 0 0 0 0 7 7 7 nul 0 0 0 0
0003160 30 30 30 00 30 30 30 30 30 30 30 00 30 30 30 30
0 0 0 nul 0 0 0 0 0 0 0 nul 0 0 0 0
0003200 30 30 30 30 30 30 30 00 30 30 30 30 30 30 30 30
0 0 0 0 0 0 0 nul 0 0 0 0 0 0 0 0
-0003220 30 30 30 00 30 31 37 30 34 33 00 20 32 66 69 6c
- 0 0 0 nul 0 1 7 0 4 3 nul sp 2 f i l
+0003220 30 30 30 00 30 31 37 30 34 37 00 20 32 66 69 6c
+ 0 0 0 nul 0 1 7 0 4 7 nul sp 2 f i l
0003240 65 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e 1 nul nul nul nul nul nul nul nul nul nul nul nul nul nul
0003260 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul
* The first one (
Note that this store path was built on this Linux machine and then fetched to the Darwin one. Bug to Nix is coming 🚂
|
Digging a bit deeper, I found that the NAR format is only described in Eelco's thesis and it includes following wording (on page 90 of the thesis, 98 of the PDF):
He then proceeds with describing NAR format that indeed ignores all permissions except the executable flag on regular files. Since NAR format is used to transfer store paths between machines, we can expect to have such discrepancies in the OS-dependant things like symlinks (and they are, very much, OS-dependant, as it appears). I guess since it's impossible to change symlink permissions on Linux, and Docker always (*) runs on Linux, and Nix doesn't care about permissions anyway, we should be forcing symlink permissions to 777 in layers. (*) Docker can natively run containers on Linux and Windows, and I know of effort to bring it to FreeBSD. FreeBSD is officially not supported by Docker, and efforts to run Docker on it without emulation didn't get anywhere (yet?). Windows is not supported by Nix (yet?), and doesn't really have Unix permissions. I don't know of other container runtimes that can run outside Linux. |
Created a PR with a fix for this. |
I've noticed that when I run patched skopeo on Linux, it succeeds, but when I run it with the same JSON on Darwin, I get
And the layer in question is a
.so
library that has symlinks in it.It looks like nix2containers produces different hashes on different OSs if the layer contains symlinks. To check this theory, I've added a symlink to test data and ran in on two different systems, I got on Darwin:
And on Linux:
Note that the digests are different in both cases, even though they should match. Without this symlink, test passes, so the digests are the same.
Note that this prevents me from using nix2container on macOS with Linux builder.
The text was updated successfully, but these errors were encountered: